//
// lws_service_fd from 0x857330 to 0x8576b6 (902 bytes)
//
// 4 xrefs:
// > lws_service_fd @ 0x85745c
// > sub_85A74C @ 0x85a9ca
// > lws_plat_service @ 0x85c036
// > lws_plat_service @ 0x85c0e2
//
// 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:37 +0000
//
int __fastcall lws_service_fd(time_t *a1, int a2)
{
time_t v3; // r3
int v5; // r2
int v6; // r3
int v7; // r10
int v8; // r6
int *v9; // r8
int v10; // r7
int v11; // r4
time_t v12; // r11
int result; // r0
int v14; // r7
int v15; // r0
_DWORD *v16; // r2
int v17; // r3
int v18; // r4
int v19; // r4
bool v20; // zf
time_t v21; // r3
__int16 v22; // r3
int v23; // r3
bool v24; // cc
int v25; // r2
int v26; // r2
int v27; // r1
int v28; // r3
int v29; // r1
int v30; // r6
int v31; // r2
unsigned int v32; // r0
int v33; // r4
int v34; // r2
int no_ssl; // r0
int v36; // r0
int v37; // r0
int v38; // r0
int v39; // r0
int v40; // [sp+0h] [bp-1Ch]
int v41; // [sp+4h] [bp-18h]
time_t timer; // [sp+Ch] [bp-10h] BYREF
int v43; // [sp+10h] [bp-Ch] BYREF
unsigned int v44; // [sp+14h] [bp-8h]
v3 = a1[1137];
if ( v3 )
v41 = *(_DWORD *)(*(_DWORD *)(a1[7] + 4 * v3) + 236);
else
v41 = 0;
time(&timer);
if ( *a1 == timer )
goto LABEL_18;
*a1 = timer;
lws_plat_service_periodic(a1);
if ( a2 )
{
v5 = *(_DWORD *)a2;
v6 = a1[1138];
v7 = *(_DWORD *)a2;
if ( v6 <= 0 )
goto LABEL_20;
}
else
{
v6 = a1[1138];
if ( v6 <= 0 )
return 0;
v7 = 0;
}
v8 = 0;
v9 = a1 + 1138;
v40 = 0;
do
{
while ( 1 )
{
v10 = *(_DWORD *)(a1[6] + 8 * v8);
v11 = *(_DWORD *)(a1[7] + 4 * v10);
if ( !v11 )
goto LABEL_8;
v12 = timer;
if ( sub_85C730(*(_DWORD *)(a1[7] + 4 * v10), 18, 0, timer) >= 0
&& *(_BYTE *)(v11 + 267)
&& v12 > *(_DWORD *)(v11 + 180) )
{
break;
}
v6 = *v9;
LABEL_8:
if ( ++v8 >= v6 )
goto LABEL_16;
}
++v8;
*(_BYTE *)(v11 + 260) |= 4u;
sub_856B30(v11, 0);
v6 = *v9;
if ( v10 == v7 )
v40 = 1;
}
while ( v8 < v6 );
LABEL_16:
if ( v40 )
return 0;
LABEL_18:
if ( !a2 )
return 0;
v5 = *(_DWORD *)a2;
LABEL_20:
v14 = *(_DWORD *)(a1[7] + 4 * v5);
if ( !v14 )
return 0;
if ( a1[1137] )
{
v15 = a1[6] + 8 * v41;
if ( a2 != v15 )
{
v16 = a1 + 1144;
v17 = a1[1144] + 1;
a1[1144] = v17;
v18 = a1[1145];
if ( v18 )
{
*v16 = 0;
v18 = v18 > 5;
LABEL_25:
v19 = v18 - 1;
while ( lws_poll_listen_fd(v15) > 0 )
{
lws_service_fd();
v20 = v19 == -1;
v19 = -1;
++a1[1145];
if ( v20 )
goto LABEL_31;
v15 = a1[6] + 8 * v41;
}
v21 = a1[1145];
if ( v21 )
a1[1145] = v21 - 1;
}
else if ( v17 == a1[1143] )
{
*v16 = 0;
goto LABEL_25;
}
}
}
LABEL_31:
v22 = *(_WORD *)(a2 + 6);
if ( (v22 & 1) == 0 && (v22 & 0x18) != 0 )
goto LABEL_70;
switch ( *(_BYTE *)(v14 + 263) )
{
case 0:
case 1:
case 6:
case 0xF:
v32 = lws_ssl_pending_no_ssl(v14);
if ( !v32 )
goto LABEL_72;
v30 = 0;
goto LABEL_54;
case 3:
case 4:
case 5:
v20 = (v22 & 4) == 0;
v23 = *(unsigned __int8 *)(v14 + 264);
if ( v20 )
goto LABEL_44;
v24 = (v23 & 0xFDu) > 5;
if ( (v23 & 0xFD) != 5 )
v24 = (unsigned int)(v23 - 11) > 1;
v25 = !v24;
if ( v23 == 9 )
v25 |= 1u;
if ( !v25 || (v37 = sub_857130(v14, a2), v23 = *(unsigned __int8 *)(v14 + 264), !v37) )
{
LABEL_44:
if ( (unsigned int)(v23 - 7) <= 1 )
{
lws_rx_flow_control(v14, 1);
*(_BYTE *)(v14 + 179) &= ~0x80u;
}
v26 = *(unsigned __int8 *)(v14 + 179);
v27 = v26 & 0x80;
if ( (v26 & 0xFFFFFF80) != 0 || (*(_BYTE *)(v14 + 260) & 8) == 0 )
goto LABEL_72;
if ( *(_BYTE *)(v14 + 264) == 5 )
{
if ( (v26 & 0x40) != 0 )
{
if ( *(_BYTE *)(v14 + 263) == 4 )
{
v39 = sub_85ADF0(v14, v27);
result = v39 & ~(v39 >> 31);
}
else
{
result = sub_858EA8(v14, v27);
}
goto LABEL_73;
}
}
else if ( (v26 & 0x40) != 0 )
{
goto LABEL_72;
}
v28 = *(_DWORD *)(v14 + 196);
if ( v28 )
{
v29 = *(_DWORD *)(v14 + 244);
v30 = 1;
v31 = *(_DWORD *)(v14 + 240);
v43 = v28 + v29;
v44 = v31 - v29;
while ( 1 )
{
while ( 1 )
{
v36 = sub_85C730(v14, 11, &v43, 0);
if ( v36 < 0 )
goto LABEL_70;
if ( !v36 )
break;
if ( v44 && lws_read(v14, v43, v44) < 0 )
goto LABEL_72;
v43 = 0;
v44 = 0;
}
if ( v44 && lws_read(v14, v43, v44) < 0 )
goto LABEL_72;
v43 = 0;
v44 = 0;
v32 = lws_ssl_pending_no_ssl(v14);
if ( !v32 )
break;
LABEL_54:
v33 = (int)(a1 + 17);
if ( v32 >= 0x1000 )
v32 = 4096;
v34 = v32;
LABEL_57:
no_ssl = lws_ssl_capable_read_no_ssl(v14, v33, v34);
v44 = no_ssl;
if ( no_ssl == -2 )
goto LABEL_72;
if ( no_ssl >= -2 && no_ssl <= 0 )
goto LABEL_70;
v43 = v33;
}
if ( v30 )
{
v38 = *(_DWORD *)(v14 + 196);
if ( v38 )
{
if ( *(_DWORD *)(v14 + 244) == *(_DWORD *)(v14 + 240) )
{
sub_8597C4(v38, 0);
*(_DWORD *)(v14 + 196) = 0;
sub_856F70(v14);
result = 0;
goto LABEL_73;
}
}
}
}
else if ( (*(_WORD *)(a2 + 6) & *(_WORD *)(a2 + 4) & 1) != 0 )
{
v30 = *(_DWORD *)(v14 + 196);
v33 = (int)(a1 + 17);
v34 = 4096;
goto LABEL_57;
}
LABEL_72:
result = 0;
LABEL_73:
*(_WORD *)(a2 + 6) = 0;
return result;
}
if ( v23 == 7 )
*(_BYTE *)(v14 + 264) = 9;
LABEL_70:
sub_856B30(v14, 0);
return 1;
default:
if ( !sub_85A570(a1, v14, a2) )
goto LABEL_72;
return 1;
}
}