//
// cocos2d::CCImage::_saveImageToPNG from 0x18007f040 to 0x18007f79f (1887 bytes)
//
// 3 xrefs:
// > cocos2d::CCImage::saveToFile @ 0x18008065f
// > ??> @ 0x18014cf68
// > ??> @ 0x1801bf0dc
//
// 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:01 +0000
//
char __fastcall cocos2d::CCImage::_saveImageToPNG(const __m128i *this, const char *a2, char a3)
{
__int64 v3; // rax
__int64 v5; // rax
FILE *v6; // rcx
FILE *v7; // r15
signed int v8; // edi
char *v9; // r14
unsigned int v10; // r8d
__m128i *v11; // rdx
__m128i v12; // xmm4
__m128i si128; // xmm7
__m128i v14; // xmm5
unsigned int v15; // ecx
__m128i v16; // xmm6
__m128i v17; // xmm4
__m128i v18; // xmm3
unsigned int v19; // eax
__m128i v20; // xmm1
int v21; // ecx
__int64 v22; // r8
__int64 v23; // r9
char *v24; // rdx
__int64 v25; // rcx
_BYTE *v26; // rsi
__m128i v27; // xmm4
int v28; // eax
int v29; // r10d
int v30; // ecx
int v31; // eax
int v32; // edx
int v33; // edx
signed int v34; // r8d
__m128i *v35; // r9
__m128i v36; // xmm7
__m128i v37; // xmm5
unsigned int v38; // ecx
__m128i v39; // xmm6
__m128i v40; // xmm3
unsigned int v41; // eax
__m128i v42; // xmm1
int v43; // ecx
__int64 v44; // r9
char *v45; // rdx
char *v46; // rcx
__int64 v47; // rax
unsigned int v48; // r8d
__m128i *v49; // rdx
__m128i v50; // xmm3
__m128i v51; // xmm5
__m128i v52; // xmm3
unsigned int v53; // ecx
__m128i v54; // xmm4
__m128i v55; // xmm2
__m128i v56; // xmm0
unsigned int v57; // eax
__m128i v58; // xmm1
int v59; // ecx
__int64 v60; // r8
char *v61; // rdx
__int64 v62; // rax
__int64 v63; // [rsp+8h] [rbp-59h] BYREF
int v64; // [rsp+30h] [rbp-31h]
int v65; // [rsp+38h] [rbp-29h]
int v66; // [rsp+40h] [rbp-21h]
int v67; // [rsp+48h] [rbp-19h]
char v68; // [rsp+58h] [rbp-9h]
__int64 v69; // [rsp+60h] [rbp-1h] BYREF
__int64 info_struct; // [rsp+68h] [rbp+7h] BYREF
FILE *Stream[2]; // [rsp+70h] [rbp+Fh]
v68 = 0;
if ( !a2 )
return 0;
Stream[0] = fopen(a2, "wb");
if ( !Stream[0] )
return 0;
v3 = png_create_write_struct("1.6.40", 0, 0, 0);
v69 = v3;
if ( !v3 )
{
fclose(Stream[0]);
return 0;
}
info_struct = png_create_info_struct(v3);
if ( !info_struct )
{
fclose(Stream[0]);
png_destroy_write_struct(&v69, 0);
return 0;
}
v5 = png_set_longjmp_fn(v69, longjmp, 256);
if ( (unsigned int)_intrinsic_setjmp(v5, &v63) )
{
v6 = Stream[0];
LABEL_10:
fclose(v6);
png_destroy_write_struct(&v69, &info_struct);
return v68;
}
v7 = Stream[0];
png_set_write_fn(v69, Stream[0], sub_180080370, sub_1800802E0);
if ( a3 || !*((_BYTE *)this + 72) )
{
v8 = 0;
v67 = 0;
v66 = 0;
v65 = 0;
v64 = 2;
}
else
{
v8 = 0;
v67 = 0;
v66 = 0;
v65 = 0;
v64 = 6;
}
png_set_IHDR(
v69,
info_struct,
*((unsigned __int16 *)this + 28),
*((unsigned __int16 *)this + 29),
8,
v64,
v65,
v66,
v67);
png_write_info(v69, info_struct);
v9 = (char *)malloc(8LL * *((unsigned __int16 *)this + 29));
if ( !v9 )
{
v6 = v7;
goto LABEL_10;
}
if ( !*((_BYTE *)this + 72) )
{
v10 = *((unsigned __int16 *)this + 29);
if ( *((_WORD *)this + 29) && v10 >= 8 && dword_1801AE328 >= 2 )
{
v11 = (__m128i *)(v9 + 32);
v12 = _mm_loadl_epi64(this + 4);
si128 = _mm_load_si128((const __m128i *)&xmmword_180107920);
v14 = _mm_load_si128((const __m128i *)&xmmword_180107930);
v15 = 4;
v16 = _mm_cvtepu16_epi32(_mm_shufflelo_epi16(_mm_cvtsi32_si128(*((__int16 *)this + 28)), 0));
v17 = _mm_unpacklo_epi64(v12, v12);
do
{
v18 = _mm_move_epi64(si128);
v11 += 4;
v11[-6] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_mullo_epi32(
_mm_mullo_epi32(
_mm_move_epi64(v16),
_mm_add_epi32(_mm_shuffle_epi32(_mm_cvtsi32_si128(v8), 0), v18)),
_mm_move_epi64(v14))),
v17);
v8 += 8;
v19 = v15 + 2;
v20 = _mm_cvtsi32_si128(v15);
v11[-5] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_mullo_epi32(
_mm_mullo_epi32(
_mm_move_epi64(v16),
_mm_add_epi32(_mm_shuffle_epi32(_mm_cvtsi32_si128(v15 - 2), 0), v18)),
_mm_move_epi64(v14))),
v17);
v15 += 8;
v11[-4] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_mullo_epi32(
_mm_mullo_epi32(_mm_move_epi64(v16), _mm_add_epi32(_mm_shuffle_epi32(v20, 0), v18)),
_mm_move_epi64(v14))),
v17);
v11[-3] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_mullo_epi32(
_mm_mullo_epi32(
_mm_move_epi64(v16),
_mm_add_epi32(_mm_shuffle_epi32(_mm_cvtsi32_si128(v19), 0), v18)),
_mm_move_epi64(v14))),
v17);
}
while ( v8 < (int)(v10 & 0xFFFFFFF8) );
}
if ( v8 < (int)v10 )
{
v21 = *((unsigned __int16 *)this + 28);
v22 = v10 - v8;
v23 = (unsigned int)(3 * v21);
v24 = &v9[8 * v8];
v25 = *((_QWORD *)this + 8) + 3 * v8 * v21;
do
{
*(_QWORD *)v24 = v25;
v24 += 8;
v25 += v23;
--v22;
}
while ( v22 );
}
LABEL_51:
png_write_image(v69, v9);
free(v9);
goto LABEL_52;
}
if ( !a3 )
{
v48 = *((unsigned __int16 *)this + 29);
if ( *((_WORD *)this + 29) && v48 >= 8 && dword_1801AE328 >= 2 )
{
v49 = (__m128i *)(v9 + 32);
v50 = _mm_loadl_epi64(this + 4);
v51 = _mm_load_si128((const __m128i *)&xmmword_180107920);
v52 = _mm_unpacklo_epi64(v50, v50);
v53 = 4;
v54 = _mm_cvtepu16_epi32(_mm_shufflelo_epi16(_mm_cvtsi32_si128(*((__int16 *)this + 28)), 0));
do
{
v55 = _mm_move_epi64(v51);
v56 = _mm_add_epi32(_mm_shuffle_epi32(_mm_cvtsi32_si128(v8), 0), v55);
v49 += 4;
v8 += 8;
v49[-6] = _mm_add_epi64(_mm_cvtepi32_epi64(_mm_slli_epi32(_mm_mullo_epi32(_mm_move_epi64(v54), v56), 2u)), v52);
v57 = v53 + 2;
v58 = _mm_cvtsi32_si128(v53);
v49[-5] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_slli_epi32(
_mm_mullo_epi32(
_mm_move_epi64(v54),
_mm_add_epi32(_mm_shuffle_epi32(_mm_cvtsi32_si128(v53 - 2), 0), v55)),
2u)),
v52);
v53 += 8;
v49[-4] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_slli_epi32(
_mm_mullo_epi32(_mm_move_epi64(v54), _mm_add_epi32(_mm_shuffle_epi32(v58, 0), v55)),
2u)),
v52);
v49[-3] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_slli_epi32(
_mm_mullo_epi32(
_mm_move_epi64(v54),
_mm_add_epi32(_mm_shuffle_epi32(_mm_cvtsi32_si128(v57), 0), v55)),
2u)),
v52);
}
while ( v8 < (int)(v48 & 0xFFFFFFF8) );
}
if ( v8 < (int)v48 )
{
v59 = *((unsigned __int16 *)this + 28);
v60 = v48 - v8;
v61 = &v9[8 * v8];
v62 = *((_QWORD *)this + 8) + 4 * v8 * v59;
do
{
*(_QWORD *)v61 = v62;
v61 += 8;
v62 += (unsigned int)(4 * v59);
--v60;
}
while ( v60 );
}
goto LABEL_51;
}
v26 = (_BYTE *)sub_1800E4C6C(3 * *((unsigned __int16 *)this + 28) * *((unsigned __int16 *)this + 29));
v27 = _mm_unpacklo_epi64((__m128i)(unsigned __int64)v26, (__m128i)(unsigned __int64)v26);
if ( !v26 )
{
fclose(v7);
png_destroy_write_struct(&v69, &info_struct);
free(v9);
return v68;
}
LOWORD(v28) = *((_WORD *)this + 29);
v29 = 0;
if ( (_WORD)v28 )
{
LOWORD(v30) = *((_WORD *)this + 28);
do
{
v31 = 0;
if ( (_WORD)v30 )
{
do
{
v26[3 * v31 + 3 * v29 * (unsigned __int16)v30] = *(_BYTE *)(4 * (v31 + v29 * (unsigned __int16)v30)
+ *((_QWORD *)this + 8));
v32 = v31 + v29 * *((unsigned __int16 *)this + 28);
v26[3 * v32 + 1] = *(_BYTE *)(4 * v32 + *((_QWORD *)this + 8) + 1LL);
v33 = v31 + v29 * *((unsigned __int16 *)this + 28);
++v31;
v26[3 * v33 + 2] = *(_BYTE *)(4 * v33 + *((_QWORD *)this + 8) + 2LL);
v30 = *((unsigned __int16 *)this + 28);
}
while ( v31 < v30 );
}
v28 = *((unsigned __int16 *)this + 29);
++v29;
}
while ( v29 < v28 );
}
v34 = (unsigned __int16)v28;
if ( (unsigned __int16)v28 >= 8u && dword_1801AE328 >= 2 )
{
v35 = (__m128i *)(v9 + 32);
v36 = _mm_load_si128((const __m128i *)&xmmword_180107920);
v37 = _mm_load_si128((const __m128i *)&xmmword_180107930);
v38 = 4;
v39 = _mm_cvtepu16_epi32(_mm_shufflelo_epi16(_mm_cvtsi32_si128(*((__int16 *)this + 28)), 0));
do
{
v40 = _mm_move_epi64(v36);
v35 += 4;
v35[-6] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_mullo_epi32(
_mm_mullo_epi32(
_mm_move_epi64(v39),
_mm_add_epi32(_mm_shuffle_epi32(_mm_cvtsi32_si128(v8), 0), v40)),
_mm_move_epi64(v37))),
v27);
v8 += 8;
v41 = v38 + 2;
v42 = _mm_cvtsi32_si128(v38);
v35[-5] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_mullo_epi32(
_mm_mullo_epi32(
_mm_move_epi64(v39),
_mm_add_epi32(_mm_shuffle_epi32(_mm_cvtsi32_si128(v38 - 2), 0), v40)),
_mm_move_epi64(v37))),
v27);
v38 += 8;
v35[-4] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_mullo_epi32(
_mm_mullo_epi32(_mm_move_epi64(v39), _mm_add_epi32(_mm_shuffle_epi32(v42, 0), v40)),
_mm_move_epi64(v37))),
v27);
v35[-3] = _mm_add_epi64(
_mm_cvtepi32_epi64(
_mm_mullo_epi32(
_mm_mullo_epi32(
_mm_move_epi64(v39),
_mm_add_epi32(_mm_shuffle_epi32(_mm_cvtsi32_si128(v41), 0), v40)),
_mm_move_epi64(v37))),
v27);
}
while ( v8 < (int)(v34 & 0xFFFFFFF8) );
}
if ( v8 < v34 )
{
v43 = *((unsigned __int16 *)this + 28);
v44 = (unsigned int)(3 * v43);
v45 = &v9[8 * v8];
v46 = &v26[3 * v8 * v43];
v47 = (unsigned int)(v34 - v8);
do
{
*(_QWORD *)v45 = v46;
v45 += 8;
v46 += v44;
--v47;
}
while ( v47 );
}
png_write_image(v69, v9);
free(v9);
j_j_free_0(v26);
LABEL_52:
png_write_end(v69, info_struct);
png_destroy_write_struct(&v69, &info_struct);
fclose(v7);
return 1;
}