// File: /workspace/github_cpp_makefile_star2_O1/logicx24[P]RayTracer/lodepng.cpp
// Function: readChunk_iTXt(LodePNGInfo*, LodePNGDecompressSettings const*, unsigned char const*, unsigned long)
static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
                               const unsigned char* data, size_t chunkLength)
{
  unsigned error = 0;
  unsigned i;

  unsigned length, begin, compressed;
  char *key = 0, *langtag = 0, *transkey = 0;
  ucvector decoded;
  ucvector_init(&decoded);

  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*/

    key[length] = 0;
    for(i = 0; i != length; ++i) key[i] = (char)data[i];

    /*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*/

    langtag[length] = 0;
    for(i = 0; i != length; ++i) langtag[i] = (char)data[begin + i];

    /*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*/

    transkey[length] = 0;
    for(i = 0; i != length; ++i) transkey[i] = (char)data[begin + i];

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

    length = chunkLength < begin ? 0 : chunkLength - begin;

    if(compressed)
    {
      /*will fail if zlib error, e.g. if length is too small*/
      error = zlib_decompress(&decoded.data, &decoded.size,
                              (unsigned char*)(&data[begin]),
                              length, zlibsettings);
      if(error) break;
      if(decoded.allocsize < decoded.size) decoded.allocsize = decoded.size;
      ucvector_push_back(&decoded, 0);
    }
    else
    {
      if(!ucvector_resize(&decoded, length + 1)) CERROR_BREAK(error, 83 /*alloc fail*/);

      decoded.data[length] = 0;
      for(i = 0; i != length; ++i) decoded.data[i] = data[begin + i];
    }

    error = lodepng_add_itext(info, key, langtag, transkey, (char*)decoded.data);

    break;
  }

  lodepng_free(key);
  lodepng_free(langtag);
  lodepng_free(transkey);
  ucvector_cleanup(&decoded);

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x5, %rcx
jae 0x1535b
movl $0x1e, %r14d
jmp 0x153a0
movq %rcx, %r14
movq %rdx, %r15
movl $0x1, %r12d
xorl %ebx, %ebx
cmpb $0x0, (%r15,%rbx)
je 0x1537b
movl %r12d, %ebx
incl %r12d
cmpq %r14, %rbx
jb 0x15369
decl %r12d
leal 0x3(%r12), %ecx
cmpq %r14, %rcx
jae 0x1539a
leal -0x50(%r12), %eax
cmpl $-0x4f, %eax
jae 0x153de
movl $0x59, %r14d
jmp 0x153a0
movl $0x4b, %r14d
xorl %edi, %edi
xorl %r15d, %r15d
xorl %ebx, %ebx
callq 0x3280
movq %r15, %rdi
callq 0x3280
movq %rbx, %rdi
callq 0x3280
xorps %xmm0, %xmm0
movups %xmm0, -0x58(%rbp)
movq -0x60(%rbp), %rdi
callq 0x3280
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, -0x48(%rbp)
movq %rsi, -0x80(%rbp)
movq %rdi, -0x78(%rbp)
movl %r12d, %r13d
leaq 0x1(%r13), %rdi
movq %rdi, -0x38(%rbp)
callq 0x32e0
testq %rax, %rax
je 0x15438
movq %rax, %rdi
movb $0x0, (%rax,%rbx)
testl %r12d, %r12d
movq %rax, -0x40(%rbp)
je 0x15422
movq -0x40(%rbp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x31b0
movq -0x40(%rbp), %rdi
xorl %r13d, %r13d
cmpb $0x0, 0x2(%r15,%rbx)
je 0x1544a
movl $0x48, %r14d
jmp 0x153a2
xorl %edi, %edi
xorl %r15d, %r15d
xorl %ebx, %ebx
movl $0x53, %r14d
jmp 0x153a7
movl -0x48(%rbp), %ebx
cmpq %r14, %rbx
jae 0x15470
leal 0x4(%r12), %eax
xorl %r13d, %r13d
movq %rbx, %rcx
cmpb $0x0, (%r15,%rcx)
je 0x15470
leal (%rax,%r13), %ecx
incl %r13d
cmpq %r14, %rcx
jb 0x1545d
movq -0x38(%rbp), %rax
movb (%r15,%rax), %al
movb %al, -0x29(%rbp)
leal 0x1(%r13), %edi
movq %rdi, -0x38(%rbp)
callq 0x32e0
testq %rax, %rax
je 0x15561
movl %r13d, %esi
movb $0x0, (%rax,%rsi)
testl %r13d, %r13d
je 0x154b1
xorl %ecx, %ecx
leal (%rbx,%rcx), %edx
movb (%r15,%rdx), %dl
movb %dl, (%rax,%rcx)
incq %rcx
cmpq %rcx, %rsi
jne 0x1549f
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rbx
addl -0x48(%rbp), %ebx
xorl %edx, %edx
cmpq %r14, %rbx
jae 0x154e0
leal (%r12,%r13), %eax
addl $0x5, %eax
xorl %edx, %edx
movq %rbx, %rcx
cmpb $0x0, (%r15,%rcx)
je 0x154e0
leal (%rax,%rdx), %ecx
incl %edx
cmpq %r14, %rcx
jb 0x154cf
movq %rdx, -0x48(%rbp)
movq %rbx, -0x38(%rbp)
leal 0x1(%rdx), %edi
movq %rdi, -0x70(%rbp)
callq 0x32e0
testq %rax, %rax
je 0x1556f
movq %rax, %rbx
movq -0x48(%rbp), %rcx
movl %ecx, %eax
movb $0x0, (%rbx,%rax)
testl %ecx, %ecx
movq -0x38(%rbp), %rsi
je 0x15522
xorl %ecx, %ecx
leal (%rsi,%rcx), %edx
movb (%r15,%rdx), %dl
movb %dl, (%rbx,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x15510
movq -0x70(%rbp), %rax
addl %esi, %eax
xorl %ecx, %ecx
subq %rax, %r14
cmovaeq %r14, %rcx
cmpb $0x0, -0x29(%rbp)
je 0x15584
leaq -0x58(%rbp), %rsi
addq %rax, %r15
movl %ecx, %ecx
leaq -0x60(%rbp), %rdi
movq %r15, %rdx
movq -0x80(%rbp), %r8
callq 0x136a8
testl %eax, %eax
je 0x155db
movl %eax, %r14d
movq -0x40(%rbp), %rdi
jmp 0x1557b
xorl %r15d, %r15d
xorl %ebx, %ebx
movq -0x40(%rbp), %rdi
jmp 0x1543f
xorl %ebx, %ebx
movq -0x40(%rbp), %rdi
movl $0x53, %r14d
movq -0x68(%rbp), %r15
jmp 0x153a7
movq %rcx, -0x38(%rbp)
leal 0x1(%rcx), %r14d
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
callq 0x13e39
testl %eax, %eax
je 0x15571
movq %r14, -0x58(%rbp)
movq -0x60(%rbp), %rax
movq -0x38(%rbp), %rdx
movl %edx, %ecx
movb $0x0, (%rax,%rcx)
testq %rcx, %rcx
je 0x1560a
movl %edx, %eax
addl -0x48(%rbp), %r12d
leal (%r12,%r13), %ecx
addl $0x5, %ecx
xorl %edx, %edx
leal (%rcx,%rdx), %esi
movb (%r15,%rsi), %sil
movq -0x60(%rbp), %rdi
movb %sil, (%rdi,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x155c2
jmp 0x1560a
movq -0x58(%rbp), %r14
cmpq %r14, -0x50(%rbp)
jae 0x155e9
movq %r14, -0x50(%rbp)
incq %r14
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
callq 0x13e39
testl %eax, %eax
je 0x1560a
movq %r14, -0x58(%rbp)
movq -0x60(%rbp), %rax
movb $0x0, -0x1(%rax,%r14)
movq -0x60(%rbp), %r8
movq -0x78(%rbp), %rdi
movq -0x40(%rbp), %r14
movq %r14, %rsi
movq -0x68(%rbp), %r15
movq %r15, %rdx
movq %rbx, %rcx
callq 0xe176
movq %r14, %rdi
movl %eax, %r14d
jmp 0x153a7