//
// sub_614DD4 from 0x614dd4 to 0x614f62 (398 bytes)
//
// 7 xrefs:
// > sub_6154B8 @ 0x615a6c
// > sub_6154B8 @ 0x61692a
// > sub_6154B8 @ 0x616a98
// > sub_6154B8 @ 0x616bb8
// > sub_6154B8 @ 0x616c12
// > sub_63AC60 @ 0x63b136
// > sub_63BAD8 @ 0x63bcc6
//
// 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
//
int __fastcall sub_614DD4(void **a1, _DWORD *a2, _DWORD *a3, int a4, int a5)
{
char *v9; // r8
int v10; // r3
int v11; // r5
unsigned int v12; // r9
size_t v13; // r7
int v14; // r7
unsigned int v15; // r10
unsigned int v16; // r1
unsigned int v17; // r12
__int64 v18; // d16
unsigned int v19; // r9
char *v20; // r1
int v22; // r3
int v23; // [sp+Ch] [bp-10h]
unsigned int v24; // [sp+Ch] [bp-10h]
unsigned int v25; // [sp+14h] [bp-8h] BYREF
v9 = (char *)*a1;
v10 = a2[a5 + 104];
v11 = *(_DWORD *)(*a2 + 332);
v12 = (unsigned int)a1[2];
if ( ((*(_DWORD *)(a2[166] + 64) & 1) != 0 || a2[62] == 2) && a2[98] != 20 )
{
v13 = (size_t)a1[2];
if ( v12 >= 0x4000 )
v13 = 0x4000;
v23 = a2[a5 + 104];
memcpy((void *)(*a2 + 18053), v9, v13);
v10 = v23;
v9 = (char *)(*a2 + 18053);
}
else
{
v13 = (size_t)a1[2];
}
v14 = sub_61831C(a2, v10, v9, v13, &v25);
if ( v14 )
goto LABEL_18;
v15 = v12 - a4;
v16 = v25;
if ( v15 >= v25 )
v15 = v25;
v17 = v25 - v15;
if ( !*(_BYTE *)(*a2 + 912) )
goto LABEL_8;
v24 = v25 - v15;
sub_6189CC(*a2, 2, v9, v15, a2);
v17 = v24;
if ( v24 )
{
sub_6189CC(*a2, 4, &v9[v15], v24, a2);
v16 = v25;
v17 = v24;
LABEL_8:
*a3 += v16;
if ( v11 )
{
LABEL_9:
*(_QWORD *)(v11 + 40) += v17;
if ( v12 != v16 )
{
v18 = *(_QWORD *)(v11 + 8);
v19 = v12 - v16;
v20 = (char *)*a1 + v16;
*(_DWORD *)(v11 + 64) = *(_DWORD *)(*a2 + 34728);
v22 = *(_DWORD *)(*a2 + 34732);
*(_QWORD *)(v11 + 80) = v18;
*(_DWORD *)(v11 + 68) = v22;
*(_DWORD *)(v11 + 72) = *(_DWORD *)(v11 + 16);
*(_DWORD *)(*a2 + 34728) = sub_614074;
*(_DWORD *)(*a2 + 34732) = a2;
*(_DWORD *)(v11 + 8) = v19;
*(_DWORD *)(v11 + 16) = v20;
*(_DWORD *)(v11 + 92) = a1;
*(_DWORD *)(v11 + 12) = 0;
*(_DWORD *)(v11 + 88) = 1;
return 0;
}
*(_DWORD *)(v11 + 88) = 2;
goto LABEL_18;
}
goto LABEL_15;
}
v16 = v25;
*a3 += v25;
if ( v11 )
goto LABEL_9;
LABEL_15:
if ( v12 != v16 )
return 55;
sub_63E994(a2);
LABEL_18:
off_ABAEB0(*a1);
off_ABAEB0(a1);
return v14;
}