// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x5, %rcx
jae 0x1516f
movl $0x1e, %ebx
jmp 0x151b1
movq %rcx, %rbx
movq %rdx, %r12
movl $0x1, %r14d
xorl %r13d, %r13d
cmpb $0x0, (%r12,%r13)
je 0x15190
movl %r14d, %r13d
incl %r14d
cmpq %rbx, %r13
jb 0x1517e
decl %r14d
leal 0x3(%r14), %ecx
cmpq %rbx, %rcx
jae 0x151ac
leal -0x50(%r14), %eax
cmpl $-0x4f, %eax
jae 0x151ef
movl $0x59, %ebx
jmp 0x151b1
movl $0x4b, %ebx
xorl %edi, %edi
xorl %r13d, %r13d
xorl %r15d, %r15d
callq 0x3280
movq %r13, %rdi
callq 0x3280
movq %r15, %rdi
callq 0x3280
xorps %xmm0, %xmm0
movups %xmm0, -0x48(%rbp)
movq -0x50(%rbp), %rdi
callq 0x3280
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, -0x38(%rbp)
movq %rsi, -0x70(%rbp)
movq %rdi, -0x58(%rbp)
movl %r14d, %r15d
leaq 0x1(%r15), %rdi
movq %rdi, -0x68(%rbp)
callq 0x32e0
testq %rax, %rax
je 0x15243
movb $0x0, (%rax,%r13)
movq %rax, -0x30(%rbp)
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x31b0
xorl %r15d, %r15d
cmpb $0x0, 0x2(%r12,%r13)
je 0x15250
movl $0x48, %ebx
xorl %r13d, %r13d
movq -0x30(%rbp), %rdi
jmp 0x151b9
xorl %edi, %edi
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x15373
movq -0x68(%rbp), %rax
movb (%r12,%rax), %al
movb %al, -0x68(%rbp)
leal 0x4(%r14), %eax
movq -0x38(%rbp), %rcx
cmpb $0x0, (%r12,%rcx)
je 0x15276
leal (%rax,%r15), %ecx
incl %r15d
cmpq %rbx, %rcx
jb 0x15263
leal 0x1(%r15), %edi
movq %rdi, %r13
callq 0x32e0
testq %rax, %rax
je 0x1535c
movl %r15d, %esi
movb $0x0, (%rax,%rsi)
testl %r15d, %r15d
movq -0x38(%rbp), %rdi
je 0x152af
xorl %ecx, %ecx
leal (%rdi,%rcx), %edx
movb (%r12,%rdx), %dl
movb %dl, (%rax,%rcx)
incq %rcx
cmpq %rcx, %rsi
jne 0x1529d
movq %rax, -0x60(%rbp)
movq %r13, %rdx
addl %edi, %edx
xorl %r13d, %r13d
cmpq %rbx, %rdx
jae 0x152e0
leal (%r15,%r14), %eax
addl $0x5, %eax
xorl %r13d, %r13d
movq %rdx, %rcx
cmpb $0x0, (%r12,%rcx)
je 0x152e0
leal (%rax,%r13), %ecx
incl %r13d
cmpq %rbx, %rcx
jb 0x152cd
movq %rdx, %r14
leal 0x1(%r13), %edi
movq %rdi, -0x38(%rbp)
callq 0x32e0
testq %rax, %rax
je 0x15368
movq %rax, %r15
movl %r13d, %eax
movb $0x0, (%r15,%rax)
testl %r13d, %r13d
movq %r14, %rsi
je 0x1531d
xorl %ecx, %ecx
leal (%rsi,%rcx), %edx
movb (%r12,%rdx), %dl
movb %dl, (%r15,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x1530a
movq -0x38(%rbp), %rax
addl %esi, %eax
xorl %r14d, %r14d
subq %rax, %rbx
cmovaeq %rbx, %r14
cmpb $0x0, -0x68(%rbp)
je 0x1537d
leaq -0x48(%rbp), %rsi
addq %rax, %r12
movl %r14d, %ecx
leaq -0x50(%rbp), %rdi
movq %r12, %rdx
movq -0x70(%rbp), %r8
callq 0x137df
testl %eax, %eax
movq -0x60(%rbp), %r13
je 0x153d0
movl %eax, %ebx
jmp 0x1523a
xorl %r13d, %r13d
xorl %r15d, %r15d
movq -0x30(%rbp), %rdi
jmp 0x15373
xorl %r15d, %r15d
movq -0x30(%rbp), %rdi
movq -0x60(%rbp), %r13
movl $0x53, %ebx
jmp 0x151b9
movq %rax, -0x38(%rbp)
leal 0x1(%r14), %ebx
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0x13f68
testl %eax, %eax
movq -0x60(%rbp), %r13
je 0x15362
movq %rbx, -0x48(%rbp)
movq -0x50(%rbp), %r8
movl %r14d, %eax
movb $0x0, (%r8,%rax)
testq %rax, %rax
je 0x15405
movl %r14d, %eax
xorl %ecx, %ecx
movq -0x58(%rbp), %rdi
movq -0x38(%rbp), %rsi
leal (%rsi,%rcx), %edx
movb (%r12,%rdx), %dl
movb %dl, (%r8,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x153bb
jmp 0x15409
movq -0x48(%rbp), %rbx
cmpq %rbx, -0x40(%rbp)
jae 0x153de
movq %rbx, -0x40(%rbp)
incq %rbx
leaq -0x50(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x13f68
movq (%r14), %r8
testl %eax, %eax
je 0x15405
movq %rbx, -0x48(%rbp)
movb $0x0, -0x1(%r8,%rbx)
movq -0x50(%rbp), %r8
movq -0x58(%rbp), %rdi
movq -0x30(%rbp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0xde2f
movq %rbx, %rdi
movl %eax, %ebx
jmp 0x151b9