//
// sub_BF2254 from 0xbf2254 to 0xbf2484 (560 bytes)
//
// 2 xrefs:
// > jinit_arith_encoder @ 0xbf471c
// > jinit_arith_encoder @ 0xbf4724
//
// 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_BF2254(__int64 a1, int a2)
{
__int64 v3; // x20
__int64 result; // x0
__int64 *v5; // x22
_DWORD *v6; // x23
int v7; // w21
__int64 v8; // x24
unsigned int v9; // w26
__int64 v10; // x26
_QWORD *v11; // x1
signed int v12; // w24
__int64 v13; // x24
void *v14; // x0
void (__fastcall **v15)(__int64); // x1
void (__fastcall *v16)(__int64); // x2
void (__fastcall **v17)(__int64); // x2
v3 = *(_QWORD *)(a1 + 560);
if ( a2 )
{
v16 = **(void (__fastcall ***)(__int64))a1;
*(_DWORD *)(*(_QWORD *)a1 + 40LL) = 49;
v16(a1);
}
if ( !*(_DWORD *)(a1 + 348) )
{
*(_QWORD *)(v3 + 8) = sub_BF3B10;
goto LABEL_9;
}
if ( *(_DWORD *)(a1 + 468) )
{
if ( *(_DWORD *)(a1 + 460) )
*(_QWORD *)(v3 + 8) = sub_BF3F38;
else
*(_QWORD *)(v3 + 8) = sub_BF4170;
LABEL_9:
if ( *(int *)(a1 + 372) <= 0 )
goto LABEL_7;
goto LABEL_10;
}
if ( *(_DWORD *)(a1 + 460) )
{
*(_QWORD *)(v3 + 8) = sub_BF4224;
goto LABEL_9;
}
*(_QWORD *)(v3 + 8) = sub_BF44C4;
if ( *(int *)(a1 + 372) > 0 )
{
LABEL_10:
v5 = (__int64 *)(a1 + 376);
v6 = (_DWORD *)(v3 + 64);
v7 = 0;
do
{
v8 = *v5;
if ( !*(_DWORD *)(a1 + 460) && !*(_DWORD *)(a1 + 468) )
{
v9 = *(_DWORD *)(v8 + 20);
if ( v9 > 0xF )
{
v17 = *(void (__fastcall ***)(__int64))a1;
*((_DWORD *)v17 + 11) = v9;
*((_DWORD *)v17 + 10) = 50;
(**(void (__fastcall ***)(__int64))a1)(a1);
}
v10 = v3 + 8LL * (int)v9;
v11 = *(_QWORD **)(v10 + 104);
if ( !v11 )
{
v11 = (_QWORD *)(**(__int64 (__fastcall ***)(__int64, __int64, __int64))(a1 + 8))(a1, 1, 64);
*(_QWORD *)(v10 + 104) = v11;
}
*v11 = 0;
v11[1] = 0;
v11[2] = 0;
v11[3] = 0;
v11[4] = 0;
v11[5] = 0;
v11[6] = 0;
v11[7] = 0;
*v6 = 0;
v6[4] = 0;
}
if ( !*(_DWORD *)(a1 + 464) )
goto LABEL_22;
v12 = *(_DWORD *)(v8 + 24);
if ( (unsigned int)v12 > 0xF )
{
v15 = *(void (__fastcall ***)(__int64))a1;
*((_DWORD *)v15 + 11) = v12;
v13 = v3 + 8LL * v12;
*((_DWORD *)v15 + 10) = 50;
(**(void (__fastcall ***)(__int64))a1)(a1);
v14 = *(void **)(v13 + 232);
if ( !v14 )
{
LABEL_25:
v14 = (void *)(**(__int64 (__fastcall ***)(__int64, __int64, __int64))(a1 + 8))(a1, 1, 256);
*(_QWORD *)(v13 + 232) = v14;
}
}
else
{
v13 = v3 + 8LL * v12;
v14 = *(void **)(v13 + 232);
if ( !v14 )
goto LABEL_25;
}
memset(v14, 0, 0x100u);
LABEL_22:
++v7;
++v5;
++v6;
}
while ( *(_DWORD *)(a1 + 372) > v7 );
}
LABEL_7:
result = *(unsigned int *)(a1 + 316);
*(_QWORD *)(v3 + 32) = 0x10000;
*(_QWORD *)(v3 + 24) = 0;
*(_DWORD *)(v3 + 56) = 11;
*(_QWORD *)(v3 + 40) = 0;
*(_QWORD *)(v3 + 48) = 0;
*(_DWORD *)(v3 + 60) = -1;
*(_QWORD *)(v3 + 96) = (unsigned int)result;
return result;
}