// File: lvandeve[P]lodepng/lodepng_util.cpp
// Function: lodepng::getChunks(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>*, 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 getChunks(std::vector<std::string> names[3],
                   std::vector<std::vector<unsigned char> > chunks[3],
                   const std::vector<unsigned char>& png) {
  const unsigned char *chunk, *next, *end;
  end = &png.back() + 1;
  chunk = &png.front() + 8;

  int location = 0;

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

    next = lodepng_chunk_next_const(chunk, end);

    if(name == "IHDR") {
      location = 0;
    } else if(name == "PLTE") {
      location = 1;
    } else if(name == "IDAT") {
      location = 2;
    } else if(name == "IEND") {
      break; // anything after IEND is not part of the PNG or the 3 groups here.
    } else {
      if(next >= end) return 1; // invalid chunk, content too far
      names[location].push_back(name);
      chunks[location].push_back(std::vector<unsigned char>(chunk, next));
    }

    chunk = next;
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x23160
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x231a0
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq -0x38(%rbp), %rcx
movb %al, -0x9a(%rbp)
jae 0x1c48a
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
cmpq $0x8, %rax
setge %al
movb %al, -0x9a(%rbp)
movb -0x9a(%rbp), %al
testb $0x1, %al
jne 0x1c499
jmp 0x1c76f
movq -0x28(%rbp), %rsi
leaq -0x41(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x4de0
leaq -0x69(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x3440
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x3340
jmp 0x1c4d6
leaq -0x69(%rbp), %rdi
callq 0x3290
leaq -0x68(%rbp), %rdi
callq 0x3190
movq %rax, -0xb8(%rbp)
jmp 0x1c4f1
movq -0xb8(%rbp), %rax
cmpq $0x4, %rax
je 0x1c53c
movl $0x1, -0x4(%rbp)
movl $0x1, -0x80(%rbp)
jmp 0x1c736
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x69(%rbp), %rdi
callq 0x3290
jmp 0x1c782
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x1c762
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x51c0
movq %rax, -0xc0(%rbp)
jmp 0x1c552
movq -0xc0(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq 0x94ff7(%rip), %rsi     # 0xb155b
leaq -0x68(%rbp), %rdi
callq 0x232b0
movb %al, -0xc1(%rbp)
jmp 0x1c575
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x1c581
jmp 0x1c58d
movl $0x0, -0x3c(%rbp)
jmp 0x1c727
leaq 0x94fcc(%rip), %rsi     # 0xb1560
leaq -0x68(%rbp), %rdi
callq 0x232b0
movb %al, -0xc2(%rbp)
jmp 0x1c5a5
movb -0xc2(%rbp), %al
testb $0x1, %al
jne 0x1c5b1
jmp 0x1c5bd
movl $0x1, -0x3c(%rbp)
jmp 0x1c725
leaq 0x963e6(%rip), %rsi     # 0xb29aa
leaq -0x68(%rbp), %rdi
callq 0x232b0
movb %al, -0xc3(%rbp)
jmp 0x1c5d5
movb -0xc3(%rbp), %al
testb $0x1, %al
jne 0x1c5e1
jmp 0x1c5ed
movl $0x2, -0x3c(%rbp)
jmp 0x1c723
leaq 0x97946(%rip), %rsi     # 0xb3f3a
leaq -0x68(%rbp), %rdi
callq 0x232b0
movb %al, -0xc4(%rbp)
jmp 0x1c605
movb -0xc4(%rbp), %al
testb $0x1, %al
jne 0x1c611
jmp 0x1c61d
movl $0x3, -0x80(%rbp)
jmp 0x1c736
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jb 0x1c63a
movl $0x1, -0x4(%rbp)
movl $0x1, -0x80(%rbp)
jmp 0x1c736
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
leaq -0x68(%rbp), %rsi
callq 0x231d0
jmp 0x1c655
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, -0xe8(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x1bfa0
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq -0xd0(%rbp), %rcx
leaq -0x98(%rbp), %rdi
callq 0x23350
jmp 0x1c6b8
movq -0xe8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x232e0
jmp 0x1c6cd
leaq -0x98(%rbp), %rdi
callq 0x1a4c0
jmp 0x1c6db
leaq -0x99(%rbp), %rdi
callq 0x1bff0
jmp 0x1c721
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x1c713
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1a4c0
jmp 0x1c711
jmp 0x1c713
leaq -0x99(%rbp), %rdi
callq 0x1bff0
jmp 0x1c762
jmp 0x1c723
jmp 0x1c725
jmp 0x1c727
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x80(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x34a8
movl -0x80(%rbp), %eax
movl %eax, -0xec(%rbp)
testl %eax, %eax
je 0x1c75d
jmp 0x1c74e
movl -0xec(%rbp), %eax
subl $0x1, %eax
je 0x1c776
jmp 0x1c75b
jmp 0x1c76f
jmp 0x1c460
leaq -0x68(%rbp), %rdi
callq 0x34a8
jmp 0x1c76d
jmp 0x1c782
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x3430
movq %rax, %rdi
callq 0x1a490
nopw %cs:(%rax,%rax)