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

  while(!error) /*not really a while loop, only used to break on error*/ {
    unsigned length, string2_begin;

    length = 0;
    while(length < chunkLength && data[length] != 0) ++length;
    /*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*/
    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;

    string2_begin = length + 1; /*skip keyword null terminator*/

    length = (unsigned)(chunkLength < string2_begin ? 0 : chunkLength - string2_begin);
    str = (char*)lodepng_malloc(length + 1);
    if(!str) CERROR_BREAK(error, 83); /*alloc fail*/

    lodepng_memcpy(str, data + string2_begin, length);
    str[length] = 0;

    error = lodepng_add_text(info, key, str);

    break;
  }

  lodepng_free(key);
  lodepng_free(str);

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
cmpl $0x0, -0x1c(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xaefd
jmp 0xb023
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x39(%rbp)
jae 0xaf28
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0xaf31
jmp 0xaf3c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xaf04
cmpl $0x1, -0x34(%rbp)
jb 0xaf48
cmpl $0x4f, -0x34(%rbp)
jbe 0xaf54
movl $0x59, -0x1c(%rbp)
jmp 0xb023
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x3bc0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xaf7a
movl $0x53, -0x1c(%rbp)
jmp 0xb023
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0x5820
movq -0x28(%rbp), %rax
movl -0x34(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl -0x38(%rbp), %ecx
cmpq %rcx, %rax
jae 0xafb4
xorl %eax, %eax
movq %rax, -0x48(%rbp)
jmp 0xafc2
movq -0x18(%rbp), %rax
movl -0x38(%rbp), %ecx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x3bc0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xafec
movl $0x53, -0x1c(%rbp)
jmp 0xb023
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x38(%rbp), %eax
addq %rax, %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0x5820
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x5d10
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4230
movq -0x30(%rbp), %rdi
callq 0x4230
movl -0x1c(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop