// File: /workspace/github_cpp_makefile_star2_O3/lvandeve[P]lodepng/lodepng_util.cpp
// Function: lodepng::getFilterTypesInterlaced(std::vector<std::vector<unsigned char, std::allocator<unsigned char>>, std::allocator<std::vector<unsigned char, std::allocator<unsigned char>>>>&, std::vector<unsigned char, std::allocator<unsigned char>> const&)
unsigned getFilterTypesInterlaced(std::vector<std::vector<unsigned char> >& filterTypes,
                                  const std::vector<unsigned char>& png) {
  //Get color type and interlace type
  lodepng::State state;
  unsigned w, h;
  unsigned error;
  error = lodepng_inspect(&w, &h, &state, png.empty() ? NULL : &png[0], png.size());

  if(error) return 1;

  //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> zdata;

  while(chunk < end && end - chunk >= 8) {
    char type[5];
    lodepng_chunk_type(type, chunk);
    if(std::string(type).size() != 4) return 1; //Probably not a PNG file

    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) {
        return 1; // corrupt chunk length
      }
      zdata.insert(zdata.end(), cdata, cdata + clength);
    }

    chunk = lodepng_chunk_next_const(chunk, end);
  }

  //Decompress all IDAT data
  std::vector<unsigned char> data;
  error = lodepng::decompress(data, zdata.empty() ? NULL : &zdata[0], zdata.size());

  if(error) return 1;

  if(state.info_png.interlace_method == 0) {
    filterTypes.resize(1);

    //A line is 1 filter byte + all pixels
    size_t linebytes = 1 + lodepng_get_raw_size(w, 1, &state.info_png.color);

    for(size_t i = 0; i < data.size(); i += linebytes) {
      filterTypes[0].push_back(data[i]);
    }
  } else {
    //Interlaced
    filterTypes.resize(7);
    static const unsigned ADAM7_IX[7] = { 0, 4, 0, 2, 0, 1, 0 }; /*x start values*/
    static const unsigned ADAM7_IY[7] = { 0, 0, 4, 0, 2, 0, 1 }; /*y start values*/
    static const unsigned ADAM7_DX[7] = { 8, 8, 4, 4, 2, 2, 1 }; /*x delta values*/
    static const unsigned ADAM7_DY[7] = { 8, 8, 8, 4, 4, 2, 2 }; /*y delta values*/
    size_t pos = 0;
    for(size_t j = 0; j < 7; j++) {
      unsigned w2 = (w - ADAM7_IX[j] + ADAM7_DX[j] - 1) / ADAM7_DX[j];
      unsigned h2 = (h - ADAM7_IY[j] + ADAM7_DY[j] - 1) / ADAM7_DY[j];
      if(ADAM7_IX[j] >= w || ADAM7_IY[j] >= h) continue;
      size_t linebytes = 1 + lodepng_get_raw_size(w2, 1, &state.info_png.color);
      for(size_t i = 0; i < h2; i++) {
        filterTypes[j].push_back(data[pos]);
        pos += linebytes;
      }
    }
  }
  return 0; /* OK */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
