//
// png_set_sPLT from 0x660540 to 0x66064a (266 bytes)
//
// 1 xrefs:
// > png_handle_sPLT @ 0x65d68a
//
// 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 png_set_sPLT(void *result, int a2, int a3, signed int a4)
{
bool v4; // zf
bool v6; // cc
signed int v8; // r7
int v9; // r8
char *v10; // r10
int v11; // r0
int v12; // r4
int v13; // r3
char *v14; // r5
size_t v15; // r10
void *v16; // r0
void *v17; // r0
const void *v18; // r1
int v19; // r3
int v20; // r3
const char *v21; // r0
const char *v22; // r1
v4 = a2 == 0;
if ( a2 )
v4 = result == nullptr;
if ( v4 )
return result;
v6 = a3 <= 0;
if ( a3 )
v6 = a4 <= 0;
v8 = a4;
if ( v6 )
return result;
v9 = (int)result;
v10 = png_realloc_array((int)result, *(const void **)(a2 + 244), *(_DWORD *)(a2 + 248), a4, 16);
v11 = v9;
if ( !v10 )
{
v22 = "too many sPLT chunks";
return (void *)png_chunk_report(v11, v22, 1);
}
v12 = a3 + 16;
png_free(v9, *(void **)(a2 + 244));
v13 = *(_DWORD *)(a2 + 232) | 0x20;
v14 = &v10[16 * *(_DWORD *)(a2 + 248)];
*(_DWORD *)(a2 + 244) = v10;
*(_DWORD *)(a2 + 232) = v13;
while ( 1 )
{
v21 = *(const char **)(v12 - 16);
if ( !v21 || !*(_DWORD *)(v12 - 8) )
{
result = (void *)png_app_error(v9, "png_set_sPLT: invalid sPLT");
goto LABEL_14;
}
v14[4] = *(_BYTE *)(v12 - 12);
v15 = strlen(v21) + 1;
v16 = png_malloc_base(v9, v15);
*(_DWORD *)v14 = v16;
if ( !v16 )
goto LABEL_19;
memcpy(v16, *(const void **)(v12 - 16), v15);
v17 = png_malloc_array(v9, *(_DWORD *)(v12 - 4), 10);
*((_DWORD *)v14 + 2) = v17;
if ( !v17 )
break;
v18 = *(const void **)(v12 - 8);
v19 = *(_DWORD *)(v12 - 4);
v14 += 16;
*((_DWORD *)v14 - 1) = v19;
result = memcpy(v17, v18, 10 * v19);
v20 = *(_DWORD *)(a2 + 248);
*(_DWORD *)(a2 + 8) |= 0x2000u;
*(_DWORD *)(a2 + 248) = v20 + 1;
LABEL_14:
--v8;
v12 += 16;
if ( !v8 )
return result;
}
png_free(v9, *(void **)v14);
*(_DWORD *)v14 = 0;
LABEL_19:
v11 = v9;
v22 = "sPLT out of memory";
return (void *)png_chunk_report(v11, v22, 1);
}