// File: /workspace/github_c_makefile_star2_O1/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: readChunk_iTXt
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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
cmpq $0x5, %rcx
jae 0xb5de
movl $0x1e, %ebx
jmp 0xb61c
movq %rcx, %r14
movq %rdx, %r15
movl $0x1, %ebx
xorl %r12d, %r12d
cmpb $0x0, (%r15,%r12)
je 0xb5fd
movl %ebx, %r12d
incl %ebx
cmpq %r14, %r12
jb 0xb5ec
decl %ebx
leal 0x3(%rbx), %r13d
cmpq %r14, %r13
jae 0xb617
leal -0x50(%rbx), %eax
cmpl $-0x4f, %eax
jae 0xb65c
movl $0x59, %ebx
jmp 0xb61c
movl $0x4b, %ebx
xorl %edi, %edi
xorl %r14d, %r14d
xorl %r13d, %r13d
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rsp)
movq 0x20(%rsp), %rdi
callq 0x1030
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
movl %ebx, %ebp
leaq 0x1(%rbp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x10f0
testq %rax, %rax
je 0xb6b5
movq %rax, %rdi
movb $0x0, (%rax,%r12)
testl %ebx, %ebx
movq %rax, 0x18(%rsp)
je 0xb6a1
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x10e0
movq 0x18(%rsp), %rdi
xorl %ebp, %ebp
cmpb $0x0, 0x2(%r15,%r12)
je 0xb6c7
movl $0x48, %ebx
jmp 0xb61e
xorl %edi, %edi
xorl %r14d, %r14d
xorl %r13d, %r13d
movl $0x53, %ebx
jmp 0xb624
movl %r13d, %r12d
cmpq %r14, %r12
jae 0xb6e8
leal 0x4(%rbx), %eax
xorl %ebp, %ebp
movq %r12, %rcx
cmpb $0x0, (%r15,%rcx)
je 0xb6e8
leal (%rax,%rbp), %ecx
incl %ebp
cmpq %r14, %rcx
jb 0xb6d7
movq 0x10(%rsp), %rax
movb (%r15,%rax), %al
movb %al, 0xf(%rsp)
leal 0x1(%rbp), %edi
movq %rdi, 0x10(%rsp)
callq 0x10f0
testq %rax, %rax
je 0xb7eb
movl %ebp, %esi
movb $0x0, (%rax,%rsi)
testl %ebp, %ebp
je 0xb72a
xorl %ecx, %ecx
leal (%r12,%rcx), %edx
movb (%r15,%rdx), %dl
movb %dl, (%rax,%rcx)
incq %rcx
cmpq %rcx, %rsi
jne 0xb717
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rdx
addl %r13d, %edx
xorl %r12d, %r12d
cmpq %r14, %rdx
jae 0xb75e
leal (%rbx,%rbp), %eax
addl $0x5, %eax
xorl %r12d, %r12d
movq %rdx, %rcx
cmpb $0x0, (%r15,%rcx)
je 0xb75e
leal (%rax,%r12), %ecx
incl %r12d
cmpq %r14, %rcx
jb 0xb74b
movq %rdx, 0x10(%rsp)
leal 0x1(%r12), %edi
movq %rdi, 0x40(%rsp)
callq 0x10f0
testq %rax, %rax
je 0xb7fb
movq %rax, %r13
movl %r12d, %eax
movb $0x0, (%r13,%rax)
testl %r12d, %r12d
movq 0x10(%rsp), %rsi
je 0xb7a7
xorl %ecx, %ecx
leal (%rsi,%rcx), %edx
movb (%r15,%rdx), %dl
movb %dl, (%r13,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0xb793
movq 0x40(%rsp), %rax
addl %esi, %eax
xorl %ecx, %ecx
subq %rax, %r14
cmovaeq %r14, %rcx
cmpb $0x0, 0xf(%rsp)
je 0xb812
leaq 0x28(%rsp), %rsi
addq %rax, %r15
movl %ecx, %ecx
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
movq 0x50(%rsp), %r8
callq 0xb99d
testl %eax, %eax
je 0xb86d
movl %eax, %ebx
movq 0x18(%rsp), %rdi
jmp 0xb808
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x18(%rsp), %rdi
jmp 0xb6bd
xorl %r13d, %r13d
movq 0x18(%rsp), %rdi
movl $0x53, %ebx
movq 0x38(%rsp), %r14
jmp 0xb624
movq %rcx, 0x10(%rsp)
leal 0x1(%rcx), %r14d
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0xa144
testl %eax, %eax
je 0xb7fe
movq %r14, 0x28(%rsp)
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rdx
movl %edx, %ecx
movb $0x0, (%rax,%rcx)
testq %rcx, %rcx
je 0xb8a2
movl %edx, %eax
addl %r12d, %ebx
leal (%rbx,%rbp), %ecx
addl $0x5, %ecx
xorl %edx, %edx
leal (%rcx,%rdx), %esi
movb (%r15,%rsi), %sil
movq 0x20(%rsp), %rdi
movb %sil, (%rdi,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0xb853
jmp 0xb8a2
movq 0x28(%rsp), %r14
cmpq %r14, 0x30(%rsp)
jae 0xb87e
movq %r14, 0x30(%rsp)
incq %r14
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0xa144
testl %eax, %eax
je 0xb8a2
movq %r14, 0x28(%rsp)
movq 0x20(%rsp), %rax
movb $0x0, -0x1(%rax,%r14)
movq 0x20(%rsp), %r8
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
movq 0x38(%rsp), %r14
movq %r14, %rdx
movq %r13, %rcx
callq 0x4908
movq %rbx, %rdi
movl %eax, %ebx
jmp 0xb624