//
// sub_180018530 from 0x180018530 to 0x18001870a (474 bytes)
//
// 5 xrefs:
// > cocos2d::extension::CCHttpClient::send @ 0x180017ad7
// > ??> @ 0x18002f29c
// > ??> @ 0x18002f2e0
// > ??> @ 0x18002f2f0
// > ??> @ 0x18004aaf4
//
// 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_180018530(_QWORD *a1)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rcx
unsigned __int64 v4; // r12
size_t v5; // rcx
void *v6; // rax
_QWORD *v7; // r14
__int64 v8; // rdi
unsigned __int64 v9; // rbx
__int64 v10; // r15
size_t v11; // rdi
const void *v12; // rdx
char *v13; // rdi
size_t v14; // r8
char *v15; // rcx
void *v16; // rcx
v2 = 1;
v3 = a1[2];
if ( v3 )
v2 = v3;
while ( v2 == v3 || v2 < 8 )
{
if ( 0x3FFFFFFFFFFFFFFLL - v2 < v2 )
sub_180018710(v3, 0x3FFFFFFFFFFFFFFLL);
v2 *= 2LL;
}
v4 = a1[3];
if ( v2 > 0x1FFFFFFFFFFFFFFFLL )
goto LABEL_25;
v5 = 8 * v2;
if ( 8 * v2 < 0x1000 )
{
if ( v5 )
v7 = operator new(v5);
else
v7 = nullptr;
goto LABEL_15;
}
if ( v5 + 39 < v5 )
LABEL_25:
Concurrency::cancel_current_task();
v6 = operator new(v5 + 39);
if ( !v6 )
goto LABEL_24;
v7 = (_QWORD *)(((unsigned __int64)v6 + 39) & 0xFFFFFFFFFFFFFFE0uLL);
*(v7 - 1) = v6;
LABEL_15:
v8 = a1[2];
v9 = v2 - v8;
v10 = 8 * v4;
v11 = 8 * v8 - 8 * v4;
memmove(&v7[v4], (const void *)(a1[1] + 8 * v4), v11);
v12 = (const void *)a1[1];
v13 = (char *)&v7[v4] + v11;
if ( v4 > v9 )
{
memmove(v13, v12, 8 * v9);
memmove(v7, (const void *)(8 * v9 + a1[1]), v10 - 8 * v9);
v15 = (char *)v7 + v10 - 8 * v9;
v14 = 8 * v9;
}
else
{
memmove(v13, v12, 8 * v4);
memset(&v13[v10], 0, 8 * (v9 - v4));
v14 = 8 * v4;
v15 = (char *)v7;
}
memset(v15, 0, v14);
v16 = (void *)a1[1];
if ( v16 )
{
if ( (unsigned __int64)(8LL * a1[2]) < 0x1000 )
{
LABEL_22:
j_j_free(v16);
goto LABEL_23;
}
if ( (unsigned __int64)v16 - *((_QWORD *)v16 - 1) - 8 <= 0x1F )
{
v16 = *((void **)v16 - 1);
goto LABEL_22;
}
LABEL_24:
invalid_parameter_noinfo_noreturn();
}
LABEL_23:
a1[2] += v9;
a1[1] = v7;
}