//
// sub_180042340 from 0x180042340 to 0x18004252d (493 bytes)
//
// 2 xrefs:
// > sub_180046ED0 @ 0x180046f44
// > ??> @ 0x1801f8028
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 10:53:11 +0000
//
__int64 __fastcall sub_180042340(__int64 a1, __int64 a2, _DWORD *a3)
{
unsigned int v6; // r11d
int v7; // ecx
__int64 v8; // r8
int v9; // r8d
int v10; // r8d
__int64 v11; // rdx
__int64 result; // rax
int v13; // eax
int v14; // eax
int v15; // eax
*a3 = 0;
while ( 1 )
{
v6 = *(_DWORD *)(a2 + 20);
if ( v6 < *(_DWORD *)(a2 + 12) )
break;
LABEL_6:
v9 = *(_DWORD *)(a2 + 16);
if ( v9 )
{
v10 = 8 * v9;
v11 = (*(_DWORD *)(*(_QWORD *)a2 + 4LL * v6) & (unsigned int)(-1 << (32 - v10))) << *(_DWORD *)(a2 + 24);
if ( (_DWORD)v11 )
{
if ( (unsigned int)v11 > 0xFFFF )
{
if ( (unsigned int)v11 > 0xFFFFFF )
v15 = byte_180165620[(unsigned __int64)(unsigned int)v11 >> 24];
else
v15 = byte_180165620[(unsigned __int64)(unsigned int)v11 >> 16] + 8;
*a3 += v15;
*(_DWORD *)(a2 + 24) += v15 + 1;
return 1;
}
else
{
if ( (unsigned int)v11 > 0xFF )
v14 = byte_180165620[(unsigned __int64)(unsigned int)v11 >> 8] + 16;
else
v14 = byte_180165620[v11] + 24;
*a3 += v14;
*(_DWORD *)(a2 + 24) += v14 + 1;
return 1;
}
}
*a3 += v10 - *(_DWORD *)(a2 + 24);
*(_DWORD *)(a2 + 24) += v10;
}
result = sub_180042A00(a1, a2);
if ( !(_DWORD)result )
return result;
}
v7 = *(_DWORD *)(a2 + 24);
while ( 1 )
{
v8 = (unsigned int)(*(_DWORD *)(*(_QWORD *)a2 + 4LL * v6) << v7);
if ( (_DWORD)v8 )
break;
*a3 += 32 - v7;
sub_180042B70(a2);
v7 = 0;
v6 = *(_DWORD *)(a2 + 20) + 1;
*(_QWORD *)(a2 + 20) = v6;
if ( v6 >= *(_DWORD *)(a2 + 12) )
goto LABEL_6;
}
if ( (unsigned int)v8 > 0xFFFF )
{
if ( (unsigned int)v8 > 0xFFFFFF )
v13 = byte_180165620[(unsigned __int64)(unsigned int)v8 >> 24];
else
v13 = byte_180165620[(unsigned __int64)(unsigned int)v8 >> 16] + 8;
}
else if ( (unsigned int)v8 > 0xFF )
{
v13 = byte_180165620[(unsigned __int64)(unsigned int)v8 >> 8] + 16;
}
else
{
v13 = byte_180165620[v8] + 24;
}
*a3 += v13;
*(_DWORD *)(a2 + 24) += v13 + 1;
if ( *(_DWORD *)(a2 + 24) >= 0x20u )
{
sub_180042B70(a2);
++*(_DWORD *)(a2 + 20);
*(_DWORD *)(a2 + 24) = 0;
}
return 1;
}