// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq 0x20(%rsi), %rax
movq %rax, 0x60(%rsp)
movups (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movaps %xmm1, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
cmpq $0x5, %rcx
jae 0x8de8
movl $0x1e, %ebx
jmp 0x8e2f
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r13
movl $0x1, %r14d
xorl %ebp, %ebp
cmpb $0x0, (%r15,%rbp)
je 0x8e0e
movl %r14d, %ebp
incl %r14d
cmpq %r12, %rbp
jb 0x8dfc
decl %r14d
leal 0x3(%r14), %ecx
cmpq %r12, %rcx
jae 0x8e2a
leal -0x50(%r14), %eax
cmpl $-0x4f, %eax
jae 0x8e5c
movl $0x59, %ebx
jmp 0x8e2f
movl $0x4b, %ebx
xorl %edi, %edi
xorl %ebp, %ebp
xorl %r13d, %r13d
callq 0x22a0
movq %rbp, %rdi
callq 0x22a0
movq %r13, %rdi
callq 0x22a0
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, 0x20(%rsp)
movl %r14d, %edi
incq %rdi
movq %rdi, 0x18(%rsp)
callq 0x22b0
testq %rax, %rax
je 0x8ead
movq %r13, 0x28(%rsp)
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x21e0
movq 0x8(%rsp), %rdi
movb $0x0, (%rdi,%rbp)
xorl %r13d, %r13d
cmpb $0x0, 0x2(%r15,%rbp)
je 0x8ebe
movl $0x48, %ebx
xorl %ebp, %ebp
jmp 0x8e36
xorl %edi, %edi
xorl %ebp, %ebp
xorl %r13d, %r13d
movl $0x53, %ebx
jmp 0x8e36
movq 0x18(%rsp), %rax
movb (%r15,%rax), %al
movb %al, 0x7(%rsp)
leal 0x4(%r14), %eax
movq 0x20(%rsp), %rcx
cmpb $0x0, (%r15,%rcx)
je 0x8ee7
leal (%rax,%r13), %ecx
incl %r13d
cmpq %r12, %rcx
jb 0x8ed4
leal 0x1(%r13), %edi
movq %rdi, 0x18(%rsp)
callq 0x22b0
testq %rax, %rax
je 0x9040
movq %rax, %rbp
movl %r13d, %eax
testl %r13d, %r13d
movq 0x20(%rsp), %rcx
je 0x8f2e
leaq (%r15,%rcx), %rsi
movq %rbp, %rdi
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdx
callq 0x21e0
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rbp, 0x10(%rsp)
movb $0x0, (%rbp,%rax)
movq 0x18(%rsp), %rdx
addl %ecx, %edx
xorl %ebp, %ebp
cmpq %r12, %rdx
jae 0x8f63
leal (%r14,%r13), %eax
addl $0x5, %eax
xorl %ebp, %ebp
movq %rdx, %rcx
cmpb $0x0, (%r15,%rcx)
je 0x8f63
leal (%rax,%rbp), %ecx
incl %ebp
cmpq %r12, %rcx
jb 0x8f52
movq %rdx, 0x18(%rsp)
leal 0x1(%rbp), %edi
movq %rdi, 0x20(%rsp)
callq 0x22b0
testq %rax, %rax
je 0x904f
movq %rax, %r13
movl %ebp, %r14d
testl %ebp, %ebp
movq 0x18(%rsp), %rbp
je 0x8f9c
leaq (%r15,%rbp), %rsi
movq %r13, %rdi
movq %r14, %rdx
callq 0x21e0
movb $0x0, (%r13,%r14)
movq 0x20(%rsp), %rcx
addl %ebp, %ecx
xorl %eax, %eax
subl %ecx, %r12d
cmovbl %eax, %r12d
cmpb $0x0, 0x7(%rsp)
movq 0x10(%rsp), %rbp
je 0x9061
xorl %eax, %eax
leaq 0x30(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x38(%rsp), %r14
movq %rax, (%r14)
movq 0x40(%rbx), %rax
leaq 0x40(%rsp), %rbx
movq %rax, 0x8(%rbx)
movl %ecx, %eax
addq %rax, %r15
movl %r12d, %r8d
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rbx, %r9
callq 0xd24c
movq (%r14), %r9
cmpq 0x8(%rbx), %r9
movl $0x70, %ebx
cmovbel %eax, %ebx
testl %eax, %eax
je 0x9010
testl %ebx, %ebx
jne 0x902c
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x5d3e
movl %eax, %ebx
movq 0x30(%rsp), %rdi
callq 0x22a0
movq 0x8(%rsp), %rdi
jmp 0x8e36
xorl %ebp, %ebp
xorl %r13d, %r13d
movq 0x8(%rsp), %rdi
jmp 0x8eb4
xorl %r13d, %r13d
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rbp
jmp 0x8eb4
movl %ecx, %eax
addq %rax, %r15
movl %r12d, %r9d
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x5d3e
movq %rbx, %rdi
movl %eax, %ebx
jmp 0x8e36