//
// sub_100615388 from 0x100615388 to 0x100615850 (1224 bytes)
//
// 1 xrefs:
// > sub_100615298 @ 0x100615318
//
// 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_100615388(__int64 a1, int a2, __int64 a3, int a4, int a5, int a6, int a7, char *a8, int *a9)
{
__int64 v16; // x24
__int64 v17; // x26
_BYTE *v18; // x27
_BYTE *v19; // x26
unsigned __int8 *v20; // x25
int v21; // w10
int v22; // w8
_BYTE *v23; // x28
_BYTE *v24; // x19
_BYTE *v25; // x0
bool v26; // zf
bool v27; // zf
unsigned __int8 *v28; // x27
void *v29; // x25
_BYTE *v30; // x26
_BYTE *v34; // x8
__int64 v35; // x8
__int64 v36; // x9
int v37; // w3
int v38; // w4
int v39; // w5
int v40; // w6
int v41; // w7
int v42; // w19
int v43; // w3
int v44; // w4
int v45; // w5
int v46; // w6
int v47; // w7
int v48; // w19
int v49; // w8
__int64 v50; // x8
__int64 v51; // x20
int v52; // w0
int v53; // w8
int v54; // w19
int v55; // w8
_BYTE *v56; // x1
__int64 v57; // x0
__int64 v58; // x20
int __c; // [xsp+8h] [xbp-D8h]
char *__dst; // [xsp+10h] [xbp-D0h]
int v62; // [xsp+1Ch] [xbp-C4h]
int v63; // [xsp+20h] [xbp-C0h]
int v64; // [xsp+28h] [xbp-B8h]
int v65; // [xsp+30h] [xbp-B0h]
int v66; // [xsp+38h] [xbp-A8h]
void *__b; // [xsp+40h] [xbp-A0h]
_BYTE *v68; // [xsp+48h] [xbp-98h]
void *v70[6]; // [xsp+60h] [xbp-80h] BYREF
sub_1005E2DF4(v70);
v16 = sub_1005EB298((__int64)a9);
v17 = sub_1005EB2A8((__int64)a9);
if ( (v17 & 0x80000000) != 0 )
return 0;
__c = a5;
v62 = a7;
__dst = a8;
v18 = sub_100588710(v16, (__int64)"p12_key.c", 141);
__b = v18;
v64 = v17;
v19 = sub_100588710(v17, (__int64)"p12_key.c", 142);
v20 = sub_100588710((unsigned int)(v16 + 1), (__int64)"p12_key.c", 143);
v21 = (a4 + (int)v16 - 1) / (int)v16 * v16;
v65 = v21;
if ( a2 )
v22 = (a2 + (int)v16 - 1) / (int)v16 * v16;
else
v22 = 0;
v66 = v22;
v63 = v22 + v21;
v23 = sub_100588710((unsigned int)(v22 + v21), (__int64)"p12_key.c", 150);
v24 = sub_1005AAD34();
v25 = sub_1005AAD34();
v68 = v25;
if ( v18 )
v26 = v19 == nullptr;
else
v26 = 1;
v27 = v26 || v20 == nullptr;
v28 = v20;
v29 = v19;
v30 = v24;
if ( !v27 && v23 != nullptr && v24 != nullptr && v25 != nullptr )
{
if ( (int)v16 >= 1 )
memset(__b, __c, (unsigned int)(v16 - 1) + 1LL);
v34 = v23;
if ( v65 >= 1 )
{
v35 = 0;
do
{
v23[v35] = *(_BYTE *)(a3 + (int)v35 % a4);
++v35;
}
while ( v65 != (_DWORD)v35 );
v34 = &v23[v65 - 1 + 1];
}
if ( v66 >= 1 )
{
v36 = 0;
do
{
v34[v36] = *(_BYTE *)(a1 + (int)v36 % a2);
++v36;
}
while ( v66 != (_DWORD)v36 );
}
if ( (unsigned int)sub_1005E2E4C((__int64)v70, a9, 0) )
{
while ( (unsigned int)sub_1005E303C((__int64)v70)
&& (unsigned int)sub_1005E303C((__int64)v70)
&& (unsigned int)sub_1005E30F8(v70, (__int64)v29, nullptr, v37, v38, v39, v40, v41) )
{
if ( a6 > 1 )
{
v42 = 1;
while ( (unsigned int)sub_1005E2E4C((__int64)v70, a9, 0)
&& (unsigned int)sub_1005E303C((__int64)v70)
&& (unsigned int)sub_1005E30F8(v70, (__int64)v29, nullptr, v43, v44, v45, v46, v47) )
{
if ( ++v42 >= a6 )
goto LABEL_40;
}
break;
}
LABEL_40:
v48 = v62;
if ( v62 >= v64 )
v49 = v64;
else
v49 = v62;
memcpy(__dst, v29, v49);
v62 -= v64;
if ( v48 <= v64 )
{
v58 = 1;
goto LABEL_66;
}
if ( (int)v16 >= 1 )
{
v50 = 0;
do
{
v28[v50] = *((_BYTE *)v29 + (int)v50 % v64);
++v50;
}
while ( (_DWORD)v16 != (_DWORD)v50 );
}
if ( !sub_1005AB1B0(v28, v16, (__int64)v68) || !(unsigned int)sub_1005AE83C((__int64)v68, 1) )
break;
if ( v63 >= 1 )
{
v51 = 0;
while ( sub_1005AB1B0(&v23[v51], v16, (__int64)v30)
&& (unsigned int)sub_1005A87F0((__int64)v30, (__int64)v30, (__int64)v68)
&& (unsigned int)sub_1005AB354((__int64)v30, v28) )
{
v52 = sub_1005AAC20((__int64)v30);
v53 = v52 + 7;
if ( v52 + 7 < 0 )
v53 = v52 + 14;
v54 = v53 >> 3;
v55 = v16 - (v53 >> 3);
if ( (int)v16 >= v54 )
{
if ( (int)v16 <= v54 )
{
v57 = (__int64)v30;
v56 = &v23[v51];
}
else
{
bzero(&v23[v51], v55);
v56 = &v23[(int)v16 + v51 - v54];
v57 = (__int64)v30;
}
if ( !(unsigned int)sub_1005AB354(v57, v56) )
goto LABEL_65;
}
else
{
if ( !(unsigned int)sub_1005AB354((__int64)v30, v28) )
goto LABEL_65;
memcpy(&v23[v51], v28 + 1, (int)v16);
}
v51 += (int)v16;
if ( v51 >= v63 )
goto LABEL_64;
}
break;
}
LABEL_64:
__dst += v64;
if ( !(unsigned int)sub_1005E2E4C((__int64)v70, a9, 0) )
break;
}
}
}
LABEL_65:
sub_1005E0E48(35, 111, 65, (__int64)"p12_key.c", 218);
v58 = 0;
LABEL_66:
sub_100588C44(v29);
sub_100588C44(v28);
sub_100588C44(__b);
sub_100588C44(v23);
sub_1005AACD0(v30);
sub_1005AACD0(v68);
sub_1005E31A4((__int64)v70);
return v58;
}