// File: phillip-h[P]fractal-gen/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;
  unsigned i;

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

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

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

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

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

    error = lodepng_add_text(info, key, str);

    break;
  }

  lodepng_free(key);
  lodepng_free(str);

  return error;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
cmpl $0x0, 0x2c(%rsp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x166e0
jmp 0x16874
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq 0x30(%rsp), %rcx
movb %al, 0xb(%rsp)
jae 0x16712
movq 0x38(%rsp), %rax
movl 0x10(%rsp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0xb(%rsp)
movb 0xb(%rsp), %al
testb $0x1, %al
jne 0x1671c
jmp 0x16729
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x166e8
cmpl $0x1, 0x10(%rsp)
jb 0x16737
cmpl $0x4f, 0x10(%rsp)
jbe 0x16744
movl $0x59, 0x2c(%rsp)
jmp 0x16874
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x6cd0
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x1676e
movl $0x53, 0x2c(%rsp)
jmp 0x16874
movq 0x20(%rsp), %rax
movl 0x10(%rsp), %ecx
movb $0x0, (%rax,%rcx)
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x10(%rsp), %eax
je 0x167b2
movq 0x38(%rsp), %rax
movl 0x14(%rsp), %ecx
movb (%rax,%rcx), %dl
movq 0x20(%rsp), %rax
movl 0x14(%rsp), %ecx
movb %dl, (%rax,%rcx)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x16783
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
movq 0x30(%rsp), %rax
movl 0xc(%rsp), %ecx
cmpq %rcx, %rax
jae 0x167d3
xorl %eax, %eax
movq %rax, (%rsp)
jmp 0x167e3
movq 0x30(%rsp), %rax
movl 0xc(%rsp), %ecx
subq %rcx, %rax
movq %rax, (%rsp)
movq (%rsp), %rax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x6cd0
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x16812
movl $0x53, 0x2c(%rsp)
jmp 0x16874
movq 0x18(%rsp), %rax
movl 0x10(%rsp), %ecx
movb $0x0, (%rax,%rcx)
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x10(%rsp), %eax
je 0x1685c
movq 0x38(%rsp), %rax
movl 0xc(%rsp), %ecx
addl 0x14(%rsp), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
movb %dl, (%rax,%rcx)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x16827
movq 0x40(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x9050
movl %eax, 0x2c(%rsp)
movq 0x20(%rsp), %rdi
callq 0x78b0
movq 0x18(%rsp), %rdi
callq 0x78b0
movl 0x2c(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)