//
// sub_180015970 from 0x180015970 to 0x180015ab9 (329 bytes)
//
// 3 xrefs:
// > fmt::BasicWriter::operator<< @ 0x18001825e
// > DS_Dictionary::setIntegerForKey @ 0x18001f11a
// > ??> @ 0x1801ae4dc
//
// 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_180015970(__int64 a1, int a2, __int64 a3)
{
char v3; // r9
unsigned int v4; // eax
unsigned int v5; // ebx
unsigned int v6; // r10d
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]
v3 = 0;
v17 = 0;
v18 = 0;
if ( a2 < 0 )
v3 = 45;
v16 = v3;
v4 = -a2;
v5 = 1;
if ( a2 >= 0 )
v4 = a2;
v6 = (unsigned int)a2 >> 31;
v7 = v4;
v8 = v4;
if ( v4 >= 0xAuLL )
{
while ( v8 >= 0x64 )
{
if ( v8 < 0x3E8 )
{
v5 += 2;
goto LABEL_14;
}
if ( v8 < 0x2710 )
{
v5 += 3;
goto LABEL_14;
}
v5 += 4;
v8 /= 0x2710u;
if ( v8 < 0xA )
goto LABEL_14;
}
++v5;
}
LABEL_14:
result = sub_180015CE0(a1, v5, a3, &v16, v6);
v10 = 1LL - v5;
v11 = v5 - 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;
}