//
// lws_read from 0xbbb4d4 to 0xbbb70c (568 bytes)
//
// 4 xrefs:
// > lws_service_fd @ 0xbbcce0
// > lws_service_fd @ 0xbbcd08
// > lws_server_socket_service @ 0xbc3b98
// > ??> @ 0x4b918
//
// 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 lws_read(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // x20
unsigned int v5; // w21
__int64 v7; // x22
__int64 v8; // x3
int v9; // w0
unsigned int v10; // w21
int v11; // w22
__int64 v12; // x4
__int64 v13; // x2
int v14; // w0
__int64 v15; // [xsp+38h] [xbp+38h] BYREF
v15 = a2;
v4 = a3;
switch ( *(_BYTE *)(a1 + 73) )
{
case 0:
goto LABEL_13;
case 1:
goto LABEL_14;
case 2:
goto LABEL_15;
case 3:
if ( !a3 )
return 0;
v10 = *(_DWORD *)(a1 + 196);
if ( !v10 )
return 0;
v8 = v15;
break;
case 5:
case 8:
v5 = sub_BBFD40(a1, &v15);
if ( v5 )
goto LABEL_16;
if ( *(_BYTE *)(a1 + 72) != 3 )
return v5;
if ( (sub_BC3E1C(a1, v15, v4) & 0x80000000) == 0 )
return 0;
goto LABEL_16;
default:
v5 = 0;
lws_log(1, "%s: Unhandled state\n", "lws_read");
return v5;
}
LABEL_20:
v11 = v10;
v12 = *(_QWORD *)(a1 + 8);
v13 = *(_QWORD *)(a1 + 144);
if ( v10 > v4 )
v11 = v4;
*(_DWORD *)(a1 + 196) = v10 - v11;
v4 -= v11;
v5 = (*(__int64 (__fastcall **)(__int64, __int64, __int64, __int64, _QWORD))(v12 + 8))(a1, 13, v13, v8, v11);
if ( !v5 )
{
v14 = *(_DWORD *)(a1 + 196);
v15 += v11;
if ( v14 )
{
lws_set_timeout(a1, 10, 5);
return v5;
}
LABEL_10:
lws_set_timeout(a1, 0, 0);
if ( !(*(unsigned int (__fastcall **)(__int64, __int64, _QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 8) + 8LL))(
a1,
14,
*(_QWORD *)(a1 + 144),
0,
0) )
{
while ( !(unsigned int)lws_http_transaction_completed(a1) )
{
if ( !v4 )
return 0;
LABEL_13:
*(_BYTE *)(a1 + 76) &= ~1u;
LABEL_14:
*(_WORD *)(a1 + 160) = 0;
*(_BYTE *)(a1 + 73) = 2;
*(_BYTE *)(a1 + 164) = 83;
LABEL_15:
if ( (unsigned int)sub_BBFD40(a1, &v15) )
break;
v7 = v15;
if ( (unsigned int)sub_BC33E4(a1, &v15, v4) )
break;
v8 = v15;
if ( (*(_BYTE *)(a1 + 76) & 1) == 0 )
return 0;
v9 = *(unsigned __int8 *)(a1 + 73);
v4 += v7 - v15;
if ( v9 != 2 )
{
if ( v9 == 3 )
{
v10 = *(_DWORD *)(a1 + 192);
*(_DWORD *)(a1 + 196) = v10;
if ( !v10 )
goto LABEL_10;
if ( !v4 )
return 0;
goto LABEL_20;
}
if ( *(_BYTE *)(a1 + 73) )
return 0;
}
}
}
}
LABEL_16:
v5 = -1;
sub_BBC0F0(a1, 0);
return v5;
}