//
// sub_180045B60 from 0x180045b60 to 0x180046250 (1776 bytes)
//
// 6 xrefs:
// > sub_1800445F0 @ 0x1800446a6
// > sub_1800446F0 @ 0x180044744
// > sub_1800447A0 @ 0x180044882
// > sub_180047910 @ 0x180047c85
// > ??> @ 0x1801f81e4
// > ??> @ 0x1801f81f0
//
// 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_180045B60(__int64 a1, __int64 a2)
{
__int64 v4; // rdx
unsigned int v5; // r13d
unsigned int v6; // edi
__int64 v7; // r8
void (__fastcall *v8)(__int64, __int64, _QWORD); // rax
__int64 v9; // rsi
unsigned int v10; // r14d
__int64 v11; // rax
size_t v12; // rdx
void *v13; // rax
__int64 v14; // rdx
__int64 v15; // rdi
__int64 v16; // rsi
unsigned int v17; // r14d
__int64 v18; // r8
void (__fastcall *v19)(__int64, __int64, _QWORD); // rax
BOOL v20; // r15d
__int64 v21; // rsi
unsigned __int64 v22; // r13
char *v23; // rsi
unsigned __int64 v24; // rdi
int v25; // eax
_BYTE *v27; // rax
void **v28; // rdx
_BYTE *v29; // rax
__int64 v30; // r8
void (__fastcall *v31)(__int64, unsigned __int64 *, _QWORD); // rax
void **v32; // rcx
unsigned int v33; // r8d
unsigned int v34; // edi
unsigned int v35; // r8d
__int64 v36; // rdi
void **v37; // rdx
void *v38; // rcx
unsigned int v39; // [rsp+20h] [rbp-B9h] BYREF
unsigned int v40; // [rsp+24h] [rbp-B5h] BYREF
size_t Size; // [rsp+28h] [rbp-B1h] BYREF
unsigned __int64 v42; // [rsp+30h] [rbp-A9h] BYREF
unsigned int v43; // [rsp+38h] [rbp-A1h] BYREF
BOOL v44; // [rsp+3Ch] [rbp-9Dh]
unsigned __int64 v45; // [rsp+40h] [rbp-99h] BYREF
int v46; // [rsp+48h] [rbp-91h]
_DWORD v47[41]; // [rsp+4Ch] [rbp-8Dh] BYREF
if ( !(unsigned int)sub_180041D20(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 120LL), &v43, 1u) )
return 0;
v4 = *(_QWORD *)(*(_QWORD *)(a2 + 8) + 120LL);
v5 = v43 != 0;
v40 = v5;
if ( !(unsigned int)sub_180041D20(a1, v4, &v39, 7u)
|| !(unsigned int)sub_180041D20(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 120LL), (unsigned int *)&Size, 0x18u) )
{
return 0;
}
v6 = v39;
if ( !v39 )
{
if ( (unsigned int)sub_180046810(a1, a2, v5, (unsigned int)Size) )
{
*(_DWORD *)(*(_QWORD *)(a2 + 8) + 472LL) = 1;
v7 = *(_QWORD *)(a2 + 8);
if ( !*(_QWORD *)(v7 + 536) && !*(_QWORD *)(v7 + 544) )
{
*(_DWORD *)(v7 + 4104) = v6;
v7 = *(_QWORD *)(a2 + 8);
}
if ( !*(_DWORD *)(v7 + 4112) )
{
if ( *(_DWORD *)(v7 + 832) )
{
v8 = *(void (__fastcall **)(__int64, __int64, _QWORD))(v7 + 48);
if ( v8 )
v8(a2, v7 + 480, *(_QWORD *)(v7 + 104));
}
}
goto LABEL_93;
}
return 0;
}
v9 = *(_QWORD *)(a2 + 8);
v10 = Size;
if ( v39 == 3 )
{
*(_DWORD *)(v9 + 656) = 3;
*(_DWORD *)(*(_QWORD *)(a2 + 8) + 660LL) = v5;
*(_DWORD *)(*(_QWORD *)(a2 + 8) + 664LL) = v10;
*(_DWORD *)(*(_QWORD *)(a2 + 8) + 672LL) = v10 / 0x12;
v11 = *(_QWORD *)(a2 + 8);
if ( *(_DWORD *)(v11 + 672) )
v12 = 24LL * *(unsigned int *)(v11 + 672);
else
v12 = 0;
v13 = j__realloc_base(*(void **)(v11 + 680), v12);
*(_QWORD *)(*(_QWORD *)(a2 + 8) + 680LL) = v13;
if ( v13 )
{
v14 = *(_QWORD *)(a2 + 8);
v15 = 0;
if ( *(_DWORD *)(v14 + 672) )
{
while ( (unsigned int)sub_180041EA0(a1, *(_QWORD *)(v14 + 120), &v42, 0x40u) )
{
v16 = 24 * v15;
*(_QWORD *)(24 * v15 + *(_QWORD *)(*(_QWORD *)(a2 + 8) + 680LL)) = v42;
if ( !(unsigned int)sub_180041EA0(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 120LL), &v42, 0x40u) )
break;
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a2 + 8) + 680LL) + v16 + 8) = v42;
if ( !(unsigned int)sub_180041D20(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 120LL), &v40, 0x10u) )
break;
v15 = (unsigned int)(v15 + 1);
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a2 + 8) + 680LL) + v16 + 16) = v40;
v14 = *(_QWORD *)(a2 + 8);
if ( (unsigned int)v15 >= *(_DWORD *)(v14 + 672) )
goto LABEL_24;
}
}
else
{
LABEL_24:
v17 = -18 * *(_DWORD *)(v14 + 672) + v10;
if ( !v17 || (unsigned int)sub_180042920(a1, *(_DWORD **)(v14 + 120), v17) )
{
*(_DWORD *)(*(_QWORD *)(a2 + 8) + 476LL) = 1;
v18 = *(_QWORD *)(a2 + 8);
if ( !*(_DWORD *)(v18 + 4112) )
{
if ( *(_DWORD *)(v18 + 844) )
{
v19 = *(void (__fastcall **)(__int64, __int64, _QWORD))(v18 + 48);
if ( v19 )
v19(a2, v18 + 656, *(_QWORD *)(v18 + 104));
}
}
goto LABEL_93;
}
}
return 0;
}
LABEL_18:
**(_DWORD **)a2 = 8;
return 0;
}
LODWORD(v42) = *(_DWORD *)(v9 + 4LL * v39 + 832);
v20 = v42 == 0;
v44 = v20;
memset(v47, 0, sizeof(v47));
v45 = __PAIR64__(v5, v39);
v46 = Size;
if ( v39 == 2 )
{
if ( !(unsigned int)sub_180041BB0(a1, *(_QWORD *)(v9 + 120), &v47[1], 4u) )
return 0;
if ( v10 < 4 )
goto LABEL_18;
v21 = *(_QWORD *)(a2 + 8);
v10 -= 4;
v22 = *(_QWORD *)(v21 + 1352);
if ( v22 )
{
v23 = *(char **)(v21 + 1344);
v24 = 0;
while ( memcmp(v23, &v47[1], 4u) )
{
++v24;
v23 += 4;
if ( v24 >= v22 )
{
v20 = v44;
goto LABEL_39;
}
}
v20 = v42 != 0;
}
LABEL_39:
v6 = v39;
v5 = v40;
}
if ( !v20 )
{
switch ( v6 )
{
case 0u:
case 3u:
goto LABEL_60;
case 1u:
v25 = sub_180042920(a1, *(_DWORD **)(*(_QWORD *)(a2 + 8) + 120LL), v10);
goto LABEL_45;
case 2u:
if ( !v10 )
{
v28 = nullptr;
*(_QWORD *)&v47[3] = 0;
goto LABEL_61;
}
v27 = j__malloc_base(v10);
*(_QWORD *)&v47[3] = v27;
if ( !v27 )
goto LABEL_18;
v25 = sub_180041BB0(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 120LL), v27, v10);
LABEL_45:
if ( !v25 )
return 0;
LABEL_54:
v6 = v39;
goto LABEL_60;
case 4u:
v25 = sub_180046A60(a1, a2, &v47[1]);
goto LABEL_45;
case 5u:
v25 = sub_180046250(a1, a2, &v47[1]);
goto LABEL_45;
case 6u:
if ( !(unsigned int)sub_1800465B0(a1, a2, &v47[1]) )
return 0;
goto LABEL_54;
default:
if ( v10 )
{
v29 = j__malloc_base(v10);
*(_QWORD *)&v47[1] = v29;
if ( !v29 )
goto LABEL_18;
if ( !(unsigned int)sub_180041BB0(a1, *(_QWORD *)(*(_QWORD *)(a2 + 8) + 120LL), v29, v10) )
return 0;
v6 = v39;
}
else
{
*(_QWORD *)&v47[1] = 0;
}
LABEL_60:
v28 = *(void ***)&v47[3];
LABEL_61:
v30 = *(_QWORD *)(a2 + 8);
if ( !*(_DWORD *)(v30 + 4112) )
{
v31 = *(void (__fastcall **)(__int64, unsigned __int64 *, _QWORD))(v30 + 48);
if ( v31 )
{
v31(a2, &v45, *(_QWORD *)(v30 + 104));
v28 = *(void ***)&v47[3];
v6 = v39;
}
}
switch ( v6 )
{
case 1u:
goto LABEL_93;
case 2u:
if ( v28 )
{
v32 = v28;
goto LABEL_92;
}
goto LABEL_93;
case 4u:
if ( v28 )
free(v28);
v33 = v47[5];
if ( v47[5] )
{
v34 = 0;
v32 = *(void ***)&v47[7];
do
{
if ( v32[2 * v34 + 1] )
{
free(v32[2 * v34 + 1]);
v32 = *(void ***)&v47[7];
v33 = v47[5];
}
++v34;
}
while ( v34 < v33 );
}
else
{
v32 = *(void ***)&v47[7];
}
goto LABEL_91;
case 5u:
v35 = v47[38];
if ( v47[38] )
{
v36 = 0;
v37 = *(void ***)&v47[39];
do
{
v38 = v37[5 * v36 + 4];
if ( v38 )
{
free(v38);
v37 = *(void ***)&v47[39];
v35 = v47[38];
}
v36 = (unsigned int)(v36 + 1);
}
while ( (unsigned int)v36 < v35 );
}
else
{
v37 = *(void ***)&v47[39];
}
if ( !v37 )
goto LABEL_93;
v32 = v37;
goto LABEL_92;
case 6u:
if ( v28 )
free(v28);
if ( *(_QWORD *)&v47[5] )
free(*(void **)&v47[5]);
v32 = *(void ***)&v47[13];
goto LABEL_91;
default:
v32 = *(void ***)&v47[1];
LABEL_91:
if ( v32 )
LABEL_92:
free(v32);
break;
}
goto LABEL_93;
}
}
if ( !(unsigned int)sub_180042920(a1, *(_DWORD **)(*(_QWORD *)(a2 + 8) + 120LL), v10) )
return 0;
LABEL_93:
if ( v5 )
{
if ( !(unsigned int)sub_180043F30(a1, a2, (_QWORD *)(*(_QWORD *)(a2 + 8) + 6848LL)) )
*(_QWORD *)(*(_QWORD *)(a2 + 8) + 6848LL) = 0;
**(_DWORD **)a2 = 2;
}
return 1;
}