//
// sub_1403CBFE0 from 0x1403cbfe0 to 0x1403cc22a (586 bytes)
//
// 5 xrefs:
// > GJChestSprite::switchToState @ 0x1403d1921
// > GJChestSprite::switchToState @ 0x1403d1974
// > GJChestSprite::switchToState @ 0x1403d20b1
// > GJChestSprite::switchToState @ 0x1403d2104
// > ??> @ 0x1406d7b74
//
// 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
//
char *__fastcall sub_1403CBFE0(char *a1, _BYTE *a2, __int64 a3, _BYTE *a4)
{
unsigned __int64 v6; // rbx
size_t v7; // rdi
size_t v8; // r8
size_t v9; // rdi
void **v10; // r13
void **v11; // rsi
char *v12; // r12
size_t v13; // rax
unsigned __int64 v14; // rax
char *v15; // rbp
int v16; // r15d
char *v17; // rbx
void *v18; // rcx
char *v19; // r9
void **v20; // rax
void *Block[2]; // [rsp+40h] [rbp-88h] BYREF
size_t v23; // [rsp+50h] [rbp-78h]
unsigned __int64 v24; // [rsp+58h] [rbp-70h]
void *Buf2[2]; // [rsp+60h] [rbp-68h] BYREF
size_t Size; // [rsp+70h] [rbp-58h]
unsigned __int64 v27; // [rsp+78h] [rbp-50h]
v6 = 0;
*(_OWORD *)a1 = 0;
*((_QWORD *)a1 + 2) = 0;
*((_QWORD *)a1 + 3) = 0;
v7 = -1;
v8 = -1;
do
++v8;
while ( a2[v8] );
sub_14003A930(a1, a2, v8);
*(_OWORD *)Buf2 = 0;
Size = 0;
v27 = 0;
sub_14003A930(Buf2, "_001", 4u);
*(_OWORD *)Block = 0;
v23 = 0;
v24 = 0;
do
++v7;
while ( a4[v7] );
sub_14003A930(Block, a4, v7);
v9 = Size;
v10 = (void **)Buf2[0];
while ( 1 )
{
v11 = Buf2;
if ( v27 > 0xF )
v11 = v10;
v12 = a1;
if ( *((_QWORD *)a1 + 3) > 0xFu )
v12 = *(char **)a1;
v13 = *((_QWORD *)a1 + 2);
if ( v9 > v13 )
break;
v14 = v13 - v9;
if ( v6 > v14 )
break;
if ( v9 )
{
v15 = &v12[v14];
v16 = *(char *)v11;
v17 = (char *)memchr(&v12[v6], v16, v14 + 1 - v6);
if ( !v17 )
break;
while ( memcmp(v17, v11, v9) )
{
v17 = (char *)memchr(v17 + 1, v16, v15 - v17);
if ( !v17 )
goto LABEL_16;
}
v6 = v17 - v12;
}
if ( v6 == -1 )
break;
v19 = (char *)Block;
if ( v24 > 0xF )
v19 = (char *)Block[0];
sub_140041FF0(a1, v6, v9, v19, v23);
v6 += v23;
}
LABEL_16:
if ( v24 > 0xF )
{
v18 = Block[0];
if ( v24 + 1 >= 0x1000 )
{
v18 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v18 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v18);
}
if ( v27 > 0xF )
{
v20 = v10;
if ( v27 + 1 >= 0x1000 )
{
v10 = (void **)*(v10 - 1);
if ( (unsigned __int64)((char *)v20 - (char *)v10 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v10);
}
return a1;
}