//
// sub_100918980 from 0x100918980 to 0x100918fef (1647 bytes)
//
// 4 xrefs:
// > sub_100915250 @ 0x1009158f1
// > sub_100915250 @ 0x1009159a0
// > sub_100915250 @ 0x100915bf1
// > sub_100918980 @ 0x1009189ca
//
// 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 12:38:13 +0000
//
__int64 __fastcall sub_100918980(int *a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
int *v6; // r12
__int64 v7; // rcx
__int64 v8; // r14
__int64 v9; // r14
__int64 result; // rax
unsigned __int64 v11; // r13
__int64 v12; // rbx
unsigned __int64 v13; // r13
__int64 v14; // r15
int *v15; // rax
int *v16; // rcx
int v17; // eax
int v18; // ecx
int **v19; // rdi
__int64 *v20; // rsi
int v21; // edx
int v22; // ecx
int **v23; // rdi
__int64 *v24; // rsi
__int64 v25; // r14
int v26; // eax
int v27; // ecx
int **v28; // rdi
__int64 *v29; // rsi
__int64 v30; // rsi
int *v31; // rdi
unsigned __int64 v32; // r13
int v33; // eax
int v34; // ecx
int **v35; // rdi
__int64 *v36; // rsi
int v37; // eax
signed int v38; // ecx
int **v39; // rdi
__int64 *v40; // rsi
__int64 v41; // rax
__int64 v42; // rbx
char v43; // dl
char v44; // r14
int v45; // ecx
int **v46; // rdi
unsigned __int64 v47; // rbx
__int64 v48; // r15
unsigned __int64 v49; // rbx
int *v50; // r15
unsigned __int64 v51; // r14
__int64 v52; // rsi
__int64 v54; // [rsp+8h] [rbp-78h] BYREF
unsigned int *v55; // [rsp+10h] [rbp-70h] BYREF
__int64 v56; // [rsp+18h] [rbp-68h]
__int64 v57; // [rsp+20h] [rbp-60h]
__int64 v58; // [rsp+28h] [rbp-58h] BYREF
__int64 v59; // [rsp+30h] [rbp-50h]
int *v60; // [rsp+38h] [rbp-48h] BYREF
int *v61; // [rsp+40h] [rbp-40h] BYREF
unsigned int *v62; // [rsp+48h] [rbp-38h] BYREF
int *v63[6]; // [rsp+50h] [rbp-30h] BYREF
LODWORD(v59) = a5;
v6 = a1;
v60 = a1;
v58 = a2;
v7 = a4 - 1;
while ( 2 )
{
v9 = a2 - (_QWORD)v6;
result = 0x6DB6DB6DB6DB6DB7LL;
v11 = 0x6DB6DB6DB6DB6DB7LL * ((a2 - (__int64)v6) >> 3);
switch ( v11 )
{
case 0uLL:
case 1uLL:
return result;
case 2uLL:
v58 = a2 - 56;
result = *(unsigned int *)(a2 - 56);
if ( (int)result < *v6 )
return sub_100916860(&v60, &v58);
return result;
case 3uLL:
v61 = v6;
v63[0] = v6 + 14;
v62 = (unsigned int *)(a2 - 56);
result = (unsigned int)v6[14];
v45 = *(_DWORD *)(a2 - 56);
if ( (int)result >= *v6 )
{
if ( v45 < (int)result )
{
sub_100916860(v63, (__int64 *)&v62);
result = (unsigned int)*v63[0];
if ( (int)result < *v61 )
return sub_100916860(&v61, (__int64 *)v63);
}
}
else
{
v46 = &v61;
if ( v45 >= (int)result )
{
sub_100916860(&v61, (__int64 *)v63);
result = *v62;
if ( (int)result >= *v63[0] )
return result;
v46 = v63;
}
return sub_100916860(v46, (__int64 *)&v62);
}
return result;
case 4uLL:
return sub_100919010(v6, v6 + 14, v6 + 28, a2 - 56, a3);
case 5uLL:
v58 = a2 - 56;
v61 = v6;
v63[0] = v6 + 14;
v62 = (unsigned int *)(v6 + 28);
v55 = (unsigned int *)(v6 + 42);
v54 = a2 - 56;
sub_100919010(v6, v6 + 14, v6 + 28, v6 + 42, a3);
result = *(unsigned int *)(a2 - 56);
if ( (int)result < v6[42] )
{
sub_100916860((int **)&v55, &v54);
result = *v55;
if ( (int)result < v6[28] )
{
sub_100916860((int **)&v62, (__int64 *)&v55);
result = *v62;
if ( (int)result < v6[14] )
{
sub_100916860(v63, (__int64 *)&v62);
result = (unsigned int)*v63[0];
if ( (int)result < *v6 )
return sub_100916860(&v61, (__int64 *)v63);
}
}
}
return result;
default:
if ( v9 <= 1343 )
{
if ( (v59 & 1) != 0 )
return sub_100919100(v6, a2, a3, v7);
else
return sub_100919320(v6, a2, a3, v7);
}
v57 = a2;
if ( v7 == -1 )
{
if ( v6 != (int *)a2 )
{
v47 = (v11 - 2) >> 1;
v59 = a3;
v48 = 14 * v47;
v49 = v47 + 1;
v50 = &v6[v48];
do
{
sub_100919ED0(v6, v59, v11, v50);
v50 -= 14;
--v49;
}
while ( v49 );
v51 = 0x6DB6DB6DB6DB6DB7LL * ((unsigned __int64)v9 >> 3);
v52 = v57;
do
{
sub_10091A170(v6, v52, v59, v51);
v52 -= 56;
result = v51 - 1;
}
while ( v51-- > 2 );
}
return result;
}
v56 = v7;
v12 = a3;
v13 = v11 >> 1;
v14 = 14 * v13;
v15 = &v6[14 * v13];
v16 = (int *)(a2 - 56);
if ( (unsigned __int64)v9 < 0x1C01 )
{
v61 = &v6[14 * v13];
v63[0] = v6;
v62 = (unsigned int *)(a2 - 56);
v21 = *v6;
v22 = *v16;
if ( *v6 >= *v15 )
{
a3 = v12;
if ( v22 >= v21 || (sub_100916860(v63, (__int64 *)&v62), *v63[0] >= *v61) )
{
LABEL_31:
v30 = v57;
v31 = v60;
if ( (v59 & 1) != 0 )
goto LABEL_57;
goto LABEL_56;
}
v23 = &v61;
v24 = (__int64 *)v63;
}
else
{
a3 = v12;
v23 = &v61;
if ( v22 >= v21 )
{
sub_100916860(&v61, (__int64 *)v63);
if ( (signed int)*v62 >= *v63[0] )
goto LABEL_31;
v23 = v63;
}
v24 = (__int64 *)&v62;
}
sub_100916860(v23, v24);
goto LABEL_31;
}
v61 = v6;
v63[0] = &v6[14 * v13];
v62 = (unsigned int *)(a2 - 56);
v17 = *v15;
v18 = *v16;
if ( v17 < *v6 )
{
v19 = &v61;
if ( v18 >= v17 )
{
sub_100916860(&v61, (__int64 *)v63);
if ( (signed int)*v62 >= *v63[0] )
goto LABEL_22;
v19 = v63;
}
v20 = (__int64 *)&v62;
goto LABEL_21;
}
if ( v18 < v17 )
{
sub_100916860(v63, (__int64 *)&v62);
if ( *v63[0] < *v61 )
{
v19 = &v61;
v20 = (__int64 *)v63;
LABEL_21:
sub_100916860(v19, v20);
}
}
LABEL_22:
v25 = 14 * (v13 - 1);
v61 = v60 + 14;
v63[0] = &v60[v25];
v62 = (unsigned int *)(v57 - 112);
v26 = v60[v25];
v27 = *(_DWORD *)(v57 - 112);
if ( v26 < v60[14] )
{
v28 = &v61;
if ( v27 >= v26 )
{
sub_100916860(&v61, (__int64 *)v63);
if ( (signed int)*v62 >= *v63[0] )
goto LABEL_37;
v28 = v63;
}
v29 = (__int64 *)&v62;
goto LABEL_36;
}
if ( v27 < v26 )
{
sub_100916860(v63, (__int64 *)&v62);
if ( *v63[0] < *v61 )
{
v28 = &v61;
v29 = (__int64 *)v63;
LABEL_36:
sub_100916860(v28, v29);
}
}
LABEL_37:
v32 = v13 + 1;
v61 = v60 + 28;
v63[0] = &v60[14 * v32];
v62 = (unsigned int *)(v57 - 168);
v33 = *v63[0];
v34 = *(_DWORD *)(v57 - 168);
if ( *v63[0] < v60[28] )
{
v35 = &v61;
if ( v34 >= v33 )
{
sub_100916860(&v61, (__int64 *)v63);
if ( (signed int)*v62 >= *v63[0] )
goto LABEL_46;
v35 = v63;
}
v36 = (__int64 *)&v62;
goto LABEL_45;
}
if ( v34 < v33 )
{
sub_100916860(v63, (__int64 *)&v62);
if ( *v63[0] < *v61 )
{
v35 = &v61;
v36 = (__int64 *)v63;
LABEL_45:
sub_100916860(v35, v36);
}
}
LABEL_46:
v61 = &v60[v25];
v63[0] = &v60[v14];
v62 = (unsigned int *)&v60[14 * v32];
v37 = v60[v14];
v38 = *v62;
if ( v37 < v60[v25] )
{
v39 = &v61;
if ( v38 >= v37 )
{
sub_100916860(&v61, (__int64 *)v63);
if ( (signed int)*v62 >= *v63[0] )
goto LABEL_55;
v39 = v63;
}
v40 = (__int64 *)&v62;
goto LABEL_54;
}
if ( v38 < v37 )
{
sub_100916860(v63, (__int64 *)&v62);
if ( *v63[0] < *v61 )
{
v39 = &v61;
v40 = (__int64 *)v63;
LABEL_54:
sub_100916860(v39, v40);
}
}
LABEL_55:
v61 = &v60[v14];
sub_100916860(&v60, (__int64 *)&v61);
a3 = v12;
v30 = v57;
v31 = v60;
if ( (v59 & 1) != 0 )
goto LABEL_57;
LABEL_56:
if ( *(v31 - 14) >= *v31 )
{
v6 = (int *)sub_100919520(v31, v30, a3);
v60 = v6;
v8 = v56;
goto LABEL_3;
}
LABEL_57:
v41 = sub_100919770(v31, v30, a3);
v42 = v41;
if ( (v43 & 1) == 0 )
{
LABEL_2:
v8 = v56;
sub_100918980(v60, v42, a3, v56, v59 & 1);
v60 = (int *)(v42 + 56);
LODWORD(v59) = 0;
v6 = (int *)(v42 + 56);
LABEL_3:
a2 = v58;
v7 = v8 - 1;
continue;
}
v44 = sub_1009199E0(v60, v41, a3);
v6 = (int *)(v42 + 56);
result = sub_1009199E0(v42 + 56, v58, a3);
if ( !(_BYTE)result )
{
if ( v44 )
{
v60 = (int *)(v42 + 56);
v8 = v56;
goto LABEL_3;
}
goto LABEL_2;
}
if ( !v44 )
{
v58 = v42;
v6 = v60;
v8 = v56;
goto LABEL_3;
}
return result;
}
}
}