//
// __trunctfdf2 from 0xe89a40 to 0xe89cfc (700 bytes)
//
// 15 xrefs:
// > mergeTwoRemaps @ 0x6749ac
// > std::_Hashtable,std::__detail::_Identity,std::equal_to,std::hash,std::__detail::_Mod_range_hashing,std::__detail::_Default_ranged_hash,std::__detail::_Prime_rehash_policy,std::__detail::_Hashtable_traits>::rehash @ 0x6754bc
// > GJBaseGameLayer::generateTargetGroups @ 0x887f50
// > fmt::BasicWriter::FormatDouble @ 0xb67e1c
// > fmt::BasicWriter::FormatDouble @ 0xb67eb4
// > fmt::BasicWriter::FormatDouble @ 0xb67f00
// > fmt::BasicWriter::FormatDouble @ 0xb692ac
// > fmt::BasicWriter::FormatDouble @ 0xb6934c
// > fmt::BasicWriter::FormatDouble @ 0xb6939c
// > _TIFFUInt64ToDouble @ 0xc2cee8
// > sub_D146DC @ 0xd14760
// > sub_D146DC @ 0xd147cc
// > sub_D147E8 @ 0xd1487c
// > sub_D147E8 @ 0xd14904
// > ??> @ 0x57a20
//
// 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
//
long double __fastcall _trunctfdf2(long double result)
{
unsigned __int64 StatusReg; // x3
__int64 v2; // x6
unsigned __int64 v3; // x1
unsigned __int64 v4; // x5
__int64 v5; // x2
__int64 v6; // x0
unsigned __int64 v7; // x1
unsigned __int64 v8; // x0
__int64 v9; // x8
unsigned __int64 v10; // x0
unsigned __int64 v11; // x1
unsigned __int64 v12; // x6
__int64 v13; // x0
_BOOL4 v14; // w5
__int64 v15; // x6
unsigned __int64 v16; // x6
bool v17; // zf
__int64 v18; // x3
unsigned __int64 v19; // x1
long double v20; // [xsp+10h] [xbp+10h]
StatusReg = _ReadStatusReg(FPCR);
v2 = HIWORD(*((_QWORD *)&result + 1)) & 0x7FFFLL;
v3 = *(__int128 *)&result >> 61;
v4 = 8LL * *(_QWORD *)&result;
if ( (((_WORD)v2 + 1) & 0x7FFFu) > 1uLL )
{
v5 = v2 - 15360;
if ( v2 - 15360 > 2046 )
{
v6 = StatusReg & 0xC00000;
if ( (StatusReg & 0xC00000) == 0 )
goto LABEL_29;
if ( v6 == 0x400000 )
{
if ( result >= 0.0 )
v7 = 0;
else
v7 = -1;
v5 = 2047;
if ( result < 0.0 )
v5 = 2046;
goto LABEL_30;
}
if ( v6 == 0x800000 && result < 0.0 )
{
LABEL_29:
v7 = 0;
v5 = 2047;
}
else
{
v7 = -1;
v5 = 2046;
}
LABEL_30:
v13 = 20;
goto LABEL_35;
}
if ( v5 > 0 )
{
v7 = (*(_QWORD *)&result << 7 != 0) | (16 * v3) | (v4 >> 60);
LABEL_34:
v13 = 0;
goto LABEL_35;
}
if ( v5 < -52 )
{
v7 = 1;
}
else
{
v8 = v3 | 0x8000000000000LL;
v9 = 15421 - v2;
if ( 15421 - v2 > 63 )
{
v12 = 0;
v11 = v8 >> (-3 - (unsigned __int8)v5);
if ( v9 != 64 )
v12 = v8 << ((unsigned __int8)v5 + 67);
v10 = (v12 | v4) != 0;
}
else
{
v10 = (v4 >> (61 - BYTE14(result))) | (v8 << (BYTE14(result) + 3));
v11 = v4 << (BYTE14(result) + 3) != 0;
}
v7 = v10 | v11;
}
LABEL_32:
v5 = 0;
goto LABEL_34;
}
if ( !v2 )
{
v7 = __PAIR128__(v3, v4) != 0;
goto LABEL_32;
}
if ( __PAIR128__(v3, v4) == 0 )
{
v7 = 0;
v5 = 2047;
goto LABEL_34;
}
v13 = 0;
if ( v2 == 0x7FFF )
v13 = ((unsigned __int8)(v3 >> 50) ^ 1) & 1;
v5 = 2047;
v7 = ((*(_OWORD *)&result * 8LL) >> 60) & 0xFFBFFFFFFFFFFFF8LL | 0x40000000000000LL;
LABEL_35:
v14 = v7 != 0 && v5 == 0;
if ( (v7 & 7) != 0 )
{
v15 = StatusReg & 0xC00000;
v13 = (unsigned int)v13 | 0x10;
if ( (StatusReg & 0xC00000) == 0x400000 )
{
if ( result >= 0.0 )
v7 += 8LL;
}
else
{
if ( v15 == 0x800000 )
{
v16 = v7 + 8;
v17 = result >= 0.0;
}
else
{
if ( v15 )
goto LABEL_70;
v16 = v7 + 4;
v17 = (v7 & 0xF) == 4;
}
if ( !v17 )
v7 = v16;
}
LABEL_70:
if ( !v14 )
goto LABEL_51;
goto LABEL_50;
}
if ( v7 != 0 && v5 == 0 && ((v13 & 0x10) != 0 || (StatusReg & 0x800) != 0) )
LABEL_50:
v13 = (unsigned int)v13 | 8;
LABEL_51:
if ( (v7 & 0x80000000000000LL) != 0 )
{
++v5;
v7 &= ~0x80000000000000uLL;
if ( v5 == 2047 )
{
v18 = StatusReg & 0xC00000;
v7 = 0;
if ( v18 )
{
if ( v18 == 0x400000 )
{
if ( result >= 0.0 )
v7 = 0;
else
v7 = -1;
if ( result < 0.0 )
v5 = 2046;
}
else if ( v18 != 0x800000 || result >= 0.0 )
{
v7 = -1;
v5 = 2046;
}
}
v13 = (unsigned int)v13 | 0x14;
}
}
v19 = v7 >> 3;
if ( v19 && v5 == 2047 )
v19 |= 0x8000000000000uLL;
*(_QWORD *)&result = v19 & 0xFFFFFFFFFFFFFLL
| ((unsigned __int64)(v5 & 0x7FF) << 52) & 0x7FFFFFFFFFFFFFFFLL
| ((unsigned __int64)(result < 0.0) << 63);
if ( (_DWORD)v13 )
{
v20 = result;
_sfp_handle_exceptions(v13);
return v20;
}
return result;
}