//
// sub_1004BE490 from 0x1004be490 to 0x1004be88c (1020 bytes)
//
// 3 xrefs:
// > sub_1004BE290 @ 0x1004be2f8
// > sub_1004BE990 @ 0x1004be9bd
// > sub_1004BEBC0 @ 0x1004bec04
//
// 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:31:04 +0000
//
id __fastcall sub_1004BE490(char *__s)
{
const char *v1; // rbx
size_t v2; // rax
const char *v3; // rbx
size_t v4; // rax
std::string::size_type v5; // r14
char *data; // r15
size_t v7; // r12
unsigned __int64 i; // rbx
std::string::size_type v9; // rax
std::string::size_type size; // r13
std::string::size_type v11; // rax
std::string::size_type v12; // r12
std::string::pointer v13; // r14
std::string::size_type v14; // r12
char *v15; // r15
std::string::size_type v16; // rbx
size_t v17; // r13
std::string::size_type v18; // rax
std::string::size_type v19; // rcx
std::string::pointer v20; // rbx
std::string::size_type v21; // rax
size_t v22; // r14
char *v23; // r15
std::string::size_type v24; // r13
size_t v25; // r12
size_t v26; // rsi
char v27; // al
char *v28; // rdx
NSString *v29; // rax
id v30; // rbx
size_t v32; // [rsp+18h] [rbp-88h]
id v33; // [rsp+20h] [rbp-80h]
unsigned __int64 v34; // [rsp+28h] [rbp-78h]
std::string::size_type v35; // [rsp+28h] [rbp-78h]
std::string v36; // [rsp+30h] [rbp-70h] BYREF
std::string __dst; // [rsp+48h] [rbp-58h] BYREF
__int64 v38; // [rsp+60h] [rbp-40h] BYREF
size_t v39; // [rsp+68h] [rbp-38h]
void *v40; // [rsp+70h] [rbp-30h]
if ( !__s )
return nullptr;
v1 = __s;
v33 = +[NSMutableArray array](&OBJC_CLASS___NSMutableArray, "array");
LABEL_5:
if ( *v1 )
{
v2 = strlen(v1);
if ( v1[v2 + 1] )
{
v3 = &v1[v2 + 1];
v4 = strlen(v3);
if ( v4 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
v5 = v4;
if ( v4 >= 0x17 )
{
v7 = (v4 | 7) + 1;
if ( (v4 | 7) == 0x17 )
v7 = 26;
data = (char *)operator new(v7);
__dst.__r_.__value_.__r.__words[2] = (std::string::size_type)data;
__dst.__r_.__value_.__r.__words[0] = v7 + 1;
__dst.__r_.__value_.__l.__size_ = v5;
}
else
{
__dst.__r_.__value_.__s.0 = (std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0)(2 * v4);
data = __dst.__r_.__value_.__s.__data_;
if ( !v4 )
goto LABEL_15;
}
memmove(data, v3, v5);
LABEL_15:
data[v5] = 0;
v32 = (size_t)&v3[strlen(v3) + 1];
for ( i = 0; ; i = size + 1 )
{
if ( (*(_BYTE *)&__dst.__r_.__value_.__s.0 & 1) != 0 )
{
if ( i > __dst.__r_.__value_.__l.__size_ )
{
operator delete(__dst.__r_.__value_.__l.__data_);
LABEL_4:
v1 = (const char *)v32;
goto LABEL_5;
}
}
else if ( i > *(_BYTE *)&__dst.__r_.__value_.__l.0 >> 1 )
{
goto LABEL_4;
}
v9 = std::string::find(&__dst, 59, i);
if ( v9 == -1 )
{
if ( (*(_BYTE *)&__dst.__r_.__value_.__s.0 & 1) != 0 )
{
size = __dst.__r_.__value_.__l.__size_;
v11 = __dst.__r_.__value_.__l.__size_ - i;
v12 = __dst.__r_.__value_.__l.__size_;
if ( __dst.__r_.__value_.__l.__size_ < i )
LABEL_74:
sub_100056810();
goto LABEL_30;
}
size = *(_BYTE *)&__dst.__r_.__value_.__l.0 >> 1;
v11 = size - i;
}
else
{
size = v9;
v11 = v9 - i;
if ( (*(_BYTE *)&__dst.__r_.__value_.__s.0 & 1) != 0 )
{
v12 = __dst.__r_.__value_.__l.__size_;
if ( __dst.__r_.__value_.__l.__size_ < i )
goto LABEL_74;
LABEL_30:
v13 = __dst.__r_.__value_.__l.__data_;
goto LABEL_31;
}
}
v12 = *(_BYTE *)&__dst.__r_.__value_.__s.0 >> 1;
v13 = __dst.__r_.__value_.__s.__data_;
if ( i > v12 )
goto LABEL_74;
LABEL_31:
v14 = v12 - i;
if ( v14 >= v11 )
v14 = v11;
if ( v14 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
if ( v14 >= 0x17 )
{
v34 = i;
v16 = size;
v17 = (v14 | 7) + 1;
if ( (v14 | 7) == 0x17 )
v17 = 26;
v15 = (char *)operator new(v17);
v36.__r_.__value_.__r.__words[2] = (std::string::size_type)v15;
v36.__r_.__value_.__r.__words[0] = v17 | 1;
v36.__r_.__value_.__l.__size_ = v14;
size = v16;
i = v34;
LABEL_40:
memmove(v15, &v13[i], v14);
goto LABEL_41;
}
v36.__r_.__value_.__s.0 = (std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0)(2 * v14);
v15 = v36.__r_.__value_.__s.__data_;
if ( v14 )
goto LABEL_40;
LABEL_41:
v15[v14] = 0;
v18 = std::string::rfind(&v36, 46, 0xFFFFFFFFFFFFFFFFLL);
if ( v18 == -1 )
goto LABEL_67;
if ( (*(_BYTE *)&v36.__r_.__value_.__s.0 & 1) != 0 )
{
v19 = v36.__r_.__value_.__l.__size_;
if ( v36.__r_.__value_.__l.__size_ <= v18 )
LABEL_76:
sub_100056810();
v20 = v36.__r_.__value_.__l.__data_;
}
else
{
v19 = *(_BYTE *)&v36.__r_.__value_.__l.0 >> 1;
v20 = v36.__r_.__value_.__s.__data_;
if ( v18 >= v19 )
goto LABEL_76;
}
v21 = v18 + 1;
v22 = v19 - v21;
if ( v19 - v21 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
if ( v22 >= 0x17 )
{
v35 = size;
v24 = v21;
v25 = (v22 | 7) + 1;
if ( (v22 | 7) == 0x17 )
v25 = 26;
v23 = (char *)operator new(v25);
v40 = v23;
v38 = v25 | 1;
v39 = v22;
v21 = v24;
size = v35;
LABEL_54:
memmove(v23, &v20[v21], v22);
goto LABEL_55;
}
LOBYTE(v38) = 2 * v22;
v23 = (char *)&v38 + 1;
if ( v19 != v21 )
goto LABEL_54;
LABEL_55:
v23[v22] = 0;
v26 = (unsigned __int8)v38 >> 1;
v27 = v38 & 1;
if ( (v38 & 1) != 0 )
v26 = v39;
if ( !v26 )
goto LABEL_65;
if ( !v27 )
{
v28 = (char *)&v38 + 1;
if ( (_WORD)v38 == 10754 )
{
LABEL_65:
if ( !v27 )
goto LABEL_67;
goto LABEL_66;
}
LABEL_64:
v29 = +[NSString stringWithUTF8String:](&OBJC_CLASS___NSString, "stringWithUTF8String:", v28);
objc_msgSend(v33, "addObject:", v29);
v27 = v38 & 1;
goto LABEL_65;
}
if ( v39 != 1 || *(_BYTE *)v40 != 42 )
{
v28 = (char *)v40;
goto LABEL_64;
}
LABEL_66:
operator delete(v40);
LABEL_67:
if ( (*(_BYTE *)&v36.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v36.__r_.__value_.__l.__data_);
}
}
}
v30 = v33;
if ( !objc_msgSend(v33, "count") )
return nullptr;
return v30;
}