// File: /workspace/github_cpp_makefile_star2_O1/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), %r14
movq %r14, %rdi
callq 0xd1a0
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 %r14, %rdx
callq 0x7c69
movl $0x1, %ebp
testl %eax, %eax
jne 0x11a31
movq (%rbx), %r12
movq %rbx, 0x78(%rsp)
movq 0x8(%rbx), %r15
addq $0x8, %r12
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rax
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x30(%rsp), %rbx
leaq 0x1b(%rsp), %r13
leaq 0x20(%rsp), %rbp
movq %r12, 0x70(%rsp)
movq %r15, %rax
subq %r12, %rax
jbe 0x11812
cmpq $0x8, %rax
jl 0x11812
movq %r13, %rdi
movq %r12, %rsi
callq 0x4e89
movq %rbx, 0x20(%rsp)
movq %r13, %rdi
callq 0x2100
leaq (%rsp,%rax), %rdx
addq $0x1b, %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1517a
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %r14
cmpq %rbx, %rdi
je 0x1174a
callq 0x2200
cmpq $0x4, %r14
jne 0x117ec
movq %rbx, 0x20(%rsp)
movq %r13, %rdi
callq 0x2100
leaq (%rsp,%rax), %rdx
addq $0x1b, %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1517a
movq %rbp, %rdi
leaq 0x64424(%rip), %rsi     # 0x75ba2
callq 0x20b0
movl %eax, %r14d
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0x11795
callq 0x2200
testl %r14d, %r14d
je 0x117ac
movq %r12, %rdi
movq %r15, %rsi
callq 0x4fe2
movq %rax, %r12
movb $0x1, %al
jmp 0x117ee
movq %r12, %rdi
callq 0x4f06
movq %rax, %r14
movq %r12, %rdi
callq 0x4e84
movl %eax, %ecx
leaq (%r12,%rcx), %rax
addq $0xc, %rax
cmpq %r15, %rax
ja 0x117ec
movq 0x78(%rsp), %rsi
movq 0x8(%rsi), %rdx
subq (%rsi), %rdx
cmpq %rcx, %rdx
setb %dl
cmpq 0x70(%rsp), %rax
setb %al
orb %dl, %al
je 0x117fb
xorl %eax, %eax
testb %al, %al
jne 0x116f5
jmp 0x1196d
movq 0x58(%rsp), %rsi
addq %r14, %rcx
leaq 0x50(%rsp), %rdi
movq %r14, %rdx
callq 0x15e12
jmp 0x1179a
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
subq %rsi, %rdx
cmoveq %rax, %rsi
leaq 0x60a0d(%rip), %rcx     # 0x72248
callq 0xcfba
movl $0x1, %ebp
testl %eax, %eax
jne 0x11a13
cmpl $0x0, 0x190(%rsp)
je 0x11977
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movl $0x7, %esi
movq 0x10(%rsp), %rdi
callq 0x150b6
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x11892
callq 0x2200
xorl %ebx, %ebx
xorl %r14d, %r14d
movl 0xc(%rsp), %ecx
leaq 0x643be(%rip), %rax     # 0x75c60
movl (%rax,%rbx,4), %esi
movl 0x4c(%rsp), %edi
leaq 0x643d0(%rip), %rax     # 0x75c80
movl (%rax,%rbx,4), %r8d
leaq 0x64405(%rip), %rax     # 0x75cc0
movl (%rax,%rbx,4), %r13d
movl %r8d, %ebp
notl %ebp
addl %edi, %ebp
addl %r13d, %ebp
movl %ebp, %eax
xorl %edx, %edx
divl %r13d
movl %eax, %r12d
cmpl %ecx, %esi
setb %al
cmpl %edi, %r8d
setb %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x1195b
leaq 0x643b4(%rip), %rax     # 0x75ca0
movl (%rax,%rbx,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 0x5517
cmpl %ebp, %r13d
ja 0x1195b
movq %rax, %r15
incq %r15
movl %r12d, %r12d
leaq (%rbx,%rbx,2), %r13
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
movq (%rax), %rax
leaq (%rax,%r13,8), %rdi
movq 0x20(%rsp), %rdx
addq %r14, %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x1194b
movb (%rdx), %al
movb %al, (%rsi)
incq 0x8(%rdi)
jmp 0x11950
callq 0x16342
incq %rbp
addq %r15, %r14
cmpq %r12, %rbp
jb 0x11923
incq %rbx
cmpq $0x7, %rbx
jne 0x11897
jmp 0x11a11
movl $0x1, %ebp
jmp 0x11a22
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movl $0x1, %esi
movq 0x10(%rsp), %rdi
callq 0x150b6
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x119ae
callq 0x2200
movl 0xc(%rsp), %edi
leaq 0x198(%rsp), %rdx
movl $0x1, %esi
callq 0x5517
movq 0x20(%rsp), %rdx
cmpq %rdx, 0x28(%rsp)
je 0x11a11
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 0x119f7
movb (%rdx), %al
movb %al, (%rsi)
incq 0x8(%rdi)
jmp 0x119fc
callq 0x16342
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rax
subq %rdx, %rax
addq %r14, %rbx
cmpq %rax, %rbx
jb 0x119d8
xorl %ebp, %ebp
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x11a22
callq 0x2200
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x11a31
callq 0x2200
leaq 0xb8(%rsp), %rdi
callq 0xd1c8
movl %ebp, %eax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11a98
movq %rax, %r14
movq 0xa0(%rsp), %rdi
jmp 0x11a6c
movq %rax, %r14
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x11a9b
callq 0x2200
jmp 0x11a9b
jmp 0x11a98
jmp 0x11a98
jmp 0x11a98
movq %rax, %r14
jmp 0x11ac0
jmp 0x11aae
jmp 0x11aae
jmp 0x11aae
movq %rax, %r14
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
jne 0x11aa5
jmp 0x11ab1
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x11ab1
callq 0x2200
jmp 0x11ab1
jmp 0x11aae
movq %rax, %r14
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x11ac0
callq 0x2200
leaq 0xb8(%rsp), %rdi
callq 0xd1c8
movq %r14, %rdi
callq 0x23b0
movq %rax, %rdi
callq 0x14f59