callq 0xd3c8
movq (%rbx), %rax
movq 0x8(%rbx), %r8
xorl %ecx, %ecx
subq %rax, %r8
cmovneq %rax, %rcx
leaq 0xc(%rsp), %rdi
leaq 0x4c(%rsp), %rsi
movq %r15, %rdx
callq 0x8215
movl $0x1, %ebp
testl %eax, %eax
jne 0x11624
movq (%rbx), %rbp
movq 0x8(%rbx), %r15
addq $0x8, %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq %r15, %rax
subq %rbp, %rax
setbe %cl
movq $0x0, 0x60(%rsp)
cmpq $0x8, %rax
setl %al
orb %cl, %al
jne 0x114a3
movq %rbx, 0x78(%rsp)
leaq 0x30(%rsp), %r14
leaq 0x1b(%rsp), %r12
leaq 0x20(%rsp), %rbx
movq %rbp, 0x70(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x544e
movq %r14, 0x20(%rsp)
movq %r12, %rdi
callq 0x2100
leaq (%rsp,%rax), %rdx
addq $0x1b, %rdx
movq %rbx, %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x14f6e
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rbx
cmpq %r14, %rdi
je 0x113c9
callq 0x2210
cmpq $0x4, %rbx
jne 0x11610
movq %r13, %rbx
movq %r14, 0x20(%rsp)
movq %r12, %rdi
callq 0x2100
leaq (%rsp,%rax), %rdx
addq $0x1b, %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x14f6e
movq %rbx, %rdi
leaq 0x648c6(%rip), %rsi     # 0x75cc6
callq 0x20b0
movl %eax, %r13d
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x11417
callq 0x2210
testl %r13d, %r13d
jne 0x11477
movq %rbp, %rdi
callq 0x54cb
movq %rax, %r13
movq %rbp, %rdi
callq 0x5449
movl %eax, %ecx
leaq (%rcx,%rbp), %rax
addq $0xc, %rax
cmpq %r15, %rax
ja 0x11610
movq 0x78(%rsp), %rsi
movq 0x8(%rsi), %rdx
subq (%rsi), %rdx
cmpq %rcx, %rdx
jb 0x11610
cmpq 0x70(%rsp), %rax
jb 0x11610
movq 0x58(%rsp), %rsi
addq %r13, %rcx
leaq 0x50(%rsp), %rdi
movq %r13, %rdx
callq 0x15bda
movq %rbp, %rdi
movq %r15, %rsi
callq 0x55b2
movq %rax, %rbp
movq %r15, %rax
subq %rbp, %rax
jbe 0x11497
cmpq $0x7, %rax
jg 0x11387
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
jmp 0x114a7
xorl %edx, %edx
xorl %esi, %esi
leaq 0x20(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
subq %rsi, %rdx
cmoveq %rax, %rsi
leaq 0x60ea2(%rip), %rcx     # 0x72368
callq 0xd1ec
movl $0x1, %ebp
testl %eax, %eax
jne 0x115fc
cmpl $0x0, 0x190(%rsp)
je 0x11645
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movl $0x7, %esi
movq 0x10(%rsp), %rdi
callq 0x14ea4
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1151d
callq 0x2210
xorl %r13d, %r13d
xorl %r14d, %r14d
movl 0xc(%rsp), %ecx
leaq 0x64962(%rip), %rax     # 0x75e90
movl (%rax,%r13,4), %esi
movl 0x4c(%rsp), %edi
leaq 0x64973(%rip), %rax     # 0x75eb0
movl (%rax,%r13,4), %r8d
leaq 0x649a8(%rip), %rax     # 0x75ef0
movl (%rax,%r13,4), %ebx
movl %r8d, %ebp
notl %ebp
addl %edi, %ebp
addl %ebx, %ebp
movl %ebp, %eax
xorl %edx, %edx
divl %ebx
movl %eax, %r12d
cmpl %ecx, %esi
setb %al
cmpl %edi, %r8d
setb %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x115ed
leaq 0x64959(%rip), %rax     # 0x75ed0
movl (%rax,%r13,4), %edi
notl %esi
addl %edi, %ecx
addl %esi, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %eax, %edi
movl $0x1, %esi
leaq 0x198(%rsp), %rdx
callq 0x5aef
cmpl %ebp, %ebx
ja 0x115ed
movq %rax, %r15
incq %r15
movl %r12d, %ebx
leaq (,%r13,2), %r12
addq %r13, %r12
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
movq (%rax), %rax
leaq (%rax,%r12,8), %rdi
movq 0x20(%rsp), %rdx
addq %r14, %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x115dd
movb (%rdx), %al
movb %al, (%rsi)
incq 0x8(%rdi)
jmp 0x115e2
callq 0x16120
incq %rbp
addq %r15, %r14
cmpq %rbx, %rbp
jb 0x115b5
incq %r13
cmpq $0x7, %r13
jne 0x11523
xorl %ebp, %ebp
movq 0x20(%rsp), %rdx
testq %rdx, %rdx
je 0x11615
movq %rdx, %rdi
callq 0x2210
jmp 0x11615
movl $0x1, %ebp
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x11624
callq 0x2210
leaq 0xb8(%rsp), %rdi
callq 0xd3f0
movl %ebp, %eax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movl $0x1, %esi
movq 0x10(%rsp), %rdi
callq 0x14ea4
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x1167c
callq 0x2210
movl 0xc(%rsp), %edi
leaq 0x198(%rsp), %rdx
movl $0x1, %esi
callq 0x5aef
movq 0x20(%rsp), %rdx
cmpq %rdx, 0x28(%rsp)
je 0x116df
movq %rax, %r14
incq %r14
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movq (%rax), %rdi
addq %rbx, %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x116c5
movb (%rdx), %al
movb %al, (%rsi)
incq 0x8(%rdi)
jmp 0x116ca
callq 0x16120
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rax
subq %rdx, %rax
addq %r14, %rbx
cmpq %rax, %rbx
jb 0x116a6
xorl %ebp, %ebp
jmp 0x11601
jmp 0x11733
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
jmp 0x11700
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x11736
callq 0x2210
jmp 0x11736
jmp 0x11733
jmp 0x11733
jmp 0x1172e
jmp 0x11733
movq %rax, %rbx
jmp 0x11754
jmp 0x1172e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
jne 0x11740
jmp 0x11745
jmp 0x1172e
jmp 0x1172e
movq %rax, %rbx
jmp 0x11745
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x11745
callq 0x2210
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x11754
callq 0x2210
leaq 0xb8(%rsp), %rdi
callq 0xd3f0
movq %rbx, %rdi
callq 0x23c0
movq %rax, %rdi
callq 0x14d36