//
// sub_99938 from 0x99938 to 0x99b76 (574 bytes)
//
// 2 xrefs:
// > sub_99830 @ 0x99906
// > sub_9AD98 @ 0x9ae56
//
// 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
//
int __fastcall sub_99938(int a1, float *a2, float *a3)
{
int v5; // lr
float v6; // s0
float v7; // s2
float v8; // s4
char v9; // r4
float v10; // s18
float v11; // r0
float v12; // s16
int v13; // r0
_DWORD *v14; // r12
float *v15; // r2
float v16; // s0
int i; // r2
_DWORD *v18; // r1
int j; // r4
float *v20; // r4
int v21; // r8
int v22; // r11
float *v23; // r6
float *v24; // r9
float v25; // s18
float v26; // s20
float v27; // r0
float v28; // r0
int v30; // [sp+4h] [bp-7Ch]
_DWORD v31[16]; // [sp+8h] [bp-78h] BYREF
memset(a3, 0, 0xA0u);
v5 = *(_DWORD *)a2;
if ( *(_DWORD *)a2 == 1 )
{
v6 = a2[1];
v7 = a2[3];
v8 = a2[2];
v9 = 0;
v10 = (float)(v6 * v6) + (float)(v7 * v7);
if ( v6 != 0.0 || v7 != 0.0 )
{
v11 = atan2f(a2[1], a2[3]);
a3[4] = sqrtf(v10);
a3[1] = v11 * 57.296;
}
v12 = sqrtf(v10 + (float)(v8 * v8));
if ( a2[7] == 0.0 )
v9 = 1;
if ( ((unsigned __int8)v9 & (a2[9] == 0.0)) == 0 )
a3[2] = atan2f(a2[7], a2[9]) * 57.296;
*a3 = 1.0;
a3[3] = v12;
}
else
{
v13 = 0;
v14 = v31;
while ( v13 < v5 )
{
v15 = &a2[12 * v13];
v16 = sqrtf((float)((float)(v15[1] * v15[1]) + (float)(v15[2] * v15[2])) + (float)(v15[3] * v15[3]));
*(float *)&v31[v13 + 8] = v16;
for ( i = 0; v13 != i; ++i )
{
if ( v16 < *(float *)&v31[v31[i] + 8] )
goto LABEL_16;
}
i = v13;
LABEL_16:
v18 = v14;
for ( j = v13; j > i; --j )
{
*v18 = *(v18 - 1);
--v18;
}
v31[i] = v13;
++v14;
++v13;
}
v20 = a3 + 2;
v21 = 0;
v30 = v5;
while ( v21 < v5 )
{
v22 = v31[v21];
v23 = a2;
v24 = &a2[12 * v22];
v25 = v24[3];
v26 = v24[1];
if ( v26 != 0.0 || v25 != 0.0 )
{
v27 = atan2f(v24[1], v24[3]);
v5 = v30;
v20[2] = sqrtf((float)(v26 * v26) + (float)(v25 * v25));
*(v20 - 1) = v27 * 57.296;
}
if ( v24[7] != 0.0 || v24[9] != 0.0 )
{
v28 = atan2f(v24[7], v24[9]);
v5 = v30;
*v20 = v28 * 57.296;
}
a2 = v23;
++v21;
v20[1] = *(float *)&v31[v22 + 8];
*(v20 - 2) = v23[v22 + 97];
v20 += 5;
}
}
return 0;
}