//
// sub_76E624 from 0x76e624 to 0x76e7a0 (380 bytes)
//
// 0 xrefs:
//
// 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_76E624(int a1, wchar_t *s1, int a3)
{
int v4; // r8
wchar_t *v5; // r5
signed int v6; // r4
wchar_t *v7; // r3
char *v8; // r1
int v9; // r6
int v10; // r3
int v11; // r2
int v12; // r0
int v13; // r3
int v14; // r2
unsigned int v15; // r3
int v16; // r3
int v17; // r0
int v18; // r8
const wchar_t *v19; // r1
int v20; // r8
size_t v21; // r2
int v22; // r0
int v23; // r3
int v25; // r3
wchar_t v27; // t1
int v28; // r3
unsigned int v29; // r2
int v30; // r3
v4 = *(unsigned __int8 *)(a1 + 84);
v5 = s1;
v6 = a3;
if ( *(_BYTE *)(a1 + 84) )
{
v7 = *(wchar_t **)(a1 + 8);
if ( a3 <= 0 )
{
v9 = 0;
v8 = *(char **)(a1 + 4);
}
else
{
v8 = *(char **)(a1 + 4);
if ( v7 == (wchar_t *)v8 )
{
v6 = a3 - 1;
v27 = *v7++;
v9 = 1;
*v5++ = v27;
}
else
{
v9 = 0;
}
}
v10 = v8 - (char *)v7;
v11 = *(_DWORD *)(a1 + 76);
v12 = *(_DWORD *)(a1 + 80);
s1 = nullptr;
*(_BYTE *)(a1 + 84) = 0;
v13 = v11 + 4 * (v10 != 0);
v14 = *(_DWORD *)(a1 + 60);
*(_DWORD *)(a1 + 12) = v12;
*(_DWORD *)(a1 + 76) = v13;
*(_DWORD *)(a1 + 4) = v14;
*(_DWORD *)(a1 + 8) = v13;
}
else
{
v9 = *(unsigned __int8 *)(a1 + 70);
if ( *(_BYTE *)(a1 + 70) )
{
if ( (*(int (__fastcall **)(int, int))(*(_DWORD *)a1 + 52))(a1, -1) == -1 )
return v4;
v25 = *(_DWORD *)(a1 + 60);
v9 = v4;
*(_DWORD *)(a1 + 20) = v4;
*(_DWORD *)(a1 + 16) = v4;
*(_DWORD *)(a1 + 24) = v4;
*(_BYTE *)(a1 + 70) = v4;
*(_DWORD *)(a1 + 4) = v25;
*(_DWORD *)(a1 + 8) = v25;
*(_DWORD *)(a1 + 12) = v25;
}
}
v15 = *(_DWORD *)(a1 + 64);
if ( v15 <= 1 )
v16 = 1;
else
v16 = v15 - 1;
if ( v6 <= v16 )
return v9 + sub_761174((_DWORD *)a1, v5, v6);
v17 = *(_DWORD *)(a1 + 88);
if ( !v17 )
sub_772FE4(0);
v18 = (*(_DWORD *)(a1 + 44) >> 3) & 1;
if ( ((*(int (__fastcall **)(int, wchar_t *))(*(_DWORD *)v17 + 24))(v17, s1) & v18) == 0 )
return v9 + sub_761174((_DWORD *)a1, v5, v6);
v19 = *(const wchar_t **)(a1 + 8);
v20 = *(_DWORD *)(a1 + 12) - (_DWORD)v19;
v21 = v20 >> 2;
if ( v20 >> 2 )
{
v9 += v21;
v6 -= v21;
wmemcpy(v5, v19, v21);
v5 = (wchar_t *)((char *)v5 + v20);
*(_DWORD *)(a1 + 8) += v20;
}
while ( 1 )
{
v22 = sub_77A0DC(a1 + 36, v5, v6);
if ( v22 == -1 )
sub_77356C("basic_filebuf::xsgetn error reading the file");
if ( !v22 )
break;
v6 -= v22;
v9 += v22;
if ( !v6 )
goto LABEL_28;
v5 += v22;
}
if ( v6 )
{
v23 = *(_DWORD *)(a1 + 60);
*(_DWORD *)(a1 + 20) = 0;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 24) = 0;
*(_BYTE *)(a1 + 69) = 0;
*(_DWORD *)(a1 + 4) = v23;
*(_DWORD *)(a1 + 8) = v23;
*(_DWORD *)(a1 + 12) = v23;
return v9;
}
LABEL_28:
if ( (*(_DWORD *)(a1 + 44) & 0x11) != 0 )
{
v29 = *(_DWORD *)(a1 + 64);
v30 = *(_DWORD *)(a1 + 60);
*(_DWORD *)(a1 + 4) = v30;
*(_DWORD *)(a1 + 8) = v30;
*(_DWORD *)(a1 + 12) = v30;
if ( v29 > 1 )
{
*(_DWORD *)(a1 + 20) = v30;
*(_DWORD *)(a1 + 16) = v30;
*(_DWORD *)(a1 + 24) = v30 + 4 * (v29 + 0x3FFFFFFF);
goto LABEL_31;
}
}
else
{
v28 = *(_DWORD *)(a1 + 60);
*(_DWORD *)(a1 + 4) = v28;
*(_DWORD *)(a1 + 8) = v28;
*(_DWORD *)(a1 + 12) = v28;
}
*(_DWORD *)(a1 + 20) = 0;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 24) = 0;
LABEL_31:
*(_BYTE *)(a1 + 69) = 1;
return v9;
}