// File: lvandeve[P]lodepng/lodepng.cpp
// Function: readChunk_zTXt(LodePNGInfo*, LodePNGDecoderSettings const*, unsigned char const*, unsigned long)
static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
                               const unsigned char* data, size_t chunkLength) {
  unsigned error = 0;

  /*copy the object to change parameters in it*/
  LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;

  unsigned length, string2_begin;
  char *key = 0;
  unsigned char* str = 0;
  size_t size = 0;

  while(!error) /*not really a while loop, only used to break on error*/ {
    for(length = 0; length < chunkLength && data[length] != 0; ++length) ;
    if(length + 2 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination, 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;

    if(data[length + 1] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/

    string2_begin = length + 2;
    if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/

    length = (unsigned)chunkLength - string2_begin;
    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[string2_begin],
                            length, &zlibsettings);
    /*error: compressed text larger than  decoder->max_text_size*/
    if(error && size > zlibsettings.max_output_size) error = 112;
    if(error) break;
    error = lodepng_add_text_sized(info, key, (char*)str, size);
    break;
  }

  lodepng_free(key);
  lodepng_free(str);

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x50(%rbp), %rdi
movl $0x28, %edx
callq 0x31e0
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
cmpl $0x0, -0x24(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xb09e
jmp 0xb205
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x71(%rbp)
jae 0xb0c9
movq -0x18(%rbp), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0xb0d2
jmp 0xb0df
jmp 0xb0d4
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xb0a5
movl -0x54(%rbp), %eax
addl $0x2, %eax
movl %eax, %eax
cmpq -0x20(%rbp), %rax
jb 0xb0f9
movl $0x4b, -0x24(%rbp)
jmp 0xb205
cmpl $0x1, -0x54(%rbp)
jb 0xb105
cmpl $0x4f, -0x54(%rbp)
jbe 0xb111
movl $0x59, -0x24(%rbp)
jmp 0xb205
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x3bc0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0xb137
movl $0x53, -0x24(%rbp)
jmp 0xb205
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x54(%rbp), %eax
movl %eax, %edx
callq 0x5820
movq -0x60(%rbp), %rax
movl -0x54(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq -0x18(%rbp), %rax
movl -0x54(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xb175
movl $0x48, -0x24(%rbp)
jmp 0xb205
movl -0x54(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpq -0x20(%rbp), %rax
jbe 0xb190
movl $0x4b, -0x24(%rbp)
jmp 0xb205
movq -0x20(%rbp), %rax
subl -0x58(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rcx
movl -0x58(%rbp), %eax
addq %rax, %rcx
movl -0x54(%rbp), %eax
movl %eax, %r8d
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x50(%rbp), %r9
callq 0x117d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xb1e5
movq -0x70(%rbp), %rax
cmpq -0x48(%rbp), %rax
jbe 0xb1e5
movl $0x70, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xb1ed
jmp 0xb205
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rcx
callq 0x5d60
movl %eax, -0x24(%rbp)
movq -0x60(%rbp), %rdi
callq 0x4230
movq -0x68(%rbp), %rdi
callq 0x4230
movl -0x24(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)