//
// sub_1005F8140 from 0x1005f8140 to 0x1005f8478 (824 bytes)
//
// 1 xrefs:
// > sub_1005F7A7C @ 0x1005f7e4c
//
// 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_1005F8140(__int64 *a1, char *a2, __int64 a3, __int64 a4, _BYTE *a5, __int64 a6)
{
int v8; // w22
__int64 *v10; // x20
__int64 v11; // x8
__int64 (__fastcall *v12)(__int64 *, char *, __int64, __int64, _BYTE *); // x6
__int64 result; // x0
__int64 v14; // x19
__int64 v15; // x0
__int64 *v16; // x25
_DWORD *v17; // x24
__int64 v18; // x0
void *v19; // x0
char *__s; // [xsp+8h] [xbp-48h] BYREF
v8 = a3;
v10 = a1;
__s = a2;
v11 = *(_QWORD *)(a6 + 32);
if ( v11 )
{
v12 = *(__int64 (__fastcall **)(__int64 *, char *, __int64, __int64, _BYTE *))(v11 + 40);
if ( v12 )
return v12(a1, a2, a3, a4, a5);
}
if ( *(_QWORD *)(a6 + 8) == -4 )
{
v14 = *a1;
if ( !*a1 )
{
v15 = sub_1005F8F80();
v14 = v15;
if ( !v15 )
{
sub_1005F8F8C(0);
return 0;
}
*v10 = v15;
}
if ( *(_DWORD *)v14 != (_DWORD)a4 )
sub_1005F0350(v14, a4, 0);
v16 = v10;
v10 = (__int64 *)(v14 + 8);
}
else
{
v14 = 0;
v16 = nullptr;
}
if ( (int)a4 <= 27 )
{
switch ( (int)a4 )
{
case 1:
if ( v8 == 1 )
{
*(_DWORD *)v10 = (unsigned __int8)*a2;
return 1;
}
sub_1005E0E48(13, 204, 106, (__int64)"tasn_dec.c", 889);
goto LABEL_50;
case 2:
case 10:
goto LABEL_22;
case 3:
if ( !sub_1005EE8EC((_DWORD **)v10, (unsigned __int8 **)&__s, v8) )
goto LABEL_50;
return 1;
case 5:
if ( v8 )
{
sub_1005E0E48(13, 204, 144, (__int64)"tasn_dec.c", 881);
goto LABEL_50;
}
*v10 = 1;
break;
case 6:
if ( !sub_1005EE434(v10, (const void **)&__s, v8) )
goto LABEL_50;
return 1;
default:
goto LABEL_26;
}
goto LABEL_34;
}
if ( (int)a4 > 257 )
{
if ( (_DWORD)a4 == 258 || (_DWORD)a4 == 266 )
{
LABEL_22:
if ( sub_1005EFB14((_DWORD **)v10, &__s, v8) )
{
*(_DWORD *)(*v10 + 4) = *(_DWORD *)(*v10 + 4) & 0x100 | a4;
goto LABEL_34;
}
goto LABEL_50;
}
}
else if ( (_DWORD)a4 == 28 )
{
if ( (v8 & 3) != 0 )
{
sub_1005E0E48(13, 204, 215, (__int64)"tasn_dec.c", 938);
goto LABEL_50;
}
}
else if ( (_DWORD)a4 == 30 && (v8 & 1) != 0 )
{
sub_1005E0E48(13, 204, 214, (__int64)"tasn_dec.c", 933);
goto LABEL_50;
}
LABEL_26:
v17 = (_DWORD *)*v10;
if ( !*v10 )
{
v18 = sub_1005FBAFC(a4);
v17 = (_DWORD *)v18;
if ( v18 )
{
*v10 = v18;
goto LABEL_30;
}
sub_1005E0E48(13, 204, 65, (__int64)"tasn_dec.c", 945);
LABEL_50:
sub_1005F8F8C(v14);
result = 0;
if ( v16 )
*v16 = 0;
return result;
}
v17[1] = a4;
LABEL_30:
if ( !*a5 )
{
if ( (unsigned int)sub_1005FB850((int)v17, __s) )
return 1;
sub_1005E0E48(13, 204, 65, (__int64)"tasn_dec.c", 962);
sub_1005FBA78(v17);
*v10 = 0;
goto LABEL_50;
}
v19 = *((void **)v17 + 1);
if ( v19 )
sub_100588C44(v19);
*((_QWORD *)v17 + 1) = __s;
*v17 = v8;
*a5 = 0;
LABEL_34:
result = 1;
if ( (_DWORD)a4 == 5 && v14 )
{
*(_QWORD *)(v14 + 8) = 0;
return 1;
}
return result;
}