//
// sub_1402F3F80 from 0x1402f3f80 to 0x1402f4238 (696 bytes)
//
// 5 xrefs:
// > sub_1402F3700 @ 0x1402f380c
// > ??> @ 0x140690350
// > ??> @ 0x140690360
// > ??> @ 0x140690374
// > ??> @ 0x1406d3f50
//
// 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_1402F3F80(char *Src, _BYTE *a2, char *a3, __int64 a4, __int64 a5, char *Srca, __int64 a7, char a8)
{
char *v11; // rdi
char *v12; // r8
char *v13; // r15
_OWORD *v14; // rdx
char *v15; // r9
char *v16; // rbx
__int128 v17; // xmm0
void *result; // rax
__int128 v19; // xmm0
size_t v20; // rbp
__int64 v21; // rbx
char *v22; // r8
char *v23; // r10
char *v24; // rdx
char *v25; // r9
char *v26; // r9
__int128 v27; // xmm0
char *v28; // r9
if ( a4 <= a5 && a4 <= a7 )
{
v11 = Srca;
memmove(Srca, Src, a2 - Src);
v12 = &Srca[a2 - Src];
v13 = v12 - 48;
*(_OWORD *)Src = *(_OWORD *)a2;
v14 = Src + 48;
v15 = a2 + 48;
*((_OWORD *)Src + 1) = *((_OWORD *)a2 + 1);
*((_OWORD *)Src + 2) = *((_OWORD *)a2 + 2);
while ( 1 )
{
v16 = (char *)(v14 + 3);
if ( (*(_DWORD *)v15 == 1) >= (unsigned int)(*(_DWORD *)v11 == 1) )
{
*v14 = *(_OWORD *)v11;
v14[1] = *((_OWORD *)v11 + 1);
v19 = *((_OWORD *)v11 + 2);
v11 += 48;
v14[2] = v19;
if ( v11 == v13 )
{
v20 = a3 - v15;
result = memmove(v16, v15, v20);
*(_OWORD *)&v16[v20] = *(_OWORD *)v13;
*(_OWORD *)&v16[v20 + 16] = *((_OWORD *)v13 + 1);
*(_OWORD *)&v16[v20 + 32] = *((_OWORD *)v13 + 2);
return result;
}
}
else
{
*v14 = *(_OWORD *)v15;
v14[1] = *((_OWORD *)v15 + 1);
v17 = *((_OWORD *)v15 + 2);
v15 += 48;
v14[2] = v17;
if ( v15 == a3 )
return memmove(v16, v11, v12 - v11);
}
v14 += 3;
}
}
if ( a5 > a7 )
return (void *)sub_1402F4240(Src, (_DWORD)a2, (_DWORD)a3, a4, a5, Srca, a7, a8);
v21 = a3 - a2;
memmove(Srca, a2, a3 - a2);
v22 = a2 - 48;
v23 = a3 - 48;
*(_OWORD *)v23 = *((_OWORD *)a2 - 3);
v24 = &Srca[v21 - 48];
*((_OWORD *)v23 + 1) = *((_OWORD *)a2 - 2);
*((_OWORD *)v23 + 2) = *((_OWORD *)a2 - 1);
while ( 2 )
{
v22 -= 48;
while ( 1 )
{
v25 = v23 - 48;
v23 -= 48;
if ( (*(_DWORD *)v24 == 1) < (unsigned int)(*(_DWORD *)v22 == 1) )
break;
*(_OWORD *)v25 = *(_OWORD *)v24;
*((_OWORD *)v25 + 1) = *((_OWORD *)v24 + 1);
v27 = *((_OWORD *)v24 + 2);
v24 -= 48;
*((_OWORD *)v25 + 2) = v27;
if ( Srca == v24 )
{
v28 = v25 - 48;
*(_OWORD *)v28 = *(_OWORD *)v22;
*((_OWORD *)v28 + 1) = *((_OWORD *)v22 + 1);
*((_OWORD *)v28 + 2) = *((_OWORD *)v22 + 2);
result = memmove(&v28[-(v22 - Src)], Src, v22 - Src);
*(_OWORD *)Src = *(_OWORD *)Srca;
*((_OWORD *)Src + 1) = *((_OWORD *)Srca + 1);
*((_OWORD *)Src + 2) = *((_OWORD *)Srca + 2);
return result;
}
}
*(_OWORD *)v25 = *(_OWORD *)v22;
*((_OWORD *)v25 + 1) = *((_OWORD *)v22 + 1);
*((_OWORD *)v25 + 2) = *((_OWORD *)v22 + 2);
if ( Src != v22 )
continue;
break;
}
v26 = v25 - 48;
*(_OWORD *)v26 = *(_OWORD *)v24;
*((_OWORD *)v26 + 1) = *((_OWORD *)v24 + 1);
*((_OWORD *)v26 + 2) = *((_OWORD *)v24 + 2);
return memmove(&v26[-(v24 - Srca)], Srca, v24 - Srca);
}