//
// sub_83F23C from 0x83f23c to 0x83f5a2 (870 bytes)
//
// 1 xrefs:
// > sub_83AF74 @ 0x83afea
//
// 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:02:19 +0000
//
int __fastcall sub_83F23C(_DWORD *a1, int a2, unsigned int a3, int a4, int *a5)
{
int result; // r0
__time_t v9; // r6
int v10; // r7
int v11; // r0
__time_t v12; // r3
struct pollfd *v13; // r6
int v14; // r4
int v15; // r3
int v16; // r3
int v17; // r3
int v18; // r3
int v19; // r0
unsigned int v20; // r0
_DWORD *v21; // r2
int v22; // r11
nfds_t v23; // r5
int v24; // r3
_DWORD *v25; // r4
int v26; // r2
struct pollfd *v27; // r1
int v28; // r2
struct pollfd *v29; // r1
int v30; // r2
struct pollfd *v31; // r1
int v32; // r2
struct pollfd *v33; // r1
struct pollfd *v34; // r2
struct pollfd *v35; // r2
int v36; // r0
struct pollfd *v37; // r10
unsigned int v38; // r3
int v39; // r2
struct pollfd *v40; // r7
__int16 v41; // r1
__int16 v42; // r0
__int16 v43; // lr
__int16 v44; // r12
int v45; // r5
struct pollfd *v46; // r4
int v47; // r9
__int16 revents; // r3
int v49; // [sp+0h] [bp-2Ch]
__time_t v50; // [sp+Ch] [bp-20h] BYREF
int v51; // [sp+10h] [bp-1Ch]
int v52; // [sp+14h] [bp-18h] BYREF
int v53; // [sp+18h] [bp-14h]
int v54; // [sp+1Ch] [bp-10h]
int v55; // [sp+20h] [bp-Ch]
int v56; // [sp+24h] [bp-8h]
if ( !a1 || *a1 != 764702 )
return 1;
if ( a1[17] )
{
sub_81FA10(&v50);
v9 = v50;
v10 = v51;
v11 = sub_844CC0(0, 0, a1[17]);
a1[17] = v11;
v12 = *(_DWORD *)(v11 + 12);
if ( v9 <= v12 && (v9 < v12 || v10 < *(_DWORD *)(v11 + 16)) )
sub_81FA58(*(_DWORD *)(v11 + 12), *(_DWORD *)(v11 + 16), v50, v51);
}
v13 = (struct pollfd *)a1[1];
if ( !v13 )
{
if ( !a3 )
{
v13 = nullptr;
goto LABEL_88;
}
v14 = a1[1];
v20 = a3;
goto LABEL_93;
}
v14 = 0;
do
{
v19 = sub_83E978((int)v13, &v52);
if ( (v19 & 1) == 0 )
{
if ( (v19 & 0x10000) == 0 )
goto LABEL_35;
v15 = v52;
LABEL_14:
++v14;
goto LABEL_15;
}
++v14;
v15 = v52;
if ( (v19 & 0x10000) != 0 )
goto LABEL_14;
LABEL_15:
if ( v15 == -1 )
goto LABEL_35;
if ( (v19 & 2) == 0 )
{
if ( (v19 & 0x20000) == 0 )
goto LABEL_35;
v16 = v53;
LABEL_19:
++v14;
goto LABEL_20;
}
++v14;
v16 = v53;
if ( (v19 & 0x20000) != 0 )
goto LABEL_19;
LABEL_20:
if ( v16 == -1 )
goto LABEL_35;
if ( (v19 & 4) == 0 )
{
if ( (v19 & 0x40000) == 0 )
goto LABEL_35;
v17 = v54;
LABEL_24:
++v14;
goto LABEL_25;
}
++v14;
v17 = v54;
if ( (v19 & 0x40000) != 0 )
goto LABEL_24;
LABEL_25:
if ( v17 == -1 )
goto LABEL_35;
if ( (v19 & 8) == 0 )
{
if ( (v19 & 0x80000) == 0 )
goto LABEL_35;
v18 = v55;
LABEL_29:
++v14;
goto LABEL_30;
}
++v14;
v18 = v55;
if ( (v19 & 0x80000) != 0 )
goto LABEL_29;
LABEL_30:
if ( v18 != -1 )
{
if ( (v19 & 0x10) != 0 )
++v14;
if ( (v19 & 0x100000) != 0 )
++v14;
}
LABEL_35:
v13 = (struct pollfd *)v13->fd;
}
while ( v13 );
v20 = v14 + a3;
if ( (v14 + a3) | a3 )
{
LABEL_93:
v13 = (struct pollfd *)off_D200AC(8 * v20);
result = 3;
if ( !v13 )
return result;
if ( !v14 )
goto LABEL_76;
LABEL_47:
if ( !a1[1] )
goto LABEL_76;
v21 = (_DWORD *)a1[1];
v22 = v14;
v23 = 0;
v24 = 4;
v25 = v21;
while ( 1 )
{
v49 = v24;
v36 = sub_83E978((int)v25, &v52);
v24 = v49;
if ( (v36 & 1) == 0 )
break;
v13[v23].fd = v52;
v13[v23++].events = 1;
v26 = v52;
if ( (v36 & 0x10000) != 0 )
goto LABEL_51;
LABEL_52:
if ( v26 == -1 )
goto LABEL_72;
if ( (v36 & 2) == 0 )
{
if ( (v36 & 0x20000) == 0 )
goto LABEL_72;
v28 = v53;
LABEL_56:
v29 = &v13[v23];
v29->fd = v28;
++v23;
v29->events = v49;
v28 = v53;
goto LABEL_57;
}
v13[v23].fd = v53;
v13[v23++].events = 1;
v28 = v53;
if ( (v36 & 0x20000) != 0 )
goto LABEL_56;
LABEL_57:
if ( v28 == -1 )
goto LABEL_72;
if ( (v36 & 4) == 0 )
{
if ( (v36 & 0x40000) == 0 )
goto LABEL_72;
v30 = v54;
LABEL_61:
v31 = &v13[v23];
v31->fd = v30;
++v23;
v31->events = v49;
v30 = v54;
goto LABEL_62;
}
v13[v23].fd = v54;
v13[v23++].events = 1;
v30 = v54;
if ( (v36 & 0x40000) != 0 )
goto LABEL_61;
LABEL_62:
if ( v30 != -1 )
{
if ( (v36 & 8) != 0 )
{
v13[v23].fd = v55;
v13[v23++].events = 1;
v32 = v55;
if ( (v36 & 0x80000) != 0 )
{
LABEL_66:
v33 = &v13[v23];
v33->fd = v32;
++v23;
v33->events = v49;
v32 = v55;
}
if ( v32 != -1 )
{
if ( (v36 & 0x10) != 0 )
{
v34 = &v13[v23];
v34->fd = v56;
++v23;
v34->events = 1;
}
if ( (v36 & 0x100000) != 0 )
{
v35 = &v13[v23];
v35->fd = v56;
++v23;
v35->events = v49;
}
}
goto LABEL_72;
}
if ( (v36 & 0x80000) != 0 )
{
v32 = v55;
goto LABEL_66;
}
}
LABEL_72:
v25 = (_DWORD *)*v25;
if ( !v25 )
{
v14 = v22;
if ( !a3 )
goto LABEL_87;
goto LABEL_77;
}
}
if ( (v36 & 0x10000) == 0 )
goto LABEL_72;
v26 = v52;
LABEL_51:
v27 = &v13[v23];
v27->fd = v26;
++v23;
v27->events = v49;
v26 = v52;
goto LABEL_52;
}
if ( v14 )
goto LABEL_47;
LABEL_76:
v23 = 0;
if ( !a3 )
goto LABEL_88;
LABEL_77:
v37 = &v13[v23];
v38 = 0;
v39 = a2;
v40 = v37;
do
{
v41 = 4;
v42 = 6;
v43 = 2;
v37[v38].fd = *(_DWORD *)(a2 + 8 * v38);
v40->events = 0;
v44 = *(_WORD *)(v39 + 4);
if ( (v44 & 1) != 0 )
{
v40->events = 1;
v44 = *(_WORD *)(v39 + 4);
v41 = 5;
v42 = 7;
v43 = 3;
}
if ( (v44 & 2) != 0 )
v40->events = v43;
++v38;
++v23;
if ( (v44 & 2) != 0 )
{
v44 = *(_WORD *)(v39 + 4);
v41 = v42;
}
v39 += 8;
++v40;
if ( (v44 & 4) != 0 )
v40[-1].events = v41;
}
while ( a3 > v38 );
LABEL_87:
if ( !v23 || (v45 = sub_842FF8(v13, v23), v45 <= 0) )
{
LABEL_88:
v45 = 0;
goto LABEL_89;
}
if ( a3 )
{
v46 = &v13[v14];
v47 = a2 + 8 * a3;
do
{
revents = v46->revents;
a2 += 8;
++v46;
*(_WORD *)(a2 - 2) = revents & 7;
}
while ( a2 != v47 );
}
LABEL_89:
off_D200B0(v13);
if ( a5 )
*a5 = v45;
return 0;
}