//
// sub_828DE8 from 0x828de8 to 0x828fbc (468 bytes)
//
// 2 xrefs:
// > sub_82A1B4 @ 0x82a288
// > sub_82AC68 @ 0x82afd6
//
// 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_828DE8(int a1, int a2)
{
int v2; // r6
size_t v3; // r5
__int64 *v4; // r8
int v5; // r7
__int64 v6; // r10
int (__fastcall *v7)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // r1
int v8; // r0
int result; // r0
int v10; // r0
_QWORD *v11; // r4
__int64 v12; // r0
size_t v13; // r2
int (__fastcall **v14)(size_t, int, unsigned int, _DWORD); // r3
__int64 v15; // r10
_DWORD *v16; // r9
__int64 v17; // r4
size_t v18; // r6
int (__fastcall **v19)(size_t, int, unsigned int, _DWORD); // r7
unsigned int v20; // r0
_BOOL4 v21; // r3
__int64 v22; // r0
bool v23; // cc
int v24; // r3
unsigned int v25; // r4
int v26; // [sp+14h] [bp-10h]
int v27; // [sp+18h] [bp-Ch]
int v28; // [sp+1Ch] [bp-8h]
v2 = a1;
v3 = *(_DWORD *)a1;
v4 = (__int64 *)(*(_DWORD *)a1 + 34688);
v5 = *(_DWORD *)(*(_DWORD *)a1 + 332);
v6 = *v4;
if ( !*v4 )
goto LABEL_10;
if ( a2 )
{
if ( v6 < 1 )
goto LABEL_10;
}
else if ( v6 < 0 )
{
result = sub_84A864(a1 + 1088, "SIZE %s", *(const char **)(a1 + 1160));
if ( !result )
*(_DWORD *)(v2 + 1192) = 25;
return result;
}
*(_BYTE *)(v3 + 892) = 1;
v7 = *(int (__fastcall **)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD))(a1 + 748);
if ( !v7 )
{
v11 = (_QWORD *)(v3 + 34712);
v12 = *(_QWORD *)(v3 + 34712);
if ( v12 < 1 )
{
result = sub_84A864(v2 + 1088, "APPE %s", *(_DWORD *)(v2 + 1160));
LABEL_12:
if ( !result )
*(_DWORD *)(v2 + 1192) = 33;
return result;
}
goto LABEL_19;
}
v8 = v7(*(_DWORD *)(a1 + 752), v7, v6, HIDWORD(v6), 0);
if ( !v8 )
{
LABEL_16:
v11 = (_QWORD *)(v3 + 34712);
v12 = *(_QWORD *)(v3 + 34712);
if ( v12 >= 1 )
{
v6 = *v4;
LABEL_19:
*v11 = v12 - v6;
if ( (int)(((unsigned __int64)(v12 - v6) >> 32) - ((_DWORD)v12 == (_DWORD)v6)) < 0 != __OFSUB__(
(unsigned __int64)(v12 - v6) >> 32,
0,
(_DWORD)v12 != (_DWORD)v6) )
{
sub_8280FC(v3, "File already completely uploaded\n");
sub_83AA00(v2, -1, -1, -1, 0, 0, -1, 0);
*(_DWORD *)(v5 + 12) = 2;
*(_DWORD *)(v2 + 1192) = 0;
return 0;
}
}
LABEL_10:
v10 = v2 + 1088;
if ( *(_BYTE *)(v3 + 892) )
result = sub_84A864(v10, "APPE %s", *(_DWORD *)(v2 + 1160));
else
result = sub_84A864(v10, "STOR %s", *(_DWORD *)(v2 + 1160));
goto LABEL_12;
}
if ( v8 == 2 )
{
v13 = v3 + 1668;
v26 = v3;
v14 = (int (__fastcall **)(size_t, int, unsigned int, _DWORD))(v3 + 34728);
v27 = v5;
v15 = 0;
v28 = v2;
v16 = (_DWORD *)(v3 + 34732);
v17 = *v4;
v18 = v13;
v19 = v14;
while ( 1 )
{
v22 = v17 - v15;
v23 = v17 - v15 > 0x4000;
v24 = -(int)(((unsigned __int64)(v17 - v15) >> 32) + ((unsigned int)(v17 - v15) > 0x4000));
v25 = 0x4000;
if ( !v23 )
v25 = nullsub_3(v22, HIDWORD(v22), 0x4000, v24);
v20 = (*v19)(v18, 1, v25, *v16);
v15 += v20;
v21 = v20 == 0;
if ( v25 < v20 )
v21 = 1;
if ( v21 )
break;
v17 = *v4;
if ( v15 >= *v4 )
{
v3 = v26;
v5 = v27;
v2 = v28;
goto LABEL_16;
}
}
sub_828178(v26, "Failed to read data");
return 31;
}
else
{
sub_828178(v3, "Could not seek stream");
return 31;
}
}