// File: lvandeve[P]lodepng/lodepng.cpp
// Function: lodepng_inspect_chunk(LodePNGState*, unsigned long, unsigned char const*, unsigned long)
unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos,
                               const unsigned char* in, size_t insize) {
  const unsigned char* chunk = in + pos;
  unsigned chunkLength;
  const unsigned char* data;
  unsigned unhandled = 0;
  unsigned error = 0;

  if(pos + 4 > insize) return 30;
  chunkLength = lodepng_chunk_length(chunk);
  if(chunkLength > 2147483647) return 63;
  data = lodepng_chunk_data_const(chunk);
  if(chunkLength + 12 > insize - pos) return 30;

  if(lodepng_chunk_type_equals(chunk, "PLTE")) {
    error = readChunk_PLTE(&state->info_png.color, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "tRNS")) {
    error = readChunk_tRNS(&state->info_png.color, data, chunkLength);
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
  } else if(lodepng_chunk_type_equals(chunk, "bKGD")) {
    error = readChunk_bKGD(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "tEXt")) {
    error = readChunk_tEXt(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "zTXt")) {
    error = readChunk_zTXt(&state->info_png, &state->decoder, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "iTXt")) {
    error = readChunk_iTXt(&state->info_png, &state->decoder, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "tIME")) {
    error = readChunk_tIME(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "pHYs")) {
    error = readChunk_pHYs(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "gAMA")) {
    error = readChunk_gAMA(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "cHRM")) {
    error = readChunk_cHRM(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "sRGB")) {
    error = readChunk_sRGB(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "iCCP")) {
    error = readChunk_iCCP(&state->info_png, &state->decoder, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "cICP")) {
    error = readChunk_cICP(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "mDCV")) {
    error = readChunk_mDCV(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "cLLI")) {
    error = readChunk_cLLI(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "eXIf")) {
    error = readChunk_eXIf(&state->info_png, data, chunkLength);
  } else if(lodepng_chunk_type_equals(chunk, "sBIT")) {
    error = readChunk_sBIT(&state->info_png, data, chunkLength);
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
  } else {
    /* unhandled chunk is ok (is not an error) */
    unhandled = 1;
  }

  if(!error && !unhandled && !state->decoder.ignore_crc) {
    if(lodepng_chunk_check_crc(chunk)) return 57; /*invalid CRC*/
  }

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
cmpq -0x28(%rbp), %rax
jbe 0xa64c
movl $0x1e, -0x4(%rbp)
jmp 0xaa87
movq -0x30(%rbp), %rdi
callq 0x4d80
movl %eax, -0x34(%rbp)
cmpl $0x7fffffff, -0x34(%rbp) # imm = 0x7FFFFFFF
jbe 0xa66d
movl $0x3f, -0x4(%rbp)
jmp 0xaa87
movq -0x30(%rbp), %rdi
callq 0x4f90
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %eax
addl $0xc, %eax
movl %eax, %eax
movq -0x28(%rbp), %rcx
subq -0x18(%rbp), %rcx
cmpq %rcx, %rax
jbe 0xa69b
movl $0x1e, -0x4(%rbp)
jmp 0xaa87
movq -0x30(%rbp), %rdi
leaq 0xa6eba(%rip), %rsi     # 0xb1560
callq 0x4e30
cmpb $0x0, %al
je 0xa6d4
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
addq $0x10, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xaa90
movl %eax, -0x48(%rbp)
jmp 0xaa52
movq -0x30(%rbp), %rdi
leaq 0xa6e86(%rip), %rsi     # 0xb1565
callq 0x4e30
cmpb $0x0, %al
je 0xa70d
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
addq $0x10, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xabf0
movl %eax, -0x48(%rbp)
jmp 0xaa50
movq -0x30(%rbp), %rdi
leaq 0xa6e52(%rip), %rsi     # 0xb156a
callq 0x4e30
cmpb $0x0, %al
je 0xa742
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xad50
movl %eax, -0x48(%rbp)
jmp 0xaa4e
movq -0x30(%rbp), %rdi
leaq 0xa6e22(%rip), %rsi     # 0xb156f
callq 0x4e30
cmpb $0x0, %al
je 0xa777
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xaec0
movl %eax, -0x48(%rbp)
jmp 0xaa4c
movq -0x30(%rbp), %rdi
leaq 0xa6df2(%rip), %rsi     # 0xb1574
callq 0x4e30
cmpb $0x0, %al
je 0xa7b0
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl -0x34(%rbp), %eax
movl %eax, %ecx
callq 0xb040
movl %eax, -0x48(%rbp)
jmp 0xaa4a
movq -0x30(%rbp), %rdi
leaq 0xa6dbe(%rip), %rsi     # 0xb1579
callq 0x4e30
cmpb $0x0, %al
je 0xa7e9
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl -0x34(%rbp), %eax
movl %eax, %ecx
callq 0xb230
movl %eax, -0x48(%rbp)
jmp 0xaa48
movq -0x30(%rbp), %rdi
leaq 0xa6d8a(%rip), %rsi     # 0xb157e
callq 0x4e30
cmpb $0x0, %al
je 0xa81e
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xb620
movl %eax, -0x48(%rbp)
jmp 0xaa46
movq -0x30(%rbp), %rdi
leaq 0xa6d5a(%rip), %rsi     # 0xb1583
callq 0x4e30
cmpb $0x0, %al
je 0xa853
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xb6e0
movl %eax, -0x48(%rbp)
jmp 0xaa44
movq -0x30(%rbp), %rdi
leaq 0xa6d2a(%rip), %rsi     # 0xb1588
callq 0x4e30
cmpb $0x0, %al
je 0xa888
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xb7a0
movl %eax, -0x48(%rbp)
jmp 0xaa42
movq -0x30(%rbp), %rdi
leaq 0xa6cfa(%rip), %rsi     # 0xb158d
callq 0x4e30
cmpb $0x0, %al
je 0xa8bd
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xb820
movl %eax, -0x48(%rbp)
jmp 0xaa40
movq -0x30(%rbp), %rdi
leaq 0xa6cca(%rip), %rsi     # 0xb1592
callq 0x4e30
cmpb $0x0, %al
je 0xa8f2
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xba30
movl %eax, -0x48(%rbp)
jmp 0xaa3e
movq -0x30(%rbp), %rdi
leaq 0xa6c9a(%rip), %rsi     # 0xb1597
callq 0x4e30
cmpb $0x0, %al
je 0xa92b
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl -0x34(%rbp), %eax
movl %eax, %ecx
callq 0xba80
movl %eax, -0x48(%rbp)
jmp 0xaa3c
movq -0x30(%rbp), %rdi
leaq 0xa6c66(%rip), %rsi     # 0xb159c
callq 0x4e30
cmpb $0x0, %al
je 0xa960
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xbcb0
movl %eax, -0x48(%rbp)
jmp 0xaa3a
movq -0x30(%rbp), %rdi
leaq 0xa6c36(%rip), %rsi     # 0xb15a1
callq 0x4e30
cmpb $0x0, %al
je 0xa995
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xbd40
movl %eax, -0x48(%rbp)
jmp 0xaa38
movq -0x30(%rbp), %rdi
leaq 0xa6c06(%rip), %rsi     # 0xb15a6
callq 0x4e30
cmpb $0x0, %al
je 0xa9c7
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xbef0
movl %eax, -0x48(%rbp)
jmp 0xaa36
movq -0x30(%rbp), %rdi
leaq 0xa6bd9(%rip), %rsi     # 0xb15ab
callq 0x4e30
cmpb $0x0, %al
je 0xa9f9
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xbfa0
movl %eax, -0x48(%rbp)
jmp 0xaa34
movq -0x30(%rbp), %rdi
leaq 0xa6bac(%rip), %rsi     # 0xb15b0
callq 0x4e30
cmpb $0x0, %al
je 0xaa2b
movq -0x10(%rbp), %rdi
addq $0xd0, %rdi
movq -0x40(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0xbfd0
movl %eax, -0x48(%rbp)
jmp 0xaa32
movl $0x1, -0x44(%rbp)
jmp 0xaa34
jmp 0xaa36
jmp 0xaa38
jmp 0xaa3a
jmp 0xaa3c
jmp 0xaa3e
jmp 0xaa40
jmp 0xaa42
jmp 0xaa44
jmp 0xaa46
jmp 0xaa48
jmp 0xaa4a
jmp 0xaa4c
jmp 0xaa4e
jmp 0xaa50
jmp 0xaa52
cmpl $0x0, -0x48(%rbp)
jne 0xaa81
cmpl $0x0, -0x44(%rbp)
jne 0xaa81
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0xaa81
movq -0x30(%rbp), %rdi
callq 0x4fb0
cmpl $0x0, %eax
je 0xaa7f
movl $0x39, -0x4(%rbp)
jmp 0xaa87
jmp 0xaa81
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq