// File: lvandeve[P]lodepng/lodepng_util.cpp
// Function: lodepng::getFilterTypes(std::vector<unsigned char, std::allocator<unsigned char>>&, std::vector<unsigned char, std::allocator<unsigned char>> const&)
unsigned getFilterTypes(std::vector<unsigned char>& filterTypes, const std::vector<unsigned char>& png) {
  std::vector<std::vector<unsigned char> > passes;
  unsigned error = getFilterTypesInterlaced(passes, png);
  if(error) return error;

  if(passes.size() == 1) {
    filterTypes.swap(passes[0]);
  } else {
    // Simplify interlaced filter types to get a single filter value per scanline:
    // put pass 6 and 7 alternating in the one vector, these filters
    // correspond to the closest to what it would be for non-interlaced
    // image. If the image is only 1 pixel wide, pass 6 doesn't exist so the
    // alternative values column0 are used. The shift values are to match
    // the y position in the interlaced sub-images.
    // NOTE: the values 0-6 match Adam7's passes 1-7.
    const unsigned column0[8] = {0, 6, 4, 6, 2, 6, 4, 6};
    const unsigned column1[8] = {5, 6, 5, 6, 5, 6, 5, 6};
    const unsigned shift0[8] = {3, 1, 2, 1, 3, 1, 2, 1};
    const unsigned shift1[8] = {1, 1, 1, 1, 1, 1, 1, 1};
    lodepng::State state;
    unsigned w, h;
    lodepng_inspect(&w, &h, &state, png.empty() ? NULL : &png[0], png.size());
    const unsigned* column = w > 1 ? column1 : column0;
    const unsigned* shift = w > 1 ? shift1 : shift0;
    for(size_t i = 0; i < h; i++) {
      filterTypes.push_back(passes[column[i & 7u]][i >> shift[i & 7u]]);
    }
  }
  return 0; /* OK */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3f0, %rsp            # imm = 0x3F0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x380(%rbp)
callq 0x238d0
movq -0x380(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1d100
movl %eax, -0x374(%rbp)
jmp 0x1dadb
movl -0x374(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x1db0d
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x1ddc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1dddd
leaq -0x30(%rbp), %rdi
callq 0x23480
movq %rax, -0x388(%rbp)
jmp 0x1db1f
movq -0x388(%rbp), %rax
cmpq $0x1, %rax
jne 0x1db67
movq -0x10(%rbp), %rax
movq %rax, -0x398(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x23840
movq %rax, -0x390(%rbp)
jmp 0x1db4d
movq -0x390(%rbp), %rsi
movq -0x398(%rbp), %rdi
callq 0x238f0
jmp 0x1db62
jmp 0x1ddba
movaps 0x95142(%rip), %xmm0    # 0xb2cb0
movaps %xmm0, -0x60(%rbp)
movaps 0x95127(%rip), %xmm0    # 0xb2ca0
movaps %xmm0, -0x70(%rbp)
movaps 0x9514c(%rip), %xmm0    # 0xb2cd0
movaps %xmm0, -0x80(%rbp)
movaps 0x95131(%rip), %xmm0    # 0xb2cc0
movaps %xmm0, -0x90(%rbp)
movaps 0x95153(%rip), %xmm0    # 0xb2cf0
movaps %xmm0, -0xa0(%rbp)
movaps 0x95135(%rip), %xmm0    # 0xb2ce0
movaps %xmm0, -0xb0(%rbp)
movaps 0x95157(%rip), %xmm0    # 0xb2d10
movaps %xmm0, -0xc0(%rbp)
movaps 0x95139(%rip), %xmm0    # 0xb2d00
movaps %xmm0, -0xd0(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x11ad0
jmp 0x1dbdc
movq -0x18(%rbp), %rdi
callq 0x1a3a0
movb %al, -0x399(%rbp)
jmp 0x1dbed
movb -0x399(%rbp), %al
testb $0x1, %al
jne 0x1dbf9
jmp 0x1dc04
xorl %eax, %eax
movq %rax, -0x3a8(%rbp)
jmp 0x1dc2a
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1a3e0
movq %rax, -0x3b0(%rbp)
jmp 0x1dc1a
movq -0x3b0(%rbp), %rax
movq %rax, -0x3a8(%rbp)
jmp 0x1dc2a
movq -0x3a8(%rbp), %rax
movq %rax, -0x3c0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1a400
movq %rax, -0x3b8(%rbp)
jmp 0x1dc4a
movq -0x3b8(%rbp), %r8
movq -0x3c0(%rbp), %rcx
leaq -0x354(%rbp), %rdi
leaq -0x358(%rbp), %rsi
leaq -0x350(%rbp), %rdx
callq 0xa1d0
jmp 0x1dc74
cmpl $0x1, -0x354(%rbp)
jbe 0x1dc8d
leaq -0x90(%rbp), %rax
movq %rax, -0x3c8(%rbp)
jmp 0x1dc9a
leaq -0x70(%rbp), %rax
movq %rax, -0x3c8(%rbp)
jmp 0x1dc9a
movq -0x3c8(%rbp), %rax
movq %rax, -0x360(%rbp)
cmpl $0x1, -0x354(%rbp)
jbe 0x1dcc1
leaq -0xd0(%rbp), %rax
movq %rax, -0x3d0(%rbp)
jmp 0x1dcd1
leaq -0xb0(%rbp), %rax
movq %rax, -0x3d0(%rbp)
jmp 0x1dcd1
movq -0x3d0(%rbp), %rax
movq %rax, -0x368(%rbp)
movq $0x0, -0x370(%rbp)
movq -0x370(%rbp), %rax
movl -0x358(%rbp), %ecx
cmpq %rcx, %rax
jae 0x1dda8
movq -0x10(%rbp), %rax
movq %rax, -0x3e0(%rbp)
movq -0x360(%rbp), %rax
movl -0x370(%rbp), %ecx
andl $0x7, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x23840
movq %rax, -0x3d8(%rbp)
jmp 0x1dd32
movq -0x3d8(%rbp), %rdi
movq -0x370(%rbp), %rsi
movq -0x368(%rbp), %rax
movl %esi, %ecx
andl $0x7, %ecx
movb (%rax,%rcx,4), %cl
shrq %cl, %rsi
callq 0x1a5f0
movq %rax, -0x3e8(%rbp)
jmp 0x1dd60
movq -0x3e8(%rbp), %rsi
movq -0x3e0(%rbp), %rdi
callq 0x23860
jmp 0x1dd75
jmp 0x1dd77
movq -0x370(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x370(%rbp)
jmp 0x1dcea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x11b20
jmp 0x1ddb8
leaq -0x350(%rbp), %rdi
callq 0x11b20
jmp 0x1ddb6
jmp 0x1ddba
jmp 0x1dddd
movl $0x0, -0x4(%rbp)
movl $0x1, -0x48(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x23940
movl -0x4(%rbp), %eax
addq $0x3f0, %rsp            # imm = 0x3F0
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x23940
jmp 0x1dde8
jmp 0x1ddea
movq -0x40(%rbp), %rdi
callq 0x3430
movq %rax, %rdi
callq 0x1a490
nopl (%rax,%rax)