// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: readChunk_zTXt(LodePNGInfo*, LodePNGDecompressSettings const*, unsigned char const*, unsigned long)
static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
                               const unsigned char* data, size_t chunkLength)
{
  unsigned error = 0;
  unsigned i;

  unsigned length, string2_begin;
  char *key = 0;
  ucvector decoded;

  ucvector_init(&decoded);

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

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

    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 = chunkLength - string2_begin;
    /*will fail if zlib error, e.g. if length is too small*/
    error = zlib_decompress(&decoded.data, &decoded.size,
                            (unsigned char*)(&data[string2_begin]),
                            length, zlibsettings);
    if(error) break;
    ucvector_push_back(&decoded, 0);

    error = lodepng_add_text(info, key, (char*)decoded.data);

    break;
  }

  lodepng_free(key);
  ucvector_cleanup(&decoded);

  return error;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x8(%rsp), %rdi
callq 0xf580
cmpl $0x0, 0x34(%rsp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x168e6
jmp 0x16a86
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq 0x38(%rsp), %rcx
movb %al, 0x7(%rsp)
jae 0x16918
movq 0x40(%rsp), %rax
movl 0x2c(%rsp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x16922
jmp 0x16931
jmp 0x16924
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x168ee
movl 0x2c(%rsp), %eax
addl $0x2, %eax
movl %eax, %eax
cmpq 0x38(%rsp), %rax
jb 0x1694e
movl $0x4b, 0x34(%rsp)
jmp 0x16a86
cmpl $0x1, 0x2c(%rsp)
jb 0x1695c
cmpl $0x4f, 0x2c(%rsp)
jbe 0x16969
movl $0x59, 0x34(%rsp)
jmp 0x16a86
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x6cd0
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x16993
movl $0x53, 0x34(%rsp)
jmp 0x16a86
movq 0x20(%rsp), %rax
movl 0x2c(%rsp), %ecx
movb $0x0, (%rax,%rcx)
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x2c(%rsp), %eax
je 0x169d7
movq 0x40(%rsp), %rax
movl 0x30(%rsp), %ecx
movb (%rax,%rcx), %dl
movq 0x20(%rsp), %rax
movl 0x30(%rsp), %ecx
movb %dl, (%rax,%rcx)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x169a8
movq 0x40(%rsp), %rax
movl 0x2c(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x169fb
movl $0x48, 0x34(%rsp)
jmp 0x16a86
movl 0x2c(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpq 0x38(%rsp), %rax
jbe 0x16a1b
movl $0x4b, 0x34(%rsp)
jmp 0x16a86
movq 0x38(%rsp), %rax
movl 0x28(%rsp), %ecx
subq %rcx, %rax
movl %eax, 0x2c(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
addq $0x8, %rsi
movq 0x40(%rsp), %rdx
movl 0x28(%rsp), %eax
addq %rax, %rdx
movl 0x2c(%rsp), %eax
movl %eax, %ecx
movq 0x48(%rsp), %r8
callq 0x10f10
movl %eax, 0x34(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x16a62
jmp 0x16a86
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movq 0x50(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x9050
movl %eax, 0x34(%rsp)
movq 0x20(%rsp), %rdi
callq 0x78b0
leaq 0x8(%rsp), %rdi
callq 0x17170
movl 0x34(%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)