// File: /workspace/github_c_makefile_star2_O3/tditlu[P]shadetabler/src/lodepng/lodepng.c
// Function: addChunk_iTXt
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 0x90(%rsp), %r8
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq $-0x1, %r11
cmpb $0x0, 0x1(%r9,%r11)
leaq 0x1(%r11), %r11
jne 0xbe4d
xorl %ebp, %ebp
cmpb $0x0, (%rdx,%rbp)
leaq 0x1(%rbp), %rbp
jne 0xbe5b
movl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
subl %ebp, %r14d
leaq 0xa(%rbp), %r13
movq $-0x1, %r15
incq %r13
decl %r14d
cmpb $0x0, 0x1(%rcx,%r15)
leaq 0x1(%r15), %r15
jne 0xbe79
leaq -0x1(%rbp), %rax
movq %rax, 0x50(%rsp)
movq $-0x1, %r12
movq %r13, %rbx
decl %r14d
incq %rbx
cmpb $0x0, 0x1(%r10,%r12)
leaq 0x1(%r12), %r12
jne 0xbe9e
leaq -0x51(%rbp), %rax
movl $0x59, 0x8(%rsp)
cmpq $-0x4f, %rax
jb 0xc006
movq %rdx, 0x48(%rsp)
movq %r11, %rdx
testl %esi, %esi
movq %r9, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movl %esi, 0x4(%rsp)
movq %r10, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
je 0xbf24
movq %rdi, 0x8(%rsp)
movq 0x18(%r8), %rax
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r9, %rdx
movq %r11, %rcx
testq %rax, %rax
je 0xbf0d
callq *%rax
jmp 0xbf12
callq 0x53d7
testl %eax, %eax
movq 0x8(%rsp), %rdi
jne 0xbff8
movq 0x10(%rsp), %rdx
subl %r14d, %edx
leaq 0x6d78(%rip), %rcx      # 0x12ca6
movq %rdi, %rsi
leaq 0x20(%rsp), %rdi
callq 0xd210
testl %eax, %eax
jne 0xbff8
movq 0x20(%rsp), %r14
leaq 0x8(%r14), %rdi
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x1130
xorl %eax, %eax
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
movb %al, 0x7(%r14,%rbp)
setne 0x8(%r14,%rbp)
movb %al, 0x9(%r14,%rbp)
testq %r15, %r15
je 0xbf91
leaq (%r14,%rbp), %rdi
addq $0xa, %rdi
movq 0x38(%rsp), %rsi
movq %r15, %rdx
callq 0x1130
movl 0x4(%rsp), %ecx
movb $0x0, -0x1(%r14,%r13)
testq %r12, %r12
je 0xbfb3
addq %r14, %r13
movq %r13, %rdi
movq 0x40(%rsp), %rsi
movq %r12, %rdx
callq 0x1130
movl 0x4(%rsp), %ecx
movb $0x0, -0x1(%r14,%rbx)
testl %ecx, %ecx
je 0xbfd4
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
je 0xbfee
movq 0x18(%rsp), %rsi
addq %r14, %rbx
movq %rbx, %rdi
jmp 0xbfe9
movq 0x30(%rsp), %rdx
testq %rdx, %rdx
je 0xbfee
addq %r14, %rbx
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x1130
movq %r14, %rdi
callq 0x568d
xorl %eax, %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
callq 0x1030
movl 0x8(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq