//
// __udivdi3 from 0xdcd70 to 0xdce7c (268 bytes)
//
// 4 xrefs:
// > j___udivdi3 @ 0xe3588
// > ??> @ 0x1ccc
// > j___udivdi3 @ 0xe3588
// > ??> @ 0xe72cc
//
// 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 _udivdi3(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r6
unsigned int v3; // r4
bool v4; // zf
unsigned int v5; // r1
unsigned int v6; // r4
char v7; // r5
bool v8; // cf
unsigned __int64 v9; // r10
__int64 result; // r0
unsigned __int64 v11; // r10
unsigned __int64 v12; // r8
v2 = a1;
if ( a2 > a1 )
return 0;
if ( HIDWORD(a2) )
v3 = __clz(HIDWORD(a2));
else
v3 = __clz(a2);
if ( !HIDWORD(a2) )
v3 += 32;
v4 = HIDWORD(a1) == 0;
if ( HIDWORD(a1) )
v5 = __clz(HIDWORD(a1));
else
v5 = __clz(a1);
if ( v4 )
v5 += 32;
v6 = v3 - v5;
v7 = v6;
v8 = HIDWORD(v2) >= a2 << v6 >> 32;
LODWORD(v9) = a2 << v6;
if ( HIDWORD(v2) == a2 << v6 >> 32 )
v8 = (unsigned int)v2 >= (unsigned int)(a2 << v6);
HIDWORD(v9) = a2 << v6 >> 32;
if ( v8 )
{
v2 -= v9;
result = 1LL << v6;
}
else
{
result = 0;
}
if ( v6 )
{
v11 = v9 >> 1;
do
{
v12 = 2 * (v2 - v11) + 1;
if ( v2 < v11 )
v12 = 2 * v2;
--v6;
v2 = v12;
}
while ( v6 );
return v12 + result - (v12 >> v7 << v7);
}
return result;
}