//
// engine_unlocked_finish from 0xd9d0f4 to 0xd9d1d0 (220 bytes)
//
// 6 xrefs:
// > ENGINE_finish @ 0xd9d2c4
// > sub_E5E148 @ 0xe5e1a0
// > sub_E5E1B4 @ 0xe5e1dc
// > engine_table_register @ 0xe5e2f8
// > engine_table_select @ 0xe5e5c8
// > ??> @ 0x7c890
//
// 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 engine_unlocked_finish(__int64 a1, int a2)
{
unsigned int v3; // w19
__int64 (*v4)(void); // x2
unsigned int v5; // w21
unsigned int v6; // w19
v3 = *(_DWORD *)(a1 + 160) - 1;
*(_DWORD *)(a1 + 160) = v3;
if ( v3 || (v4 = *(__int64 (**)(void))(a1 + 104)) == nullptr )
{
v5 = 1;
v6 = engine_free_util(a1, 0);
if ( v6 )
return v5;
}
else
{
if ( a2 )
{
CRYPTO_THREAD_unlock(global_engine_lock);
v5 = (*(__int64 (__fastcall **)(__int64))(a1 + 104))(a1);
CRYPTO_THREAD_write_lock(global_engine_lock);
}
else
{
v5 = v4();
}
if ( !v5 )
return v3;
v6 = engine_free_util(a1, 0);
if ( v6 )
return v5;
}
ERR_put_error(38, 191, 106, "crypto/engine/eng_init.c", 69);
return v6;
}