//
// _free_osfhnd from 0x1801361b4 to 0x18013626e (186 bytes)
//
// 2 xrefs:
// > _close_nolock @ 0x180138c96
// > ??> @ 0x1802034dc
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// 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 10:55:00 +0000
//
__int64 __fastcall free_osfhnd(int a1)
{
__int64 v2; // rsi
__int64 v3; // rdi
__int64 v4; // rax
int v5; // ebx
DWORD v6; // ecx
if ( a1 >= 0 && a1 < (unsigned int)dword_1801F5560 )
{
v2 = (__int64)a1 >> 6;
v3 = 9LL * (a1 & 0x3F);
v4 = qword_1801F5160[v2];
if ( (*(_BYTE *)(v4 + 72LL * (a1 & 0x3F) + 56) & 1) != 0 && *(_QWORD *)(v4 + 72LL * (a1 & 0x3F) + 40) != -1 )
{
if ( (unsigned int)sub_180138EF0() == 1 )
{
if ( !a1 )
{
v6 = -10;
goto LABEL_12;
}
v5 = a1 - 1;
if ( !v5 )
{
v6 = -11;
goto LABEL_12;
}
if ( v5 == 1 )
{
v6 = -12;
LABEL_12:
SetStdHandle(v6, nullptr);
}
}
*(_QWORD *)(qword_1801F5160[v2] + 8 * v3 + 40) = -1;
return 0;
}
}
*errno() = 9;
*_doserrno() = 0;
return 0xFFFFFFFFLL;
}