//
// sub_1800158E0 from 0x1800158e0 to 0x180015a29 (329 bytes)
//
// 3 xrefs:
// > fmt::BasicWriter::operator<< @ 0x180017ece
// > DS_Dictionary::setIntegerForKey @ 0x18001f2ba
// > ??> @ 0x1801b8590
//
// 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 11:21:24 +0000
//
__int64 __fastcall sub_1800158E0(__int64 a1, int a2, __int64 a3)
{
unsigned int v3; // ebx
BOOL v4; // r10d
char v5; // r9
unsigned int v6; // eax
unsigned int v7; // edi
unsigned __int64 v8; // rdx
__int64 result; // rax
__int64 v10; // rsi
__int64 v11; // rbx
_BYTE *i; // r9
__int64 v13; // rcx
__int64 v14; // r8
__int64 v15; // rcx
char v16; // [rsp+48h] [rbp+10h] BYREF
__int16 v17; // [rsp+49h] [rbp+11h]
char v18; // [rsp+4Bh] [rbp+13h]
v17 = 0;
v18 = 0;
v3 = 1;
v4 = a2 < 0;
v5 = 0;
if ( a2 < 0 )
v5 = 45;
v6 = -a2;
v16 = v5;
if ( a2 >= 0 )
v6 = a2;
v7 = v6;
v8 = v6;
if ( v6 >= 0xAuLL )
{
while ( v8 >= 0x64 )
{
if ( v8 < 0x3E8 )
{
v3 += 2;
goto LABEL_14;
}
if ( v8 < 0x2710 )
{
v3 += 3;
goto LABEL_14;
}
v3 += 4;
v8 /= 0x2710u;
if ( v8 < 0xA )
goto LABEL_14;
}
++v3;
}
LABEL_14:
result = sub_180015C60(a1, v3, a3, &v16, v4);
v10 = 1LL - v3;
v11 = v3 - 1;
for ( i = (_BYTE *)(result + v10); v7 >= 0x64; i[v13] = result )
{
v13 = (unsigned int)(v11 - 1);
v14 = 2 * (v7 % 0x64);
v7 /= 0x64u;
i[v11] = a00010203040506[(unsigned int)(v14 + 1)];
v11 = (unsigned int)(v11 - 2);
result = (unsigned __int8)a00010203040506[v14];
}
if ( v7 >= 0xA )
{
v15 = 2 * v7;
i[1] = a00010203040506[(unsigned int)(v15 + 1)];
result = (unsigned __int8)a00010203040506[v15];
*i = result;
}
else
{
*i = v7 + 48;
}
return result;
}