//
// sub_6313B8 from 0x6313b8 to 0x631614 (604 bytes)
//
// 2 xrefs:
// > sub_631614 @ 0x63161c
// > sub_631634 @ 0x631638
//
// 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
//
int __fastcall sub_6313B8(int a1, int a2, int a3, _DWORD *a4)
{
int v7; // r0
size_t v8; // r4
int v10; // r0
int v11; // r3
size_t v12; // r10
int *v13; // r9
int ***v14; // r6
int **v15; // r11
int **v16; // r4
int v17; // r0
int **v18; // r1
int **v19; // r1
int v20; // r3
int v21; // r0
struct sigaction *v22; // r4
_DWORD *v23; // r3
size_t **v24; // r2
size_t *v25; // r2
struct sigaction *v26; // r5
int v27; // r2
size_t **v28; // r2
int v29; // [sp+0h] [bp-1Ch]
int v31; // [sp+14h] [bp-8h] BYREF
int v32; // [sp+18h] [bp-4h] BYREF
__time_t v33; // [sp+1Ch] [bp+0h] BYREF
int v34; // [sp+20h] [bp+4h]
int v35; // [sp+24h] [bp+8h]
int v36; // [sp+28h] [bp+Ch]
int v37; // [sp+2Ch] [bp+10h] BYREF
int v38; // [sp+30h] [bp+14h]
int v39; // [sp+34h] [bp+18h]
int v40; // [sp+38h] [bp+1Ch]
int v41; // [sp+3Ch] [bp+20h] BYREF
int v42; // [sp+40h] [bp+24h]
int v43; // [sp+44h] [bp+28h]
int v44; // [sp+48h] [bp+2Ch]
unsigned __int8 v45; // [sp+4Ch] [bp+30h]
sub_60F990(&v33);
if ( a2 == -1 )
{
*(_BYTE *)(a1 + 188) = 0;
*(_BYTE *)(a1 + 189) = 0;
v29 = 0;
*(_BYTE *)(a1 + 190) = 0;
*(_BYTE *)(a1 + 191) = 0;
*(_BYTE *)(a1 + 192) = 0;
*(_BYTE *)(a1 + 193) = 0;
*(_BYTE *)(a1 + 194) = 0;
*(_BYTE *)(a1 + 195) = 0;
goto LABEL_7;
}
v32 = a2;
v7 = sub_62E514((int *)(a1 + 72), (int)&v32, 4);
if ( !v7 )
{
v29 = 0;
goto LABEL_7;
}
v8 = *(_DWORD *)v7;
if ( *(_DWORD *)(*(_DWORD *)v7 + 34956) != -1059136595 )
return 4;
v23 = *(_DWORD **)(v8 + 8);
if ( v23 )
{
if ( ((a3 & 2) == 0 || (v24 = (size_t **)v23[182]) == nullptr || (v25 = *v24) == nullptr)
&& ((a3 & 1) == 0 || (v28 = (size_t **)v23[183]) == nullptr || (v25 = *v28) == nullptr)
|| (v8 = *v25, (v23 = *(_DWORD **)(*v25 + 8)) != nullptr) )
{
if ( (*(_DWORD *)(v23[166] + 64) & 8) == 0 )
v23[308] = a3;
}
}
v45 = *(_BYTE *)(v8 + 932);
v26 = (struct sigaction *)v45;
if ( !v45 )
{
v41 = 0;
v42 = 0;
v43 = 0;
v44 = 0;
sigaction(13, nullptr, (struct sigaction *)&v41);
v38 = v42;
v39 = v43;
v40 = v44;
v37 = 1;
sigaction(13, (const struct sigaction *)&v37, v26);
}
v29 = sub_630064(a1, v33, v34, v8);
if ( !v45 )
sigaction(13, (const struct sigaction *)&v41, nullptr);
v27 = *(_DWORD *)(v8 + 8);
if ( v27 && (*(_DWORD *)(*(_DWORD *)(v27 + 664) + 64) & 8) == 0 )
*(_DWORD *)(v27 + 1232) = 0;
if ( v29 <= 0 )
sub_62E9C8((_DWORD *)a1, v8);
sub_60F990(&v33);
LABEL_7:
while ( 1 )
{
v10 = sub_634D70(v33, v34, *(_DWORD *)(a1 + 68), &v31);
v11 = v31;
*(_DWORD *)(a1 + 68) = v10;
if ( !v11 )
break;
v12 = *(_DWORD *)(v11 + 20);
v13 = (int *)(v12 + 34612);
v14 = *(int ****)(v12 + 34644);
v35 = v33;
v36 = v34;
v15 = *v14;
if ( *v14 )
{
do
{
v16 = (int **)v15[2];
v17 = sub_60F9D8(**v15, (*v15)[1], v35, v36);
v18 = v15;
v15 = v16;
if ( v17 > 0 )
break;
sub_62E19C((int)v14, v18, 0);
}
while ( v16 );
v19 = *v14;
if ( *v14 )
{
v20 = (*v19)[1];
*v13 = **v19;
*(_DWORD *)(v12 + 34616) = v20;
sub_62E19C((int)v14, v19, 0);
v21 = sub_634CE0(*v13, *(_DWORD *)(v12 + 34616), *(_DWORD *)(a1 + 68), v12 + 34620);
v11 = v31;
*(_DWORD *)(a1 + 68) = v21;
goto LABEL_14;
}
v11 = v31;
}
*v13 = 0;
*(_DWORD *)(v12 + 34616) = 0;
LABEL_14:
if ( !v11 )
break;
v45 = *(_BYTE *)(v12 + 932);
v22 = (struct sigaction *)v45;
if ( !v45 )
{
v41 = 0;
v42 = 0;
v43 = 0;
v44 = 0;
sigaction(13, nullptr, (struct sigaction *)&v41);
v38 = v42;
v39 = v43;
v40 = v44;
v37 = 1;
sigaction(13, (const struct sigaction *)&v37, v22);
}
v29 = sub_630064(a1, v33, v34, v12);
if ( !v45 )
sigaction(13, (const struct sigaction *)&v41, nullptr);
if ( v29 <= 0 )
sub_62E9C8((_DWORD *)a1, v12);
}
*a4 = *(_DWORD *)(a1 + 16);
return v29;
}