// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: addChunk_iTXt(ucvector*, unsigned int, char const*, char const*, char const*, char const*, LodePNGCompressSettings*)
static unsigned addChunk_iTXt(ucvector* out, unsigned compressed, const char* keyword, const char* langtag,
                              const char* transkey, const char* textstring, LodePNGCompressSettings* zlibsettings)
{
  unsigned error = 0;
  ucvector data;
  size_t i, textsize = strlen(textstring);

  ucvector_init(&data);

  for(i = 0; keyword[i] != 0; ++i) ucvector_push_back(&data, (unsigned char)keyword[i]);
  if(i < 1 || i > 79) return 89; /*error: invalid keyword size*/
  ucvector_push_back(&data, 0); /*null termination char*/
  ucvector_push_back(&data, compressed ? 1 : 0); /*compression flag*/
  ucvector_push_back(&data, 0); /*compression method*/
  for(i = 0; langtag[i] != 0; ++i) ucvector_push_back(&data, (unsigned char)langtag[i]);
  ucvector_push_back(&data, 0); /*null termination char*/
  for(i = 0; transkey[i] != 0; ++i) ucvector_push_back(&data, (unsigned char)transkey[i]);
  ucvector_push_back(&data, 0); /*null termination char*/

  if(compressed)
  {
    ucvector compressed_data;
    ucvector_init(&compressed_data);
    error = zlib_compress(&compressed_data.data, &compressed_data.size,
                          (unsigned char*)textstring, textsize, zlibsettings);
    if(!error)
    {
      for(i = 0; i != compressed_data.size; ++i) ucvector_push_back(&data, compressed_data.data[i]);
    }
    ucvector_cleanup(&compressed_data);
  }
  else /*not compressed*/
  {
    for(i = 0; textstring[i] != 0; ++i) ucvector_push_back(&data, (unsigned char)textstring[i]);
  }

  if(!error) error = addChunk(out, "iTXt", data.data, data.size);
  ucvector_cleanup(&data);
  return error;
}

// Assembly:
subq $0x88, %rsp
movq 0x90(%rsp), %rax
movq %rdi, 0x78(%rsp)
movl %esi, 0x74(%rsp)
movq %rdx, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
movq %r8, 0x58(%rsp)
movq %r9, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movq 0x50(%rsp), %rdi
callq 0x30d0
movq %rax, 0x20(%rsp)
leaq 0x30(%rsp), %rdi
callq 0xf580
movq $0x0, 0x28(%rsp)
movq 0x68(%rsp), %rax
movq 0x28(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x10281
movq 0x68(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %rdi
movzbl (%rax,%rcx), %esi
callq 0x81d0
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x10246
cmpq $0x1, 0x28(%rsp)
jb 0x10291
cmpq $0x4f, 0x28(%rsp)
jbe 0x102a1
movl $0x59, 0x84(%rsp)
jmp 0x10488
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movl 0x74(%rsp), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
leaq 0x30(%rsp), %rdi
movzbl %al, %esi
callq 0x81d0
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movq $0x0, 0x28(%rsp)
movq 0x60(%rsp), %rax
movq 0x28(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1031b
movq 0x60(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %rdi
movzbl (%rax,%rcx), %esi
callq 0x81d0
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x102e0
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movq $0x0, 0x28(%rsp)
movq 0x58(%rsp), %rax
movq 0x28(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1036b
movq 0x58(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %rdi
movzbl (%rax,%rcx), %esi
callq 0x81d0
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x10330
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
cmpl $0x0, 0x74(%rsp)
je 0x10407
leaq 0x8(%rsp), %rdi
callq 0xf580
leaq 0x8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
addq $0x8, %rsi
movq 0x50(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x90(%rsp), %r8
callq 0x110c0
movl %eax, 0x4c(%rsp)
cmpl $0x0, 0x4c(%rsp)
jne 0x103fb
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0x103f9
movq 0x8(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %rdi
movzbl (%rax,%rcx), %esi
callq 0x81d0
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x103c5
jmp 0x103fb
leaq 0x8(%rsp), %rdi
callq 0x17170
jmp 0x1044d
movq $0x0, 0x28(%rsp)
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1044b
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %rdi
movzbl (%rax,%rcx), %esi
callq 0x81d0
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x10410
jmp 0x1044d
cmpl $0x0, 0x4c(%rsp)
jne 0x10473
movq 0x78(%rsp), %rdi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
leaq 0xd31c(%rip), %rsi      # 0x1d786
callq 0x19c40
movl %eax, 0x4c(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x17170
movl 0x4c(%rsp), %eax
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopw (%rax,%rax)