//
// sub_657580 from 0x657580 to 0x657612 (146 bytes)
//
// 3 xrefs:
// > png_image_begin_read_from_stdio @ 0x6577d0
// > png_image_begin_read_from_file @ 0x65783a
// > png_image_begin_read_from_memory @ 0x6578c8
//
// 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
//
int __fastcall sub_657580(_DWORD *a1)
{
_DWORD *v3; // r7
_BYTE *v4; // r0
_BYTE *v5; // r7
int v6; // r1
void *v7; // r2
char v8; // r3
_DWORD *v9; // [sp+0h] [bp-Ch] BYREF
void *info_struct; // [sp+4h] [bp-8h] BYREF
if ( *a1 )
return png_image_error((int)a1, (int)"png_image_read: opaque pointer not NULL");
v3 = png_create_read_struct((int)"1.6.16", (int)a1, (int)png_safe_error, (int)png_safe_warning);
v9 = v3;
memset(a1, 0, 0x60u);
a1[1] = 1;
if ( v3 )
{
info_struct = png_create_info_struct(v3);
if ( info_struct )
{
v4 = png_malloc_warn((int)v9, 0x18u);
v5 = v4;
if ( v4 )
{
memset(v4, 0, 0x18u);
v6 = (int)v9;
v7 = info_struct;
v8 = v5[20];
*a1 = v5;
*(_DWORD *)v5 = v6;
v5[20] = v8 & 0xFE;
*((_DWORD *)v5 + 1) = v7;
return 1;
}
png_destroy_info_struct((int)v9, &info_struct);
}
png_destroy_read_struct((int *)&v9, nullptr, nullptr);
}
return png_image_error((int)a1, (int)"png_image_read: out of memory");
}