//
// png_write_sBIT from 0x874d50 to 0x874e58 (264 bytes)
//
// 1 xrefs:
// > png_write_info_before_PLTE @ 0x871930
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 12:03:01 +0000
//
int __fastcall png_write_sBIT(int a1, unsigned __int8 *a2, int a3)
{
unsigned int v4; // r0
unsigned int v5; // r3
unsigned int v6; // r5
unsigned int v7; // r3
int result; // r0
int v9; // r7
unsigned int v10; // r3
unsigned int v11; // r6
_BOOL4 v12; // r3
unsigned int v13; // lr
_BYTE v15[4]; // [sp+4h] [bp-Ch] BYREF
_BYTE v16[4]; // [sp+8h] [bp-8h] BYREF
_BYTE var4[28]; // [sp+Ch] [bp-4h] BYREF
if ( (a3 & 2) != 0 )
{
v4 = *a2;
v5 = __clz(v4);
if ( a3 == 3 )
v6 = 8;
else
v6 = *(unsigned __int8 *)(a1 + 537);
v7 = v5 >> 5;
if ( v6 < v4 )
v7 |= 1u;
if ( v7 )
return png_warning(a1, "Invalid sBIT depth specified");
v11 = a2[1];
v12 = v11 == 0;
if ( v6 < v11 )
v12 = 1;
if ( v12 )
return png_warning(a1, "Invalid sBIT depth specified");
v13 = a2[2];
if ( v6 < v13 || v13 == 0 )
return png_warning(a1, "Invalid sBIT depth specified");
v15[0] = *a2;
v9 = 4;
v15[1] = v11;
result = 3;
v15[2] = v13;
}
else
{
if ( !a2[3] || *(unsigned __int8 *)(a1 + 537) < (unsigned int)a2[3] )
return png_warning(a1, "Invalid sBIT depth specified");
v9 = 2;
result = 1;
v15[0] = a2[3];
}
if ( (a3 & 4) != 0 )
{
v10 = a2[4];
if ( a2[4] && *(unsigned __int8 *)(a1 + 537) >= v10 )
{
var4[result - 8] = v10;
LABEL_16:
*(_DWORD *)(a1 + 900) = 34;
png_save_uint_32(v16, v9);
png_save_uint_32(var4, 1933723988);
png_write_data(a1);
*(_DWORD *)(a1 + 476) = 1933723988;
png_reset_crc(a1);
png_calculate_crc((_DWORD *)a1, (int)var4, 4);
*(_DWORD *)(a1 + 900) = 66;
png_write_chunk_data((_DWORD *)a1, (int)v15, v9);
return png_write_chunk_end(a1);
}
return png_warning(a1, "Invalid sBIT depth specified");
}
v9 = result;
if ( a1 )
goto LABEL_16;
return result;
}