// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movq 0x20(%rsi), %rax
movq %rax, 0x70(%rsp)
movups (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
cmpq $0x5, %rcx
jae 0x8860
movl $0x1e, %ebx
jmp 0x88a1
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r14
movl $0x1, %ebp
xorl %ebx, %ebx
cmpb $0x0, (%r15,%rbx)
je 0x8883
movl %ebp, %ebx
incl %ebp
cmpq %r12, %rbx
jb 0x8873
decl %ebp
leal 0x3(%rbp), %ecx
cmpq %r12, %rcx
jae 0x889c
leal -0x50(%rbp), %eax
cmpl $-0x4f, %eax
jae 0x88cf
movl $0x59, %ebx
jmp 0x88a1
movl $0x4b, %ebx
xorl %edi, %edi
xorl %r12d, %r12d
xorl %r14d, %r14d
callq 0x2290
movq %r12, %rdi
callq 0x2290
movq %r14, %rdi
callq 0x2290
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, 0x20(%rsp)
movl %ebp, %edi
incq %rdi
movq %rdi, 0x18(%rsp)
callq 0x22a0
testq %rax, %rax
je 0x891e
movq %rax, %rdi
movq %r14, 0x38(%rsp)
testl %ebp, %ebp
je 0x8905
movq %rdi, %r14
movq %r15, %rsi
movq %rbx, %rdx
callq 0x21d0
movq %r14, %rdi
movb $0x0, (%rdi,%rbx)
xorl %r14d, %r14d
cmpb $0x0, 0x2(%r15,%rbx)
je 0x8930
movl $0x48, %ebx
xorl %r12d, %r12d
jmp 0x88a9
xorl %edi, %edi
xorl %r12d, %r12d
xorl %r14d, %r14d
movl $0x53, %ebx
jmp 0x88a9
movq 0x20(%rsp), %rcx
cmpq %r12, %rcx
jae 0x8953
leal 0x4(%rbp), %eax
xorl %r14d, %r14d
cmpb $0x0, (%r15,%rcx)
je 0x8953
leal (%rax,%r14), %ecx
incl %r14d
cmpq %r12, %rcx
jb 0x8940
movq %rdi, 0x10(%rsp)
movq 0x18(%rsp), %rax
movb (%r15,%rax), %bl
leal 0x1(%r14), %edi
movq %rdi, 0x18(%rsp)
callq 0x22a0
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x8ac0
movb %bl, 0xf(%rsp)
movl %r14d, %eax
testl %r14d, %r14d
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %rcx
je 0x89b3
leaq (%r15,%rcx), %rsi
movq %rbx, %rdi
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdx
callq 0x21d0
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %rax
movb $0x0, (%rbx,%rax)
movq 0x18(%rsp), %rdx
addl %ecx, %edx
xorl %ebx, %ebx
cmpq %r12, %rdx
jae 0x89e2
leal (%r14,%rbp), %eax
addl $0x5, %eax
xorl %ebx, %ebx
movq %rdx, %rcx
cmpb $0x0, (%r15,%rcx)
je 0x89e2
leal (%rax,%rbx), %ecx
incl %ebx
cmpq %r12, %rcx
jb 0x89d1
movq %rdx, 0x18(%rsp)
leal 0x1(%rbx), %edi
movq %rdi, 0x20(%rsp)
callq 0x22a0
testq %rax, %rax
je 0x8ad0
movq %rax, %r14
movl %ebx, %ebp
testl %ebx, %ebx
movq 0x18(%rsp), %rbx
je 0x8a1a
leaq (%r15,%rbx), %rsi
movq %r14, %rdi
movq %rbp, %rdx
callq 0x21d0
movb $0x0, (%r14,%rbp)
movq 0x20(%rsp), %rcx
addl %ebx, %ecx
xorl %eax, %eax
subl %ecx, %r12d
cmovbl %eax, %r12d
cmpb $0x0, 0xf(%rsp)
je 0x8ae7
xorl %eax, %eax
leaq 0x40(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x48(%rsp), %rbp
movq %rax, (%rbp)
movq 0x40(%r13), %rax
leaq 0x50(%rsp), %r13
movq %rax, 0x8(%r13)
movl %ecx, %eax
addq %rax, %r15
movl %r12d, %r8d
movq %rbp, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %r13, %r9
callq 0xd01a
movq (%rbp), %r9
cmpq 0x8(%r13), %r9
movl $0x70, %ebx
cmovbel %eax, %ebx
testl %eax, %eax
cmovel %eax, %ebx
testl %ebx, %ebx
movq 0x28(%rsp), %r12
jne 0x8aac
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x5766
movl %eax, %ebx
movq 0x40(%rsp), %rdi
callq 0x2290
movq 0x10(%rsp), %rdi
jmp 0x88a9
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
jmp 0x8926
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
movl $0x53, %ebx
movq 0x28(%rsp), %r12
jmp 0x88a9
movl %ecx, %eax
addq %rax, %r15
movl %r12d, %r9d
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq 0x28(%rsp), %r12
movq %r12, %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x5766
movq %rbx, %rdi
movl %eax, %ebx
jmp 0x88a9