// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: lodepng_zlib_decompress(unsigned char**, unsigned long*, unsigned char const*, unsigned long, LodePNGDecompressSettings const*)
unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in,
                                 size_t insize, const LodePNGDecompressSettings* settings)
{
  unsigned error = 0;
  unsigned CM, CINFO, FDICT;

  if(insize < 2) return 53; /*error, size of zlib data too small*/
  /*read information from zlib header*/
  if((in[0] * 256 + in[1]) % 31 != 0)
  {
    /*error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made that way*/
    return 24;
  }

  CM = in[0] & 15;
  CINFO = (in[0] >> 4) & 15;
  /*FCHECK = in[1] & 31;*/ /*FCHECK is already tested above*/
  FDICT = (in[1] >> 5) & 1;
  /*FLEVEL = (in[1] >> 6) & 3;*/ /*FLEVEL is not used here*/

  if(CM != 8 || CINFO > 7)
  {
    /*error: only compression method 8: inflate with sliding window of 32k is supported by the PNG spec*/
    return 25;
  }
  if(FDICT != 0)
  {
    /*error: the specification of PNG says about the zlib stream:
      "The additional flags shall not specify a preset dictionary."*/
    return 26;
  }

  error = inflate(out, outsize, in + 2, insize - 2, settings);
  if(error) return error;

  if(!settings->ignore_adler32)
  {
    unsigned ADLER32 = lodepng_read32bitInt(&in[insize - 4]);
    unsigned checksum = adler32(*out, (unsigned)(*outsize));
    if(checksum != ADLER32) return 58; /*error, adler checksum not correct, data must be corrupted*/
  }

  return 0; /*no error*/
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
cmpq $0x2, 0x20(%rsp)
jae 0x7e6a
movl $0x35, 0x44(%rsp)
jmp 0x7f93
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movq 0x28(%rsp), %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
movl $0x1f, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x7e9a
movl $0x18, 0x44(%rsp)
jmp 0x7f93
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
andl $0xf, %eax
movl %eax, 0x10(%rsp)
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
sarl $0x4, %eax
andl $0xf, %eax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
movzbl 0x1(%rax), %eax
sarl $0x5, %eax
andl $0x1, %eax
movl %eax, 0x8(%rsp)
cmpl $0x8, 0x10(%rsp)
jne 0x7edc
cmpl $0x7, 0xc(%rsp)
jbe 0x7ee9
movl $0x19, 0x44(%rsp)
jmp 0x7f93
cmpl $0x0, 0x8(%rsp)
je 0x7efd
movl $0x1a, 0x44(%rsp)
jmp 0x7f93
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq $0x2, %rdx
movq 0x20(%rsp), %rcx
subq $0x2, %rcx
movq 0x18(%rsp), %r8
callq 0x7fa0
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x7f38
movl 0x14(%rsp), %eax
movl %eax, 0x44(%rsp)
jmp 0x7f93
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x7f8b
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
subq $0x4, %rax
addq %rax, %rdi
callq 0x6b40
movl %eax, 0x4(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %eax, %esi
callq 0x8020
movl %eax, (%rsp)
movl (%rsp), %eax
cmpl 0x4(%rsp), %eax
je 0x7f89
movl $0x3a, 0x44(%rsp)
jmp 0x7f93
jmp 0x7f8b
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopl (%rax)