//
// sub_80B408 from 0x80b408 to 0x80b56c (356 bytes)
//
// 1 xrefs:
// > ??> @ 0xa323ac
//
// 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 sub_80B408(int a1, int a2, int a3, void *a4)
{
_DWORD *v6; // r5
bool v7; // zf
int v8; // r0
int result; // r0
int v10; // r0
int v11; // r0
bool v12; // zf
int v13; // r0
int v14; // r0
v6 = *(_DWORD **)(a1 + 20);
switch ( a2 )
{
case 4099:
if ( !a4 )
goto LABEL_7;
*v6 = a4;
result = 1;
break;
case 4100:
v12 = a3 == 0;
if ( a3 )
v12 = a4 == nullptr;
if ( v12 )
goto LABEL_23;
if ( a3 < 0 )
goto LABEL_7;
v13 = v6[1];
if ( v13 )
CRYPTO_clear_free(v13, v6[2], "crypto/kdf/hkdf.c", 88);
v14 = CRYPTO_memdup(a4, a3, "crypto/kdf/hkdf.c", 90);
v6[1] = v14;
if ( !v14 )
goto LABEL_7;
v6[2] = a3;
result = 1;
break;
case 4101:
if ( a3 < 0 )
goto LABEL_7;
v10 = v6[3];
if ( v10 )
CRYPTO_clear_free(v10, v6[4], "crypto/kdf/hkdf.c", 102);
v11 = CRYPTO_memdup(a4, a3, "crypto/kdf/hkdf.c", 104);
v6[3] = v11;
if ( !v11 )
goto LABEL_7;
v6[4] = a3;
result = 1;
break;
case 4102:
v7 = a3 == 0;
if ( a3 )
v7 = a4 == nullptr;
if ( v7 )
{
LABEL_23:
result = 1;
}
else if ( a3 >= 0 && (v8 = v6[261], a3 <= 1024 - v8) )
{
memcpy((char *)v6 + v8 + 20, a4, a3);
v6[261] += a3;
result = 1;
}
else
{
LABEL_7:
result = 0;
}
break;
default:
result = -2;
break;
}
return result;
}