//
// sub_8791C0 from 0x8791c0 to 0x879c20 (2656 bytes)
//
// 3 xrefs:
// > sub_879C94 @ 0x879cc8
// > ??> @ 0xac12ac
// > ??> @ 0xac12d4
//
// 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_8791C0(int a1, _DWORD *a2, int *a3)
{
int v3; // r8
size_t *v5; // r5
int v6; // r2
_DWORD *v7; // r4
int v8; // r0
int v10; // r9
int v11; // r10
const char *v12; // r4
int v13; // r0
int v14; // r3
unsigned __int8 *v15; // r12
bool v16; // zf
int v17; // r3
int v18; // r2
int v19; // t1
bool v20; // zf
int v21; // r1
bool v22; // r2
int v23; // r10
int v24; // lr
__int16 v25; // r12
const char *v26; // r9
const char *v27; // r1
int v28; // r3
int v29; // t1
__int16 v30; // r2
__int16 v31; // r3
int v32; // t1
char *ii; // r2
int v34; // r4
char *i; // r3
int v36; // t1
__int16 v37; // r2
char *j; // r12
char *k; // r0
int m; // r1
int v41; // r0
const char *v42; // r2
const char *v43; // r11
char *jj; // r1
char *v45; // r2
int v46; // t1
int v47; // r0
__int16 v48; // r1
char *v49; // r2
char *v50; // r10
int v51; // t1
int v52; // t1
char *v53; // r12
char *v54; // r2
int v55; // t1
size_t v56; // r0
char *v57; // r0
size_t v58; // r0
_DWORD *v59; // r1
char *n; // r1
int v61; // t1
bool v62; // zf
int v63; // r11
_BYTE *v64; // r0
const char *v65; // r0
int kk; // r2
int v67; // r2
int v69; // [sp+10h] [bp-34h]
_DWORD *section; // [sp+20h] [bp-24h]
char *v72; // [sp+24h] [bp-20h]
char *v73; // [sp+2Ch] [bp-18h] BYREF
_BYTE v74[20]; // [sp+30h] [bp-14h] BYREF
v3 = 0;
v69 = *(_DWORD *)(a1 + 8);
v73 = nullptr;
v5 = (size_t *)BUF_MEM_new();
if ( v5 )
{
v73 = (char *)CRYPTO_strdup("default", (int)"crypto/conf/conf_def.c", 177);
if ( !v73 )
{
v6 = 179;
LABEL_6:
v7 = nullptr;
ERR_put_error(14, 121, 65, (int)"crypto/conf/conf_def.c", v6);
v3 = 0;
goto LABEL_7;
}
if ( !CONF_new_data(a1) )
{
v6 = 184;
goto LABEL_6;
}
section = CONF_new_section(a1, v73);
if ( section )
{
v10 = 0;
v11 = 0;
while ( 1 )
{
if ( !BUF_MEM_grow(v5, v11 + 512) )
{
v7 = nullptr;
ERR_put_error(14, 121, 7, (int)"crypto/conf/conf_def.c", 198);
goto LABEL_7;
}
v12 = (const char *)(v5[1] + v11);
*v12 = 0;
BIO_gets(a2, (int)v12, 511);
*((_BYTE *)v12 + 511) = 0;
v13 = strlen(v12);
if ( !(v13 | v10) )
{
BUF_MEM_free((int)v5);
CRYPTO_free(v73, (int)"crypto/conf/conf_def.c", 343);
return 1;
}
if ( v13 <= 0 )
{
v17 = v13;
v22 = 1;
LABEL_38:
if ( v13 )
v13 = v22;
else
v13 = 0;
if ( !v13 )
goto LABEL_28;
LABEL_42:
v11 += v17;
if ( v11 > 0 )
{
v13 = 1;
goto LABEL_32;
}
LABEL_37:
v10 = 1;
}
else
{
v14 = (unsigned __int8)v12[v13 - 1];
v15 = (unsigned __int8 *)&v12[v13 - 1];
v16 = v14 == 10;
if ( v14 != 10 )
v16 = v14 == 13;
v17 = v13;
if ( !v16 )
goto LABEL_42;
while ( --v17 )
{
v19 = *--v15;
v18 = v19;
v20 = v19 == 10;
if ( v19 != 10 )
v20 = v18 == 13;
if ( !v20 )
{
v22 = v13 == v17;
goto LABEL_38;
}
}
LABEL_28:
v11 += v17;
v12[v17] = 0;
++v3;
if ( v11 > 0 )
v13 = 0;
else
v12 = (const char *)v5[1];
if ( v11 <= 0 )
{
LABEL_45:
v23 = *(unsigned __int8 *)v12;
v24 = *(_DWORD *)(a1 + 4);
v25 = *(_WORD *)(v24 + 2 * v23);
v26 = v12;
if ( (v25 & 0x800) != 0 )
{
v27 = v12;
}
else if ( (v25 & 0x10) != 0 )
{
v27 = v12;
while ( 1 )
{
v29 = *(unsigned __int8 *)++v27;
v28 = v29;
v30 = *(_WORD *)(v24 + 2 * v29);
if ( (v30 & 0x800) != 0 )
break;
if ( (v30 & 0x10) == 0 )
goto LABEL_72;
}
}
else
{
v30 = *(_WORD *)(v24 + 2 * v23);
v28 = *(unsigned __int8 *)v12;
v27 = v12;
LABEL_72:
while ( (v30 & 0x80) == 0 )
{
if ( (v30 & 0x400) == 0 )
{
while ( 1 )
{
if ( (v30 & 0x40) != 0 )
{
v63 = v28;
while ( 1 )
{
v28 = *((unsigned __int8 *)v27 + 1);
v64 = v27 + 1;
v30 = *(_WORD *)(v24 + 2 * v28);
if ( (v30 & 8) != 0 )
break;
if ( v63 == v28 )
goto LABEL_140;
++v27;
if ( (v30 & 0x20) != 0 )
{
v28 = (unsigned __int8)v64[1];
v27 = v64 + 1;
v30 = *(_WORD *)(v24 + 2 * v28);
if ( (v30 & 8) != 0 )
goto LABEL_72;
}
}
++v27;
if ( v63 != v28 )
goto LABEL_72;
LABEL_140:
v28 = (unsigned __int8)v64[1];
v27 = v64 + 1;
v30 = *(_WORD *)(v24 + 2 * v28);
goto LABEL_72;
}
if ( (v30 & 0x20) == 0 )
break;
v28 = *((unsigned __int8 *)v27 + 1);
v30 = *(_WORD *)(v24 + 2 * v28);
if ( (v30 & 8) != 0 )
++v27;
else
v28 = *((unsigned __int8 *)v27 + 2);
if ( (v30 & 8) == 0 )
{
v30 = *(_WORD *)(v24 + 2 * v28);
v27 += 2;
}
if ( (v30 & 0x80) != 0 )
goto LABEL_50;
if ( (v30 & 0x400) != 0 )
goto LABEL_83;
}
if ( (v30 & 8) == 0 )
{
v28 = *(unsigned __int8 *)++v27;
v30 = *(_WORD *)(v24 + 2 * v28);
continue;
}
v31 = *(_WORD *)(v24 + 2 * v23);
goto LABEL_52;
}
LABEL_83:
v41 = v28;
v28 = *(unsigned __int8 *)++v27;
v30 = *(_WORD *)(v24 + 2 * v28);
if ( (v30 & 8) != 0 )
{
LABEL_131:
if ( v41 == v28 )
{
v28 = *(unsigned __int8 *)++v27;
v30 = *(_WORD *)(v24 + 2 * (__int16)v28);
}
}
else
{
while ( 1 )
{
v42 = v27;
if ( v41 == v28 )
{
v28 = *((unsigned __int8 *)v27 + 1);
v42 = v27 + 1;
if ( v41 != v28 )
break;
}
v28 = *((unsigned __int8 *)v42 + 1);
v27 = v42 + 1;
v30 = *(_WORD *)(v24 + 2 * v28);
if ( (v30 & 8) != 0 )
goto LABEL_131;
}
++v27;
v30 = *(_WORD *)(v24 + 2 * (__int16)v28);
}
}
}
LABEL_50:
*v27 = 0;
v23 = *(unsigned __int8 *)v12;
v24 = *(_DWORD *)(a1 + 4);
v31 = *(_WORD *)(v24 + 2 * v23);
LABEL_52:
while ( (v31 & 0x18) == 0x10 )
{
v32 = *(unsigned __int8 *)++v26;
v23 = v32;
v31 = *(_WORD *)(v24 + 2 * v32);
}
if ( (v31 & 8) != 0 )
goto LABEL_122;
if ( v23 == 91 )
{
v34 = *((unsigned __int8 *)v26 + 1);
for ( i = (char *)(v26 + 1); ; ++i )
{
v37 = *(_WORD *)(v24 + 2 * v34);
if ( (v37 & 0x18) != 0x10 )
break;
v36 = (unsigned __int8)i[1];
v34 = v36;
}
for ( j = i; ; j = n )
{
for ( k = j; ; ++k )
{
for ( m = v37 & 0x307; (v37 & 0x20) != 0; m = v37 & 0x307 )
{
v34 = (unsigned __int8)k[1];
v37 = *(_WORD *)(v24 + 2 * v34);
if ( (v37 & 8) != 0 )
++k;
else
v34 = (unsigned __int8)k[2];
if ( (v37 & 8) == 0 )
{
v37 = *(_WORD *)(v24 + 2 * v34);
k += 2;
}
}
if ( !m )
break;
v34 = (unsigned __int8)k[1];
v37 = *(_WORD *)(v24 + 2 * v34);
}
for ( n = k; (v37 & 0x18) == 0x10; v37 = *(_WORD *)(v24 + 2 * v61) )
{
v61 = (unsigned __int8)*++n;
v34 = v61;
}
if ( v34 == 93 )
break;
v62 = v34 == 0;
if ( v34 )
v62 = j == n;
if ( v62 )
{
v7 = nullptr;
ERR_put_error(14, 121, 100, (int)"crypto/conf/conf_def.c", 267);
goto LABEL_7;
}
}
*k = 0;
if ( sub_878BE4(a1, nullptr, (void **)&v73, i) )
{
section = (_DWORD *)CONF_get_section(a1, (int)v73);
if ( section )
goto LABEL_122;
v7 = CONF_new_section(a1, v73);
section = v7;
if ( v7 )
goto LABEL_122;
ERR_put_error(14, 121, 103, (int)"crypto/conf/conf_def.c", 277);
}
else
{
v7 = nullptr;
}
goto LABEL_7;
}
for ( ii = (char *)v26; ; ++ii )
{
v43 = (const char *)(v31 & 0x307);
if ( (v31 & 0x20) != 0 )
break;
if ( (v31 & 0x307) == 0 )
goto LABEL_99;
LABEL_90:
v23 = (unsigned __int8)ii[1];
v31 = *(_WORD *)(v24 + 2 * v23);
}
do
{
v23 = (unsigned __int8)ii[1];
v31 = *(_WORD *)(v24 + 2 * v23);
if ( (v31 & 8) != 0 )
++ii;
else
v23 = (unsigned __int8)ii[2];
if ( (v31 & 8) == 0 )
{
v31 = *(_WORD *)(v24 + 2 * v23);
ii += 2;
}
v43 = (const char *)(v31 & 0x307);
}
while ( (v31 & 0x20) != 0 );
if ( (v31 & 0x307) != 0 )
goto LABEL_90;
LABEL_99:
jj = ii;
if ( v23 != 58 )
goto LABEL_100;
if ( ii[1] == 58 )
{
*ii = (char)v43;
v65 = ii + 2;
v23 = (unsigned __int8)ii[2];
v24 = *(_DWORD *)(a1 + 4);
v31 = *(_WORD *)(v24 + 2 * v23);
for ( jj = ii + 2; ; ++jj )
{
for ( kk = v31 & 0x307; (v31 & 0x20) != 0; kk = v31 & 0x307 )
{
v23 = (unsigned __int8)jj[1];
v31 = *(_WORD *)(v24 + 2 * v23);
if ( (v31 & 8) != 0 )
++jj;
else
v23 = (unsigned __int8)jj[2];
if ( (v31 & 8) == 0 )
{
v31 = *(_WORD *)(v24 + 2 * v23);
jj += 2;
}
}
if ( !kk )
break;
v23 = (unsigned __int8)jj[1];
v31 = *(_WORD *)(v24 + 2 * v23);
}
v43 = v26;
v26 = v65;
LABEL_100:
if ( (v31 & 0x18) == 0x10 )
goto LABEL_101;
v45 = jj;
}
else
{
if ( (v31 & 0x18) != 0x10 )
{
LABEL_146:
ERR_put_error(14, 121, 101, (int)"crypto/conf/conf_def.c", 294);
v7 = nullptr;
goto LABEL_7;
}
LABEL_101:
v45 = jj;
do
{
v46 = (unsigned __int8)*++v45;
v23 = v46;
}
while ( (*(_WORD *)(v24 + 2 * v46) & 0x18) == 0x10 );
}
if ( v23 != 61 )
goto LABEL_146;
*jj = 0;
v47 = *(_DWORD *)(a1 + 4);
v48 = *(_WORD *)(v47 + 2 * (unsigned __int8)v45[1]);
v49 = v45 + 1;
v50 = v49;
if ( (v48 & 0x18) == 0x10 )
{
do
v51 = (unsigned __int8)*++v50;
while ( (*(_WORD *)(v47 + 2 * v51) & 0x18) == 0x10 );
}
if ( (v48 & 8) == 0 )
{
do
v52 = (unsigned __int8)*++v49;
while ( (*(_WORD *)(v47 + 2 * v52) & 8) == 0 );
}
v53 = v49 - 1;
if ( v49 - 1 == v50 )
{
LABEL_113:
v53 = v50;
}
else if ( (*(_WORD *)(v47 + 2 * (unsigned __int8)*(v49 - 1)) & 0x10) != 0 )
{
v54 = v49 - 2;
do
{
v53 = v54;
if ( v54 == v50 )
goto LABEL_113;
v55 = (unsigned __int8)*v54--;
}
while ( (*(_WORD *)(v47 + 2 * v55) & 0x10) != 0 );
}
v53[1] = 0;
v7 = CRYPTO_malloc(&byte_9[3], (int)"crypto/conf/conf_def.c", 308);
if ( !v7 )
{
v67 = 309;
LABEL_173:
ERR_put_error(14, 121, 65, (int)"crypto/conf/conf_def.c", v67);
goto LABEL_7;
}
if ( !v43 )
v43 = v73;
v56 = strlen(v26);
v57 = (char *)CRYPTO_malloc((void *)(v56 + 1), (int)"crypto/conf/conf_def.c", 314);
v7[1] = v57;
v7[2] = 0;
if ( !v57 )
{
v67 = 317;
goto LABEL_173;
}
v72 = v57;
v58 = strlen(v26);
OPENSSL_strlcpy(v72, v26, v58 + 1);
if ( !sub_878BE4(a1, v43, (void **)v7 + 2, v50) )
goto LABEL_7;
if ( !strcmp(v43, v73) )
{
v59 = section;
}
else
{
v59 = (_DWORD *)CONF_get_section(a1, (int)v43);
if ( !v59 )
{
v59 = CONF_new_section(a1, v43);
if ( !v59 )
{
ERR_put_error(14, 121, 103, (int)"crypto/conf/conf_def.c", 330);
goto LABEL_7;
}
}
}
if ( !CONF_add_string(a1, v59, v7) )
{
ERR_put_error(14, 121, 65, (int)"crypto/conf/conf_def.c", 336);
goto LABEL_7;
}
LABEL_122:
v10 = 0;
v11 = 0;
}
else
{
LABEL_32:
v12 = (const char *)v5[1];
v21 = *(_DWORD *)(a1 + 4);
if ( (*(_WORD *)(v21 + 2 * (unsigned __int8)v12[v11 - 1]) & 0x20) == 0
|| v11 != 1 && (*(_WORD *)(v21 + 2 * (unsigned __int8)v12[v11 - 2]) & 0x20) != 0 )
{
if ( v13 )
goto LABEL_37;
goto LABEL_45;
}
--v11;
v10 = 1;
}
}
}
}
v7 = nullptr;
ERR_put_error(14, 121, 103, (int)"crypto/conf/conf_def.c", 190);
v3 = 0;
}
else
{
ERR_put_error(14, 121, 7, (int)"crypto/conf/conf_def.c", 173);
v7 = nullptr;
v3 = 0;
}
LABEL_7:
BUF_MEM_free((int)v5);
CRYPTO_free(v73, (int)"crypto/conf/conf_def.c", 347);
if ( a3 )
*a3 = v3;
BIO_snprintf(v74, 0xDu, "%ld", v3);
ERR_add_error_data(2, "line ", v74);
v8 = *(_DWORD *)(a1 + 8);
if ( v8 != v69 )
{
CONF_free(v8);
*(_DWORD *)(a1 + 8) = 0;
}
if ( v7 )
{
CRYPTO_free((void *)v7[1], (int)"crypto/conf/conf_def.c", 357);
CRYPTO_free((void *)v7[2], (int)"crypto/conf/conf_def.c", 358);
CRYPTO_free(v7, (int)"crypto/conf/conf_def.c", 359);
}
return 0;
}