//
// OPENSSL_uni2utf8 from 0xdcbb8c to 0xdcbde0 (596 bytes)
//
// 2 xrefs:
// > PKCS12_get_friendlyname @ 0xe65c10
// > ??> @ 0x76338
//
// 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
//
_BYTE *__fastcall OPENSSL_uni2utf8(__int64 a1, int a2)
{
int v4; // w19
int v5; // w21
unsigned __int8 *v6; // x0
unsigned __int64 v7; // x2
__int64 v8; // x2
__int64 v9; // x3
int v10; // w1
__int64 v11; // x0
_BYTE *v12; // x24
int v13; // w19
int v14; // w21
unsigned __int8 *v15; // x5
unsigned __int64 v16; // x2
__int64 v17; // x3
__int64 v18; // x2
int v19; // w1
__int64 v20; // x20
_BYTE *result; // x0
v4 = a2 & 1;
if ( (a2 & 1) != 0 )
return nullptr;
if ( a2 > 0 )
{
v5 = 0;
while ( 1 )
{
v10 = a2 - v4;
if ( a2 == v4 )
goto LABEL_15;
if ( v10 <= 1 )
return OPENSSL_uni2asc(a1, a2);
v6 = (unsigned __int8 *)(a1 + v4);
v7 = v6[1] | (*v6 << 8);
if ( v7 - 55296 <= 0x7FF )
{
if ( v10 <= 3 )
return OPENSSL_uni2asc(a1, a2);
v8 = (v7 - 55296) << 10;
v9 = (v6[3] | (v6[2] << 8)) - 56320;
if ( (unsigned int)v9 > 0x3FF )
return OPENSSL_uni2asc(a1, a2);
v7 = (v9 | v8) + 0x10000;
}
if ( v10 > 4 )
v10 = 4;
v10 = UTF8_putc(nullptr, v10, v7);
if ( v10 < 0 )
return OPENSSL_uni2asc(a1, a2);
if ( v10 != 4 )
{
LABEL_15:
v4 += 2;
v5 += v10;
if ( v4 >= a2 )
goto LABEL_16;
}
else
{
v4 += 4;
v5 += 4;
if ( v4 >= a2 )
goto LABEL_16;
}
}
}
v5 = 0;
if ( !a2 )
goto LABEL_17;
LABEL_16:
v11 = a1 + a2;
if ( *(_BYTE *)(v11 - 2) || *(_BYTE *)(v11 - 1) )
LABEL_17:
++v5;
v12 = CRYPTO_malloc((void *)v5, (__int64)"crypto/pkcs12/p12_utl.c", 197);
if ( !v12 )
return nullptr;
if ( a2 > 0 )
{
v13 = 0;
v14 = 0;
while ( 1 )
{
v19 = a2 - v13;
if ( a2 == v13 )
goto LABEL_31;
if ( v19 <= 1 )
goto LABEL_37;
v15 = (unsigned __int8 *)(a1 + v13);
v16 = v15[1] | (*v15 << 8);
if ( v16 - 55296 <= 0x7FF )
{
if ( v19 <= 3 || (v17 = (v16 - 55296) << 10, v18 = (v15[3] | (v15[2] << 8)) - 56320, (unsigned int)v18 > 0x3FF) )
{
LABEL_37:
v19 = -1;
v13 += 2;
goto LABEL_32;
}
v16 = (v18 | v17) + 0x10000;
}
if ( v19 > 4 )
v19 = 4;
v19 = UTF8_putc(&v12[v14], v19, v16);
if ( v19 != 4 )
{
LABEL_31:
v13 += 2;
LABEL_32:
v14 += v19;
if ( v13 >= a2 )
goto LABEL_33;
}
else
{
v13 += 4;
v14 += 4;
if ( v13 >= a2 )
goto LABEL_33;
}
}
}
v14 = 0;
if ( !a2 )
goto LABEL_34;
LABEL_33:
v20 = a1 + a2;
if ( *(_BYTE *)(v20 - 2) || (result = v12, *(_BYTE *)(v20 - 1)) )
{
LABEL_34:
v12[v14] = 0;
return v12;
}
return result;
}