//
// sub_853DC from 0x853dc to 0x856c4 (744 bytes)
//
// 1 xrefs:
// > sub_85370 @ 0x85370
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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:41:20 +0000
//
int __fastcall sub_853DC(int a1, __int16 a2)
{
int result; // r0
unsigned __int16 *v5; // r6
int v6; // r10
bool v7; // zf
const void *v8; // r9
_DWORD *v9; // r6
int v10; // r8
unsigned __int64 v11; // r0
unsigned __int64 v12; // r0
_DWORD *v13; // r2
int v14; // r1
int v15; // r0
int v16; // r0
__int64 v17; // kr00_8
bool v18; // zf
bool v19; // zf
unsigned int v20; // r1
unsigned int v21; // r8
int v22; // r11
unsigned int v23; // r9
unsigned int v24; // r2
unsigned __int16 v25; // r0
int v26; // r0
_DWORD *v27; // [sp+4h] [bp-2Ch]
_BYTE v28[4]; // [sp+8h] [bp-28h] BYREF
int v29; // [sp+Ch] [bp-24h]
_BYTE v30[4]; // [sp+10h] [bp-20h] BYREF
*(_DWORD *)(a1 + 216) = 0;
*(_DWORD *)(a1 + 188) = 0;
*(_DWORD *)(a1 + 20) = 15;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 168) = 0;
*(_DWORD *)(a1 + 172) = 0;
*(_DWORD *)(a1 + 176) = 0;
*(_DWORD *)(a1 + 180) = 0;
result = sub_BB750(*(_DWORD *)(a1 + 220), v28, 1, 8, 0);
if ( result )
return result;
if ( sub_BE2BC(v28, "RIFF", 4) )
return 19;
result = sub_BB750(*(_DWORD *)(a1 + 220), v30, 1, 4, 0);
if ( result )
return result;
if ( sub_BE2BC(v30, "WAVE", 4) )
return 19;
memset((void *)(a1 + 264), 0, 0x34u);
*(_DWORD *)(a1 + 152) = -1;
*(_DWORD *)(a1 + 4) = a1 + 264;
*(_DWORD *)(a1 + 316) = 0;
*(_DWORD *)(a1 + 320) = 0;
result = sub_8608C(a1, v29, 0);
if ( result )
return result;
v5 = *(unsigned __int16 **)(a1 + 380);
if ( !v5 )
return 19;
if ( *(_DWORD *)(a1 + 152) == -1 )
{
sub_BD7AC(*(int *)((char *)&dword_14C + (_DWORD)off_E8000), v5, "../../src/fmod_codec_wav.cpp", 149, 1);
*(_DWORD *)(a1 + 152) = 0;
*(_DWORD *)(a1 + 380) = 0;
return 19;
}
memset((void *)(a1 + 224), 0, 0x28u);
*(_WORD *)(a1 + 224) = 1;
result = 19;
v6 = *v5;
v7 = v6 == 80;
if ( v6 != 80 )
v7 = v6 == 85;
if ( v7 )
return result;
if ( v6 == 65534 )
{
v8 = v5 + 12;
if ( memcmp(v5 + 12, &unk_409E4, 0x10u) && memcmp(v5 + 12, &unk_409F4, 0x10u) )
return 19;
qmemcpy((void *)(a1 + 224), v5, 0x28u);
v9 = *(_DWORD **)(a1 + 4);
v10 = *(unsigned __int16 *)(a1 + 238);
HIDWORD(v11) = v9[4];
LODWORD(v11) = 8 * HIDWORD(v11);
HIDWORD(v11) >>= 29;
v9[5] = v11 / *(unsigned __int16 *)(a1 + 238) / *(unsigned __int16 *)(a1 + 226);
if ( memcmp(v8, &unk_409F4, 0x10u) )
{
LABEL_17:
result = ((int (__fastcall *)(int, _DWORD *))loc_70150)(v10, v9 + 1);
if ( result )
return result;
goto LABEL_23;
}
goto LABEL_22;
}
if ( (v6 | 2) == 3 )
{
qmemcpy((void *)(a1 + 224), v5, 0x12u);
v9 = *(_DWORD **)(a1 + 4);
v10 = *(unsigned __int16 *)(a1 + 238);
HIDWORD(v12) = v9[4];
LODWORD(v12) = 8 * HIDWORD(v12);
HIDWORD(v12) >>= 29;
v9[5] = v12 / *(unsigned __int16 *)(a1 + 238) / *(unsigned __int16 *)(a1 + 226);
if ( v6 != 3 )
goto LABEL_17;
LABEL_22:
v9[1] = 5;
if ( v10 != 32 )
return 19;
goto LABEL_23;
}
v19 = v6 == 105;
if ( v6 != 105 )
v19 = v6 == 17;
if ( !v19 )
return 19;
qmemcpy((void *)(a1 + 224), v5, 0x12u);
if ( v5[8] != 2 )
return 19;
v20 = v5[1];
if ( v20 > 2 )
return 19;
v21 = v5[6];
if ( !v5[6] )
return 19;
v22 = v5[9];
if ( (int)(2 * (v21 / v20) - 7) < v22 )
return 19;
v27 = *(_DWORD **)(a1 + 4);
v23 = v27[5];
v24 = v27[4] / v21 * v22;
if ( v24 <= v23 )
v24 = (v23 / v21 + 1) * v21;
v27[1] = 2;
v27[5] = v24;
*(_WORD *)(a1 + 238) = 16;
*(_WORD *)(a1 + 224) = 1;
*(_DWORD *)(a1 + 324) = v22;
v25 = 2 * *(_WORD *)(a1 + 226);
*(_WORD *)(a1 + 236) = v25;
*(_DWORD *)(a1 + 232) = v25 * *(_DWORD *)(a1 + 228);
if ( (a2 & 0x200) != 0 )
{
v26 = 0;
}
else
{
v27[6] = v22;
v26 = v5[6];
}
*(_DWORD *)(a1 + 332) = v26;
LABEL_23:
v13 = *(_DWORD **)(a1 + 4);
if ( (unsigned int)(v13[1] - 1) > 4 )
return 19;
v14 = *(_DWORD *)(a1 + 332);
if ( v14 )
{
v15 = sub_BD580(*(int *)((char *)&dword_14C + (_DWORD)off_E8000), v14, "../../src/fmod_codec_wav.cpp", 386, 0);
*(_DWORD *)(a1 + 328) = v15;
if ( !v15 )
return 38;
v13 = *(_DWORD **)(a1 + 4);
}
v16 = *(_DWORD *)(a1 + 380);
v13[2] = *(unsigned __int16 *)(v16 + 2);
v13[3] = *(_DWORD *)(v16 + 4);
v17 = *(_QWORD *)(a1 + 156);
if ( HIDWORD(v17) > (unsigned int)v17 )
{
v13[7] = v17;
v13[8] = *(_DWORD *)(a1 + 160);
v13[9] = 2;
}
v18 = v6 == 105;
if ( v6 != 105 )
v18 = v6 == 17;
if ( v18 && (a2 & 0x200) != 0 )
{
*(_DWORD *)(a1 + 96) = 2;
*(_DWORD *)(a1 + 332) = *(unsigned __int16 *)(v16 + 12);
}
else
{
*(_DWORD *)(a1 + 96) = 0;
}
*(_DWORD *)(a1 + 12) = 0;
return 0;
}