//
// sub_180021A50 from 0x180021a50 to 0x180021b15 (197 bytes)
//
// 2 xrefs:
// > ??> @ 0x1800e6ba8
// > ??> @ 0x1801aee54
//
// 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 sub_180021A50(__int64 a1)
{
unsigned __int8 *v2; // rbx
unsigned __int64 v4; // rax
unsigned __int64 v5; // rsi
__int64 v6; // rbx
__int64 v7; // rax
v2 = (unsigned __int8 *)std::streambuf::gptr(a1);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( (unsigned __int64)v2 < std::streambuf::egptr(a1) )
return *v2;
v4 = std::streambuf::pptr(a1);
if ( !v4 || (*(_BYTE *)(a1 + 112) & 4) != 0 )
return 0xFFFFFFFFLL;
v5 = *(_QWORD *)(a1 + 104);
if ( v5 < v4 )
v5 = v4;
if ( v5 <= (unsigned __int64)v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 104) = v5;
v6 = std::streambuf::gptr(a1);
v7 = std::streambuf::eback(a1);
std::streambuf::setg(a1, v7, v6, v5);
return *(unsigned __int8 *)std::streambuf::gptr(a1);
}