//
// GameToolbox::keepLastPathSegments from 0x3d1118 to 0x3d132a (530 bytes)
//
// 2 xrefs:
// > SetTextPopup::addPathLabel @ 0x5d5e56
// > SFXBrowser::fitFolderPath @ 0x6c57a4
//
// 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:46:41 +0000
//
int *__fastcall GameToolbox::keepLastPathSegments(int *a1, unsigned __int8 *a2, char *a3, int a4)
{
int v8; // r6
unsigned __int8 *v9; // r11
unsigned int v10; // r6
size_t v11; // r0
unsigned int v12; // r4
unsigned __int8 *v13; // r6
int v14; // r6
unsigned int v15; // r6
unsigned __int8 *v16; // r11
size_t v17; // r0
unsigned __int8 *v18; // r6
_DWORD *v20; // r0
int v21; // r1
int v22; // r2
char *v23; // r1
size_t v24; // r2
int *v25; // r0
int v26; // r1
int v27; // r2
size_t v28; // [sp+14h] [bp-50h]
unsigned __int8 *v29[2]; // [sp+24h] [bp-40h] BYREF
char *v30; // [sp+2Ch] [bp-38h] BYREF
char *v31; // [sp+30h] [bp-34h]
char *v32; // [sp+34h] [bp-30h]
int v33[3]; // [sp+38h] [bp-2Ch] BYREF
_DWORD v34[3]; // [sp+44h] [bp-20h] BYREF
int v35[3]; // [sp+50h] [bp-14h] BYREF
v28 = strlen(a3);
v31 = (char *)operator new(4u);
v30 = v31;
v32 = v31 + 4;
*(_DWORD *)v31 = 0;
v8 = *a2;
v31 += 4;
if ( (v8 & 1) != 0 )
{
v9 = *((unsigned __int8 **)a2 + 2);
v10 = *((_DWORD *)a2 + 1);
}
else
{
v9 = a2 + 1;
v10 = v8 >> 1;
}
v11 = strlen(a3);
if ( v10 < v11 )
goto LABEL_5;
if ( !v11 )
{
v12 = 0;
goto LABEL_10;
}
v13 = &v9[v10];
std::__search(
v29,
v9,
v13,
(unsigned __int8 *)a3,
(unsigned __int8 *)&a3[v11],
(int (__fastcall *)(int, _DWORD))std::char_traits::eq);
if ( v29[0] == v13 )
LABEL_5:
v12 = -1;
else
v12 = v29[0] - v9;
LABEL_10:
while ( v12 != -1 )
{
v12 += v28;
v29[0] = (unsigned __int8 *)v12;
if ( v31 >= v32 )
{
std::vector::__push_back_slow_path((int)&v30, v29);
}
else
{
if ( v31 )
*(_DWORD *)v31 = v12;
v31 += 4;
}
v14 = *a2;
if ( (v14 & 1) != 0 )
{
v15 = *((_DWORD *)a2 + 1);
v16 = *((unsigned __int8 **)a2 + 2);
}
else
{
v15 = v14 >> 1;
v16 = a2 + 1;
}
v17 = strlen(a3);
if ( v12 > v15 || v15 - v12 < v17 )
break;
if ( v17 )
{
v18 = &v16[v15];
std::__search(
v29,
&v16[v12],
v18,
(unsigned __int8 *)a3,
(unsigned __int8 *)&a3[v17],
(int (__fastcall *)(int, _DWORD))std::char_traits::eq);
if ( v29[0] == v18 )
break;
v12 = v29[0] - v16;
}
}
if ( a4 <= 0 || a4 >= (v31 - v30) >> 2 )
{
std::string::basic_string(a1, (int)a2);
}
else
{
memset(v33, 0, sizeof(v33));
std::string::__init(v33, "...", 3u);
v20 = std::string::append(v33, a3);
v21 = v20[1];
v22 = v20[2];
v34[0] = *v20;
v34[1] = v21;
v34[2] = v22;
*v20 = 0;
v20[1] = 0;
v20[2] = 0;
std::string::basic_string(v35, a2, *(_DWORD *)&v30[4 * (((v31 - v30) >> 2) - a4)], 0xFFFFFFFF);
if ( (v35[0] & 1) != 0 )
{
v23 = (char *)v35[2];
v24 = v35[1];
}
else
{
v24 = (int)LOBYTE(v35[0]) >> 1;
v23 = (char *)v35 + 1;
}
v25 = std::string::append(v34, v23, v24);
v26 = v25[1];
v27 = v25[2];
*a1 = *v25;
a1[1] = v26;
a1[2] = v27;
*v25 = 0;
v25[1] = 0;
v25[2] = 0;
std::string::~string((int)v35);
std::string::~string((int)v34);
std::string::~string((int)v33);
}
std::__vector_base::~__vector_base(&v30);
return a1;
}