//
// sub_180021F80 from 0x180021f80 to 0x180022045 (197 bytes)
//
// 2 xrefs:
// > ??> @ 0x1800ecbf8
// > ??> @ 0x1801b8f38
//
// 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 11:21:28 +0000
//
__int64 __fastcall sub_180021F80(__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);
}