//
// sub_636980 from 0x636980 to 0x636e1c (1180 bytes)
//
// 0 xrefs:
//
// 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_636980(int *a1, unsigned __int8 *a2, unsigned int a3, _DWORD *a4)
{
const void *v4; // r9
int v5; // r8
size_t v9; // r0
int v10; // r11
size_t v11; // r10
size_t v12; // r7
unsigned int v14; // r5
unsigned __int8 *v15; // r4
int v16; // r3
unsigned __int8 *v17; // r7
unsigned int v18; // r5
_BYTE *v19; // r6
unsigned __int8 *v20; // r3
bool v21; // zf
unsigned __int8 *v22; // r1
char *v23; // r10
unsigned int v24; // r5
_BYTE *v25; // r6
unsigned __int8 *v26; // r4
unsigned __int8 *v27; // r2
unsigned int v28; // r5
_BYTE *v29; // r6
unsigned __int8 *v30; // r4
unsigned __int8 *v31; // r2
unsigned __int8 *v32; // r8
size_t v33; // r0
unsigned __int8 *v34; // r6
unsigned int v35; // r5
_BYTE *v36; // r6
unsigned __int8 *v37; // r4
unsigned __int8 *v38; // r2
unsigned __int8 *v39; // r3
unsigned __int8 *v40; // r1
int v41; // r0
unsigned __int8 *v42; // r2
bool v43; // cc
unsigned __int8 *v44; // r8
size_t v46; // [sp+8h] [bp-Ch]
unsigned __int8 *v47; // [sp+Ch] [bp-8h]
v4 = a1 + 296;
v5 = *a1;
v9 = strlen((const char *)a1 + 1184);
v10 = *(_DWORD *)(v5 + 332);
v11 = v9 + 1;
v12 = v9;
if ( v9 + 1 > a3 || memcmp(v4, a2, v9) || a2[v12] != 32 )
{
if ( a3 <= 1 || memcmp("* ", a2, 2u) )
{
if ( !v10 || *(_DWORD *)(v10 + 28) )
return 0;
if ( a3 == 3 )
{
if ( *a2 == 43 )
{
LABEL_19:
v16 = a1[286];
if ( v16 != 5 && v16 != 11 )
{
sub_6180F8(v5, "Unexpected continuation response");
LABEL_22:
*a4 = -1;
return 1;
}
*a4 = 43;
return 1;
}
}
else if ( a3 <= 1 )
{
return 0;
}
if ( !memcmp("+ ", a2, 2u) )
goto LABEL_19;
return 0;
}
switch ( a1[286] )
{
case 2:
v35 = (unsigned int)&a2[a3];
v36 = a2 + 2;
if ( v35 <= (unsigned int)(a2 + 2) || (unsigned int)a2[2] - 48 > 9 )
goto LABEL_89;
v37 = a2 + 3;
do
{
v21 = v37 == (unsigned __int8 *)v35;
v38 = v37++;
}
while ( !v21 && (unsigned int)*v38 - 48 <= 9 );
if ( (unsigned __int8 *)v35 != v38 && *v38 == 32 )
{
v36 = v38 + 1;
LABEL_89:
if ( v35 >= (unsigned int)(v36 + 10)
&& sub_62AB64(v36, "CAPABILITY", 10)
&& (v36[10] == 32 || (_BYTE *)v35 == v36 + 12) )
{
goto LABEL_37;
}
}
return 0;
case 7:
v23 = *(char **)(v10 + 28);
if ( v23 )
{
v18 = (unsigned int)&a2[a3];
v17 = a2 + 2;
}
else
{
v17 = a2 + 2;
v18 = (unsigned int)&a2[a3];
v19 = a2 + 2;
if ( v18 > (unsigned int)(a2 + 2) && (unsigned int)a2[2] - 48 <= 9 )
{
v20 = a2 + 3;
do
{
v21 = v20 == (unsigned __int8 *)v18;
v22 = v20++;
}
while ( !v21 && (unsigned int)*v22 - 48 <= 9 );
if ( (unsigned __int8 *)v18 == v22 || *v22 != 32 )
return 0;
v19 = v22 + 1;
}
if ( v18 < (unsigned int)(v19 + 4) || !sub_62AB64(v19, "LIST", 4) || v19[4] != 32 && (_BYTE *)v18 != v19 + 6 )
return 0;
v23 = *(char **)(v10 + 28);
if ( !v23 )
{
LABEL_37:
*a4 = 42;
return 1;
}
}
v32 = v17;
v33 = strlen(v23);
if ( v18 <= (unsigned int)v17 || (unsigned int)a2[2] - 48 > 9 )
{
v34 = v17;
}
else
{
v39 = a2 + 3;
do
{
v21 = v39 == (unsigned __int8 *)v18;
v40 = v39++;
}
while ( !v21 && (unsigned int)*v40 - 48 <= 9 );
if ( (unsigned __int8 *)v18 == v40 )
{
LABEL_71:
if ( strcmp(v23, "STORE") )
goto LABEL_72;
if ( v18 <= (unsigned int)v17 || (unsigned int)a2[2] - 48 > 9 )
goto LABEL_109;
v42 = a2 + 3;
do
{
LABEL_105:
v43 = v18 > (unsigned int)v42;
v44 = v42++;
}
while ( v43 && (unsigned int)*v44 - 48 <= 9 );
if ( (unsigned __int8 *)v18 == v44 || *v44 != 32 )
{
LABEL_72:
if ( strcmp(v23, "SELECT")
&& strcmp(v23, "EXAMINE")
&& strcmp(v23, "SEARCH")
&& strcmp(v23, "EXPUNGE")
&& strcmp(v23, "LSUB")
&& strcmp(v23, "UID")
&& strcmp(v23, "NOOP") )
{
return 0;
}
goto LABEL_37;
}
v32 = v44 + 1;
LABEL_109:
if ( v18 >= (unsigned int)(v32 + 5) )
{
if ( sub_62AB64(v32, "FETCH", 5) && (v32[5] == 32 || (unsigned __int8 *)v18 == v32 + 7) )
goto LABEL_37;
v23 = *(char **)(v10 + 28);
}
goto LABEL_72;
}
if ( *v40 != 32 )
{
v41 = strcmp(v23, "STORE");
v42 = a2 + 3;
if ( v41 )
goto LABEL_72;
goto LABEL_105;
}
v34 = v40 + 1;
}
if ( v18 >= (unsigned int)&v34[v33] )
{
v47 = &v34[v33];
v46 = v33;
if ( sub_62AB64(v34, v23, v33) && (*v47 == 32 || (unsigned __int8 *)v18 == &v34[v46 + 2]) )
goto LABEL_37;
v23 = *(char **)(v10 + 28);
}
goto LABEL_71;
case 8:
goto LABEL_37;
case 9:
v28 = (unsigned int)&a2[a3];
v29 = a2 + 2;
if ( v28 <= (unsigned int)(a2 + 2) || (unsigned int)a2[2] - 48 > 9 )
goto LABEL_61;
v30 = a2 + 3;
do
{
v21 = v30 == (unsigned __int8 *)v28;
v31 = v30++;
}
while ( !v21 && (unsigned int)*v31 - 48 <= 9 );
if ( (unsigned __int8 *)v28 != v31 && *v31 == 32 )
{
v29 = v31 + 1;
LABEL_61:
if ( v28 >= (unsigned int)(v29 + 5)
&& sub_62AB64(v29, "FETCH", 5)
&& (v29[5] == 32 || (_BYTE *)v28 == v29 + 7) )
{
goto LABEL_37;
}
}
return 0;
case 13:
v24 = (unsigned int)&a2[a3];
v25 = a2 + 2;
if ( v24 <= (unsigned int)(a2 + 2) || (unsigned int)a2[2] - 48 > 9 )
goto LABEL_47;
v26 = a2 + 3;
do
{
v21 = v26 == (unsigned __int8 *)v24;
v27 = v26++;
}
while ( !v21 && (unsigned int)*v27 - 48 <= 9 );
if ( (unsigned __int8 *)v24 != v27 && *v27 == 32 )
{
v25 = v27 + 1;
LABEL_47:
if ( v24 >= (unsigned int)(v25 + 6)
&& sub_62AB64(v25, "SEARCH", 6)
&& (v25[6] == 32 || (_BYTE *)v24 == v25 + 8) )
{
goto LABEL_37;
}
}
return 0;
default:
return 0;
}
}
v14 = a3 - v12 - 1;
if ( v14 <= 1 )
{
LABEL_118:
sub_6180F8(v5, "Bad tagged response");
goto LABEL_22;
}
v15 = &a2[v11];
if ( !memcmp(v15, "OK", 2u) )
{
*a4 = 79;
return 1;
}
else
{
if ( memcmp(v15, "NO", 2u) )
{
if ( v14 != 2 && !memcmp(v15, "BAD", 3u) )
{
*a4 = 66;
return 1;
}
goto LABEL_118;
}
*a4 = 78;
return 1;
}
}