//
// ssl_choose_server_version from 0x9bc064 to 0x9bc31c (696 bytes)
//
// 3 xrefs:
// > tls_process_client_hello @ 0x9bd628
// > tls_process_client_hello @ 0x9bdd14
// > ??> @ 0x76f2c
//
// 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:07:02 +0000
//
int __fastcall ssl_choose_server_version(int *a1)
{
_DWORD *v1; // r2
int v2; // r6
int *v3; // r4
int v4; // r3
int v6; // r0
int *v7; // r0
int v8; // r2
int *v9; // r9
int v10; // r8
int v11; // r0
int v12; // t1
int (__fastcall *v13)(int); // r1
int v14; // r2
int v15; // t1
int result; // r0
int v17; // r3
int v18; // r2
int v19; // r3
int v20; // r3
int v21; // r3
v1 = (_DWORD *)a1[1];
v2 = a1[81];
if ( *v1 == 0x10000 )
{
v3 = &dword_D15FD4;
goto LABEL_4;
}
if ( *v1 == 0x1FFFF )
{
v3 = &dword_D15FA4;
LABEL_4:
v4 = *v3;
if ( !*v3 )
return 396;
v6 = 0;
while ( 1 )
{
v13 = (int (__fastcall *)(int))v3[2];
if ( !v13 )
goto LABEL_13;
if ( v2 == v4 )
break;
if ( (*(_DWORD *)(*(_DWORD *)(a1[1] + 100) + 52) & 8) != 0 )
{
if ( v2 == 256 )
{
if ( v4 == 256 )
break;
v14 = 65280;
}
else
{
v14 = v2;
if ( v4 == 256 )
v4 = 65280;
}
if ( v4 >= v14 )
break;
v15 = v3[3];
v3 += 3;
v4 = v15;
if ( !v15 )
{
LABEL_22:
if ( v6 )
return 258;
else
return 396;
}
}
else
{
if ( v2 >= v4 )
break;
LABEL_13:
v12 = v3[3];
v3 += 3;
v4 = v12;
if ( !v12 )
goto LABEL_22;
}
}
v7 = (int *)v13(v6);
v8 = a1[77];
v9 = v7;
v10 = *v7;
if ( v8 && v10 != v8 )
{
if ( (*(_DWORD *)(*(_DWORD *)(a1[1] + 100) + 52) & 8) != 0 )
{
if ( v10 == 256 )
{
if ( v8 == 256 )
goto LABEL_11;
v19 = 65280;
}
else
{
v19 = *v7;
if ( v8 == 256 )
v8 = 65280;
}
if ( v19 > v8 )
goto LABEL_12;
}
else if ( v10 < v8 )
{
LABEL_12:
v6 = 1;
goto LABEL_13;
}
}
LABEL_11:
v11 = ssl_security((int)a1, 9);
if ( !v11 )
goto LABEL_12;
v20 = a1[78];
if ( v20 && v10 != v20 )
{
if ( (*(_DWORD *)(*(_DWORD *)(a1[1] + 100) + 52) & 8) != 0 )
{
if ( v10 == 256 )
{
if ( v20 == 256 )
goto LABEL_12;
v10 = 65280;
}
else if ( v20 == 256 )
{
v20 = 65280;
}
if ( v10 <= v20 || (v9[2] & a1[75]) != 0 )
goto LABEL_12;
goto LABEL_43;
}
if ( v10 >= v20 )
goto LABEL_12;
}
if ( (v9[2] & a1[75]) != 0 )
goto LABEL_12;
LABEL_43:
v21 = v9[1];
if ( ((v21 & 2) == 0 || (*(_DWORD *)(a1[50] + 16) & 0x30000) == 0) && ((v21 & 1) == 0 || !FIPS_mode(v11)) )
{
*a1 = *v3;
a1[1] = (int)v9;
return 0;
}
goto LABEL_12;
}
v17 = *a1;
v18 = *(_DWORD *)(v1[25] + 52) & 8;
if ( v2 == *a1 )
return 0;
if ( v18 )
{
if ( v2 != 256 )
{
if ( v17 == 256 )
v17 = 65280;
goto LABEL_30;
}
if ( v17 != 256 )
{
v2 = 65280;
LABEL_30:
result = 266;
if ( v17 >= v2 )
return 0;
return result;
}
return 0;
}
result = 266;
if ( v2 >= v17 )
return 0;
return result;
}