//
// sub_1004B3D58 from 0x1004b3d58 to 0x1004b3ed4 (380 bytes)
//
// 2 xrefs:
// > sub_1004AAF50 @ 0x1004ab1e8
// > sub_1004B3ED4 @ 0x1004b3ff4
//
// 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_1004B3D58(_BYTE *a1, __int64 a2, int a3)
{
__int64 result; // x0
int v5; // w13
int v6; // w9
int v7; // w11
int v8; // w12
unsigned __int8 *v9; // x10
int v10; // t1
unsigned __int64 v11; // x13
__int64 v12; // x12
__int64 v13; // x15
int v14; // t1
unsigned __int64 v15; // x10
__int64 v16; // x13
__int64 v17; // x12
int v18; // w8
char v19; // w10
result = 31;
if ( a1 && a2 )
{
v5 = (unsigned __int8)*a1;
if ( *a1 )
{
v6 = 0;
v7 = 0;
v8 = 0;
v9 = a1 + 1;
do
{
while ( 1 )
{
v11 = (unsigned int)(v8 + v5);
if ( ++v7 == 3 )
break;
v8 = (_DWORD)v11 << 8;
v10 = *v9++;
v5 = v10;
if ( !v10 )
goto LABEL_12;
}
if ( v6 == a3 )
return 31;
v12 = v6 + 1LL;
*(_BYTE *)(a2 + v6) = aAbcdefghijklmn_6[(int)v11 >> 18];
if ( (_DWORD)v12 == a3 )
return 31;
*(_BYTE *)(a2 + v12) = aAbcdefghijklmn_6[(v11 >> 12) & 0x3F];
if ( v6 + 2 == a3 )
return 31;
v13 = v6 + 3LL;
*(_BYTE *)(a2 + v6 + 2LL) = aAbcdefghijklmn_6[(v11 >> 6) & 0x3F];
if ( v6 + 3 == a3 )
return 31;
v8 = 0;
v7 = 0;
v6 += 4;
*(_BYTE *)(a2 + v13) = aAbcdefghijklmn_6[v11 & 0x3F];
v14 = *v9++;
v5 = v14;
}
while ( v14 );
LABEL_12:
if ( v7 )
{
if ( v6 == a3 )
return 31;
v15 = (unsigned int)(v8 << (16 - 8 * v7));
v16 = v6 + 1LL;
*(_BYTE *)(a2 + v6) = aAbcdefghijklmn_6[(int)v15 >> 18];
if ( (_DWORD)v16 == a3 )
return 31;
v17 = v6 + 2LL;
*(_BYTE *)(a2 + v16) = aAbcdefghijklmn_6[(v15 >> 12) & 0x3F];
if ( v7 == 1 )
{
if ( (_DWORD)v17 == a3 )
return 31;
v18 = v6 + 3;
v19 = 61;
}
else
{
if ( (_DWORD)v17 == a3 )
return 31;
v19 = aAbcdefghijklmn_6[(v15 >> 6) & 0x3F];
v18 = v6 + 3;
}
*(_BYTE *)(a2 + v17) = v19;
if ( v18 != a3 )
{
v6 += 4;
*(_BYTE *)(a2 + v18) = 61;
if ( v6 != a3 )
goto LABEL_25;
}
return 31;
}
}
else
{
v6 = 0;
}
if ( v6 != a3 )
{
LABEL_25:
*(_BYTE *)(a2 + v6) = 0;
return 0;
}
return 31;
}
return result;
}