//
// lws_read from 0x6462e8 to 0x646402 (282 bytes)
//
// 2 xrefs:
// > lws_service_fd @ 0x64758c
// > lws_service_fd @ 0x6475f2
//
// 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_read(int a1, int a2, unsigned int a3)
{
int v3; // r3
unsigned int v5; // r6
int v6; // r3
unsigned int v7; // r3
int result; // r0
int v9; // r5
int v10; // r5
unsigned int v11; // r7
int v12; // r2
unsigned int v13; // r1
int v14; // r3
int v15; // r3
int v16; // [sp+Ch] [bp-8h] BYREF
v3 = *(unsigned __int8 *)(a1 + 264);
v16 = a2;
v5 = a3;
switch ( v3 )
{
case 0:
goto LABEL_8;
case 1:
goto LABEL_9;
case 2:
goto LABEL_10;
case 3:
if ( !a3 )
return 0;
v7 = *(_DWORD *)(a1 + 28);
if ( !v7 )
return 0;
break;
case 5:
case 8:
if ( !((int (*)(void))sub_6499D8)() )
return 0;
goto LABEL_11;
default:
lws_log(1, "%s: Unhandled state\n", "lws_read");
return 0;
}
while ( 1 )
{
v10 = *(_DWORD *)(a1 + 188);
v11 = v7;
v12 = *(_DWORD *)(a1 + 192);
if ( v7 >= v5 )
v11 = v5;
v13 = v7 - v11;
v14 = v16;
*(_DWORD *)(a1 + 28) = v13;
v5 -= v11;
v9 = (*(int (__fastcall **)(int, int, int, int, unsigned int))(v10 + 4))(a1, 13, v12, v14, v11);
if ( v9 )
{
LABEL_11:
sub_646AB0(a1, 0);
return -1;
}
v15 = *(_DWORD *)(a1 + 28);
v16 += v11;
if ( v15 )
break;
while ( 2 )
{
lws_set_timeout(a1, 0, 0);
if ( (*(int (__fastcall **)(int, int, _DWORD, _DWORD, _DWORD))(*(_DWORD *)(a1 + 188) + 4))(
a1,
14,
*(_DWORD *)(a1 + 192),
0,
0) )
{
goto LABEL_11;
}
while ( 1 )
{
do
{
if ( !v5 )
return 0;
LABEL_8:
*(_BYTE *)(a1 + 260) &= ~1u;
LABEL_9:
*(_BYTE *)(a1 + 264) = 2;
*(_BYTE *)(a1 + 18) = 83;
*(_WORD *)(a1 + 12) = 0;
LABEL_10:
result = sub_6499D8(a1, &v16, v5);
if ( result )
goto LABEL_11;
if ( (*(_BYTE *)(a1 + 260) & 1) == 0 )
return 0;
v6 = *(unsigned __int8 *)(a1 + 264);
}
while ( v6 == 2 );
if ( v6 == 3 )
break;
if ( *(_BYTE *)(a1 + 264) )
return result;
}
v7 = *(_DWORD *)(a1 + 24);
*(_DWORD *)(a1 + 28) = v7;
if ( !v7 )
continue;
break;
}
if ( !v5 )
return 0;
}
lws_set_timeout(a1, 10, 5);
return v9;
}