//
// sub_BD8DB0 from 0xbd8db0 to 0xbd919c (1004 bytes)
//
// 3 xrefs:
// > EditorUI::pasteObjects @ 0xbd955c
// > EditorUI::pasteObjects @ 0xbd97b8
// > EditorUI::pasteObjects @ 0xbd9814
//
// 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 13:03:42 +0000
//
__int64 __fastcall sub_BD8DB0(unsigned __int8 *a1, char *a2, __int64 *a3)
{
int v6; // w19
unsigned __int8 *v7; // x26
__int64 v8; // x24
size_t v9; // x0
__int64 v10; // x26
unsigned __int64 v11; // x28
size_t v12; // x0
unsigned __int64 v13; // x19
unsigned __int8 *i; // x25
size_t v15; // x19
char *v16; // x3
int v17; // w25
size_t v18; // x1
__int64 *v19; // x0
char v20; // w1
size_t v21; // x3
unsigned __int8 *v22; // x26
unsigned __int64 v23; // x27
size_t v24; // x0
unsigned __int8 *v25; // x5
unsigned __int8 *v26; // x27
char *v27; // x0
int v28; // w3
char *v29; // x1
unsigned __int64 v30; // x0
__int64 v31; // x27
char *v32; // x0
int v34; // w20
size_t v35; // x0
char *v36; // x0
__int64 v37; // x3
unsigned __int8 *v38; // x2
int v39; // w24
char *v40; // x20
std::logic_error *exception; // x19
__int64 v42; // [xsp+60h] [xbp+60h] BYREF
size_t v43; // [xsp+68h] [xbp+68h]
void *v44; // [xsp+70h] [xbp+70h]
v6 = *a1;
if ( (v6 & 1) != 0 )
{
v7 = *((unsigned __int8 **)a1 + 2);
v8 = *((_QWORD *)a1 + 1);
v9 = strlen(a2);
if ( !v9 )
goto LABEL_4;
if ( !v8 )
goto LABEL_4;
v37 = (__int64)&v7[v8];
v36 = &a2[v9];
if ( v7 == &v7[v8] )
goto LABEL_4;
LABEL_55:
v38 = v7;
while ( 1 )
{
if ( a2 != v36 )
{
v39 = *v38;
if ( (unsigned __int8)*a2 == v39 )
{
LABEL_65:
v10 = v38 - v7;
LABEL_66:
v34 = v6 >> 1;
if ( (v6 & 1) != 0 )
{
v8 = *((_QWORD *)a1 + 1);
goto LABEL_5;
}
LABEL_69:
v8 = v34;
goto LABEL_5;
}
v40 = a2;
while ( v36 != ++v40 )
{
if ( (unsigned __int8)*v40 == v39 )
goto LABEL_65;
}
}
if ( (unsigned __int8 *)v37 == ++v38 )
{
v10 = -1;
goto LABEL_66;
}
}
}
v34 = v6 >> 1;
v35 = strlen(a2);
v8 = v6 >> 1;
if ( v35 && v34 )
{
v7 = a1 + 1;
v36 = &a2[v35];
v37 = (__int64)&a1[v34 + 1];
if ( a1 + 1 == (unsigned __int8 *)v37 )
{
v10 = -1;
goto LABEL_69;
}
goto LABEL_55;
}
LABEL_4:
v10 = -1;
LABEL_5:
v11 = 0;
LABEL_6:
v42 = 0;
v12 = v10 - v11;
v43 = 0;
v44 = nullptr;
if ( (v6 & 1) == 0 )
goto LABEL_32;
LABEL_7:
v13 = *((_QWORD *)a1 + 1);
if ( v11 > v13 )
{
LABEL_70:
exception = (std::logic_error *)_cxa_allocate_exception(0x10u);
std::logic_error::logic_error(exception, "basic_string");
*(_QWORD *)exception = off_1536D68;
_cxa_throw(
exception,
(struct type_info *)&`typeinfo for'std::out_of_range,
(void (*)(void *))std::logic_error::~logic_error);
}
for ( i = *((unsigned __int8 **)a1 + 2); ; i = a1 + 1 )
{
v15 = v13 - v11;
if ( v15 > v12 )
v15 = v12;
if ( v15 > 0xFFFFFFFFFFFFFFEFLL )
sub_62FBBC();
if ( v15 > 0x16 )
{
v30 = (v15 + 16) & 0xFFFFFFFFFFFFFFF0LL;
v31 = v30 | 1;
v32 = (char *)operator new(v30);
v42 = v31;
v16 = v32;
v44 = v32;
v43 = v15;
}
else
{
LOBYTE(v42) = 2 * v15;
v16 = (char *)&v42 + 1;
if ( !v15 )
goto LABEL_14;
}
v16 = (char *)memcpy(v16, &i[v11], v15);
LABEL_14:
v16[v15] = 0;
v17 = v42 & 1;
v18 = (unsigned __int8)v42 >> 1;
if ( (v42 & 1) != 0 )
v18 = v43;
if ( !v18 && v11 == v8 )
goto LABEL_24;
v19 = (__int64 *)a3[1];
if ( v19 != (__int64 *)a3[2] )
{
if ( v19 )
{
*v19 = 0;
v19[1] = 0;
v20 = v42;
v19[2] = 0;
if ( (v20 & 1) != 0 )
{
std::string::__init(v19, v44, v43);
}
else
{
v21 = v43;
*v19 = v42;
v19[1] = v21;
v19[2] = (__int64)v44;
}
v19 = (__int64 *)a3[1];
v17 = v42 & 1;
}
a3[1] = (__int64)(v19 + 3);
LABEL_24:
if ( v10 == -1 )
break;
goto LABEL_25;
}
std::vector::__push_back_slow_path(a3, &v42);
v17 = v42 & 1;
if ( v10 == -1 )
break;
LABEL_25:
v6 = *a1;
v11 = v10 + 1;
if ( (v6 & 1) != 0 )
{
v22 = *((unsigned __int8 **)a1 + 2);
v23 = *((_QWORD *)a1 + 1);
}
else
{
v22 = a1 + 1;
v23 = (unsigned __int8)v6 >> 1;
}
v24 = strlen(a2);
if ( !v24 || v11 >= v23 || (v25 = &v22[v11], v26 = &v22[v23], v27 = &a2[v24], &v22[v11] == v26) )
{
v10 = -1;
goto LABEL_30;
}
do
{
if ( a2 != v27 )
{
v28 = *v25;
if ( (unsigned __int8)*a2 == v28 )
{
LABEL_45:
v10 = v25 - v22;
if ( v17 )
goto LABEL_31;
goto LABEL_6;
}
v29 = a2;
while ( v27 != ++v29 )
{
if ( (unsigned __int8)*v29 == v28 )
goto LABEL_45;
}
}
++v25;
}
while ( v26 != v25 );
v10 = -1;
LABEL_30:
if ( !v17 )
goto LABEL_6;
LABEL_31:
operator delete(v44);
v6 = *a1;
v42 = 0;
v12 = v10 - v11;
v43 = 0;
v44 = nullptr;
if ( (v6 & 1) != 0 )
goto LABEL_7;
LABEL_32:
v13 = v6 >> 1;
if ( v11 > v13 )
goto LABEL_70;
}
if ( v17 )
operator delete(v44);
return _stack_chk_guard;
}