//
// sub_10004E838 from 0x10004e838 to 0x10004eacc (660 bytes)
//
// 2 xrefs:
// > LocalLevelManager::tryRecoverAutoSaves @ 0x10025fbd8
// > sub_100530FA8 @ 0x100531018
//
// This function is hookable on this platform (idp: arm, 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 10:57:42 +0000
//
DIR *__fastcall sub_10004E838(__int64 a1, void ***a2, const void **a3, __int64 a4)
{
const char *v8; // x0
DIR *result; // x0
DIR *v10; // x23
dirent *v11; // x0
dirent *v12; // x8
_QWORD *v13; // x0
unsigned __int8 v14; // w28
_WORD *v15; // x8
__int64 v16; // x8
unsigned __int64 v17; // x26
size_t v18; // x24
const void *v19; // x1
std::string::size_type size; // x8
std::string *p_dst; // x9
const std::string::value_type *v22; // x1
std::string::size_type v23; // x2
std::string *v24; // x0
int v25; // w24
off_t st_size; // x8
off_t v27; // [xsp+8h] [xbp-128h] BYREF
stat v28; // [xsp+10h] [xbp-120h] BYREF
std::string __dst; // [xsp+A0h] [xbp-90h] BYREF
_BYTE *v30; // [xsp+C0h] [xbp-70h] BYREF
size_t v31; // [xsp+C8h] [xbp-68h]
unsigned __int8 v32; // [xsp+D7h] [xbp-59h]
sub_100018290(a2);
if ( a4 )
*(_QWORD *)(a4 + 8) = *(_QWORD *)a4;
if ( *(char *)(a1 + 23) >= 0 )
v8 = (const char *)a1;
else
v8 = *(const char **)a1;
result = opendir(v8);
if ( result )
{
v10 = result;
v11 = readdir(result);
if ( v11 )
{
v12 = v11;
while ( 1 )
{
v13 = sub_100009900(&v30, v12->d_name);
v14 = v32;
if ( ((char)v32 & 0x8000000000000000LL) != 0 )
break;
if ( v32 != 1 )
{
if ( v32 == 2 )
{
v15 = &v30;
goto LABEL_16;
}
goto LABEL_19;
}
if ( (unsigned __int8)v30 != 46 )
goto LABEL_19;
LABEL_67:
v12 = readdir(v10);
if ( !v12 )
return (DIR *)closedir(v10);
}
if ( v31 == 1 && *v30 == 46 )
goto LABEL_65;
if ( v31 == 2 )
{
v15 = v30;
LABEL_16:
if ( *v15 == 11822 )
{
LABEL_65:
if ( (v14 & 0x80) != 0 )
operator delete(v30);
goto LABEL_67;
}
}
LABEL_19:
v16 = *((char *)a3 + 23);
if ( v16 < 0 )
{
v17 = (unsigned __int64)a3[1];
if ( !v17 )
goto LABEL_37;
}
else
{
if ( !*((_BYTE *)a3 + 23) )
goto LABEL_37;
v17 = *((char *)a3 + 23);
}
if ( (char)v32 < 0 )
{
if ( v17 == -1 )
LABEL_73:
sub_100050040(v13);
v13 = v30;
if ( v31 >= v17 )
v18 = v17;
else
v18 = v31;
}
else
{
if ( v17 == -1 )
goto LABEL_73;
if ( (char)v32 >= v17 )
v18 = v17;
else
v18 = (char)v32;
}
if ( (int)v16 >= 0 )
v19 = a3;
else
v19 = *a3;
if ( memcmp(v13, v19, v18) || v18 != v17 )
goto LABEL_65;
LABEL_37:
if ( *(char *)(a1 + 23) < 0 )
sub_1000097D0(&__dst, *(void **)a1, *(_QWORD *)(a1 + 8));
else
__dst = *(std::string *)a1;
size = SHIBYTE(__dst.__r_.__value_.__r.__words[2]);
if ( (SHIBYTE(__dst.__r_.__value_.__r.__words[2]) & 0x8000000000000000LL) != 0 )
{
size = __dst.__r_.__value_.__l.__size_;
if ( __dst.__r_.__value_.__l.__size_ )
{
p_dst = (std::string *)__dst.__r_.__value_.__r.__words[0];
LABEL_45:
if ( p_dst->__r_.__value_.__s.__data_[size - 1] != 47 )
std::string::push_back(&__dst, 47);
}
}
else if ( *((_BYTE *)&__dst.__r_.__value_.__s + 23) )
{
p_dst = &__dst;
goto LABEL_45;
}
if ( (v32 & 0x80u) == 0 )
v22 = (const std::string::value_type *)&v30;
else
v22 = v30;
if ( (v32 & 0x80u) == 0 )
v23 = v32;
else
v23 = v31;
std::string::append(&__dst, v22, v23);
if ( (__dst.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
v24 = &__dst;
else
v24 = (std::string *)__dst.__r_.__value_.__r.__words[0];
v25 = stat((const char *)v24, &v28);
if ( v25 || (v28.st_mode & 0xF000) != 0x4000 )
{
sub_100017C70((__int64)a2);
if ( a4 )
{
st_size = v28.st_size;
if ( v25 )
st_size = 0;
v27 = st_size;
sub_10004BA60((const void **)a4, &v27);
}
}
if ( SHIBYTE(__dst.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__dst.__r_.__value_.__l.__data_);
v14 = v32;
goto LABEL_65;
}
return (DIR *)closedir(v10);
}
return result;
}