//
// sub_1800BD1E0 from 0x1800bd1e0 to 0x1800bd5c3 (995 bytes)
//
// 3 xrefs:
// > sub_1800BCE10 @ 0x1800bcfdc
// > sub_1800BD5D0 @ 0x1800bd60b
// > ??> @ 0x1801fd74c
//
// 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
//
__int64 __fastcall sub_1800BD1E0(__int64 a1, __int64 a2, float *a3, unsigned int a4)
{
bool v4; // zf
unsigned int v5; // r15d
float *v6; // r12
float *v7; // r13
__int64 v9; // r11
__int64 v10; // rbx
unsigned int v11; // esi
int v12; // edx
int v13; // r9d
unsigned __int64 v14; // r8
unsigned int v15; // r14d
__int64 v16; // rax
__int64 v17; // r8
int v18; // edx
int v19; // edx
int v20; // edx
unsigned __int64 v21; // rcx
__int64 v22; // rax
__int64 result; // rax
unsigned int v24; // r8d
unsigned int v25; // r9d
unsigned int v26; // r10d
unsigned __int64 v27; // rcx
float *v28; // r10
unsigned int v29; // ecx
float *v30; // rcx
unsigned int v31; // eax
unsigned int v32; // eax
__int64 v33; // rbx
float *v34; // r10
unsigned int v35; // ebx
__int64 (__fastcall *v36)(__int64, __int64, float *, float *, unsigned int, unsigned int); // rax
__int64 v37; // rcx
__int64 v38; // rcx
float *v39; // [rsp+50h] [rbp-19h] BYREF
float *v40; // [rsp+58h] [rbp-11h] BYREF
__int64 v41; // [rsp+60h] [rbp-9h]
unsigned int v43; // [rsp+D8h] [rbp+6Fh] BYREF
float *v44; // [rsp+E0h] [rbp+77h]
unsigned int v45; // [rsp+E8h] [rbp+7Fh] BYREF
v4 = *(_QWORD *)(a2 + 80) == 0;
v5 = a4;
v6 = *(float **)(a2 + 88);
v7 = a3;
v44 = v6;
v9 = a1;
if ( v4 )
v44 = a3;
if ( a4 )
{
v10 = a1 + 8;
v11 = 0;
if ( !a1 )
v10 = 0;
v41 = v10;
while ( 1 )
{
v12 = *(_DWORD *)(a2 + 24);
v13 = *(_DWORD *)(a2 + 32);
v14 = *(unsigned int *)(a2 + 20);
if ( v12 == 1 )
{
v15 = 8;
LABEL_23:
v16 = 8;
goto LABEL_24;
}
if ( *(_DWORD *)(a2 + 24) == 2 )
break;
if ( *(_DWORD *)(a2 + 24) == 3 )
{
v15 = 24;
LABEL_19:
v16 = 24;
goto LABEL_24;
}
if ( (unsigned int)(*(_DWORD *)(a2 + 24) - 4) < 2 )
{
v15 = 32;
LABEL_17:
v16 = 32;
LABEL_24:
v14 = (v16 * v14) >> 3;
goto LABEL_25;
}
v15 = 0;
switch ( v12 )
{
case 1:
goto LABEL_23;
case 2:
goto LABEL_21;
case 3:
goto LABEL_19;
}
if ( (unsigned int)(v12 - 4) < 2 )
goto LABEL_17;
LABEL_25:
v17 = (unsigned int)(*(_DWORD *)(a2 + 32) * v14);
v18 = v12 - 1;
if ( v18 )
{
v19 = v18 - 1;
if ( v19 )
{
v20 = v19 - 1;
if ( v20 )
{
if ( (unsigned int)(v20 - 1) >= 2 )
{
LODWORD(v21) = v5;
goto LABEL_35;
}
v22 = 32;
}
else
{
v22 = 24;
}
}
else
{
v22 = 16;
}
}
else
{
v22 = 8;
}
v21 = (v22 * (unsigned __int64)v5) >> 3;
LABEL_35:
v40 = nullptr;
v39 = nullptr;
v45 = 0;
v43 = 0;
result = (*(__int64 (__fastcall **)(__int64, __int64, __int64, _QWORD, float **, float **, unsigned int *, unsigned int *))(v9 + 1024))(
v10,
a2,
v17,
(unsigned int)(v21 * v13),
&v40,
&v39,
&v45,
&v43);
if ( (_DWORD)result )
return result;
v24 = v43;
v25 = v45;
v26 = *(_DWORD *)(a2 + 32);
if ( v26 )
{
switch ( *(_DWORD *)(a2 + 24) )
{
case 1:
v27 = 8;
break;
case 2:
v27 = 16;
break;
case 3:
v27 = 24;
break;
default:
if ( (unsigned int)(*(_DWORD *)(a2 + 24) - 4) >= 2 )
{
v11 = v43 + v45;
goto LABEL_47;
}
v27 = 32;
break;
}
v11 = (unsigned int)(8 * (unsigned __int64)(v43 + v45) / v27) / v26;
}
LABEL_47:
if ( *(_DWORD *)(a2 + 24) != 1 )
goto LABEL_58;
v28 = v40;
if ( v40 && v45 )
{
v29 = 0;
do
{
*(_BYTE *)v28 ^= 0x80u;
v28 = (float *)((char *)v28 + 1);
v25 = v45;
++v29;
}
while ( v29 < v45 );
v24 = v43;
}
v30 = v39;
if ( v39 && v24 )
{
v31 = 0;
do
{
*(_BYTE *)v30 ^= 0x80u;
v30 = (float *)((char *)v30 + 1);
v24 = v43;
++v31;
}
while ( v31 < v43 );
v25 = v45;
LABEL_58:
v30 = v39;
}
if ( v40 && v25 )
{
v32 = 8 * v25 / v15;
v33 = v32;
sub_180062BA0(v44, v40, 5, *(_DWORD *)(a2 + 24), v32, 1u, 1, 1.0, 1);
v30 = v39;
v25 = v45;
v24 = v43;
v34 = &v44[v33];
v44 = v34;
}
else
{
v34 = v44;
}
if ( v30 && v24 )
{
v35 = 8 * v24 / v15;
sub_180062BA0(v34, v30, 5, *(_DWORD *)(a2 + 24), v35, 1u, 1, 1.0, 1);
v30 = v39;
v25 = v45;
v24 = v43;
v44 += v35;
}
v10 = v41;
v36 = *(__int64 (__fastcall **)(__int64, __int64, float *, float *, unsigned int, unsigned int))(a1 + 1032);
if ( v36 )
{
result = v36(v41, a2, v40, v30, v25, v24);
if ( (_DWORD)result )
return result;
}
v37 = *(_QWORD *)(a2 + 80);
if ( v37 )
{
result = (*(__int64 (__fastcall **)(__int64, float *, float *, _QWORD))(*(_QWORD *)v37 + 16LL))(
v37,
v6,
v7,
v11);
if ( (_DWORD)result )
return result;
v38 = *(_QWORD *)(a2 + 80);
v6 += *(_DWORD *)(v38 + 8) * v11;
v7 += *(_DWORD *)(v38 + 12) * v11;
}
*(_DWORD *)(a2 + 20) = (v11 + *(_DWORD *)(a2 + 20)) % *(_DWORD *)(a2 + 36);
v5 -= v11;
if ( !v5 )
return 0;
v9 = a1;
v11 = 0;
}
v15 = 16;
LABEL_21:
v16 = 16;
goto LABEL_24;
}
return 0;
}