// File: lvandeve[P]lodepng/lodepng.cpp
// Function: lodepng_zlib_decompressv(ucvector*, unsigned char const*, unsigned long, LodePNGDecompressSettings const*)
static unsigned lodepng_zlib_decompressv(ucvector* out,
                                         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 = inflatev(out, in + 2, insize - 2, settings);
  if(error) return error;

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

  return 0; /*no error*/
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpq $0x2, -0x20(%rbp)
jae 0x4772
movl $0x35, -0x4(%rbp)
jmp 0x4878
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movq -0x18(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
movl $0x1f, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x479f
movl $0x18, -0x4(%rbp)
jmp 0x4878
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
andl $0xf, %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
sarl $0x4, %eax
andl $0xf, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x1(%rax), %eax
sarl $0x5, %eax
andl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0x8, -0x30(%rbp)
jne 0x47d9
cmpl $0x7, -0x34(%rbp)
jbe 0x47e5
movl $0x19, -0x4(%rbp)
jmp 0x4878
cmpl $0x0, -0x38(%rbp)
je 0x47f7
movl $0x1a, -0x4(%rbp)
jmp 0x4878
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
movq -0x20(%rbp), %rdx
subq $0x2, %rdx
movq -0x28(%rbp), %rcx
callq 0x16610
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x4825
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4878
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x4871
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rax
subq $0x4, %rax
addq %rax, %rdi
callq 0x4da0
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %esi
callq 0x4ac0
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x486f
movl $0x3a, -0x4(%rbp)
jmp 0x4878
jmp 0x4871
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)