//
// ssl3_read_n from 0x99d2ac to 0x99d5c8 (796 bytes)
//
// 5 xrefs:
// > ssl3_get_record @ 0x9a0b10
// > ssl3_get_record @ 0x9a0cec
// > dtls1_get_record @ 0x9a18e0
// > dtls1_get_record @ 0x9a192c
// > ??> @ 0x7435c
//
// 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:06:46 +0000
//
int __fastcall ssl3_read_n(_DWORD *a1, int a2, int a3, int a4, int a5)
{
int v6; // r3
int v10; // r10
int v11; // r4
unsigned __int8 *v12; // r1
int v13; // r8
unsigned __int8 *v14; // r7
_BOOL4 v15; // r3
int v16; // r6
bool v18; // cc
int v19; // r6
__int64 v20; // r2
_DWORD *v21; // r0
int v22; // r3
int v23; // r0
int v24; // r3
int v25; // r2
int v26; // r3
int v27; // r1
int v28; // r2
int v29; // r3
int v30; // r1
bool v31; // cc
int v32; // r2
int v33; // r3
int v34; // [sp+Ch] [bp-2Ch]
if ( a2 <= 0 )
return a2;
v6 = a1[144];
if ( !v6 )
{
if ( !ssl3_setup_read_buffer(a1) )
return -1;
v6 = a1[144];
}
v10 = (3 - (_BYTE)v6) & 7;
v11 = a1[148];
if ( a4 )
{
v12 = (unsigned __int8 *)a1[693];
v13 = a1[694];
v14 = (unsigned __int8 *)(v6 + v10);
v34 = v13;
}
else
{
if ( v11 )
{
v30 = a1[147];
v31 = v10 == 0;
if ( ((3 - (_BYTE)v6) & 7) != 0 )
v31 = v11 <= 4;
if ( v31 )
{
v14 = (unsigned __int8 *)(v6 + v10);
v12 = (unsigned __int8 *)(v6 + v30);
}
else
{
v32 = *(unsigned __int8 *)(v6 + v30);
v12 = (unsigned __int8 *)(v6 + v30);
if ( v32 == 23 && (v12[4] | (v12[3] << 8)) > 127 )
{
memmove((void *)(v6 + v10), v12, a1[148]);
v33 = a1[144];
a1[147] = v10;
v14 = (unsigned __int8 *)(v33 + v10);
v12 = (unsigned __int8 *)(v33 + v10);
}
else
{
v14 = (unsigned __int8 *)(v6 + v10);
}
}
}
else
{
v14 = (unsigned __int8 *)(v6 + v10);
v12 = (unsigned __int8 *)(v6 + v10);
a1[147] = v10;
}
v13 = 0;
v34 = 0;
a1[693] = v12;
a1[694] = 0;
}
v15 = v14 != v12;
if ( a5 != 1 )
v15 = 0;
if ( v15 )
{
memmove(v14, v12, v11 + v34);
a1[147] = v13 + v10;
a1[693] = v14;
}
if ( (*(_DWORD *)(*(_DWORD *)(a1[1] + 100) + 52) & 8) != 0 )
{
v16 = a4 != 0;
if ( v11 )
v16 = 0;
if ( v16 )
return 0;
v18 = a2 <= v11;
if ( a2 > v11 )
v18 = v11 <= 0;
if ( !v18 )
goto LABEL_35;
}
if ( a2 <= v11 )
{
v16 = v11 - a2;
v11 = a2;
LABEL_35:
v25 = a1[694] + v11;
v26 = a1[147] + v11;
a1[148] = v16;
a1[694] = v25;
a1[147] = v26;
return v11;
}
v19 = a1[146] - a1[147];
if ( a2 <= v19 )
{
LODWORD(v20) = a1[140];
HIDWORD(v20) = *(_DWORD *)(*(_DWORD *)(a1[1] + 100) + 52) & 8;
if ( v20 && a2 <= a3 )
{
if ( v19 >= a3 )
v19 = a3;
}
else
{
v19 = a2;
}
while ( 1 )
{
v21 = (_DWORD *)_errno();
v22 = a1[2];
*v21 = 0;
if ( !v22 )
break;
a1[5] = 3;
v23 = BIO_read(v22, &v14[v11 + v13], v19 - v11);
if ( v23 <= 0 )
goto LABEL_39;
v11 += v23;
if ( ((a2 > v11) & (*(_DWORD *)(*(_DWORD *)(a1[1] + 100) + 52) >> 3)) != 0 )
{
v24 = 0;
goto LABEL_37;
}
if ( a2 <= v11 )
{
v24 = v11 - a2;
v11 = a2;
LABEL_37:
v27 = a1[147] + v11;
v28 = a1[694] + v11;
a1[148] = v24;
a1[147] = v27;
a1[694] = v28;
a1[5] = 1;
return v11;
}
}
ERR_put_error(20, 149, 211, "ssl/record/rec_layer_s3.c", 306);
LABEL_39:
v29 = a1[76];
a1[148] = v11;
if ( (v29 & 0x10) != 0 && (*(_DWORD *)(*(_DWORD *)(a1[1] + 100) + 52) & 8) == 0 && !(v34 + v11) )
ssl3_release_read_buffer(a1);
return -1;
}
ERR_put_error(20, 149, 68, "ssl/record/rec_layer_s3.c", 279);
return -1;
}