// File: /workspace/github_c_makefile_star2_O1/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 %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 0xbf11
xorl %ebp, %ebp
cmpb $0x0, (%rdx,%rbp)
leaq 0x1(%rbp), %rbp
jne 0xbf1f
movq %r9, 0x40(%rsp)
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 0xbf42
movq %rcx, 0x50(%rsp)
movq %rax, 0x18(%rsp)
leaq -0x1(%rbp), %r9
movq $-0x1, %r12
movq %r13, %rbx
decl %r14d
incq %rbx
cmpb $0x0, 0x1(%r10,%r12)
leaq 0x1(%r12), %r12
jne 0xbf6c
leaq -0x51(%rbp), %rcx
movl $0x59, %eax
cmpq $-0x4f, %rcx
jb 0xc111
testl %esi, %esi
movl %esi, 0x4(%rsp)
movq %r10, 0x8(%rsp)
movq %rdx, 0x38(%rsp)
movq %r9, 0x30(%rsp)
je 0xbfcf
movq %r11, 0x10(%rsp)
movq 0x18(%r8), %rax
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
testq %rax, %rax
je 0xbfd3
movq 0x40(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq *%rax
jmp 0xbfe2
xorl %eax, %eax
jmp 0xbff6
movq 0x40(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x5071
movq 0x8(%rsp), %r10
movq 0x38(%rsp), %rdx
movq 0x10(%rsp), %r11
movq 0x30(%rsp), %r9
testl %eax, %eax
jne 0xc032
movq 0x18(%rsp), %rax
movl %eax, %edx
cmpl $0x0, 0x4(%rsp)
je 0xc00c
movl 0x20(%rsp), %edx
subl %r14d, %edx
leaq 0x6b90(%rip), %rcx      # 0x12ba6
leaq 0x48(%rsp), %rdi
movq %r11, %rsi
callq 0xd3f7
movq 0x8(%rsp), %r10
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %r9
movl %eax, 0x10(%rsp)
testl %eax, %eax
jne 0xc103
movq 0x48(%rsp), %rdi
cmpq $0x1, %rbp
movq %rdi, %r14
je 0xc063
leaq 0x8(%r14), %rdi
movq %rdx, %rsi
movq %r9, %rdx
callq 0x1130
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 0xc09e
leaq (%r14,%rbp), %rdi
addq $0xa, %rdi
movq 0x50(%rsp), %rsi
movq %r15, %rdx
callq 0x1130
movq %r14, %rdi
movq 0x8(%rsp), %r10
movl 0x4(%rsp), %ecx
movb $0x0, -0x1(%rdi,%r13)
testq %r12, %r12
je 0xc0c1
addq %rdi, %r13
movq %r13, %rdi
movq %r10, %rsi
movq %r12, %rdx
callq 0x1130
movq %r14, %rdi
movl 0x4(%rsp), %ecx
movb $0x0, -0x1(%rdi,%rbx)
testl %ecx, %ecx
je 0xc0e1
movq 0x20(%rsp), %rdx
testq %rdx, %rdx
je 0xc0fe
movq 0x28(%rsp), %rsi
addq %rdi, %rbx
movq %rbx, %rdi
jmp 0xc0f6
movq 0x18(%rsp), %rdx
testq %rdx, %rdx
je 0xc0fe
addq %rdi, %rbx
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
callq 0x1130
movq %r14, %rdi
callq 0x53c4
movq 0x28(%rsp), %rdi
callq 0x1030
movl 0x10(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq