// File: /workspace/github_cpp_makefile_star2_O1/lvandeve[P]lodepng/lodepng.cpp
// Function: addChunk_iTXt(ucvector*, unsigned int, char const*, char const*, char const*, char const*, LodePNGCompressSettings*)
static unsigned addChunk_iTXt(ucvector* out, unsigned compress, const char* keyword, const char* langtag,
                              const char* transkey, const char* textstring, LodePNGCompressSettings* zlibsettings) {
  unsigned error = 0;
  unsigned char* chunk = 0;
  unsigned char* compressed = 0;
  size_t compressedsize = 0;
  size_t textsize = lodepng_strlen(textstring);
  size_t keysize = lodepng_strlen(keyword), langsize = lodepng_strlen(langtag), transsize = lodepng_strlen(transkey);

  if(keysize < 1 || keysize > 79) return 89; /*error: invalid keyword size*/

  if(compress) {
    error = zlib_compress(&compressed, &compressedsize,
                          (const unsigned char*)textstring, textsize, zlibsettings);
  }
  if(!error) {
    size_t size = keysize + 3 + langsize + 1 + transsize + 1 + (compress ? compressedsize : textsize);
    error = lodepng_chunk_init(&chunk, out, size, "iTXt");
  }
  if(!error) {
    size_t pos = 8;
    lodepng_memcpy(chunk + pos, keyword, keysize);
    pos += keysize;
    chunk[pos++] = 0; /*null termination char*/
    chunk[pos++] = (compress ? 1 : 0); /*compression flag*/
    chunk[pos++] = 0; /*compression method: 0*/
    lodepng_memcpy(chunk + pos, langtag, langsize);
    pos += langsize;
    chunk[pos++] = 0; /*null termination char*/
    lodepng_memcpy(chunk + pos, transkey, transsize);
    pos += transsize;
    chunk[pos++] = 0; /*null termination char*/
    if(compress) {
      lodepng_memcpy(chunk + pos, compressed, compressedsize);
    } else {
      lodepng_memcpy(chunk + pos, textstring, textsize);
    }
    lodepng_chunk_generate_crc(chunk);
  }

  lodepng_free(compressed);
  return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r10
movq %rdi, %r11
movq 0x90(%rsp), %r8
xorl %eax, %eax
movq %rax, 0x48(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, 0x20(%rsp)
movq $-0x1, %rax
cmpb $0x0, 0x1(%r9,%rax)
leaq 0x1(%rax), %rax
jne 0xca9b
xorl %ebp, %ebp
cmpb $0x0, (%rdx,%rbp)
leaq 0x1(%rbp), %rbp
jne 0xcaa9
movq %r9, 0x40(%rsp)
movq $-0x2, %r14
subq %rbp, %r14
leaq 0xa(%rbp), %r13
movq $-0x1, %r15
incq %r13
decq %r14
cmpb $0x0, 0x1(%rcx,%r15)
leaq 0x1(%r15), %r15
jne 0xcacd
movq %rax, 0x18(%rsp)
leaq -0x1(%rbp), %r9
movq $-0x1, %r12
movq %r13, %rbx
decq %r14
incq %rbx
cmpb $0x0, 0x1(%r10,%r12)
leaq 0x1(%r12), %r12
jne 0xcaf2
leaq -0x51(%rbp), %rdi
movl $0x59, %eax
cmpq $-0x4f, %rdi
jb 0xcc84
movq %rcx, 0x50(%rsp)
movl %esi, 0x4(%rsp)
testl %esi, %esi
movq %r10, 0x8(%rsp)
movq %rdx, 0x38(%rsp)
movq %r9, 0x30(%rsp)
je 0xcb68
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %r11, 0x10(%rsp)
callq 0xd16b
movq 0x30(%rsp), %r9
movq 0x10(%rsp), %r11
movq 0x38(%rsp), %rdx
movq 0x8(%rsp), %r10
jmp 0xcb6a
xorl %eax, %eax
testl %eax, %eax
jne 0xcba5
movq 0x18(%rsp), %rdx
cmpl $0x0, 0x4(%rsp)
je 0xcb7f
movq 0x20(%rsp), %rdx
subq %r14, %rdx
leaq 0x67be8(%rip), %rcx     # 0x74771
leaq 0x48(%rsp), %rdi
movq %r11, %rsi
callq 0xe9f0
movq 0x8(%rsp), %r10
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %r9
movl %eax, 0x10(%rsp)
testl %eax, %eax
jne 0xcc76
movq 0x48(%rsp), %rdi
cmpq $0x1, %rbp
movq %rdi, %r14
je 0xcbd6
leaq 0x8(%r14), %rdi
movq %rdx, %rsi
movq %r9, %rdx
callq 0x21d0
movq %r14, %rdi
movq 0x8(%rsp), %r10
xorl %eax, %eax
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
movb %al, 0x7(%rdi,%rbp)
setne 0x8(%rdi,%rbp)
movb %al, 0x9(%rdi,%rbp)
testq %r15, %r15
je 0xcc11
leaq (%r14,%rbp), %rdi
addq $0xa, %rdi
movq 0x50(%rsp), %rsi
movq %r15, %rdx
callq 0x21d0
movq %r14, %rdi
movq 0x8(%rsp), %r10
movl 0x4(%rsp), %ecx
movb $0x0, -0x1(%rdi,%r13)
testq %r12, %r12
je 0xcc34
addq %rdi, %r13
movq %r13, %rdi
movq %r10, %rsi
movq %r12, %rdx
callq 0x21d0
movq %r14, %rdi
movl 0x4(%rsp), %ecx
movb $0x0, -0x1(%rdi,%rbx)
testl %ecx, %ecx
je 0xcc54
movq 0x20(%rsp), %rdx
testq %rdx, %rdx
je 0xcc71
movq 0x28(%rsp), %rsi
addq %rdi, %rbx
movq %rbx, %rdi
jmp 0xcc69
movq 0x18(%rsp), %rdx
testq %rdx, %rdx
je 0xcc71
addq %rdi, %rbx
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
callq 0x21d0
movq %r14, %rdi
callq 0x4f2f
movq 0x28(%rsp), %rdi
callq 0x2290
movl 0x10(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq