//
// sub_1002270B0 from 0x1002270b0 to 0x100227335 (645 bytes)
//
// 1 xrefs:
// > fmt::internal::PrintfParser::Format @ 0x100226714
//
// 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_1002270B0(__int64 a1, int **a2, unsigned int *a3, _QWORD *a4)
{
int *v4; // r8
int v5; // r9d
__int64 result; // rax
int v7; // ebx
int *v8; // r10
int v9; // r11d
bool v10; // cf
unsigned int v11; // r8d
unsigned int v12; // r9d
int v13; // r11d
int v14; // r9d
unsigned int v15; // edi
__int64 v16; // rsi
int *v17; // rsi
__int64 v18; // rsi
v4 = *a2;
v5 = **a2;
result = 0xFFFFFFFFLL;
if ( (unsigned int)(v5 - 48) <= 9 )
{
v7 = 0;
v8 = v4 + 1;
v9 = **a2;
do
{
result = (unsigned int)(v9 + 10 * v7 - 48);
v10 = (unsigned int)result < v7;
v7 = v9 + 10 * v7 - 48;
if ( v10 )
v7 = -1;
v9 = *v8;
v11 = *v8++ - 48;
}
while ( v11 < 0xA );
v4 = v8 - 1;
*a2 = v8 - 1;
if ( v7 >= 0 || (result = 0, *a4) )
{
if ( v9 == 36 )
{
LABEL_9:
v4 = v8;
goto LABEL_16;
}
}
else
{
*a4 = "number is too big in format";
if ( v9 == 36 )
goto LABEL_9;
}
if ( v5 == 48 )
a3[1] = 48;
if ( (_DWORD)result )
{
*a3 = result;
return 0xFFFFFFFFLL;
}
result = 0xFFFFFFFFLL;
}
LABEL_16:
v12 = a3[3];
while ( 2 )
{
v13 = *v4;
switch ( *v4 )
{
case ' ':
v12 |= 1u;
goto LABEL_23;
case '#':
v12 |= 4u;
goto LABEL_23;
case '+':
v12 |= 3u;
LABEL_23:
a3[3] = v12;
++v4;
continue;
case '-':
a3[2] = 1;
++v4;
continue;
case '0':
a3[1] = 48;
++v4;
continue;
default:
*a2 = v4;
if ( (unsigned int)(v13 - 48) <= 9 )
{
v14 = 0;
do
{
v15 = v13 + 10 * v14 - 48;
v13 = v4[1];
++v4;
v10 = v15 < v14;
v14 = v15;
if ( v10 )
v14 = -1;
}
while ( (unsigned int)(v13 - 48) < 0xA );
*a2 = v4;
if ( v14 < 0 )
{
v15 = 0;
if ( !*a4 )
*a4 = "number is too big in format";
}
*a3 = v15;
return result;
}
if ( v13 != 42 )
return result;
*a2 = v4 + 1;
v16 = *(int *)(a1 + 16);
if ( v16 < 0 )
{
v16 = 0xFFFFFFFFLL;
if ( !*a4 )
{
*a4 = "cannot switch from manual to automatic argument indexing";
v16 = 0xFFFFFFFFLL;
}
}
else
{
*(_DWORD *)(a1 + 16) = v16 + 1;
}
if ( *(_QWORD *)(a1 + 8) <= (unsigned __int64)v16 )
{
v17 = dword_100817DA0;
if ( !*a4 )
*a4 = "argument index is out of range in format";
}
else
{
v17 = (int *)(*(_QWORD *)a1 + 32 * v16);
}
break;
}
break;
}
switch ( *v17 )
{
case 0:
v18 = v17[4];
if ( v18 < 0 )
goto LABEL_48;
goto LABEL_44;
case 1:
v18 = (unsigned int)v17[4];
if ( (unsigned __int64)v18 >= 0x80000000 )
goto LABEL_45;
goto LABEL_57;
case 2:
v18 = *((_QWORD *)v17 + 2);
if ( v18 >= 0 )
{
LABEL_44:
if ( (unsigned __int64)v18 >= 0x80000000 )
goto LABEL_45;
LABEL_57:
*a3 = v18;
return result;
}
LABEL_48:
a3[2] = 1;
v18 = -v18;
if ( (unsigned __int64)v18 < 0x80000000 )
goto LABEL_57;
LABEL_45:
if ( !*a4 )
*a4 = "number is too big in format";
return result;
case 3:
v18 = *((_QWORD *)v17 + 2);
if ( (unsigned __int64)v18 < 0x80000000 )
goto LABEL_57;
goto LABEL_45;
default:
if ( !*a4 )
*a4 = "width is not integer";
LODWORD(v18) = 0;
goto LABEL_57;
}
}