//
// sub_607480 from 0x607480 to 0x6076a6 (550 bytes)
//
// 4 xrefs:
// > sub_607480 @ 0x607628
// > sub_607480 @ 0x607650
// > pugi::xpath_node_set::sort @ 0x607ab8
// > sub_607BBC @ 0x607c80
//
// 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
//
void (*__fastcall sub_607480(void (*result)(), int *a2, pugi::xml_node_struct *a3))()
{
int *v3; // r6
pugi::xml_node_struct *v5; // r11
int *v6; // r7
int v7; // r5
int *v8; // r4
int *v9; // r0
int *v10; // r1
pugi::xml_node_struct *v11; // r2
int v12; // r5
pugi::xml_node_struct *v13; // r2
int *v14; // r5
int *i; // r5
int v16; // r1
int *k; // r7
int *j; // r3
int v19; // r1
int v20; // r1
int v21; // r1
int v22; // r1
int *v23; // r9
int *v24; // r7
int *v25; // r3
int *v26; // r1
int *v27; // r0
void (*v28)(); // [sp+Ch] [bp-10h] BYREF
int v29; // [sp+10h] [bp-Ch]
v3 = (int *)result;
v5 = a3;
while ( (char *)a2 - (char *)v3 >= 264 )
{
v6 = a2 - 2;
v7 = (char *)(a2 - 2) - (char *)v3;
v8 = &v3[2 * (((char *)a2 - (char *)v3) >> 4)];
if ( v7 >= 328 )
{
v12 = ((v7 >> 3) + 1) >> 3;
sub_607280(v3, &v3[2 * v12], (pugi::xml_node_struct *)&v3[2 * v12 + 2 * v12]);
sub_607280(&v8[-2 * v12], &v3[2 * (((char *)a2 - (char *)v3) >> 4)], (pugi::xml_node_struct *)&v8[2 * v12]);
sub_607280(&v6[-4 * v12], &v6[-2 * v12], (pugi::xml_node_struct *)(a2 - 2));
v10 = &v3[2 * (((char *)a2 - (char *)v3) >> 4)];
v11 = (pugi::xml_node_struct *)&v6[-2 * v12];
v9 = &v3[2 * v12];
}
else
{
v9 = v3;
v10 = &v3[2 * (((char *)a2 - (char *)v3) >> 4)];
v11 = (pugi::xml_node_struct *)(a2 - 2);
}
sub_607280(v9, v10, v11);
v14 = v8 + 2;
while ( v8 != v3 && pugi::xpath_node::operator==(v8 - 2, v8) )
v8 -= 2;
while ( v14 != a2 && pugi::xpath_node::operator==(v14, v8) )
v14 += 2;
v23 = v8;
v24 = v14;
while ( 1 )
{
LABEL_28:
if ( v14 == a2 )
goto LABEL_34;
if ( !sub_60703C((void (**)())v8, (pugi::xml_attribute_struct *)v14, v13) )
break;
LABEL_32:
v14 += 2;
}
if ( pugi::xpath_node::operator==(v14, v8) )
{
sub_600614(v14, v24);
v24 += 2;
goto LABEL_32;
}
LABEL_34:
while ( v23 != v3 )
{
v23 -= 2;
if ( !sub_60703C((void (**)())v23, (pugi::xml_attribute_struct *)v8, v13) )
{
if ( !pugi::xpath_node::operator==(v8, v23) )
{
if ( v14 == a2 )
{
v8 -= 2;
if ( v23 != v8 )
sub_600614(v23, v8);
v24 -= 2;
sub_600614(v8, v24);
}
else
{
sub_600614(v14, v23);
v14 += 2;
}
goto LABEL_28;
}
v8 -= 2;
sub_600614(v23, v8);
}
}
v25 = v8;
if ( v14 != a2 )
{
if ( v24 != v14 )
{
sub_600614(v8, v24);
v25 = v8;
}
sub_600614(v14, v25);
v13 = (pugi::xml_node_struct *)(v14 + 2);
v24 += 2;
v8 += 2;
v14 += 2;
goto LABEL_28;
}
if ( ((char *)a2 - (char *)v24) >> 3 >= ((char *)v8 - (char *)v3) >> 3 )
{
v27 = v3;
v3 = v24;
result = (void (*)())sub_607480(v27, v8, v5);
}
else
{
v26 = a2;
a2 = v8;
result = (void (*)())sub_607480(v24, v26, v5);
}
}
if ( v3 != a2 )
{
for ( i = v3 + 2; i != a2; i += 2 )
{
v16 = i[1];
v28 = (void (*)())*i;
v29 = v16;
if ( sub_60703C(&v28, (pugi::xml_attribute_struct *)v3, a3) )
{
for ( j = i; v3 != j; j[3] = v19 )
{
j -= 2;
a3 = (pugi::xml_node_struct *)(j + 2);
v19 = j[1];
j[2] = *j;
}
result = v28;
v20 = v29;
*v3 = (int)v28;
v3[1] = v20;
}
else
{
for ( k = i; sub_60703C(&v28, (pugi::xml_attribute_struct *)(k - 2), a3); k -= 2 )
{
v21 = *(k - 1);
*k = *(k - 2);
k[1] = v21;
}
result = v28;
v22 = v29;
*k = (int)v28;
k[1] = v22;
}
}
}
return result;
}