//
// sub_1800B72A0 from 0x1800b72a0 to 0x1800b742f (399 bytes)
//
// 3 xrefs:
// > sub_1800B6E80 @ 0x1800b71d4
// > sub_1800B6E80 @ 0x1800b720f
// > ??> @ 0x1801fd128
//
// 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:59 +0000
//
__int64 __fastcall sub_1800B72A0(__int64 a1, int a2, int a3, int a4)
{
int v5; // ebx
__int64 v8; // rbp
int v10; // esi
int v11; // eax
int v12; // edx
__int64 v13; // r8
int v14; // eax
int v15; // eax
int v16; // ecx
int v17; // eax
__int64 v18; // rax
__int64 result; // rax
int v20; // r15d
int v21; // esi
__int64 v22; // rdx
int v23; // eax
int v24; // eax
int v25; // ecx
int v26; // r11d
v5 = a2 & 7;
v8 = a2 / 8;
v10 = a4;
v11 = a2 & 0x1F;
if ( (a2 & 0x1F) != 0 )
{
v12 = 32 - v11;
if ( 32 - v11 > a4 )
v12 = a4;
if ( v12 )
{
v13 = v8;
v10 = a4 - v12;
do
{
v14 = *(unsigned __int8 *)(*(_QWORD *)a1 + v13);
if ( a3 )
v15 = v14 | (1 << v5);
else
v15 = v14 & ~(1 << v5);
*(_BYTE *)(*(_QWORD *)a1 + v13) = v15;
v16 = v5 + 1;
v5 = 0;
v17 = v8 + 1;
if ( v16 < 8 )
{
v17 = v8;
v5 = v16;
}
LODWORD(v8) = v17;
v18 = v13 + 1;
if ( v16 < 8 )
v18 = v13;
v13 = v18;
--v12;
}
while ( v12 );
}
}
result = (unsigned int)(v10 / 8);
v20 = result;
if ( (_DWORD)result )
{
result = (__int64)memset((void *)(*(_QWORD *)a1 + (int)v8), (unsigned __int8)-(a3 != 0), (int)result);
LODWORD(v8) = v20 + v8;
LOBYTE(v10) = v10 - 8 * v20;
}
v21 = v10 & 0x1F;
if ( v21 )
{
v22 = (int)v8;
do
{
v23 = *(unsigned __int8 *)(*(_QWORD *)a1 + v22);
if ( a3 )
v24 = v23 | (1 << v5);
else
v24 = v23 & ~(1 << v5);
*(_BYTE *)(*(_QWORD *)a1 + v22) = v24;
v25 = v5 + 1;
v5 = 0;
result = v22 + 1;
if ( v25 < 8 )
{
result = v22;
v5 = v25;
}
v22 = result;
--v21;
}
while ( v21 );
}
v26 = *(_DWORD *)(a1 + 64);
if ( a3 )
{
if ( a2 == v26 )
{
v26 = a2 + a4;
*(_DWORD *)(a1 + 64) = a2 + a4;
}
result = *(_QWORD *)a1;
if ( ((unsigned __int8)(1 << (v26 & 7)) & *(_BYTE *)(v26 / 8 + *(_QWORD *)a1)) != 0 )
{
result = sub_1800B69F0((__int64 *)a1, v26, *(_DWORD *)(a1 + 52), 1);
*(_DWORD *)(a1 + 64) = result;
}
}
else if ( a2 < v26 )
{
*(_DWORD *)(a1 + 64) = a2;
}
return result;
}