//
// sub_B9ACF0 from 0xb9acf0 to 0xb9b228 (1336 bytes)
//
// 1 xrefs:
// > sub_B94C64 @ 0xb94d58
//
// 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_B9ACF0(__int64 *a1, __int64 a2, unsigned int a3, __int64 a4, int *a5)
{
__int64 v9; // x2
__int64 result; // x0
__time_t v11; // x19
__int64 v12; // x1
__int64 v13; // x20
__int64 v14; // x0
__time_t v15; // x2
struct pollfd *v16; // x20
int v17; // w19
__int64 v18; // x0
int v19; // w1
int v20; // w1
int v21; // w1
int v22; // w1
__int64 v23; // x9
__int64 v24; // x9
unsigned int v25; // w22
__int64 v26; // x6
unsigned int v27; // w5
struct pollfd *v28; // x1
__int16 v29; // w3
__int16 v30; // w4
__int16 v31; // w7
__int16 v32; // w0
int v33; // w21
__int64 v34; // x26
__int64 v35; // x2
__int64 v36; // x0
int v37; // w1
struct pollfd *v38; // x3
struct pollfd *v39; // x3
struct pollfd *v40; // x3
int v41; // w1
struct pollfd *v42; // x3
int v43; // w1
struct pollfd *v44; // x3
int v45; // w1
struct pollfd *v46; // x3
struct pollfd *v47; // x1
_WORD *v48; // x23
__int16 revents; // w2
__int16 v50; // w1
struct pollfd *v51; // x3
struct pollfd *v52; // x3
struct pollfd *v53; // x3
__int64 v54; // [xsp+60h] [xbp+60h]
__int64 v55; // [xsp+68h] [xbp+68h]
int v56; // [xsp+68h] [xbp+68h]
__int64 v57; // [xsp+68h] [xbp+68h]
int v58; // [xsp+78h] [xbp+78h] BYREF
int v59; // [xsp+7Ch] [xbp+7Ch]
int v60; // [xsp+80h] [xbp+80h]
int v61; // [xsp+84h] [xbp+84h]
int v62; // [xsp+88h] [xbp+88h]
if ( !a1 )
return 1;
v9 = *a1;
result = 1;
if ( v9 != 764702 )
return result;
if ( a1[16] )
{
v11 = sub_B70B94();
v13 = v12;
v14 = sub_BA2CF0(0, 0, a1[16]);
v15 = *(_QWORD *)(v14 + 24);
a1[16] = v14;
if ( v11 <= v15 && (v11 < v15 || v13 < *(_QWORD *)(v14 + 32)) )
sub_B70BFC(*(_QWORD *)(v14 + 24), *(_QWORD *)(v14 + 32), v11, v13);
}
v16 = (struct pollfd *)a1[1];
if ( !v16 )
{
if ( !a3 )
goto LABEL_47;
v23 = a3;
v17 = 0;
goto LABEL_105;
}
v17 = 0;
do
{
while ( 1 )
{
if ( BYTE1(v16[4501].fd) )
goto LABEL_10;
v18 = sub_B9A1C4((__int64)v16, &v58);
if ( (v18 & 1) != 0 )
{
++v17;
v19 = v58;
if ( (v18 & 0x10000) == 0 )
goto LABEL_14;
}
else
{
if ( (v18 & 0x10000) == 0 )
goto LABEL_10;
v19 = v58;
}
++v17;
LABEL_14:
if ( v19 == -1 )
goto LABEL_10;
if ( (v18 & 2) == 0 )
{
if ( (v18 & 0x20000) == 0 )
goto LABEL_10;
v20 = v59;
LABEL_18:
++v17;
goto LABEL_19;
}
++v17;
v20 = v59;
if ( (v18 & 0x20000) != 0 )
goto LABEL_18;
LABEL_19:
if ( v20 == -1 )
goto LABEL_10;
if ( (v18 & 4) != 0 )
{
++v17;
v21 = v60;
if ( (v18 & 0x40000) == 0 )
goto LABEL_24;
}
else
{
if ( (v18 & 0x40000) == 0 )
goto LABEL_10;
v21 = v60;
}
++v17;
LABEL_24:
if ( v21 != -1 )
{
if ( (v18 & 8) != 0 )
{
++v17;
v22 = v61;
if ( (v18 & 0x80000) == 0 )
goto LABEL_29;
goto LABEL_28;
}
if ( (v18 & 0x80000) != 0 )
break;
}
LABEL_10:
v16 = (struct pollfd *)*v16;
if ( !v16 )
goto LABEL_34;
}
v22 = v61;
LABEL_28:
++v17;
LABEL_29:
if ( v22 == -1 )
goto LABEL_10;
if ( (v18 & 0x10) != 0 )
++v17;
if ( (v18 & 0x100000) == 0 )
goto LABEL_10;
v16 = (struct pollfd *)*v16;
++v17;
}
while ( v16 );
LABEL_34:
v23 = v17 + a3;
if ( !((unsigned int)v23 | a3) )
{
v24 = (unsigned int)v16;
goto LABEL_36;
}
LABEL_105:
v57 = v23;
v16 = (struct pollfd *)off_1231000(8LL * (unsigned int)v23);
v24 = v57;
if ( !v16 )
return 3;
LABEL_36:
if ( !v17 || (v34 = a1[1]) == 0 )
{
v25 = 0;
if ( !a3 )
goto LABEL_47;
goto LABEL_38;
}
v25 = 0;
v35 = 4;
while ( 2 )
{
while ( 2 )
{
if ( *(_BYTE *)(v34 + 36009) )
goto LABEL_62;
v54 = v35;
v55 = v24;
v36 = sub_B9A1C4(v34, &v58);
v37 = -1;
v24 = v55;
v35 = v54;
if ( (v36 & 1) != 0 )
{
v38 = &v16[v25++];
v38->fd = v58;
v38->events = 1;
v37 = v58;
}
if ( (v36 & 0x10000) != 0 )
{
v39 = &v16[v25++];
v39->fd = v58;
v39->events = v54;
v37 = v58;
}
if ( v37 == -1 )
goto LABEL_62;
if ( (v36 & 2) == 0 )
{
if ( (v36 & 0x20000) != 0 )
goto LABEL_71;
goto LABEL_62;
}
v51 = &v16[v25++];
v51->fd = v59;
v51->events = 1;
v41 = v59;
if ( (v36 & 0x20000) != 0 )
{
LABEL_71:
v40 = &v16[v25++];
v40->fd = v59;
v40->events = v54;
v41 = v59;
}
if ( v41 == -1 )
{
LABEL_62:
v34 = *(_QWORD *)v34;
if ( !v34 )
goto LABEL_85;
continue;
}
break;
}
if ( (v36 & 4) != 0 )
{
v52 = &v16[v25++];
v52->fd = v60;
v52->events = 1;
v43 = v60;
if ( (v36 & 0x40000) != 0 )
goto LABEL_75;
}
else
{
if ( (v36 & 0x40000) == 0 )
goto LABEL_62;
LABEL_75:
v42 = &v16[v25++];
v42->fd = v60;
v42->events = v54;
v43 = v60;
}
if ( v43 == -1 )
goto LABEL_62;
if ( (v36 & 8) != 0 )
{
v53 = &v16[v25++];
v53->fd = v61;
v53->events = 1;
v45 = v61;
if ( (v36 & 0x80000) != 0 )
goto LABEL_79;
}
else
{
if ( (v36 & 0x80000) == 0 )
goto LABEL_62;
LABEL_79:
v44 = &v16[v25++];
v44->fd = v61;
v44->events = v54;
v45 = v61;
}
if ( v45 == -1 )
goto LABEL_62;
if ( (v36 & 0x10) != 0 )
{
v46 = &v16[v25++];
v46->fd = v62;
v46->events = 1;
}
if ( (v36 & 0x100000) == 0 )
goto LABEL_62;
v47 = &v16[v25];
v34 = *(_QWORD *)v34;
++v25;
v47->fd = v62;
v47->events = v54;
if ( v34 )
continue;
break;
}
LABEL_85:
v27 = v25;
if ( !a3 )
{
if ( v25 )
goto LABEL_87;
LABEL_47:
v33 = 0;
goto LABEL_48;
}
LABEL_38:
v26 = a2;
v27 = v25;
do
{
v28 = &v16[v27];
v29 = 4;
v30 = 6;
v31 = 2;
v28->fd = *(_DWORD *)v26;
v28->events = 0;
v32 = *(_WORD *)(v26 + 4);
if ( (v32 & 1) != 0 )
{
v28->events = 1;
v29 = 5;
v30 = 7;
v31 = 3;
}
++v27;
if ( (v32 & 2) != 0 )
{
v28->events = v31;
v29 = v30;
}
v26 += 8;
if ( (v32 & 4) != 0 )
v28->events = v29;
}
while ( a3 > v27 - v25 );
if ( !v27 )
goto LABEL_47;
LABEL_87:
v56 = v24;
v33 = sub_BA03A8(v16, v27);
if ( v33 <= 0 )
goto LABEL_47;
if ( a3 )
{
v48 = (_WORD *)(a2 + 6);
do
{
revents = v16[v17++].revents;
v50 = revents & 1;
if ( (revents & 4) != 0 )
v50 = revents & 1 | 4;
if ( (revents & 2) != 0 )
v50 |= 2u;
*v48 = v50;
v48 += 4;
}
while ( v56 != v17 );
}
LABEL_48:
off_1231008(v16);
if ( a5 )
*a5 = v33;
return 0;
}