//
// png_image_write_to_file from 0xbe915c to 0xbe92bc (352 bytes)
//
// 1 xrefs:
// > ??> @ 0x59b80
//
// 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
//
__int64 __fastcall png_image_write_to_file(
_DWORD *a1,
char *filename,
unsigned int a3,
void *a4,
unsigned int a5,
void *a6)
{
const char *v6; // x1
FILE *v9; // x22
unsigned int v10; // w23
int v11; // w20
char *v12; // x1
int *v14; // x0
char *v15; // x1
if ( !a1 )
return 0;
if ( a1[2] == 1 )
{
if ( !filename )
{
v6 = "png_image_write_to_file: invalid argument";
return png_image_error((__int64)a1, (__int64)v6);
}
v9 = fopen(filename, "wb");
if ( !v9 )
{
v14 = (int *)__errno();
v15 = strerror(*v14);
return png_image_error((__int64)a1, (__int64)v15);
}
v10 = png_image_write_to_stdio(a1, (__int64)v9, a3, a4, a5, a6);
if ( v10 )
{
if ( fflush(v9) || ferror(v9) )
{
v11 = *(_DWORD *)__errno();
fclose(v9);
LABEL_12:
remove(filename);
v12 = strerror(v11);
return png_image_error((__int64)a1, (__int64)v12);
}
if ( fclose(v9) )
{
v11 = *(_DWORD *)__errno();
goto LABEL_12;
}
return 1;
}
else
{
fclose(v9);
remove(filename);
}
return v10;
}
v6 = "png_image_write_to_file: incorrect PNG_IMAGE_VERSION";
return png_image_error((__int64)a1, (__int64)v6);
}