//
// sub_CF9F68 from 0xcf9f68 to 0xcfa100 (408 bytes)
//
// 4 xrefs:
// > sub_B417A4 @ 0xb4180c
// > sub_CD1954 @ 0xcd199c
// > sub_CEE250 @ 0xcee29c
// > sub_CF9A94 @ 0xcf9aa0
//
// 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_CF9F68(_QWORD *a1, _QWORD *a2, _BYTE *a3)
{
unsigned __int64 v5; // x19
unsigned __int8 *v6; // x1
unsigned __int8 v8; // w2
__int64 v9; // x19
__int64 v10; // x21
__int64 v11; // x0
int v12; // w0
unsigned __int64 v13; // x19
__int64 i; // x1
unsigned __int8 *v15; // x0
unsigned __int64 v16; // x0
unsigned __int8 *v17; // x0
int v19; // w0
v5 = a1[3];
v6 = (unsigned __int8 *)a1[2];
*a3 = 1;
if ( (unsigned __int64)v6 < v5 )
{
v8 = *v6;
LABEL_3:
v9 = v5 - (_QWORD)v6;
v10 = 0;
if ( v9 <= 1 )
goto LABEL_8;
while ( 1 )
{
v11 = (*(__int64 (__fastcall **)(_QWORD *))(*a2 + 96LL))(a2);
v10 += v11;
a1[2] += v11;
if ( v9 > v11 )
break;
LABEL_5:
v12 = (*(__int64 (__fastcall **)(_QWORD *))(*a1 + 72LL))(a1);
v8 = v12;
if ( v12 == -1 )
return v10;
v13 = a1[3];
for ( i = a1[2]; ; i = a1[2] )
{
v9 = v13 - i;
if ( v9 > 1 )
break;
LABEL_8:
v15 = (unsigned __int8 *)a2[5];
if ( (unsigned __int64)v15 >= a2[6] )
{
if ( (*(unsigned int (__fastcall **)(_QWORD *, _QWORD))(*a2 + 104LL))(a2, v8) == -1 )
goto LABEL_17;
}
else
{
*v15 = v8;
++a2[5];
}
v16 = a1[2];
++v10;
v13 = a1[3];
if ( v16 >= v13 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD *))(*a1 + 80LL))(a1) == -1 )
return v10;
v17 = (unsigned __int8 *)a1[2];
v13 = a1[3];
}
else
{
v17 = (unsigned __int8 *)(v16 + 1);
a1[2] = v17;
}
if ( (unsigned __int64)v17 >= v13 )
goto LABEL_5;
v8 = *v17;
}
}
LABEL_17:
*a3 = 0;
return v10;
}
v19 = (*(__int64 (__fastcall **)(_QWORD *))(*a1 + 72LL))(a1);
v8 = v19;
if ( v19 != -1 )
{
v6 = (unsigned __int8 *)a1[2];
v5 = a1[3];
goto LABEL_3;
}
return 0;
}