// File: /workspace/github_cpp_makefile_star2_O2/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
callq 0x1908e
cmpl $0x0, 0x2d8(%rbx)
jne 0x14e70
movq %rbx, %rdi
callq 0x19242
testb %al, %al
je 0x14e70
movq 0x20(%rbx), %r15
movq 0x28(%rbx), %r14
addq $0x8, %r15
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x63(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %r15, 0x58(%rsp)
movq %r14, %rax
subq %r15, %rax
jbe 0x14d3f
cmpq $0x8, %rax
jl 0x14d3f
movq %r12, %rdi
movq %r15, %rsi
callq 0x4544
movq %r13, %rdi
movq %r12, %rsi
leaq 0xf(%rsp), %rdx
callq 0x20b0
movq 0x38(%rsp), %rbp
movq %r13, %rdi
callq 0x22a0
cmpq $0x4, %rbp
jne 0x14e2e
movq %r13, %rdi
movq %r12, %rsi
leaq 0xf(%rsp), %rdx
callq 0x20b0
movq %r13, %rdi
leaq 0x8f01(%rip), %rsi      # 0x1dbc2
callq 0x12180
movl %eax, %ebp
movq %r13, %rdi
callq 0x22a0
testb %bpl, %bpl
je 0x14d2c
movq %r15, %rdi
callq 0x45e4
movq %rax, %rbp
movq %r15, %rdi
callq 0x453d
movl %eax, %ecx
leaq (%r15,%rcx), %rax
addq $0xc, %rax
cmpq %r14, %rax
ja 0x14e4b
movq 0x28(%rbx), %rdx
subq 0x20(%rbx), %rdx
cmpq %rcx, %rdx
jb 0x14e4b
cmpq 0x58(%rsp), %rax
jb 0x14e4b
movq 0x18(%rsp), %rsi
addq %rbp, %rcx
leaq 0x10(%rsp), %rdi
movq %rbp, %rdx
callq 0x12d04
movq %r15, %rdi
movq %r14, %rsi
callq 0x46d5
movq %rax, %r15
jmp 0x14c5f
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
cmpq $0x3, %rcx
jb 0x14d8f
movzbl 0x2(%rax), %ebp
testb $0x1, %bpl
leaq 0x9cb4(%rip), %rax      # 0x1ea15
leaq 0x9c81(%rip), %rsi      # 0x1e9e9
cmoveq %rax, %rsi
movq 0x1225d(%rip), %rdi     # 0x26fd0
callq 0x2210
shrl %ebp
andl $0x3, %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x2390
movq %rax, %rdi
callq 0x2100
movq 0x1223a(%rip), %rdi     # 0x26fd0
leaq 0x9cb3(%rip), %rsi      # 0x1ea50
callq 0x2210
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x2100
leaq 0x30(%rsp), %rdi
andq $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
xorl %esi, %esi
subq %rax, %rdx
cmovneq %rax, %rsi
leaq 0x547a(%rip), %rcx      # 0x1a260
callq 0xb65d
movl %eax, 0x2d8(%rbx)
testl %eax, %eax
jne 0x14e22
movq 0x121d4(%rip), %rdi     # 0x26fd0
leaq 0x9c64(%rip), %rsi      # 0x1ea67
callq 0x2210
movq 0x38(%rsp), %rsi
subq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x2100
leaq 0x30(%rsp), %rdi
callq 0xea4c
jmp 0x14e66
movq 0x1219b(%rip), %rdi     # 0x26fd0
leaq 0x9b8c(%rip), %rsi      # 0x1e9c8
callq 0x2210
movq %rax, %rdi
callq 0x2100
jmp 0x14e66
movq 0x1217e(%rip), %rdi     # 0x26fd0
leaq 0x9b7b(%rip), %rsi      # 0x1e9d4
callq 0x2210
movq %rax, %rdi
callq 0x2100
leaq 0x10(%rsp), %rdi
callq 0xea4c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14eaf
jmp 0x14eaf
jmp 0x14eaf
jmp 0x14eaf
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xea4c
jmp 0x14eb2
jmp 0x14eaf
jmp 0x14eaf
jmp 0x14eaf
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x22a0
jmp 0x14eb2
jmp 0x14eaf
jmp 0x14eaf
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xea4c
movq %rbx, %rdi
callq 0x23a0
movq %rax, %rdi
callq 0xe69c