//
// tk::spline::solve from 0x596790 to 0x596a9e (782 bytes)
//
// 0 xrefs:
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
tk::spline *__fastcall tk::spline::solve(tk::spline *this, int a2, double a3, bool a4)
{
int v7; // r2
int v8; // r9
unsigned int j; // r7
void *v10; // r2
int v11; // r3
unsigned int i; // r6
double v13; // d6
unsigned int v14; // r8
void *v15; // r2
int v16; // r3
double v17; // r0
double v18; // d9
double v19; // d6
double *v20; // r2
double *v21; // r3
double v22; // d8
int v24; // r6
void *v25; // r2
int v26; // r3
unsigned int k; // r7
double v28; // d6
unsigned int v29; // r0
unsigned int v30; // r11
char *v31; // r10
const void *v32; // r1
signed int v33; // r3
char *v34; // r3
int v35; // [sp+24h] [bp-50h]
signed int v36; // [sp+34h] [bp-40h]
char *v37; // [sp+34h] [bp-40h]
double *v38; // [sp+3Ch] [bp-38h] BYREF
int v39; // [sp+40h] [bp-34h]
int v40; // [sp+44h] [bp-30h]
void *v41[3]; // [sp+48h] [bp-2Ch] BYREF
void *v42[3]; // [sp+54h] [bp-20h] BYREF
double v43; // [sp+60h] [bp-14h] BYREF
int v44; // [sp+6Ch] [bp-8h]
*((_DWORD *)this + 1) = 0;
*((_DWORD *)this + 2) = 0;
v38 = nullptr;
v39 = 0;
v40 = 0;
v7 = _stack_chk_guard;
*(_DWORD *)this = 0;
v44 = v7;
v35 = (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 3;
if ( !a4 )
{
internal::solve_cubic(
(internal *)v41,
*(double *)*(_DWORD *)(a2 + 12) - a3,
*(double *)*(_DWORD *)(a2 + 24),
*(double *)(a2 + 64),
0.0,
1);
sub_594C68((void **)&v38, v41, v10, v11);
std::_Vector_base::~_Vector_base(v41);
for ( i = 0; i < (v39 - (int)v38) >> 3; ++i )
{
v13 = v38[i];
if ( v13 < 0.0 )
{
v43 = *(double *)*(_DWORD *)a2 + v13;
std::vector::emplace_back((const void **)this, (__int64 *)&v43);
}
}
}
v8 = 8;
for ( j = 0; j < v35 - 1; ++j )
{
internal::solve_cubic(
(internal *)v42,
*(double *)(*(_DWORD *)(a2 + 12) + 8 * j) - a3,
*(double *)(*(_DWORD *)(a2 + 24) + 8 * j),
*(double *)(*(_DWORD *)(a2 + 36) + 8 * j),
*(double *)(*(_DWORD *)(a2 + 48) + 8 * j),
1);
v14 = 0;
sub_594C68((void **)&v38, v42, v15, v16);
LODWORD(v17) = std::_Vector_base::~_Vector_base(v42);
while ( v14 < (v39 - (int)v38) >> 3 )
{
v18 = COERCE_DOUBLE(internal::get_eps((internal *)LODWORD(v17))) * 512.0;
LODWORD(v17) = fmin();
v19 = v38[v14];
if ( -(v18 * v17) <= v19 )
{
v20 = (double *)(*(_DWORD *)a2 + 8 * j);
if ( v19 < *(double *)(*(_DWORD *)a2 + v8) - *v20 )
{
v21 = *((double **)this + 1);
v22 = *v20 + v19;
if ( ((unsigned int)v21 - *(_DWORD *)this) >> 3 && v18 * v17 + *(v21 - 1) > v22 )
{
*(v21 - 1) = v22;
}
else if ( v21 == *((double **)this + 2) )
{
v29 = std::vector::_M_check_len(this, 1u, (int)"vector::_M_emplace_back_aux");
v30 = v29;
if ( v29 )
v31 = (char *)sub_594790(v29);
else
v31 = nullptr;
v32 = *(const void **)this;
v33 = *((_DWORD *)this + 1) - *(_DWORD *)this;
if ( &v31[v33] )
*(double *)&v31[v33] = v22;
if ( v33 >> 3 )
{
v36 = v33;
memmove(v31, v32, v33);
v33 = v36;
}
LODWORD(v17) = *(_DWORD *)this;
v34 = &v31[v33 + 8];
if ( *(_DWORD *)this )
{
v37 = v34;
operator delete((void *)LODWORD(v17));
v34 = v37;
}
*((_DWORD *)this + 1) = v34;
*(_DWORD *)this = v31;
*((_DWORD *)this + 2) = &v31[8 * v30];
}
else
{
if ( v21 )
*v21 = v22;
*((_DWORD *)this + 1) = v21 + 1;
}
}
}
++v14;
}
v8 += 8;
}
if ( !a4 )
{
v24 = 8 * (v35 - 1);
internal::solve_cubic(
(internal *)&v43,
*(double *)(*(_DWORD *)(a2 + 12) + v24) - a3,
*(double *)(*(_DWORD *)(a2 + 24) + v24),
*(double *)(*(_DWORD *)(a2 + 36) + v24),
0.0,
1);
sub_594C68((void **)&v38, (void **)&v43, v25, v26);
std::_Vector_base::~_Vector_base((void **)&v43);
for ( k = 0; k < (v39 - (int)v38) >> 3; ++k )
{
v28 = v38[k];
if ( v28 >= 0.0 )
{
v43 = *(double *)(*(_DWORD *)a2 + v24) + v28;
std::vector::emplace_back((const void **)this, (__int64 *)&v43);
}
}
}
std::_Vector_base::~_Vector_base((void **)&v38);
return this;
}