//
// sub_CD1D38 from 0xcd1d38 to 0xcd1f48 (528 bytes)
//
// 2 xrefs:
// > sub_CD1F48 @ 0xcd1f94
// > sub_CD1F48 @ 0xcd1fd4
//
// 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
//
unsigned __int64 *__fastcall sub_CD1D38(unsigned __int64 *a1, _BYTE *a2, __int64 a3, unsigned __int8 a4)
{
int v7; // w22
_QWORD *v8; // x20
unsigned __int8 *v9; // x0
int v10; // w0
unsigned __int64 v11; // x0
unsigned __int64 v12; // x2
int v13; // w1
bool v15; // zf
char v16; // [xsp+58h] [xbp+58h] BYREF
a1[1] = 0;
v7 = a4;
sub_CD14C0(&v16, a1, 1);
if ( v16 )
{
v8 = *(_QWORD **)((char *)a1 + *(_QWORD *)(*a1 - 24) + 232);
v9 = (unsigned __int8 *)v8[2];
if ( (unsigned __int64)v9 >= v8[3] )
goto LABEL_9;
LABEL_3:
v10 = *v9;
while ( v10 != -1 && v10 != v7 )
{
if ( (__int64)(a1[1] + 1) >= a3 )
break;
*a2++ = v10;
v11 = v8[2];
v12 = v8[3];
++a1[1];
if ( v11 >= v12 )
{
v15 = (*(unsigned int (__fastcall **)(_QWORD *))(*v8 + 80LL))(v8) == -1;
v10 = -1;
if ( v15 )
continue;
v9 = (unsigned __int8 *)v8[2];
v12 = v8[3];
}
else
{
v9 = (unsigned __int8 *)(v11 + 1);
v8[2] = v9;
}
if ( (unsigned __int64)v9 < v12 )
goto LABEL_3;
LABEL_9:
v10 = (*(__int64 (__fastcall **)(_QWORD *))(*v8 + 72LL))(v8);
}
if ( v10 == -1 )
v13 = 2;
else
v13 = 0;
}
else
{
v13 = 0;
}
if ( a3 > 0 )
*a2 = 0;
if ( !a1[1] )
{
v13 |= 4u;
LABEL_17:
sub_CCE830((__int64)a1 + *(_QWORD *)(*a1 - 24), v13 | *(_DWORD *)((char *)a1 + *(_QWORD *)(*a1 - 24) + 32));
return a1;
}
if ( v13 )
goto LABEL_17;
return a1;
}