// File: /workspace/github_c_makefile_star2_O2/aap[P]pdp11/lodepng.c
// Function: readChunk_iTXt
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, (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 0xb7db
pushq $0x1e
jmp 0xb817
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
pushq $-0x50
popq %r12
leal 0x50(%r12), %ebp
cmpq %r13, %rbp
jae 0xb801
cmpb $0x0, (%r15,%rbp)
je 0xb801
incl %r12d
jmp 0xb7eb
leal 0x53(%r12), %eax
cmpq %r13, %rax
jae 0xb815
cmpl $-0x4f, %r12d
jae 0xb846
pushq $0x59
jmp 0xb817
pushq $0x4b
popq %rbx
xorl %edi, %edi
xorl %r12d, %r12d
xorl %r14d, %r14d
callq 0x2030
movq %r12, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x18(%rsp)
addl $0x51, %r12d
movq %r12, %rdi
callq 0x21a0
testq %rax, %rax
je 0xb892
movq %r14, 0x20(%rsp)
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x8adc
movq 0x10(%rsp), %rdi
movb $0x0, (%rdi,%rbp)
xorl %r14d, %r14d
cmpb $0x0, 0x2(%r15,%rbp)
je 0xb89f
pushq $0x48
popq %rbx
xorl %r12d, %r12d
jmp 0xb820
xorl %edi, %edi
xorl %r12d, %r12d
xorl %r14d, %r14d
pushq $0x53
popq %rbx
jmp 0xb820
movb (%r15,%r12), %al
movb %al, 0xf(%rsp)
movq 0x18(%rsp), %rbp
movl %ebp, %ebp
cmpq %r13, %rbp
jae 0xb8c1
cmpb $0x0, (%r15,%rbp)
je 0xb8c1
incl %r14d
incl %ebp
jmp 0xb8ac
leal 0x1(%r14), %edi
callq 0x21a0
testq %rax, %rax
je 0xb9e4
movq %rax, %r12
movq 0x18(%rsp), %rax
leaq (%r15,%rax), %rsi
movl %r14d, %r14d
movq %r12, %rdi
movq %r14, %rdx
callq 0x8adc
xorl %eax, %eax
movq %r12, 0x18(%rsp)
movb $0x0, (%r12,%r14)
incl %ebp
movl %ebp, %r12d
movl %r12d, %r12d
cmpq %r13, %r12
jae 0xb914
cmpb $0x0, (%r15,%r12)
je 0xb914
incl %eax
incl %r12d
jmp 0xb8fe
leal 0x1(%rax), %edi
movq %rax, 0x30(%rsp)
callq 0x21a0
testq %rax, %rax
je 0xb9f4
movq %rax, %r14
movl %ebp, %esi
addq %r15, %rsi
movl 0x30(%rsp), %ebp
movq %rax, %rdi
movq %rbp, %rdx
callq 0x8adc
movb $0x0, (%r14,%rbp)
incl %r12d
subl %r12d, %r13d
movl $0x0, %eax
cmovbl %eax, %r13d
cmpb $0x0, 0xf(%rsp)
je 0xba09
leaq 0x28(%rsp), %rdi
andq $0x0, (%rdi)
leaq 0x38(%rsp), %rbp
andq $0x0, (%rbp)
movq 0x40(%rbx), %rax
leaq 0x40(%rsp), %rbx
movq %rax, 0x8(%rbx)
movl %r12d, %eax
addq %rax, %r15
movl %r13d, %r8d
movq %rbp, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rbx, %r9
callq 0x10157
movq (%rbp), %r9
cmpq 0x8(%rbx), %r9
pushq $0x70
popq %rbx
cmovbel %eax, %ebx
testl %eax, %eax
movq 0x18(%rsp), %r12
je 0xb9b4
testl %ebx, %ebx
jne 0xb9d0
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x8ea0
movl %eax, %ebx
movq 0x28(%rsp), %rdi
callq 0x2030
movq 0x10(%rsp), %rdi
jmp 0xb820
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
jmp 0xb89a
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
pushq $0x53
popq %rbx
movq 0x18(%rsp), %r12
jmp 0xb820
movl %r12d, %eax
addq %rax, %r15
movl %r13d, %r9d
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq 0x18(%rsp), %r12
movq %r12, %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x8ea0
movq %rbx, %rdi
movl %eax, %ebx
jmp 0xb820