//
// sub_C0FD64 from 0xc0fd64 to 0xc10058 (756 bytes)
//
// 2 xrefs:
// > sub_C12350 @ 0xc12538
// > sub_C12730 @ 0xc12c00
//
// 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_C0FD64(__int64 *a1, _BYTE *a2, unsigned int a3, __int64 a4)
{
__int64 v4; // x3
__int64 v7; // x2
__int64 result; // x0
int v9; // w1
int v10; // w0
__int64 v11; // x2
char v12; // w1
__int64 v13; // x2
__int64 v14; // x2
int v15; // w5
int v16; // w4
void (__fastcall *v17)(__int64 *, __int64); // x4
unsigned int v18; // w2
__int64 v19; // x3
__int64 v20; // x3
__int64 v21; // x20
__int64 v22; // x2
__int64 v23; // [xsp+28h] [xbp+28h]
__int64 v24; // [xsp+28h] [xbp+28h]
v4 = a4 + a3;
if ( a3 <= 0xD )
{
if ( a3 <= 5 || *a2 != 74 || a2[1] != 70 )
goto LABEL_3;
v9 = (unsigned __int8)a2[2];
LABEL_11:
if ( v9 == 88 && a2[3] == 88 && !a2[4] )
{
v10 = (unsigned __int8)a2[5];
v11 = *a1;
if ( v10 == 17 )
{
*(_DWORD *)(v11 + 44) = v4;
*(_DWORD *)(v11 + 40) = 111;
return (*(__int64 (__fastcall **)(__int64 *, __int64))(*a1 + 8))(a1, 1);
}
else if ( v10 == 19 )
{
*(_DWORD *)(v11 + 44) = v4;
*(_DWORD *)(v11 + 40) = 112;
return (*(__int64 (__fastcall **)(__int64 *, __int64))(*a1 + 8))(a1, 1);
}
else
{
if ( v10 == 16 )
{
*(_DWORD *)(v11 + 44) = v4;
*(_DWORD *)(v11 + 40) = 110;
}
else
{
*(_DWORD *)(v11 + 40) = 91;
*(_DWORD *)(v11 + 44) = (unsigned __int8)a2[5];
*(_DWORD *)(*a1 + 48) = v4;
}
return (*(__int64 (__fastcall **)(__int64 *, __int64))(*a1 + 8))(a1, 1);
}
}
LABEL_3:
v7 = *a1;
*(_DWORD *)(v7 + 44) = v4;
*(_DWORD *)(v7 + 40) = 79;
return (*(__int64 (__fastcall **)(__int64 *, __int64))(*a1 + 8))(a1, 1);
}
if ( *a2 != 74 || a2[1] != 70 )
goto LABEL_3;
v9 = (unsigned __int8)a2[2];
if ( v9 != 73 )
goto LABEL_11;
if ( a2[3] != 70 || a2[4] )
goto LABEL_3;
*((_DWORD *)a1 + 94) = 1;
v12 = a2[5];
*((_BYTE *)a1 + 380) = v12;
*((_BYTE *)a1 + 381) = a2[6];
*((_BYTE *)a1 + 382) = a2[7];
*((_WORD *)a1 + 192) = ((unsigned __int8)a2[8] << 8) + (unsigned __int8)a2[9];
*((_WORD *)a1 + 193) = ((unsigned __int8)a2[10] << 8) + (unsigned __int8)a2[11];
if ( (unsigned __int8)(v12 - 1) > 1u )
{
v13 = *a1;
v23 = v4;
*(_DWORD *)(v13 + 40) = 122;
*(_DWORD *)(v13 + 44) = *((unsigned __int8 *)a1 + 380);
*(_DWORD *)(*a1 + 48) = *((unsigned __int8 *)a1 + 381);
(*(void (__fastcall **)(__int64 *, __int64))(*a1 + 8))(a1, 0xFFFFFFFFLL);
v4 = v23;
}
v14 = *a1;
v15 = *((unsigned __int16 *)a1 + 192);
*(_DWORD *)(v14 + 44) = *((unsigned __int8 *)a1 + 380);
v16 = *((unsigned __int16 *)a1 + 193);
*(_DWORD *)(v14 + 48) = *((unsigned __int8 *)a1 + 381);
*(_DWORD *)(v14 + 56) = v16;
*(_DWORD *)(v14 + 52) = v15;
v17 = *(void (__fastcall **)(__int64 *, __int64))(v14 + 8);
*(_DWORD *)(v14 + 60) = *((unsigned __int8 *)a1 + 382);
*(_DWORD *)(v14 + 40) = 89;
v24 = v4;
v17(a1, 1);
v18 = 0;
v19 = v24;
result = (unsigned __int8)(a2[13] | a2[12]);
if ( *((_WORD *)a2 + 6) )
{
v22 = *a1;
*(_DWORD *)(v22 + 40) = 92;
*(_DWORD *)(v22 + 44) = (unsigned __int8)a2[12];
*(_DWORD *)(*a1 + 48) = (unsigned __int8)a2[13];
(*(void (__fastcall **)(__int64 *, __int64))(*a1 + 8))(a1, 1);
result = (unsigned __int8)a2[12];
v18 = (unsigned __int8)a2[13];
v19 = v24;
}
v20 = v19 - 14;
if ( 3 * (unsigned int)result * (unsigned __int64)v18 != v20 )
{
v21 = *a1;
*(_DWORD *)(v21 + 44) = v20;
*(_DWORD *)(v21 + 40) = 90;
return (*(__int64 (__fastcall **)(__int64 *, __int64))(*a1 + 8))(a1, 1);
}
return result;
}