// File: /workspace/github_cpp_makefile_star2_O2/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 $0x328, %rsp            # imm = 0x328
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
callq 0xb84c
movq (%rbx), %rax
movq %rbx, 0x18(%rsp)
movq 0x8(%rbx), %r8
xorl %ecx, %ecx
subq %rax, %r8
cmovneq %rax, %rcx
leaq 0x4(%rsp), %rdi
leaq 0x14(%rsp), %rsi
movq %r14, %rdx
callq 0x6f45
testl %eax, %eax
je 0xf107
pushq $0x1
popq %r14
jmp 0xf37d
movq 0x18(%rsp), %rax
movq (%rax), %r12
movq 0x8(%rax), %r15
addq $0x8, %r12
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x6b(%rsp), %r13
leaq 0x40(%rsp), %rbp
leaq 0x3(%rsp), %rbx
movq %r12, 0x60(%rsp)
movq %r15, %rax
subq %r12, %rax
jbe 0xf21f
cmpq $0x8, %rax
jl 0xf21f
movq %r13, %rdi
movq %r12, %rsi
callq 0x4574
movq %rbp, %rdi
movq %r13, %rsi
movq %rbx, %r14
movq %rbx, %rdx
callq 0x20c0
movq 0x48(%rsp), %rbx
movq %rbp, %rdi
callq 0x2270
cmpq $0x4, %rbx
jne 0xf216
movq %r14, %rbx
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x20c0
movq %rbp, %rdi
leaq 0x50a23(%rip), %rsi     # 0x5fbc2
callq 0x121b0
movl %eax, %r14d
movq %rbp, %rdi
callq 0x2270
testb %r14b, %r14b
je 0xf203
movq %r12, %rdi
callq 0x4614
movq %rax, %r14
movq %r12, %rdi
callq 0x456d
movl %eax, %ecx
leaq (%r12,%rcx), %rax
addq $0xc, %rax
cmpq %r15, %rax
ja 0xf216
movq 0x18(%rsp), %rsi
movq 0x8(%rsi), %rdx
subq (%rsi), %rdx
cmpq %rcx, %rdx
jb 0xf216
cmpq 0x60(%rsp), %rax
jb 0xf216
movq 0x28(%rsp), %rsi
addq %r14, %rcx
leaq 0x20(%rsp), %rdi
movq %r14, %rdx
callq 0x12d34
movq %r12, %rdi
movq %r15, %rsi
callq 0x4705
movq %rax, %r12
jmp 0xf13b
pushq $0x1
popq %r14
jmp 0xf373
leaq 0x40(%rsp), %rdi
andq $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdx
xorl %esi, %esi
subq %rax, %rdx
cmovneq %rax, %rsi
leaq 0x4d017(%rip), %rcx     # 0x5c260
callq 0xb68d
testl %eax, %eax
je 0xf25b
pushq $0x1
popq %r14
jmp 0xf369
cmpl $0x0, 0x180(%rsp)
je 0xf39f
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
pushq $0x7
popq %rsi
movq 0x8(%rsp), %rdi
callq 0x122e2
leaq 0x70(%rsp), %rdi
callq 0xea7c
leaq 0x509e9(%rip), %r10     # 0x5fc80
leaq 0x50a02(%rip), %r11     # 0x5fca0
leaq 0x50a3b(%rip), %rbx     # 0x5fce0
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpq $0x7, %r15
je 0xf366
movl 0x4(%rsp), %ecx
movl (%r10,%r15,4), %esi
movl 0x14(%rsp), %edi
movl (%r11,%r15,4), %r8d
movl (%rbx,%r15,4), %r9d
movl %r8d, %eax
notl %eax
addl %edi, %eax
addl %r9d, %eax
xorl %edx, %edx
divl %r9d
movl %eax, %r13d
cmpl %ecx, %esi
setb %al
cmpl %edi, %r8d
setb %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0xf35e
leaq 0x509cd(%rip), %rax     # 0x5fcc0
movl (%rax,%r15,4), %edi
notl %esi
addl %edi, %ecx
addl %esi, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %eax, %edi
pushq $0x1
popq %rsi
leaq 0x188(%rsp), %rdx
callq 0x4b9a
movq %rax, %r12
incq %r12
movl %r13d, %r13d
imulq $0x18, %r15, %r14
xorl %ebx, %ebx
cmpq %r13, %rbx
jae 0xf349
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq %r14, %rdi
movq 0x40(%rsp), %rsi
addq %rbp, %rsi
callq 0x1231e
incq %rbx
addq %r12, %rbp
jmp 0xf324
leaq 0x50930(%rip), %r10     # 0x5fc80
leaq 0x50949(%rip), %r11     # 0x5fca0
leaq 0x50982(%rip), %rbx     # 0x5fce0
incq %r15
jmp 0xf2aa
xorl %r14d, %r14d
leaq 0x40(%rsp), %rdi
callq 0xea7c
leaq 0x20(%rsp), %rdi
callq 0xea7c
leaq 0xa8(%rsp), %rdi
callq 0xb874
movl %r14d, %eax
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
pushq $0x1
popq %rsi
movq 0x8(%rsp), %rdi
callq 0x122e2
leaq 0x90(%rsp), %rdi
callq 0xea7c
movl 0x4(%rsp), %edi
leaq 0x188(%rsp), %rdx
pushq $0x1
popq %rsi
callq 0x4b9a
movq %rax, %r15
incq %r15
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rax
subq %rsi, %rax
cmpq %rax, %rbx
jae 0xf369
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq %rbx, %rsi
callq 0x1231e
addq %r15, %rbx
jmp 0xf3eb
jmp 0xf464
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xea7c
jmp 0xf467
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xea7c
jmp 0xf467
jmp 0xf45f
jmp 0xf464
jmp 0xf443
jmp 0xf464
jmp 0xf464
movq %rax, %rbx
jmp 0xf47b
jmp 0xf45f
jmp 0xf45f
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2270
jmp 0xf471
jmp 0xf45f
jmp 0xf45f
movq %rax, %rbx
jmp 0xf471
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xea7c
leaq 0x20(%rsp), %rdi
callq 0xea7c
leaq 0xa8(%rsp), %rdi
callq 0xb874
movq %rbx, %rdi
callq 0x2380
movq %rax, %rdi
callq 0xe6cc