// File: lvandeve[P]lodepng/lodepng.cpp
// Function: readChunk_iTXt(LodePNGInfo*, LodePNGDecoderSettings const*, unsigned char const*, unsigned long)
static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
                               const unsigned char* data, size_t chunkLength) {
  unsigned error = 0;
  unsigned i;

  /*copy the object to change parameters in it*/
  LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;

  unsigned length, begin, compressed;
  char *key = 0, *langtag = 0, *transkey = 0;

  while(!error) /*not really a while loop, only used to break on error*/ {
    /*Quick check if the chunk length isn't too small. Even without check
    it'd still fail with other error checks below if it's too short. This just gives a different error code.*/
    if(chunkLength < 5) CERROR_BREAK(error, 30); /*iTXt chunk too short*/

    /*read the key*/
    for(length = 0; length < chunkLength && data[length] != 0; ++length) ;
    if(length + 3 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination char, corrupt?*/
    if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/

    key = (char*)lodepng_malloc(length + 1);
    if(!key) CERROR_BREAK(error, 83); /*alloc fail*/

    lodepng_memcpy(key, data, length);
    key[length] = 0;

    /*read the compression method*/
    compressed = data[length + 1];
    if(data[length + 2] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/

    /*even though it's not allowed by the standard, no error is thrown if
    there's no null termination char, if the text is empty for the next 3 texts*/

    /*read the langtag*/
    begin = length + 3;
    length = 0;
    for(i = begin; i < chunkLength && data[i] != 0; ++i) ++length;

    langtag = (char*)lodepng_malloc(length + 1);
    if(!langtag) CERROR_BREAK(error, 83); /*alloc fail*/

    lodepng_memcpy(langtag, data + begin, length);
    langtag[length] = 0;

    /*read the transkey*/
    begin += length + 1;
    length = 0;
    for(i = begin; i < chunkLength && data[i] != 0; ++i) ++length;

    transkey = (char*)lodepng_malloc(length + 1);
    if(!transkey) CERROR_BREAK(error, 83); /*alloc fail*/

    lodepng_memcpy(transkey, data + begin, length);
    transkey[length] = 0;

    /*read the actual text*/
    begin += length + 1;

    length = (unsigned)chunkLength < begin ? 0 : (unsigned)chunkLength - begin;

    if(compressed) {
      unsigned char* str = 0;
      size_t size = 0;
      zlibsettings.max_output_size = decoder->max_text_size;
      /*will fail if zlib error, e.g. if length is too small*/
      error = zlib_decompress(&str, &size, 0, &data[begin],
                              length, &zlibsettings);
      /*error: compressed text larger than  decoder->max_text_size*/
      if(error && size > zlibsettings.max_output_size) error = 112;
      if(!error) error = lodepng_add_itext_sized(info, key, langtag, transkey, (char*)str, size);
      lodepng_free(str);
    } else {
      error = lodepng_add_itext_sized(info, key, langtag, transkey, (const char*)(data + begin), length);
    }

    break;
  }

  lodepng_free(key);
  lodepng_free(langtag);
  lodepng_free(transkey);

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x50(%rbp), %rdi
movl $0x28, %edx
callq 0x31e0
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
cmpl $0x0, -0x24(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xb28e
jmp 0xb5ea
cmpq $0x5, -0x20(%rbp)
jae 0xb2a1
movl $0x1e, -0x24(%rbp)
jmp 0xb5ea
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x89(%rbp)
jae 0xb2d2
movq -0x18(%rbp), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0xb2de
jmp 0xb2eb
jmp 0xb2e0
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xb2a8
movl -0x54(%rbp), %eax
addl $0x3, %eax
movl %eax, %eax
cmpq -0x20(%rbp), %rax
jb 0xb305
movl $0x4b, -0x24(%rbp)
jmp 0xb5ea
cmpl $0x1, -0x54(%rbp)
jb 0xb311
cmpl $0x4f, -0x54(%rbp)
jbe 0xb31d
movl $0x59, -0x24(%rbp)
jmp 0xb5ea
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x3bc0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0xb343
movl $0x53, -0x24(%rbp)
jmp 0xb5ea
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x54(%rbp), %eax
movl %eax, %edx
callq 0x5820
movq -0x68(%rbp), %rax
movl -0x54(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq -0x18(%rbp), %rax
movl -0x54(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x5c(%rbp)
movq -0x18(%rbp), %rax
movl -0x54(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xb394
movl $0x48, -0x24(%rbp)
jmp 0xb5ea
movl -0x54(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x8a(%rbp)
jae 0xb3d4
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0xb3e0
jmp 0xb3f4
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xb3aa
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x3bc0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0xb41a
movl $0x53, -0x24(%rbp)
jmp 0xb5ea
movq -0x70(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x58(%rbp), %eax
addq %rax, %rsi
movl -0x54(%rbp), %eax
movl %eax, %edx
callq 0x5820
movq -0x70(%rbp), %rax
movl -0x54(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x8b(%rbp)
jae 0xb480
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x8b(%rbp)
movb -0x8b(%rbp), %al
testb $0x1, %al
jne 0xb48c
jmp 0xb4a0
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xb456
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x3bc0
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0xb4c6
movl $0x53, -0x24(%rbp)
jmp 0xb5ea
movq -0x78(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x58(%rbp), %eax
addq %rax, %rsi
movl -0x54(%rbp), %eax
movl %eax, %edx
callq 0x5820
movq -0x78(%rbp), %rax
movl -0x54(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x20(%rbp), %rax
cmpl -0x58(%rbp), %eax
jae 0xb508
xorl %eax, %eax
movl %eax, -0x90(%rbp)
jmp 0xb515
movq -0x20(%rbp), %rax
subl -0x58(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0xb5c0
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rcx
movl -0x58(%rbp), %eax
addq %rax, %rcx
movl -0x54(%rbp), %eax
movl %eax, %r8d
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x50(%rbp), %r9
callq 0x117d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xb58c
movq -0x88(%rbp), %rax
cmpq -0x48(%rbp), %rax
jbe 0xb58c
movl $0x70, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0xb5b5
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %r8
movq -0x88(%rbp), %r9
callq 0x60b0
movl %eax, -0x24(%rbp)
movq -0x80(%rbp), %rdi
callq 0x4230
jmp 0xb5e8
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq -0x18(%rbp), %r8
movl -0x58(%rbp), %eax
addq %rax, %r8
movl -0x54(%rbp), %eax
movl %eax, %r9d
callq 0x60b0
movl %eax, -0x24(%rbp)
jmp 0xb5ea
movq -0x68(%rbp), %rdi
callq 0x4230
movq -0x70(%rbp), %rdi
callq 0x4230
movq -0x78(%rbp), %rdi
callq 0x4230
movl -0x24(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)