//
// sub_828554 from 0x828554 to 0x8287ae (602 bytes)
//
// 2 xrefs:
// > sub_8287C8 @ 0x82880a
// > sub_83B2EC @ 0x83b332
//
// 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 12:01:58 +0000
//
int __fastcall sub_828554(int *a1, int a2, char *a3, size_t a4)
{
int v5; // r7
size_t v6; // r4
char v8; // r3
int (__fastcall *v9)(char *, int, int, _DWORD); // r9
int (__fastcall *v10)(char *, int, int, int); // r10
int v11; // r11
int v12; // r5
int v13; // r2
int v14; // r0
int v15; // r0
void *v16; // r0
void *v17; // r5
int v18; // r3
void *v19; // r0
void *v20; // r8
int v21; // r3
int i; // r3
int v23; // r5
int v24; // r0
size_t v25; // r10
char *v26; // r0
char *v27; // r9
v5 = *a1;
v6 = a4;
if ( !a4 )
return 0;
if ( (*(_DWORD *)(v5 + 304) & 0x10) != 0 )
{
if ( *(_DWORD *)(v5 + 34476) != a2 )
return 56;
v25 = a4 + *(_DWORD *)(v5 + 34472);
v26 = (char *)off_D200B4(*(void **)(v5 + 34468), v25);
v27 = v26;
if ( v26 )
{
memcpy(&v26[*(_DWORD *)(v5 + 34472)], a3, v6);
*(_DWORD *)(v5 + 34468) = v27;
*(_DWORD *)(v5 + 34472) = v25;
return 0;
}
return 27;
}
v8 = a2;
v9 = (int (__fastcall *)(char *, int, int, _DWORD))(a2 & 1);
if ( (a2 & 1) != 0 )
{
v8 = a2;
v9 = *(int (__fastcall **)(char *, int, int, _DWORD))(v5 + 424);
}
if ( (v8 & 2) == 0 )
goto LABEL_19;
v10 = *(int (__fastcall **)(char *, int, int, int))(v5 + 428);
if ( v10 )
{
if ( v9 )
goto LABEL_11;
for ( i = *(_DWORD *)(v5 + 360); ; i = *(_DWORD *)(v5 + 360) )
{
LABEL_45:
v23 = v6;
if ( v6 >= 0x4000 )
v23 = 0x4000;
v24 = v10(a3, 1, v23, i);
if ( v24 == 268435457 )
break;
a3 += v24;
if ( v24 != v23 )
goto LABEL_38;
v6 -= v24;
if ( !v6 )
return 0;
}
LABEL_36:
v16 = off_D200AC(v6);
v17 = v16;
if ( v16 )
{
memcpy(v16, a3, v6);
v18 = *(_DWORD *)(v5 + 304);
*(_DWORD *)(v5 + 34468) = v17;
*(_DWORD *)(v5 + 304) = v18 | 0x10;
*(_DWORD *)(v5 + 34472) = v6;
*(_DWORD *)(v5 + 34476) = 2;
return 0;
}
return 27;
}
i = *(_DWORD *)(v5 + 360);
if ( !i )
{
LABEL_19:
if ( v9 )
goto LABEL_20;
goto LABEL_27;
}
v10 = *(int (__fastcall **)(char *, int, int, int))(v5 + 424);
if ( !v9 )
{
if ( v10 )
goto LABEL_45;
do
{
LABEL_27:
if ( v6 > 0x4000 )
v6 -= 0x4000;
else
v6 = 0;
}
while ( v6 );
return 0;
}
if ( v10 )
{
while ( 1 )
{
LABEL_11:
v11 = v6;
if ( v6 >= 0x4000 )
v11 = 0x4000;
v12 = v9(a3, 1, v11, *(_DWORD *)(v5 + 352));
v13 = v12;
if ( v12 == 268435457 )
break;
if ( v12 != v11 )
{
LABEL_35:
sub_828178(v5, "Failed writing body (%zu != %zu)", v12, v11);
return 23;
}
v14 = v10(a3, 1, v12, *(_DWORD *)(v5 + 360));
if ( v14 == 268435457 )
goto LABEL_36;
a3 += v14;
if ( v14 != v12 )
{
LABEL_38:
sub_828178(v5, "Failed writing header");
return 23;
}
v6 -= v14;
if ( !v6 )
return 0;
}
}
else
{
while ( 1 )
{
LABEL_20:
v11 = v6;
if ( v6 >= 0x4000 )
v11 = 0x4000;
v15 = v9(a3, 1, v11, *(_DWORD *)(v5 + 352));
if ( v15 == 268435457 )
break;
a3 += v15;
if ( v15 != v11 )
{
v12 = v15;
goto LABEL_35;
}
v6 -= v15;
if ( !v6 )
return 0;
}
}
if ( (*(_DWORD *)(a1[166] + 64) & 0x10) != 0 )
{
sub_828178(v5, "Write callback asked for PAUSE when not supported!", v13);
return 23;
}
v19 = off_D200AC(v6);
v20 = v19;
if ( !v19 )
return 27;
memcpy(v19, a3, v6);
v21 = *(_DWORD *)(v5 + 304);
*(_DWORD *)(v5 + 34468) = v20;
*(_DWORD *)(v5 + 304) = v21 | 0x10;
*(_DWORD *)(v5 + 34472) = v6;
*(_DWORD *)(v5 + 34476) = a2;
return 0;
}