//
// sub_10003E520 from 0x10003e520 to 0x10003e801 (737 bytes)
//
// 3 xrefs:
// > EditorUI::pasteObjects @ 0x10003a743
// > EditorUI::pasteObjects @ 0x10003a874
// > EditorUI::pasteObjects @ 0x10003a905
//
// 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_10003E520(unsigned __int8 *a1, char *p_dst, _QWORD *a3, double a4)
{
char *v5; // r15
unsigned int v6; // r14d
unsigned __int8 *v7; // rbx
__int64 v8; // r14
_QWORD *v9; // rdi
size_t v10; // rax
unsigned __int8 *v11; // rdx
__int64 v12; // r14
unsigned __int8 *v13; // rcx
bool v14; // zf
unsigned int v15; // r13d
unsigned __int64 v16; // r13
unsigned __int8 *v17; // r12
unsigned __int64 v18; // r15
size_t v19; // r13
char *v20; // rbx
size_t v21; // r15
__int64 v22; // rcx
__int64 v23; // r15
unsigned __int64 v24; // r12
__int64 v25; // r12
unsigned int v26; // ebx
unsigned __int64 v27; // rbx
size_t v28; // rax
unsigned __int8 *v29; // rcx
unsigned __int8 *v30; // rbx
_QWORD *v31; // [rsp+8h] [rbp-78h]
__int64 v33; // [rsp+18h] [rbp-68h]
unsigned __int8 *v34; // [rsp+20h] [rbp-60h]
char *__s; // [rsp+28h] [rbp-58h]
unsigned __int8 *v36; // [rsp+30h] [rbp-50h]
__int128 __dst; // [rsp+38h] [rbp-48h] BYREF
void *__p; // [rsp+48h] [rbp-38h]
unsigned __int64 v39; // [rsp+50h] [rbp-30h]
v5 = p_dst;
v6 = *a1;
v7 = a1 + 1;
v34 = a1 + 1;
if ( (v6 & 1) != 0 )
{
v7 = *((unsigned __int8 **)a1 + 2);
v8 = *((_QWORD *)a1 + 1);
}
else
{
v8 = v6 >> 1;
}
v9 = p_dst;
v10 = strlen(p_dst);
v33 = v8;
LOBYTE(v11) = v8 == 0 || v10 == 0;
v12 = -1;
if ( !(_BYTE)v11 )
{
v13 = &v7[v33];
v11 = v7;
LABEL_6:
p_dst = (char *)*v11;
v9 = nullptr;
while ( (_BYTE)p_dst != *((_BYTE *)v9 + (_QWORD)v5) )
{
v9 = (_QWORD *)((char *)v9 + 1);
if ( (_QWORD *)v10 == v9 )
{
if ( ++v11 != v13 )
goto LABEL_6;
v11 = &v7[v33];
break;
}
}
v12 = -1;
if ( v11 != v13 )
v12 = v11 - v7;
}
v39 = 0;
__s = v5;
v31 = a3;
do
{
v15 = *a1;
if ( (v15 & 1) != 0 )
{
v16 = *((_QWORD *)a1 + 1);
v18 = v39;
if ( v16 < v39 )
LABEL_58:
sub_1000547C0(v9, p_dst, v11);
v17 = *((unsigned __int8 **)a1 + 2);
}
else
{
v16 = v15 >> 1;
v17 = v34;
v18 = v39;
if ( v39 > v16 )
goto LABEL_58;
}
v19 = v16 - v18;
if ( v19 >= v12 - v18 )
v19 = v12 - v18;
if ( v19 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(a4);
if ( v19 >= 0x17 )
{
v21 = (v19 | 7) + 1;
if ( (v19 | 7) == 0x17 )
v21 = 26;
v20 = (char *)operator new(v21);
__p = v20;
*(_QWORD *)&__dst = v21 + 1;
v18 = v39;
*((_QWORD *)&__dst + 1) = v19;
LABEL_29:
v9 = v20;
p_dst = (char *)&v17[v18];
memmove(v20, &v17[v18], v19);
goto LABEL_30;
}
LOBYTE(__dst) = 2 * v19;
v20 = (char *)&__dst + 1;
if ( v19 )
goto LABEL_29;
LABEL_30:
v20[v19] = 0;
v22 = (unsigned __int8)__dst >> 1;
v11 = *((unsigned __int8 **)&__dst + 1);
if ( (__dst & 1) != 0 )
v22 = *((_QWORD *)&__dst + 1);
if ( v22 || v18 != v33 )
{
v24 = v31[1];
if ( v24 >= v31[2] )
{
v9 = v31;
p_dst = (char *)&__dst;
v25 = sub_100054890(v31, &__dst);
}
else
{
if ( (__dst & 1) != 0 )
{
p_dst = (char *)__p;
v9 = (_QWORD *)v31[1];
sub_100006B70(v9, __p, *((unsigned __int64 *)&__dst + 1), a4);
}
else
{
*(_QWORD *)(v24 + 16) = __p;
a4 = *(double *)&__dst;
*(_OWORD *)v24 = __dst;
}
v25 = v24 + 24;
v31[1] = v25;
}
v31[1] = v25;
v23 = -1;
if ( v12 == -1 )
goto LABEL_55;
}
else
{
v23 = -1;
if ( v12 == -1 )
goto LABEL_55;
}
v26 = *a1;
if ( (v26 & 1) != 0 )
{
v36 = *((unsigned __int8 **)a1 + 2);
v27 = *((_QWORD *)a1 + 1);
}
else
{
v27 = v26 >> 1;
v36 = v34;
}
v9 = __s;
v28 = strlen(__s);
LOBYTE(v11) = v27 <= v12 + 1 || v28 == 0;
v39 = v12 + 1;
if ( !(_BYTE)v11 )
{
v29 = &v36[v12 + 1];
v30 = &v36[v27];
v9 = __s;
LABEL_48:
v11 = (unsigned __int8 *)*v29;
p_dst = nullptr;
while ( (_BYTE)v11 != p_dst[(_QWORD)__s] )
{
if ( (char *)v28 == ++p_dst )
{
if ( ++v29 != v30 )
goto LABEL_48;
v29 = v30;
break;
}
}
v23 = v29 - v36;
if ( v29 == v30 )
v23 = -1;
}
LABEL_55:
if ( (__dst & 1) != 0 )
{
v9 = __p;
operator delete(__p);
}
v14 = v12 == -1;
v12 = v23;
}
while ( !v14 );
}