//
// sub_10059295C from 0x10059295c to 0x100592bbc (608 bytes)
//
// 5 xrefs:
// > sub_1005215B0 @ 0x100521798
// > sub_10053414C @ 0x100534374
// > sub_1005931C4 @ 0x1005931f8
// > sub_1005EBB28 @ 0x1005ebbd0
// > sub_100615E2C @ 0x100615f48
//
// 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_10059295C(__int64 *a1, const void *a2, signed int a3, __int64 a4, __int64 a5)
{
__int64 v6; // x20
signed int v7; // w22
__int64 v10; // x9
__int64 result; // x0
int v12; // w8
int v13; // w0
int v14; // w3
int v15; // w4
int v16; // w5
int v17; // w6
int v18; // w7
__int64 *v19; // x22
__int64 i; // x8
char v21; // w9
_BYTE *v22; // x11
int v23; // w0
__int64 j; // x8
char v25; // w10
_BYTE *v26; // x12
int v27; // w0
_BYTE v28[128]; // [xsp+8h] [xbp-C8h] BYREF
v6 = a4;
v7 = a3;
v10 = *a1;
if ( !a4 )
{
v12 = 0;
result = 0;
v6 = v10;
if ( !v10 )
return result;
LABEL_7:
if ( a2 )
{
v13 = sub_1005EB298(v6);
if ( v13 >= 129 )
sub_1005884E4((char)"hmac.c", 116, (int)"j <= (int)sizeof(ctx->key)", v14, v15, v16, v17, v18);
if ( v13 >= v7 )
{
if ( (unsigned int)v7 > 0x80 )
return 0;
memcpy((char *)a1 + 156, a2, v7);
*((_DWORD *)a1 + 38) = v7;
}
else
{
if ( !(unsigned int)sub_1005E2E4C(a1 + 1, v6, a5)
|| !(unsigned int)sub_1005E303C(a1 + 1, a2, v7)
|| !(unsigned int)sub_1005E30F8(a1 + 1, (char *)a1 + 156, a1 + 19) )
{
return 0;
}
v7 = *((_DWORD *)a1 + 38);
}
if ( v7 != 128 )
bzero((char *)a1 + (unsigned int)v7 + 156, (unsigned int)(128 - v7));
}
else if ( !v12 )
{
v19 = a1 + 7;
goto LABEL_29;
}
for ( i = 0; i != 128; i += 2 )
{
v21 = *((_BYTE *)a1 + i + 157) ^ 0x36;
v22 = &v28[i];
*v22 = *((_BYTE *)a1 + i + 156) ^ 0x36;
v22[1] = v21;
}
v19 = a1 + 7;
if ( (unsigned int)sub_1005E2E4C(a1 + 7, v6, a5) )
{
v23 = sub_1005EB298(v6);
if ( (unsigned int)sub_1005E303C(a1 + 7, v28, v23) )
{
for ( j = 0; j != 128; j += 2 )
{
v25 = *((_BYTE *)a1 + j + 157) ^ 0x5C;
v26 = &v28[j];
*v26 = *((_BYTE *)a1 + j + 156) ^ 0x5C;
v26[1] = v25;
}
if ( (unsigned int)sub_1005E2E4C(a1 + 13, v6, a5) )
{
v27 = sub_1005EB298(v6);
if ( (unsigned int)sub_1005E303C(a1 + 13, v28, v27) )
{
LABEL_29:
if ( (unsigned int)sub_1005E326C(a1 + 1, v19) )
return 1;
}
}
}
}
return 0;
}
if ( v10 == a4 || (result = 0, a2) && (a3 & 0x80000000) == 0 )
{
*a1 = a4;
v12 = 1;
goto LABEL_7;
}
return result;
}