//
// sub_1800A2080 from 0x1800a2080 to 0x1800a242a (938 bytes)
//
// 4 xrefs:
// > cocos2d::CCTileMapAtlas::loadTGAfile @ 0x1800aeb8e
// > ??> @ 0x1801482c8
// > ??> @ 0x1801482d8
// > ??> @ 0x1801c183c
//
// 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 11:22:14 +0000
//
_BYTE *__fastcall sub_1800A2080(__int64 a1)
{
struct cocos2d::CCFileUtils *v2; // rax
void *v3; // r13
_BYTE *v4; // rdi
unsigned int v5; // eax
char v6; // bl
int v7; // ecx
int v8; // edx
unsigned int v9; // r8d
bool v10; // zf
__int64 v11; // r14
int v12; // ebp
int v13; // esi
int v14; // eax
char v15; // bl
int v16; // ebp
__int64 v17; // rsi
unsigned __int64 v18; // rdx
int v19; // edi
char v20; // cl
char v21; // cl
signed __int64 v22; // rbx
signed __int64 i; // rdx
char v24; // cl
int v25; // r14d
void *v26; // r12
int v27; // ebx
int v28; // r15d
char *v29; // rbp
char *v30; // rbx
unsigned int v32; // [rsp+20h] [rbp-68h]
int v33; // [rsp+24h] [rbp-64h]
unsigned int v34; // [rsp+28h] [rbp-60h]
int v35; // [rsp+2Ch] [rbp-5Ch]
_BYTE *v36; // [rsp+30h] [rbp-58h]
unsigned __int64 v37; // [rsp+38h] [rbp-50h]
char *v38; // [rsp+40h] [rbp-48h]
__int64 v39; // [rsp+48h] [rbp-40h]
char Src; // [rsp+98h] [rbp+10h] BYREF
char v41; // [rsp+9Ah] [rbp+12h]
unsigned int v42; // [rsp+A0h] [rbp+18h] BYREF
int v43; // [rsp+A8h] [rbp+20h]
v42 = 0;
v2 = cocos2d::CCFileUtils::sharedFileUtils();
v39 = (*(__int64 (__fastcall **)(struct cocos2d::CCFileUtils *, __int64, const char *, unsigned int *))(*(_QWORD *)v2 + 24LL))(
v2,
a1,
"rb",
&v42);
v3 = (void *)v39;
if ( !v39 )
return nullptr;
v4 = malloc(0x20u);
v36 = v4;
v5 = v42;
if ( v42 < 3 )
goto LABEL_41;
v6 = *(_BYTE *)(v39 + 2);
v4[4] = v6;
if ( v5 < 0x11 )
goto LABEL_41;
v7 = *(__int16 *)(v39 + 12);
v8 = *(__int16 *)(v39 + 14);
v9 = *(unsigned __int8 *)(v39 + 16);
*((_WORD *)v4 + 3) = *(_WORD *)(v39 + 12);
*((_WORD *)v4 + 4) = v8;
v4[5] = v9;
if ( v5 < 0x12 )
goto LABEL_41;
v10 = (*(_BYTE *)(v39 + 17) & 0x20) == 0;
*((_DWORD *)v4 + 6) = 0;
if ( !v10 )
*((_DWORD *)v4 + 6) = 1;
if ( v6 == 1 )
{
*(_DWORD *)v4 = 3;
goto LABEL_42;
}
if ( ((v6 - 2) & 0xF6) != 0 || v6 == 11 )
{
*(_DWORD *)v4 = 5;
goto LABEL_42;
}
v35 = v7;
v11 = v9 >> 3;
v12 = v7;
v13 = v8;
v33 = v8;
v38 = (char *)malloc(v7 * (int)v11 * v8);
*((_QWORD *)v4 + 2) = v38;
if ( !v38 )
goto LABEL_41;
v14 = v13 * v12;
v34 = v13 * v12;
if ( v6 != 10 )
{
v22 = (int)v11 * v14;
if ( v22 + 18 <= (unsigned __int64)v42 )
{
memcpy(v38, (const void *)(v39 + 18), v22);
if ( (unsigned int)v11 >= 3 && v22 > 0 )
{
for ( i = 0; i < v22; i += (unsigned int)v11 )
{
v24 = v38[i];
v38[i] = v38[i + 2];
v38[i + 2] = v24;
}
}
goto LABEL_32;
}
*(_DWORD *)v4 = 2;
goto LABEL_42;
}
v15 = 0;
v43 = 0;
v32 = 0;
v16 = 0;
v17 = 18;
if ( !v14 )
goto LABEL_26;
v18 = v42;
v19 = 0;
v37 = v42;
do
{
if ( v15 )
{
--v15;
if ( v19 )
goto LABEL_24;
}
else
{
if ( v17 + 1 > v18 )
break;
v20 = *(_BYTE *)(v17 + v39);
++v17;
v19 = v20 & 0x80;
v15 = v20 + 0x80;
if ( (v20 & 0x80) == 0 )
v15 = v20;
}
if ( v11 + v17 > v18 )
break;
memcpy(&Src, (const void *)(v17 + v39), (unsigned int)v11);
v17 += v11;
v16 = v43;
if ( (unsigned int)v11 >= 3 )
{
v21 = Src;
Src = v41;
v41 = v21;
}
LABEL_24:
memcpy(&v38[v16], &Src, (unsigned int)v11);
v16 += v11;
v18 = v37;
v43 = v16;
++v32;
}
while ( v32 < v34 );
v4 = v36;
LABEL_26:
v12 = v35;
LABEL_32:
v10 = *((_DWORD *)v4 + 6) == 0;
*(_DWORD *)v4 = 0;
if ( !v10 )
{
v25 = v12 * v11;
v26 = malloc(v25);
if ( v26 )
{
v27 = v33;
v28 = 0;
if ( v33 / 2 > 0 )
{
v29 = v38;
do
{
memcpy(v26, v29, v25);
v30 = &v38[v25 * (v27 - v28 - 1)];
memcpy(v29, v30, v25);
memcpy(v30, v26, v25);
v27 = v33;
++v28;
v29 += v25;
}
while ( v28 < v33 / 2 );
v4 = v36;
v3 = (void *)v39;
}
free(v26);
*((_DWORD *)v4 + 6) = 0;
goto LABEL_42;
}
LABEL_41:
*(_DWORD *)v4 = 4;
}
LABEL_42:
j_j_free_0(v3);
return v4;
}