// File: /workspace/github_cpp_makefile_star2_O3/mhe[P]raytracerframework_cpp/lodepng.cpp
// Function: LodeZlib_decompress(unsigned char**, unsigned long*, unsigned char const*, unsigned long, LodeZlib_DecompressSettings const*)
unsigned LodeZlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodeZlib_DecompressSettings* settings)
{
  unsigned error = 0;
  unsigned CM, CINFO, FDICT;
  ucvector outv;
  
  if(insize < 2) { error = 53; return error; } /*error, size of zlib data too small*/
  /*read information from zlib header*/
  if((in[0] * 256 + in[1]) % 31 != 0) { error = 24; return error; } /*error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made that way*/

  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; //not really important, all it does it to give a compiler warning about unused variable, we don't care what encoding setting the encoder used*/
  
  if(CM != 8 || CINFO > 7) { error = 25; return error; } /*error: only compression method 8: inflate with sliding window of 32k is supported by the PNG spec*/
  if(FDICT != 0) { error = 26; return error; } /*error: the specification of PNG says about the zlib stream: "The additional flags shall not specify a preset dictionary."*/
  
  ucvector_init_buffer(&outv, *out, *outsize); /*ucvector-controlled version of the output buffer, for dynamic array*/
  error = LodeFlate_inflate(&outv, in, insize, 2);
  *out = outv.data;
  *outsize = outv.size;
  if(error) return error;
  
  if(!settings->ignoreAdler32)
  {
    unsigned ADLER32 = LodeZlib_read32bitInt(&in[insize - 4]);
    unsigned checksum = adler32(outv.data, (unsigned)outv.size);
    if(checksum != ADLER32) { error = 58; return error; }
  }
  
  return error;
}

// Assembly:
movl $0x35, %eax
cmpq $0x2, %rcx
jb 0x1be7f
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
movzbl (%rdx), %edx
movl %edx, %eax
shll $0x8, %eax
movzbl 0x1(%r14), %ecx
orl %ecx, %eax
imull $0x7bdf, %eax, %eax     # imm = 0x7BDF
movzwl %ax, %esi
movl $0x18, %eax
cmpl $0x842, %esi            # imm = 0x842
ja 0x1be71
movl %edx, %eax
andl $0xf, %eax
cmpl $0x8, %eax
setne %al
testb %dl, %dl
sets %dl
orb %al, %dl
movl $0x19, %eax
jne 0x1be71
movl $0x1a, %eax
testb $0x20, %cl
jne 0x1be71
movq %r8, %r15
movq %rdi, %r13
movq (%rdi), %rax
movq (%r12), %rcx
leaq -0x40(%rbp), %rdi
movq %rax, (%rdi)
movq %rcx, 0x8(%rdi)
movq %rcx, 0x10(%rdi)
movl $0x2, %ecx
movq %r14, %rsi
movq %rbx, %rdx
callq 0x19fd0
leaq -0x40(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, (%r13)
movq 0x8(%rdx), %rdx
movq %rdx, (%r12)
testl %eax, %eax
jne 0x1be71
xorl %eax, %eax
cmpl $0x0, (%r15)
jne 0x1be71
movl -0x4(%r14,%rbx), %eax
bswapl %eax
testl %edx, %edx
je 0x1be60
movl $0x1, %edi
xorl %esi, %esi
movl $0x15ae, %r8d           # imm = 0x15AE
movl $0x15ae, %r9d           # imm = 0x15AE
movl $0x80078071, %r10d      # imm = 0x80078071
cmpl %r8d, %edx
movl $0x15ae, %r11d          # imm = 0x15AE
cmovbl %edx, %r11d
movl %edx, %ebx
cmpq %r9, %rbx
cmovaeq %r9, %rbx
xorl %r14d, %r14d
movzbl (%rcx,%r14), %r15d
addl %r15d, %edi
addl %edi, %esi
incq %r14
cmpl %r14d, %ebx
jne 0x1be18
movl %r11d, %ebx
addq %rbx, %rcx
movl %edi, %ebx
imulq %r10, %rbx
shrq $0x2f, %rbx
imull $0xfff1, %ebx, %ebx     # imm = 0xFFF1
subl %ebx, %edi
movl %esi, %ebx
imulq %r10, %rbx
shrq $0x2f, %rbx
imull $0xfff1, %ebx, %ebx     # imm = 0xFFF1
subl %ebx, %esi
subl %r11d, %edx
jne 0x1bdff
shll $0x10, %esi
orl %edi, %esi
jmp 0x1be65
movl $0x1, %esi
xorl %ecx, %ecx
cmpl %eax, %esi
movl $0x3a, %eax
cmovel %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq