//
// lws_plat_service from 0x64bf34 to 0x64c06a (310 bytes)
//
// 1 xrefs:
// > lws_service @ 0x647638
//
// 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 lws_plat_service(int a1, int a2)
{
int v2; // r4
int v5; // r2
int v6; // r2
int v7; // r0
int v8; // r2
bool v9; // zf
int v10; // r3
int v11; // r0
int *v12; // r6
int v13; // r4
int v14; // r0
bool v15; // zf
int v16; // r3
int v17; // r1
int v18; // r2
int result; // r0
int v20; // r3
_DWORD buf[73]; // [sp+Ch] [bp-124h] BYREF
if ( !a1 )
return 1;
v2 = *(_DWORD *)(a1 + 4596);
if ( !v2 )
{
memset(buf, 0, 0x10Cu);
v20 = *(_DWORD *)(a1 + 44);
buf[46] = a1;
v2 = (*(int (__fastcall **)(_DWORD *, int, _DWORD, _DWORD, _DWORD))(v20 + 4))(buf, 31, 0, 0, 0);
*(_DWORD *)(a1 + 4596) = v2;
}
v5 = *(_DWORD *)(a1 + 56);
*(_DWORD *)(a1 + 4592) = v2;
if ( v5 )
v6 = 0;
else
v6 = a2;
v7 = poll(*(struct pollfd **)(a1 + 24), *(_DWORD *)(a1 + 4552), v6);
v8 = *(_DWORD *)(a1 + 56);
v9 = v7 == 0;
if ( !v7 )
v9 = v8 == 0;
if ( v9 )
{
lws_service_fd((time_t *)a1, 0);
return 0;
}
else
{
if ( v7 >= 0 )
{
for ( ; v8; v8 = *(_DWORD *)(v8 + 8) )
{
v10 = *(_DWORD *)(a1 + 24) + 8 * *(_DWORD *)(v8 + 236);
*(_WORD *)(v10 + 6) |= *(_WORD *)(v10 + 4) & 1;
}
v11 = *(_DWORD *)(a1 + 4552);
if ( v11 <= 0 )
return 0;
v12 = (int *)(a1 + 4552);
v13 = 0;
while ( 1 )
{
v16 = *(_DWORD *)(a1 + 24);
v17 = v16 + 8 * v13;
if ( !*(_WORD *)(v17 + 6) )
goto LABEL_18;
v18 = *(_DWORD *)(v16 + 8 * v13);
if ( v18 == *(_DWORD *)(a1 + 4600) )
{
if ( read(v18, buf, 1u) != 1 )
lws_log(1, "Cannot read from dummy pipe.");
v11 = *v12;
if ( ++v13 >= *v12 )
return 0;
}
else
{
v14 = lws_service_fd((time_t *)a1, v17);
v15 = v14 == 0;
if ( v14 < 0 )
return -1;
v11 = *v12;
if ( !v15 )
--v13;
LABEL_18:
if ( ++v13 >= v11 )
return 0;
}
}
}
result = *(_DWORD *)_errno() - 4;
if ( result )
return -1;
}
return result;
}