//
// sub_7405A4 from 0x7405a4 to 0x74084e (682 bytes)
//
// 3 xrefs:
// > gzopen @ 0x74085a
// > gzopen64 @ 0x740862
// > gzdopen @ 0x74088a
//
// 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
//
_DWORD *__fastcall sub_7405A4(const char *a1, int a2, unsigned __int8 *a3)
{
_DWORD *v6; // r0
_DWORD *v7; // r6
int v8; // r4
int v9; // r11
int v10; // r10
int v11; // t1
int v12; // r3
size_t v13; // r5
char *v14; // r0
int v15; // r3
int v16; // r1
int v17; // r0
int v18; // r2
int v19; // r0
void *v20; // r0
int v22; // t1
int v23; // t1
int v24; // t1
int v25; // t1
int v26; // t1
int v27; // t1
int v28; // t1
int v29; // t1
int v30; // t1
__off_t v31; // r0
int v32; // r1
if ( !a1 )
return nullptr;
v6 = malloc(0x8Cu);
v7 = v6;
if ( !v6 )
return nullptr;
v8 = *a3;
v6[6] = 0;
v6[20] = 0;
v6[3] = 0;
v6[16] = 0;
v6[10] = 0;
v6[7] = 0x2000;
v6[15] = -1;
if ( !v8 )
goto LABEL_39;
v9 = 0;
v10 = 0;
do
{
while ( 2 )
{
if ( (unsigned __int8)(v8 - 48) > 9u )
{
switch ( v8 )
{
case '+':
goto LABEL_39;
case 'F':
v30 = *++a3;
v8 = v30;
v6[16] = 4;
if ( !v30 )
goto LABEL_10;
continue;
case 'R':
v29 = *++a3;
v8 = v29;
v6[16] = 3;
if ( !v29 )
goto LABEL_10;
continue;
case 'T':
v28 = *++a3;
v8 = v28;
v6[10] = 1;
if ( !v28 )
goto LABEL_10;
continue;
case 'a':
v27 = *++a3;
v8 = v27;
v6[3] = 1;
if ( !v27 )
goto LABEL_10;
continue;
case 'e':
v25 = *++a3;
v8 = v25;
v10 = 1;
if ( !v25 )
goto LABEL_10;
continue;
case 'f':
v24 = *++a3;
v8 = v24;
v6[16] = 1;
if ( !v24 )
goto LABEL_10;
continue;
case 'h':
v6[16] = 2;
goto LABEL_9;
case 'r':
v23 = *++a3;
v8 = v23;
v6[3] = 7247;
if ( !v23 )
goto LABEL_10;
continue;
case 'w':
v22 = *++a3;
v8 = v22;
v6[3] = 31153;
if ( !v22 )
goto LABEL_10;
continue;
case 'x':
v26 = *++a3;
v8 = v26;
v9 = 1;
if ( !v26 )
goto LABEL_10;
continue;
default:
goto LABEL_9;
}
}
break;
}
v6[15] = v8 - 48;
LABEL_9:
v11 = *++a3;
v8 = v11;
}
while ( v11 );
LABEL_10:
v12 = v6[3];
if ( !v12 )
goto LABEL_39;
if ( v12 != 7247 )
goto LABEL_14;
if ( v6[10] )
{
LABEL_39:
free(v7);
return nullptr;
}
v6[10] = 1;
LABEL_14:
v13 = strlen(a1) + 1;
v14 = (char *)malloc(v13);
v7[5] = v14;
if ( !v14 )
goto LABEL_39;
snprintf(v14, v13, "%s", a1);
v15 = v7[3];
if ( v10 )
v16 = 655360;
else
v16 = 0x20000;
if ( v15 != 7247 )
{
v17 = 705;
v18 = 1217;
if ( !v9 )
{
v17 = 577;
v18 = 1089;
}
if ( v15 == 31153 )
v18 = v17;
v16 |= v18;
}
if ( a2 >= 0 )
{
v7[4] = a2;
v19 = a2;
goto LABEL_27;
}
v19 = open(a1, v16, 438);
v7[4] = v19;
if ( v19 == -1 )
{
free((void *)v7[5]);
goto LABEL_39;
}
v15 = v7[3];
LABEL_27:
if ( v15 == 1 )
{
v7[3] = 31153;
}
else if ( v15 == 7247 )
{
v31 = lseek(v19, 0, 1);
v32 = v7[3];
v7[12] = v31;
if ( v31 == -1 )
v7[12] = 0;
*v7 = 0;
if ( v32 == 7247 )
{
v7[13] = 0;
v7[14] = 0;
v7[11] = 0;
}
goto LABEL_31;
}
*v7 = 0;
LABEL_31:
v20 = (void *)v7[20];
v7[18] = 0;
if ( v20 )
{
if ( v7[19] != -4 )
free(v20);
v7[20] = 0;
}
v7[19] = 0;
v7[2] = 0;
v7[22] = 0;
return v7;
}