//
// sub_140667810 from 0x140667810 to 0x1406678b1 (161 bytes)
//
// 2 xrefs:
// > sub_1406678C0 @ 0x1406678e0
// > ??> @ 0x140931e38
//
// 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:35:51 +0000
//
unsigned __int64 __fastcall sub_140667810(__int64 *a1, double a2)
{
__int64 v2; // r8
unsigned __int64 v3; // rdx
double v4; // xmm0_8
unsigned __int64 v5; // rcx
v2 = *a1;
v3 = (a1[1] - *a1) >> 3;
while ( (__int64)v3 > 0 )
{
if ( *(double *)(v2 + 8 * (v3 >> 1)) <= a2 )
{
v2 += 8 * (v3 >> 1) + 8;
v3 += -1LL - (v3 >> 1);
}
else
{
v3 >>= 1;
}
}
v4 = fmax((double)(int)(((v2 - *a1) >> 3) - 1), 0.0);
v5 = 0;
if ( v4 >= 9.223372036854776e18 )
{
v4 = v4 - 9.223372036854776e18;
if ( v4 < 9.223372036854776e18 )
v5 = 0x8000000000000000uLL;
}
return v5 + (unsigned int)(int)v4;
}