// File: /workspace/github_cpp_makefile_star2_O3/lvandeve[P]lodepng/pngdetail.cpp
// Function: printZlibInfo(Data&)
void printZlibInfo(Data& data) {
  data.loadFile();
  if(data.error || !data.isPng()) return;
  const std::vector<unsigned char>& png = data.buffer;

  //Read literal data from all IDAT chunks
  const unsigned char *chunk, *begin, *end;
  end = &png.back() + 1;
  begin = chunk = &png.front() + 8;

  std::vector<unsigned char> compressed;

  while(chunk < end && end - chunk >= 8) {
    char type[5];
    lodepng_chunk_type(type, chunk);
    if(std::string(type).size() != 4) {
      std::cout << "invalid png" << std::endl;
      return;
    }

    if(std::string(type) == "IDAT") {
      const unsigned char* cdata = lodepng_chunk_data_const(chunk);
      unsigned clength = lodepng_chunk_length(chunk);
      if(chunk + clength + 12 > end || clength > png.size() || chunk + clength + 12 < begin) {
        std::cout << "corrupt chunk length" << std::endl;
        return;
      }
      compressed.insert(compressed.end(), cdata, cdata + clength);
    }

    chunk = lodepng_chunk_next_const(chunk, end);
  }

  if(compressed.size() >= 3) {
    int bfinal = compressed[2] & 1;
    int btype = (compressed[2] & 6) >> 1;
    if(bfinal) {
      std::cout << "zlib data stored in a single block, btype: " << btype << std::endl;
    } else {
      std::cout << "zlib data spread over multiple blocks. First block btype: " << btype << std::endl;
    }
  }

  std::cout << "zlib compressed size: " << compressed.size() << std::endl;

  //Decompress all IDAT data (if the while loop ended early, this might fail)
  std::vector<unsigned char> uncompressed;
  data.error = lodepng::decompress(uncompressed, compressed.empty() ? NULL : &compressed[0], compressed.size());
  if(data.error) return;

  std::cout << "zlib uncompressed size: " << uncompressed.size() << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x20(%rdi), %rax
cmpq 0x28(%rdi), %rax
je 0x184f0
leaq 0x2d8(%rbx), %r15
movl $0x0, 0x2d8(%rbx)
movq %rbx, %rdi
callq 0x1e3c6
testb %al, %al
je 0x186fc
movq 0x20(%rbx), %rbp
movq 0x28(%rbx), %r14
addq $0x8, %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq %r14, %rax
subq %rbp, %rax
setbe %cl
cmpq $0x8, %rax
setl %dl
xorl %eax, %eax
orb %cl, %dl
movl $0x0, %ecx
jne 0x1848e
movq %r15, 0x58(%rsp)
leaq 0x40(%rsp), %r12
leaq 0xb(%rsp), %r15
movq %rbp, 0x60(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x53ae
movq %r12, 0x30(%rsp)
movq %r15, %rdi
callq 0x20e0
leaq (%rsp,%rax), %rdx
addq $0xb, %rdx
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x14ece
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %r13
cmpq %r12, %rdi
je 0x183b3
callq 0x2210
cmpq $0x4, %r13
jne 0x18516
movq %r12, 0x30(%rsp)
movq %r15, %rdi
callq 0x20e0
leaq (%rsp,%rax), %rdx
addq $0xb, %rdx
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x14ece
movq %r13, %rdi
leaq 0xa8da(%rip), %rsi      # 0x22cc6
callq 0x2090
movl %eax, %r13d
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x18403
callq 0x2210
testl %r13d, %r13d
jne 0x1845f
movq %rbp, %rdi
callq 0x542b
movq %rax, %r13
movq %rbp, %rdi
callq 0x53a9
movl %eax, %ecx
leaq (%rcx,%rbp), %rax
addq $0xc, %rax
cmpq %r14, %rax
ja 0x186a7
movq 0x28(%rbx), %rdx
subq 0x20(%rbx), %rdx
cmpq %rcx, %rdx
jb 0x186a7
cmpq 0x60(%rsp), %rax
jb 0x186a7
movq 0x18(%rsp), %rsi
addq %r13, %rcx
leaq 0x10(%rsp), %rdi
movq %r13, %rdx
callq 0x15b3a
movq %rbp, %rdi
movq %r14, %rsi
callq 0x5512
movq %rax, %rbp
movq %r14, %rax
subq %rbp, %rax
jbe 0x1847f
cmpq $0x7, %rax
jg 0x18372
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq 0x58(%rsp), %r15
subq %rax, %rcx
cmpq $0x3, %rcx
jb 0x185b1
movzbl 0x2(%rax), %eax
movl %eax, %ebx
shrl %ebx
andl $0x3, %ebx
testb $0x1, %al
jne 0x18561
movq 0x12b1b(%rip), %rdi     # 0x2afd0
leaq 0xb715(%rip), %rsi      # 0x23bd1
movl $0x3a, %edx
callq 0x2290
movq 0x12b03(%rip), %rdi     # 0x2afd0
movl %ebx, %esi
callq 0x2390
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
jmp 0x1859e
leaq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0xd09e
movl %eax, 0x2d8(%rbx)
testl %eax, %eax
jne 0x186fc
leaq 0x2d8(%rbx), %r15
jmp 0x18312
movq 0x12ab3(%rip), %rbx     # 0x2afd0
leaq 0xb660(%rip), %rsi      # 0x23b84
movl $0xb, %edx
movq %rbx, %rdi
callq 0x2290
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq 0x12a81(%rip), %rdi     # 0x2afd0
callq 0x2040
movq %rax, %rdi
callq 0x2170
jmp 0x186ed
movq 0x12a68(%rip), %rdi     # 0x2afd0
leaq 0xb636(%rip), %rsi      # 0x23ba5
movl $0x2b, %edx
callq 0x2290
movq 0x12a50(%rip), %rdi     # 0x2afd0
movl %ebx, %esi
callq 0x2390
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq 0x12a18(%rip), %rdi     # 0x2afd0
leaq 0xb64d(%rip), %rsi      # 0x23c0c
movl $0x16, %edx
callq 0x2290
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
movq 0x129f6(%rip), %rdi     # 0x2afd0
callq 0x2160
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movaps %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
subq %rsi, %rdx
cmoveq %rax, %rsi
leaq 0x6d36(%rip), %rcx      # 0x1f368
callq 0xd14c
movl %eax, (%r15)
testl %eax, %eax
jne 0x18696
movq 0x1298b(%rip), %rdi     # 0x2afd0
leaq 0xb5d7(%rip), %rsi      # 0x23c23
movl $0x18, %edx
callq 0x2290
movq 0x38(%rsp), %rsi
subq 0x30(%rsp), %rsi
movq 0x12969(%rip), %rdi     # 0x2afd0
callq 0x2160
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x186ed
callq 0x2210
jmp 0x186ed
movq 0x12922(%rip), %rbx     # 0x2afd0
leaq 0xb4db(%rip), %rsi      # 0x23b90
movl $0x14, %edx
movq %rbx, %rdi
callq 0x2290
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq 0x128f0(%rip), %rdi     # 0x2afd0
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x186fc
callq 0x2210
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1873e
jmp 0x1873e
jmp 0x1873e
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
jne 0x18735
jmp 0x18741
jmp 0x1873e
jmp 0x1873e
jmp 0x1873e
jmp 0x1873e
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x18741
callq 0x2210
jmp 0x18741
jmp 0x1873e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x18750
callq 0x2210
movq %rbx, %rdi
callq 0x23a0