//
// sub_18003DA00 from 0x18003da00 to 0x18003db14 (276 bytes)
//
// 2 xrefs:
// > sub_18003FD60 @ 0x180040961
// > sub_180040CB0 @ 0x18004175b
//
// 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_18003DA00(__int64 a1, _BYTE *a2)
{
__int64 v2; // r8
__int64 v4; // r9
int v5; // ecx
int v6; // eax
int v7; // eax
int v8; // edx
int v9; // r11d
int v10; // ecx
int v11; // ecx
int v12; // eax
v2 = *(_QWORD *)(a1 + 8);
v4 = *(int *)(v2 + 180);
if ( a2[1287] )
{
if ( a2[1287] == 1 )
{
v7 = 64;
if ( (int)v4 >= 128 )
v7 = -64;
v5 = v7;
}
else
{
if ( a2[1287] == 2 )
{
v6 = ((int)v4 + 128) % 256;
}
else
{
if ( a2[1287] != 3 )
{
v5 = 0;
goto LABEL_14;
}
v6 = (384 - v4) & 0x800000FF;
if ( 384 - (int)v4 < 0 )
{
v5 = (int)(128 - (((0x80 - (_BYTE)v4 - 1) | 0xFFFFFF00) + 1)) >> 1;
goto LABEL_14;
}
}
v5 = (128 - v6) >> 1;
}
}
else
{
v5 = byte_1801AEF00[v4];
}
LABEL_14:
v8 = (unsigned __int8)a2[1288];
v9 = *(_DWORD *)(v2 + 184);
v10 = (unsigned __int8)a2[1289] * v5;
if ( (_BYTE)v8 )
v10 = v10 * v9 / v8;
*(_DWORD *)(v2 + 80) += v10 >> 6;
v11 = v9 + 1;
*(_DWORD *)(v2 + 184) = v9 + 1;
if ( v9 + 1 > (unsigned __int8)a2[1288] )
v11 = (unsigned __int8)a2[1288];
*(_DWORD *)(v2 + 184) = v11;
v12 = v4 + (unsigned __int8)a2[1290];
*(_DWORD *)(v2 + 180) = v12;
if ( v12 > 255 )
*(_DWORD *)(v2 + 180) = v12 - 256;
*(_BYTE *)(v2 + 60) |= 1u;
return 0;
}