//
// sub_CB6640 from 0xcb6640 to 0xcb67b0 (368 bytes)
//
// 4 xrefs:
// > sub_CB6D54 @ 0xcb6ddc
// > sub_CB6D54 @ 0xcb6fd4
// > sub_CB6D54 @ 0xcb7074
// > sub_CB7190 @ 0xcb7314
//
// 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_CB6640(__int64 result)
{
int v1; // w3
int v2; // w1
unsigned __int64 v3; // x23
__int64 v4; // x19
unsigned __int64 v5; // x22
__int64 v6; // x20
unsigned __int64 v7; // x21
unsigned __int64 v8; // x22
void *v9; // x0
__int64 v10; // x21
size_t v11; // x2
__int64 v12; // x1
int v13; // w0
bool v14; // cc
v1 = *(_DWORD *)(result + 12);
v2 = *(_DWORD *)(result + 4);
v3 = (unsigned int)(v2 >> (v1 + 8));
*(_DWORD *)(result + 12) = v1 - 8;
*(_DWORD *)(result + 4) = v2 - ((_DWORD)v3 << (v1 + 8));
if ( (unsigned __int8)(v2 >> (v1 + 8)) == 255 )
{
++*(_DWORD *)(result + 8);
return result;
}
v4 = result;
v5 = *(_QWORD *)(result + 32);
v6 = *(_QWORD *)(result + 24);
v7 = v6 + *(_DWORD *)(result + 8) + 1;
if ( v7 <= v5 )
{
result = *(_QWORD *)(result + 16);
}
else
{
v8 = 2 * v5;
if ( v7 >= v8 )
v8 = v6 + *(_DWORD *)(result + 8) + 1;
if ( v8 <= 0x3FF )
v8 = 1024;
v9 = (void *)WebPSafeMalloc(1, v8);
v10 = (__int64)v9;
if ( !v9 )
{
*(_DWORD *)(v4 + 40) = 1;
return 1;
}
v11 = *(_QWORD *)(v4 + 24);
if ( v11 )
memcpy(v9, *(const void **)(v4 + 16), v11);
WebPSafeFree(*(void **)(v4 + 16));
*(_QWORD *)(v4 + 16) = v10;
*(_QWORD *)(v4 + 32) = v8;
result = v10;
}
if ( ((v3 >> 8) & 1) != 0 && v6 )
{
++*(_BYTE *)(result + v6 - 1);
result = *(_QWORD *)(v4 + 16);
}
if ( *(int *)(v4 + 8) <= 0 )
{
v12 = v6;
}
else
{
do
{
*(_BYTE *)(result + v6) = -!(v3 & 0x100);
v12 = ++v6;
v13 = *(_DWORD *)(v4 + 8) - 1;
*(_DWORD *)(v4 + 8) = v13;
v14 = v13 <= 0;
result = *(_QWORD *)(v4 + 16);
}
while ( !v14 );
}
*(_BYTE *)(result + v12) = v3;
*(_QWORD *)(v4 + 24) = v12 + 1;
return result;
}