//
// __aeabi_uidiv from 0xdb768 to 0xdb810 (168 bytes)
//
// 7 xrefs:
// > ??> @ 0xdb766
// > __aeabi_uidivmod @ 0xdb81c
// > j___aeabi_uidiv @ 0xe1318
// > ??> @ 0x51fc
// > ??> @ 0x5d3c
// > j___aeabi_uidiv @ 0xe1318
// > ??> @ 0xe6a30
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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:42:06 +0000
//
// Alternative name is '__udivsi3'
unsigned int __fastcall _aeabi_uidiv(unsigned int result, unsigned int a2)
{
char v2; // r2
unsigned int v3; // r1
unsigned int v4; // r3
int v5; // r2
bool v6; // zf
if ( a2 != 1 )
{
if ( a2 )
{
if ( result <= a2 )
{
return result == a2;
}
else if ( (a2 & (a2 - 1)) != 0 )
{
v2 = __clz(a2) - __clz(result);
v3 = a2 << v2;
v4 = 1 << v2;
v5 = 0;
while ( 1 )
{
if ( result >= v3 )
{
result -= v3;
v5 |= v4;
}
if ( result >= v3 >> 1 )
{
result -= v3 >> 1;
v5 |= v4 >> 1;
}
if ( result >= v3 >> 2 )
{
result -= v3 >> 2;
v5 |= v4 >> 2;
}
if ( result >= v3 >> 3 )
{
result -= v3 >> 3;
v5 |= v4 >> 3;
}
v6 = result == 0;
if ( result )
{
v4 >>= 4;
v6 = v4 == 0;
}
if ( v6 )
break;
v3 >>= 4;
}
return v5;
}
else
{
result >>= 31 - __clz(a2);
}
}
else
{
if ( result )
result = -1;
return j___aeabi_idiv0(result);
}
}
return result;
}