//
// sub_100576B48 from 0x100576b48 to 0x10057720c (1732 bytes)
//
// 1 xrefs:
// > sub_1005759F8 @ 0x100575a2c
//
// 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_100576B48(__int64 a1, unsigned __int8 *a2, __int64 a3, int *a4)
{
__int64 v8; // x21
__int64 v9; // x26
const void *v10; // x25
size_t v11; // x24
size_t v12; // x27
unsigned __int8 *v13; // x0
__int64 result; // x0
unsigned __int64 v15; // x23
unsigned __int8 *v16; // x21
unsigned __int8 *v17; // x8
int v18; // w9
int v19; // w8
char *v20; // x23
unsigned __int64 v21; // x25
unsigned __int8 *v22; // x21
unsigned __int8 *v23; // x22
unsigned __int8 *v24; // x9
unsigned __int8 *v25; // x8
unsigned __int64 v26; // x23
unsigned __int8 *v27; // x21
unsigned __int8 *v28; // x8
unsigned __int64 v29; // x23
unsigned __int8 *v30; // x21
unsigned __int8 *v31; // x8
size_t v32; // x0
size_t v33; // x22
unsigned __int8 *v34; // x24
unsigned __int8 *v35; // x9
unsigned __int8 *v36; // x8
unsigned __int8 *v37; // x8
const char *v38; // x20
v8 = *(_QWORD *)a1;
v9 = *(_QWORD *)(*(_QWORD *)a1 + 536LL);
v10 = (const void *)(a1 + 1496);
v11 = strlen((const char *)(a1 + 1496));
v12 = v11 + 1;
if ( v11 + 1 <= a3 && !memcmp(v10, a2, v11) && a2[v11] == 32 )
{
if ( a3 - v12 >= 2 )
{
v13 = &a2[v12];
if ( *(_WORD *)&a2[v12] == 19279 )
{
v19 = 79;
goto LABEL_132;
}
if ( *(_WORD *)v13 == 20302 )
{
v19 = 78;
goto LABEL_132;
}
if ( a3 - v12 >= 3 && !memcmp(v13, "BAD", 3u) )
{
v19 = 66;
goto LABEL_132;
}
}
sub_100552734(v8, "Bad tagged response");
goto LABEL_33;
}
if ( (unsigned __int64)a3 < 2 || *(_WORD *)a2 != 8234 )
{
if ( *(_QWORD *)(v9 + 56) )
return 0;
if ( a3 != 3 || *a2 != 43 )
{
if ( (unsigned __int64)a3 < 2 )
return 0;
if ( *(_WORD *)a2 != 8235 )
return 0;
}
v18 = *(_DWORD *)(a1 + 1448);
v19 = 43;
if ( v18 == 5 || v18 == 11 )
goto LABEL_132;
sub_100552734(v8, "Unexpected continuation response");
LABEL_33:
v19 = -1;
goto LABEL_132;
}
result = 0;
switch ( *(_DWORD *)(a1 + 1448) )
{
case 2:
v15 = (unsigned __int64)&a2[a3];
v16 = a2 + 2;
if ( a3 < 3 || (unsigned int)*v16 - 48 > 9 )
goto LABEL_28;
while ( 1 )
{
v17 = v16++;
if ( (unsigned __int64)v16 >= v15 )
break;
if ( (unsigned int)*v16 - 48 >= 0xA )
{
v16 = v17 + 1;
break;
}
}
if ( v16 == (unsigned __int8 *)v15 )
return 0;
if ( v17[1] != 32 )
return 0;
v16 = v17 + 2;
LABEL_28:
if ( (unsigned __int64)(v16 + 10) > v15 )
return 0;
if ( !sub_10057405C(v16, "CAPABILITY", 10) )
return 0;
if ( v16 + 12 == (unsigned __int8 *)v15 || v16[10] == 32 )
goto LABEL_131;
return 0;
case 7:
v20 = *(char **)(v9 + 56);
v21 = (unsigned __int64)&a2[a3];
v22 = a2 + 2;
if ( v20 )
goto LABEL_97;
v23 = a2 + 2;
if ( a3 < 3 )
goto LABEL_46;
v23 = v22;
if ( (unsigned int)*v22 - 48 > 9 )
goto LABEL_46;
v24 = v22;
while ( 1 )
{
v25 = v24++;
if ( (unsigned __int64)v24 >= v21 )
break;
if ( (unsigned int)*v24 - 48 >= 0xA )
{
v24 = v25 + 1;
break;
}
}
if ( v24 == (unsigned __int8 *)v21 )
return 0;
if ( v25[1] != 32 )
return 0;
v23 = v25 + 2;
LABEL_46:
if ( (unsigned __int64)(v23 + 4) > v21 )
return 0;
if ( !sub_10057405C(v23, "LIST", 4) )
return 0;
if ( v23 + 6 != (unsigned __int8 *)v21 && v23[4] != 32 )
return 0;
v20 = *(char **)(v9 + 56);
if ( !v20 )
goto LABEL_131;
LABEL_97:
v32 = strlen(v20);
v33 = v32;
v34 = v22;
if ( a3 < 3 )
goto LABEL_106;
v34 = v22;
if ( (unsigned int)*v22 - 48 > 9 )
goto LABEL_106;
v35 = v22;
while ( 1 )
{
v36 = v35++;
if ( (unsigned __int64)v35 >= v21 )
break;
if ( (unsigned int)*v35 - 48 >= 0xA )
{
v35 = v36 + 1;
break;
}
}
if ( v35 != (unsigned __int8 *)v21 && v36[1] == 32 )
{
v34 = v36 + 2;
LABEL_106:
if ( (unsigned __int64)&v34[v32] <= v21
&& sub_10057405C(v34, v20, v32)
&& (v34[v33] == 32 || &v34[v33 + 2] == (unsigned __int8 *)v21) )
{
goto LABEL_131;
}
}
if ( strcmp(*(const char **)(v9 + 56), "STORE") )
goto LABEL_123;
if ( a3 < 3 || (unsigned int)*v22 - 48 > 9 )
goto LABEL_119;
while ( 1 )
{
v37 = v22++;
if ( (unsigned __int64)v22 >= v21 )
break;
if ( (unsigned int)*v22 - 48 >= 0xA )
{
v22 = v37 + 1;
break;
}
}
if ( v22 != (unsigned __int8 *)v21 && v37[1] == 32 )
{
v22 = v37 + 2;
LABEL_119:
if ( (unsigned __int64)(v22 + 5) <= v21
&& sub_10057405C(v22, "FETCH", 5)
&& (v22 + 7 == (unsigned __int8 *)v21 || v22[5] == 32) )
{
goto LABEL_131;
}
}
LABEL_123:
v38 = *(const char **)(v9 + 56);
if ( !strcmp(v38, "SELECT")
|| !strcmp(v38, "EXAMINE")
|| !strcmp(v38, "SEARCH")
|| !strcmp(v38, "EXPUNGE")
|| !strcmp(v38, "LSUB")
|| !strcmp(v38, "UID")
|| !strcmp(v38, "NOOP") )
{
goto LABEL_131;
}
return 0;
case 8:
goto LABEL_131;
case 9:
v26 = (unsigned __int64)&a2[a3];
v27 = a2 + 2;
if ( a3 < 3 || (unsigned int)*v27 - 48 > 9 )
goto LABEL_56;
while ( 1 )
{
v28 = v27++;
if ( (unsigned __int64)v27 >= v26 )
break;
if ( (unsigned int)*v27 - 48 >= 0xA )
{
v27 = v28 + 1;
break;
}
}
if ( v27 == (unsigned __int8 *)v26 )
return 0;
if ( v28[1] != 32 )
return 0;
v27 = v28 + 2;
LABEL_56:
if ( (unsigned __int64)(v27 + 5) > v26 )
return 0;
if ( !sub_10057405C(v27, "FETCH", 5) )
return 0;
if ( v27 + 7 != (unsigned __int8 *)v26 && v27[5] != 32 )
return 0;
goto LABEL_131;
case 0xD:
v29 = (unsigned __int64)&a2[a3];
v30 = a2 + 2;
if ( a3 < 3 || (unsigned int)*v30 - 48 > 9 )
goto LABEL_66;
break;
default:
return result;
}
while ( 1 )
{
v31 = v30++;
if ( (unsigned __int64)v30 >= v29 )
break;
if ( (unsigned int)*v30 - 48 >= 0xA )
{
v30 = v31 + 1;
break;
}
}
if ( v30 == (unsigned __int8 *)v29 )
return 0;
if ( v31[1] != 32 )
return 0;
v30 = v31 + 2;
LABEL_66:
if ( (unsigned __int64)(v30 + 6) > v29 )
return 0;
if ( !sub_10057405C(v30, "SEARCH", 6) )
return 0;
if ( v30 + 8 != (unsigned __int8 *)v29 && v30[6] != 32 )
return 0;
LABEL_131:
v19 = 42;
LABEL_132:
*a4 = v19;
return 1;
}