//
// sub_BA80C0 from 0xba80c0 to 0xba8820 (1888 bytes)
//
// 1 xrefs:
// > sub_BA7AFC @ 0xba7b4c
//
// 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
//
__int64 __fastcall sub_BA80C0(__int64 a1)
{
__int64 v1; // x19
int v2; // w20
unsigned int v4; // w23
__int64 result; // x0
int v6; // w21
__int64 v7; // x21
__int64 v8; // x0
__int64 v9; // x20
__int64 v10; // x0
__int64 v11; // x20
size_t v12; // x0
__int64 v13; // x21
size_t v14; // x0
int v15; // w0
unsigned __int64 v16; // x4
const char *v17; // x2
size_t v18; // x27
unsigned __int8 *v19; // x0
int v20; // w1
unsigned __int8 *v21; // x1
__int64 v22; // x20
unsigned __int8 *v23; // x6
char v24; // w4
int v25; // t1
unsigned __int8 *v26; // x21
int v27; // w0
int v28; // w0
int v29; // w1
void *v30; // x1
const char *v31; // x2
int v32; // w3
unsigned __int8 *v33; // x2
__int64 v34; // x1
const void *v35; // x21
int v36; // t1
size_t v37; // x1
size_t v38; // x20
void *v39; // x0
unsigned int v40; // [xsp+78h] [xbp+78h]
unsigned int v41; // [xsp+78h] [xbp+78h]
size_t v42; // [xsp+78h] [xbp+78h]
unsigned int v43; // [xsp+8Ch] [xbp+8Ch] BYREF
__int64 v44; // [xsp+90h] [xbp+90h] BYREF
__int64 v45; // [xsp+98h] [xbp+98h]
v1 = a1 + 1560;
v2 = *(_DWORD *)(a1 + 1672);
v44 = 0;
v4 = *(_DWORD *)(a1 + 608);
if ( v2 != 4 )
{
if ( *(_QWORD *)(a1 + 1608) )
return sub_BAAA28(v1);
while ( 1 )
{
result = sub_BAA6B8(v4, v1, &v43, &v44);
if ( (_DWORD)result )
return result;
if ( !v43 )
return 0;
v6 = *(_DWORD *)(v1 + 112);
switch ( v6 )
{
case 1:
v13 = *(_QWORD *)a1;
v41 = v43;
v14 = strlen((const char *)(*(_QWORD *)a1 + 2824LL));
if ( v41 != 43 )
{
sub_B7B690(v13, "Got unexpected pop3-server response");
return 8;
}
if ( v14 <= 3 )
goto LABEL_44;
v16 = v14 - 2;
if ( *(_BYTE *)(v13 + 2824 + v14 - 2) != 62 || v16 <= 3 )
goto LABEL_44;
v32 = *(unsigned __int8 *)(v13 + 2827);
v33 = (unsigned __int8 *)(v13 + 2828);
v34 = 3;
v35 = (const void *)(v13 + 2827);
if ( v32 == 60 )
goto LABEL_114;
while ( v16 != ++v34 )
{
v35 = v33;
v36 = *v33++;
if ( v36 == 60 )
{
LABEL_114:
v37 = v14 - v34;
v38 = v37 - 1;
if ( v37 != 1 )
{
v39 = off_1231020(1u, v37);
*(_QWORD *)(v1 + 176) = v39;
if ( v39 )
{
memcpy(v39, v35, v38);
*(_BYTE *)(*(_QWORD *)(v1 + 176) + v38) = 0;
*(_DWORD *)(v1 + 168) |= 2u;
}
}
break;
}
}
LABEL_44:
*(_DWORD *)(v1 + 148) = 0;
*(_DWORD *)(v1 + 156) = 0;
*(_BYTE *)(v1 + 184) = 0;
result = sub_BAA4B0(v1, "%s", "CAPA");
if ( !(_DWORD)result )
goto LABEL_45;
return result;
case 2:
v11 = *(_QWORD *)a1;
v40 = v43;
v12 = strlen((const char *)(*(_QWORD *)a1 + 2824LL));
if ( v40 == 42 )
{
if ( v12 <= 3 )
goto LABEL_24;
v42 = v12;
if ( !memcmp((const void *)(v11 + 2824), "STLS", 4u) )
{
*(_BYTE *)(v1 + 184) = 1;
}
else if ( !memcmp((const void *)(v11 + 2824), "USER", 4u) )
{
*(_DWORD *)(v1 + 168) |= 1u;
}
else if ( v42 != 4 && !memcmp((const void *)(v11 + 2824), "SASL ", 5u) )
{
*(_DWORD *)(v1 + 168) |= 4u;
v18 = v42 - 5;
if ( v42 != 5 )
{
v19 = (unsigned __int8 *)(v11 + 2829);
while ( 1 )
{
v20 = *v19;
if ( v20 == 13 || v20 == 32 || (unsigned __int8)(v20 - 9) <= 1u )
{
--v18;
++v19;
if ( !v18 )
goto LABEL_69;
}
else
{
if ( !v18 )
{
v26 = v19;
v22 = 0;
goto LABEL_65;
}
v21 = v19 + 1;
v22 = 0;
while ( ++v22 != v18 )
{
v23 = v21;
v25 = *v21++;
v24 = v25;
if ( v25 == 13 || v25 == 32 || (unsigned __int8)(v24 - 9) <= 1u )
{
v26 = v23;
goto LABEL_65;
}
}
v26 = &v19[v22];
LABEL_65:
v27 = sub_BAE6FC(v19);
if ( v27 && v22 == v45 )
*(_DWORD *)(v1 + 148) |= v27;
v18 -= v22;
v19 = v26;
if ( !v18 )
{
LABEL_69:
v6 = *(_DWORD *)(v1 + 112);
break;
}
}
}
}
}
LABEL_23:
if ( !v6 )
return 0;
goto LABEL_24;
}
if ( v40 != 43 )
{
*(_DWORD *)(v1 + 168) |= 1u;
result = sub_BA7D5C(a1);
if ( !(_DWORD)result )
goto LABEL_32;
return result;
}
v15 = *(_DWORD *)(v11 + 1584);
if ( !v15 || *(_BYTE *)(a1 + 664) )
{
LABEL_40:
result = sub_BA7D5C(a1);
if ( (_DWORD)result )
return result;
LABEL_32:
v6 = *(_DWORD *)(v1 + 112);
goto LABEL_23;
}
if ( !*(_BYTE *)(v1 + 184) )
{
if ( v15 == 1 )
goto LABEL_40;
sub_B7B690(v11, "STLS not supported.");
return 64;
}
result = sub_BAA4B0(v1, "%s", "STLS");
if ( (_DWORD)result )
return result;
*(_DWORD *)(v1 + 112) = 3;
LABEL_24:
if ( !(unsigned __int8)sub_BAAB00(v1) )
return 0;
break;
case 3:
v10 = *(_QWORD *)a1;
if ( v43 == 43 )
{
result = sub_BB9FA4(a1, 0, a1 + 1676);
if ( (_DWORD)result )
return result;
if ( *(_DWORD *)(v1 + 112) != 4 )
*(_DWORD *)(v1 + 112) = 4;
if ( *(_BYTE *)(v1 + 116) )
{
*(_QWORD *)(a1 + 1024) = &off_111CB40;
*(_BYTE *)(a1 + 952) = 1;
*(_DWORD *)(v1 + 148) = 0;
*(_DWORD *)(v1 + 156) = 0;
*(_BYTE *)(v1 + 184) = 0;
result = sub_BAA4B0(v1, "%s", "CAPA");
if ( (_DWORD)result )
return result;
LABEL_45:
*(_DWORD *)(v1 + 112) = 2;
}
goto LABEL_24;
}
if ( *(_DWORD *)(v10 + 1584) != 1 )
{
sub_B7B690(v10, "STARTTLS denied. %c", v43);
return 64;
}
goto LABEL_40;
case 5:
v9 = *(_QWORD *)a1;
result = sub_BAEE2C(a1 + 1696, a1);
if ( (_DWORD)result )
return result;
if ( (_DWORD)v45 )
{
if ( (_DWORD)v45 == 2 )
*(_DWORD *)(v1 + 112) = 0;
LABEL_22:
v6 = *(_DWORD *)(v1 + 112);
goto LABEL_23;
}
v28 = *(_DWORD *)(v1 + 172) & *(_DWORD *)(v1 + 168);
if ( (v28 & 2) == 0 )
{
if ( (v28 & 1) == 0 )
{
sub_B7B690(v9, "Authentication cancelled");
return 67;
}
if ( *(_BYTE *)(a1 + 960) )
{
v31 = *(const char **)(a1 + 536);
if ( !v31 )
v31 = &byte_F288A0;
result = sub_BAA4B0(v1, "USER %s", v31);
if ( (_DWORD)result )
return result;
*(_DWORD *)(v1 + 112) = 7;
goto LABEL_22;
}
LABEL_73:
*(_DWORD *)(v1 + 112) = 0;
v6 = *(_DWORD *)(v1 + 112);
goto LABEL_23;
}
if ( !*(_BYTE *)(a1 + 960) )
goto LABEL_73;
result = sub_BA774C(a1);
if ( (_DWORD)result )
return result;
goto LABEL_32;
case 6:
if ( v43 == 43 )
goto LABEL_6;
sub_B7B690(*(_QWORD *)a1, aAuthentication_2);
return 67;
case 7:
v8 = *(_QWORD *)a1;
if ( v43 != 43 )
goto LABEL_15;
v17 = *(const char **)(a1 + 544);
if ( !v17 )
v17 = &byte_F288A0;
result = sub_BAA4B0(v1, "PASS %s", v17);
if ( (_DWORD)result )
return result;
*(_DWORD *)(v1 + 112) = 8;
goto LABEL_24;
case 8:
v8 = *(_QWORD *)a1;
if ( v43 == 43 )
{
*(_DWORD *)(v1 + 112) = 0;
return 0;
}
LABEL_15:
sub_B7B690(v8, aAccessDenied);
return 67;
case 9:
v7 = *(_QWORD *)a1;
if ( v43 != 43 )
{
*(_DWORD *)(v1 + 112) = 0;
return 56;
}
v29 = **(_DWORD **)(*(_QWORD *)a1 + 536LL);
*(_QWORD *)(v1 + 120) = 2;
*(_QWORD *)(v1 + 128) = 2;
if ( v29 || (sub_B94394(a1, 0, -1, 0, 0, -1, 0), (v30 = *(void **)v1) == nullptr) )
{
LABEL_6:
*(_DWORD *)(v1 + 112) = 0;
return 0;
}
if ( *(_BYTE *)(v7 + 1568) )
goto LABEL_79;
result = sub_BA7E80((__int64 *)a1, (__int64)v30, *(_QWORD *)(v1 + 8));
if ( (_DWORD)result )
return result;
v30 = *(void **)v1;
LABEL_79:
off_1231008(v30);
*(_QWORD *)v1 = 0;
*(_QWORD *)(v1 + 8) = 0;
*(_DWORD *)(v1 + 112) = 0;
return 0;
default:
goto LABEL_6;
}
}
}
result = sub_BB9FA4(a1, 0, a1 + 1676);
if ( !(_DWORD)result )
{
if ( *(_DWORD *)(v1 + 112) != 4 )
*(_DWORD *)(v1 + 112) = 4;
if ( *(_BYTE *)(v1 + 116) )
{
*(_BYTE *)(a1 + 952) = 1;
*(_QWORD *)(a1 + 1024) = &off_111CB40;
*(_DWORD *)(v1 + 148) = 0;
*(_DWORD *)(v1 + 156) = 0;
*(_BYTE *)(v1 + 184) = 0;
result = sub_BAA4B0(v1, "%s", "CAPA");
if ( !(_DWORD)result )
*(_DWORD *)(v1 + 112) = 2;
}
else
{
return 0;
}
}
return result;
}