//
// sub_100594F00 from 0x100594f00 to 0x1005951c4 (708 bytes)
//
// 2 xrefs:
// > sub_100594E60 @ 0x100594eb0
// > sub_100594E60 @ 0x100594ee0
//
// 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 int *__fastcall sub_100594F00(unsigned int *result, char *__src, unsigned __int64 a3)
{
unsigned __int64 v3; // x20
char *v4; // x21
unsigned int *v5; // x19
unsigned int v6; // w24
int v7; // w23
int v8; // w26
__int64 v9; // x8
__int64 v10; // x8
__int64 v11; // x8
unsigned int v12; // w27
unsigned int v13; // w8
unsigned __int64 v14; // x9
unsigned __int64 v15; // x23
size_t v16; // x20
char v17; // w25
unsigned __int8 *i; // x21
unsigned int v19; // w8
int v20; // w22
unsigned __int64 v21; // x28
int v22; // w20
unsigned int v23; // w8
unsigned int v24; // w9
unsigned int v25; // w8
char *v26; // [xsp+8h] [xbp-58h]
v3 = a3;
v4 = __src;
v5 = result;
v6 = result[32];
v7 = v6 & 7;
v8 = -(int)a3 & 7;
v9 = *((_QWORD *)result + 17);
*((_QWORD *)result + 17) = v9 + a3;
if ( __CFADD__(v9, a3) )
{
v10 = *((_QWORD *)result + 18) + 1LL;
*((_QWORD *)result + 18) = v10;
if ( !v10 )
{
v11 = *((_QWORD *)result + 19) + 1LL;
*((_QWORD *)result + 19) = v11;
if ( !v11 )
++*((_QWORD *)result + 20);
}
}
if ( !(v8 | v7) )
{
LABEL_12:
while ( v3 )
{
while ( !v6 && v3 >> 9 )
{
result = (unsigned int *)sub_1005953C0(v5, v4, v3 >> 9);
v6 = 0;
v4 += 64 * (v3 >> 9);
v3 &= 0x1FFu;
if ( !v3 )
return result;
}
v13 = v6 >> 3;
v14 = 512 - v6;
v15 = v3 - v14;
if ( v3 >= v14 )
{
v16 = (unsigned int)v14 >> 3;
memcpy((char *)v5 + v13 + 64, v4, v16);
v4 += v16;
result = (unsigned int *)sub_1005953C0(v5, v5 + 16, 1);
v6 = 0;
v3 = v15;
}
else
{
result = (unsigned int *)memcpy((char *)v5 + v13 + 64, v4, v3 >> 3);
v6 += v3;
v3 = 0;
}
v5[32] = v6;
}
return result;
}
if ( !a3 )
return result;
v26 = (char *)(result + 16);
v12 = 8 - v8;
if ( v7 == v8 )
{
v4 = __src + 1;
*((_BYTE *)result + (v6 >> 3) + 64) |= *__src & (0xFFu >> v8);
v6 += v12;
v3 = a3 - v12;
if ( v6 == 512 )
{
result = (unsigned int *)sub_1005953C0(result, v26, 1);
v6 = 0;
}
v5[32] = v6;
goto LABEL_12;
}
v17 = 8 - v7;
for ( i = (unsigned __int8 *)(__src + 1); ; ++i )
{
v19 = v6 >> 3;
v20 = *(i - 1) << v8;
v21 = v3 - 8;
if ( v3 < 8 )
break;
v22 = (*i >> v12) | v20;
if ( v7 )
*((_BYTE *)v5 + v19 + 64) |= (unsigned __int8)((*i >> v12) | v20) >> v7;
else
*((_BYTE *)v5 + v19 + 64) = v22;
v6 += 8;
if ( v6 < 0x200 )
{
v23 = v19 + 1;
}
else
{
result = (unsigned int *)sub_1005953C0(v5, v26, 1);
v23 = 0;
v6 &= 0x1FFu;
}
if ( v7 )
*((_BYTE *)v5 + v23 + 64) = (unsigned __int8)v22 << v17;
v5[32] = v6;
v3 = v21;
if ( !v21 )
return result;
}
if ( v7 )
*((_BYTE *)v5 + v19 + 64) |= (unsigned __int8)(*(i - 1) << v8) >> v7;
else
*((_BYTE *)v5 + v19 + 64) = v20;
v24 = v3 + v6;
if ( (_DWORD)v3 + v6 == 512 )
{
result = (unsigned int *)sub_1005953C0(v5, v26, 1);
v24 = 0;
v25 = 0;
}
else
{
v25 = v19 + 1;
}
if ( v7 )
*((_BYTE *)v5 + v25 + 64) = (unsigned __int8)v20 << v17;
v5[32] = v24;
return result;
}