//
// sub_180010050 from 0x180010050 to 0x1800102e6 (662 bytes)
//
// 7 xrefs:
// > ??> @ 0x18016c7c0
// > ??> @ 0x18016ca38
// > ??> @ 0x18017eb74
// > ??> @ 0x18017eb84
// > ??> @ 0x18017eb9c
// > ??> @ 0x18017ebac
// > ??> @ 0x1801f6dd4
//
// 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_180010050(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r15
__int64 v4; // r12
__int64 result; // rax
int v8; // ecx
int v9; // edx
__int64 v10; // rax
int v11; // r9d
__int64 v12; // rax
__int64 v13; // r8
__int64 v14; // r8
char v15; // r14
__int64 v16; // rdi
unsigned int v17; // esi
__int64 v18; // rdx
__int64 v19; // [rsp+30h] [rbp-10h] BYREF
__int64 v20; // [rsp+38h] [rbp-8h] BYREF
int v21; // [rsp+80h] [rbp+40h] BYREF
int v22; // [rsp+88h] [rbp+48h] BYREF
v21 = a3;
v3 = *(_QWORD *)(a1 + 96);
v4 = *(_QWORD *)(a1 + 112);
v19 = 0;
v20 = 0;
if ( !v3 )
return 9;
if ( a3 == -1 )
{
a3 = 0;
v21 = 0;
}
else
{
if ( a3 == -3 )
{
a3 = *(_DWORD *)(a1 + 24) - 1;
v21 = a3;
}
else if ( a3 == -2 )
{
result = (*(__int64 (__fastcall **)(__int64, __int64, int *))(*(_QWORD *)a1 + 312LL))(a1, v4, &v21);
if ( (_DWORD)result )
return result;
a3 = v21;
}
if ( a3 < 0 )
return 31;
}
if ( a3 >= *(_DWORD *)(a1 + 24) )
return 31;
result = (*(__int64 (__fastcall **)(__int64, __int64, int *))(*(_QWORD *)a1 + 312LL))(a1, a2, &v22);
if ( (_DWORD)result )
return result;
v8 = v21;
v9 = v22;
if ( v21 == v22 )
return result;
if ( v22 )
{
v10 = v19;
if ( !v21 )
v10 = a2;
v19 = v10;
}
else
{
result = (*(__int64 (__fastcall **)(__int64, __int64, __int64 *))(*(_QWORD *)a1 + 288LL))(a1, 1, &v19);
if ( (_DWORD)result )
return result;
v8 = v21;
v9 = v22;
}
v11 = *(_DWORD *)(a1 + 24);
if ( v9 == v11 - 1 )
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD, __int64 *))(*(_QWORD *)a1 + 288LL))(
a1,
(unsigned int)(v11 - 2),
&v20);
if ( (_DWORD)result )
return result;
v8 = v21;
v9 = v22;
}
else
{
v12 = v20;
if ( v8 == v11 - 1 )
v12 = a2;
v20 = v12;
}
if ( v8 <= v9 )
{
if ( v8 < v9 )
{
v14 = 8LL * v9;
do
{
v14 -= 8;
--v9;
*(_QWORD *)(*(_QWORD *)(a1 + 16) + v14 + 8) = *(_QWORD *)(*(_QWORD *)(a1 + 16) + v14);
v8 = v21;
}
while ( v9 > v21 );
}
}
else
{
v13 = 8LL * v9;
do
{
v13 += 8;
++v9;
*(_QWORD *)(*(_QWORD *)(a1 + 16) + v13 - 8) = *(_QWORD *)(*(_QWORD *)(a1 + 16) + v13);
v8 = v21;
}
while ( v9 < v21 );
}
v15 = 0;
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v8) = a2;
v16 = *(_QWORD *)(a1 + 8);
if ( v16 )
{
sub_1801021C0(*(_QWORD *)(a1 + 8), 1);
v15 = 1;
}
v17 = sub_180092550(v3, a2, v22, v21, 1, 0);
if ( v17 )
goto LABEL_38;
v18 = v19;
if ( v19 )
{
v17 = sub_180069950(v4, v19 + 8, 0);
if ( v17 )
{
LABEL_38:
if ( v15 )
{
if ( v16 )
sub_180102300(v16, 1);
}
return v17;
}
v18 = v19;
}
if ( v15 && v16 )
{
sub_180102300(v16, 1);
v18 = v19;
}
if ( !v18 && !v20 )
return 0;
result = (*(__int64 (__fastcall **)(__int64, __int64, __int64))(*(_QWORD *)a1 + 488LL))(a1, v18, v20);
if ( !(_DWORD)result )
return 0;
return result;
}