// File: /workspace/github_c_makefile_star2_O1/ggerganov[P]font-rasterizer/./stb_image_write.h
// Function: stbi_write_tga_core
static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, void *data)
{
   int has_alpha = (comp == 2 || comp == 4);
   int colorbytes = has_alpha ? comp-1 : comp;
   int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3

   if (y < 0 || x < 0)
      return 0;

   if (!stbi_write_tga_with_rle) {
      return stbiw__outfile(s, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0,
         "111 221 2222 11", 0, 0, format, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8);
   } else {
      int i,j,k;
      int jend, jdir;

      stbiw__writef(s, "111 221 2222 11", 0,0,format+8, 0,0,0, 0,0,x,y, (colorbytes + has_alpha) * 8, has_alpha * 8);

      if (stbi__flip_vertically_on_write) {
         j = 0;
         jend = y;
         jdir = 1;
      } else {
         j = y-1;
         jend = -1;
         jdir = -1;
      }
      for (; j != jend; j += jdir) {
         unsigned char *row = (unsigned char *) data + j * x * comp;
         int len;

         for (i = 0; i < x; i += len) {
            unsigned char *begin = row + i * comp;
            int diff = 1;
            len = 1;

            if (i < x - 1) {
               ++len;
               diff = memcmp(begin, row + (i + 1) * comp, comp);
               if (diff) {
                  const unsigned char *prev = begin;
                  for (k = i + 2; k < x && len < 128; ++k) {
                     if (memcmp(prev, row + k * comp, comp)) {
                        prev += comp;
                        ++len;
                     } else {
                        --len;
                        break;
                     }
                  }
               } else {
                  for (k = i + 2; k < x && len < 128; ++k) {
                     if (!memcmp(begin, row + k * comp, comp)) {
                        ++len;
                     } else {
                        break;
                     }
                  }
               }
            }

            if (diff) {
               unsigned char header = STBIW_UCHAR(len - 1);
               s->func(s->context, &header, 1);
               for (k = 0; k < len; ++k) {
                  stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp);
               }
            } else {
               unsigned char header = STBIW_UCHAR(len - 129);
               s->func(s->context, &header, 1);
               stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin);
            }
         }
      }
   }
   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, -0x88(%rbp)
leal -0x2(%rcx), %eax
xorl %r13d, %r13d
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
sete %r13b
movq %rcx, -0x58(%rbp)
movl %ecx, %r10d
subl %r13d, %r10d
xorl %r12d, %r12d
cmpl $0x2, %r10d
setl %al
movl %edx, %ecx
movq %rsi, -0x38(%rbp)
orl %esi, %ecx
js 0x17ec
movl %edx, %ebx
movb %al, %r12b
orl $0x2, %r12d
cmpl $0x0, 0x10c66(%rip)     # 0x12124
je 0x17f7
orl $0x8, %r12d
addl %r13d, %r10d
shll $0x3, %r10d
leal (,%r13,8), %r11d
xorl %r14d, %r14d
movq %rdi, -0xa0(%rbp)
xorl %edx, %edx
xorl %ecx, %ecx
movl %r12d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %rbx
movq -0x38(%rbp), %r15
pushq %r15
pushq %r14
pushq %r14
pushq %r14
pushq %r14
callq 0xa445
addq $0x40, %rsp
movl 0x10c21(%rip), %ecx     # 0x12130
leal -0x1(%rbx), %edx
testl %ecx, %ecx
cmovnel %r14d, %edx
cmpl $0x1, %ecx
sbbl %r14d, %r14d
orl %ebx, %r14d
movl $0x1, %eax
movq %r14, -0xb8(%rbp)
cmpl %r14d, %edx
je 0x17ee
testl %ecx, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmoveq %rax, %rcx
movq -0x58(%rbp), %r9
movl %r9d, %eax
imull %r15d, %eax
leal -0x1(%r15), %esi
movl %esi, -0x7c(%rbp)
movslq %r9d, %r8
movslq %r15d, %rsi
movq %rsi, -0xa8(%rbp)
movl %edx, %esi
movq %rsi, -0x60(%rbp)
imull %eax, %edx
movq %rcx, -0xb0(%rbp)
movl %eax, -0x74(%rbp)
imull %eax, %ecx
movl %ecx, -0x78(%rbp)
movq %r13, -0x98(%rbp)
movq %r15, %rbx
movq %r8, -0x48(%rbp)
movslq %edx, %rdx
movq %rdx, -0x90(%rbp)
testl %ebx, %ebx
jle 0x17c0
movl -0x74(%rbp), %eax
imull -0x60(%rbp), %eax
movslq %eax, %r13
movq -0x88(%rbp), %rax
addq %rax, %r13
movq -0x90(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
xorl %r14d, %r14d
movq %r13, -0x40(%rbp)
movl %r14d, %eax
imull %r9d, %eax
cltq
movq %rax, -0x70(%rbp)
leaq (%rax,%r13), %r12
cmpl -0x7c(%rbp), %r14d
movq %r14, -0xc0(%rbp)
movq %r12, -0x50(%rbp)
jge 0x166d
leal 0x1(%r14), %eax
imull %r9d, %eax
movslq %eax, %rsi
addq %r13, %rsi
movq %r12, %rdi
movq %r8, %rdx
callq 0x1180
leal 0x2(%r14), %ecx
testl %eax, %eax
je 0x1674
cmpl %ebx, %ecx
jge 0x16d3
movslq %ecx, %r14
movq -0x48(%rbp), %rdx
movq %rdx, %rbx
imulq %r14, %rbx
addq -0x68(%rbp), %rbx
incq %r14
movl $0x1, %esi
movq %rsi, %r13
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1180
testl %eax, %eax
je 0x16dd
movq %r13, %rsi
incl %esi
cmpq -0xa8(%rbp), %r14
movq -0x48(%rbp), %rdx
jge 0x1666
addq %rdx, %r12
addq %rdx, %rbx
incq %r14
cmpl $0x7f, %esi
jb 0x1630
incl %esi
xorl %r12d, %r12d
jmp 0x16cd
movl $0x1, %esi
jmp 0x16d8
movb $0x1, %r12b
movl $0x2, %esi
cmpl %ebx, %ecx
jge 0x16eb
movslq %ecx, %r14
movq -0x48(%rbp), %rdx
movq %rdx, %rbx
imulq %r14, %rbx
addq -0x68(%rbp), %rbx
incq %r14
movl $0x2, %r13d
movq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0x1180
testl %eax, %eax
jne 0x16e0
leal 0x1(%r13), %eax
cmpq -0xa8(%rbp), %r14
jge 0x16cb
movq -0x48(%rbp), %rdx
addq %rdx, %rbx
incq %r14
cmpl $0x7f, %r13d
movl %eax, %r13d
jb 0x169b
movl %eax, %esi
movq -0x38(%rbp), %rbx
jmp 0x16e7
movl $0x2, %esi
xorl %r12d, %r12d
jmp 0x16eb
xorl %r12d, %r12d
movq -0x38(%rbp), %rbx
movq %r13, %rsi
movq -0x40(%rbp), %r13
testb %r12b, %r12b
je 0x1735
leal 0x7f(%rsi), %eax
movb %al, -0x29(%rbp)
movq -0xa0(%rbp), %r14
movq 0x8(%r14), %rdi
movq %rsi, %r15
leaq -0x29(%rbp), %rsi
movl $0x1, %edx
callq *(%r14)
movq %r14, %rdi
movq -0x58(%rbp), %r14
movl %r14d, %esi
movq -0x98(%rbp), %rdx
xorl %ecx, %ecx
movq -0x50(%rbp), %r8
callq 0xa32c
movq %r14, %r9
movq -0x48(%rbp), %r8
jmp 0x17ad
leal -0x1(%rsi), %eax
movb %al, -0x2a(%rbp)
movq -0xa0(%rbp), %r13
movq 0x8(%r13), %rdi
movq %rsi, %rbx
leaq -0x2a(%rbp), %rsi
movl $0x1, %edx
callq *(%r13)
movq %rbx, -0x50(%rbp)
testl %ebx, %ebx
movq -0x58(%rbp), %r9
movq -0x48(%rbp), %r15
movq -0x98(%rbp), %r12
movq -0x70(%rbp), %r8
jle 0x179e
movl -0x50(%rbp), %ebx
addq -0x68(%rbp), %r8
movq %r8, -0x70(%rbp)
movq %r13, %rdi
movl %r9d, %esi
movl %r12d, %edx
xorl %ecx, %ecx
movq %r9, %r14
callq 0xa32c
movq %r14, %r9
movq -0x70(%rbp), %r8
addq %r15, %r8
decq %rbx
jne 0x1778
movq -0x38(%rbp), %rbx
movq %r15, %r8
movq -0x40(%rbp), %r13
movq -0x50(%rbp), %r15
addl -0xc0(%rbp), %r15d
movl %r15d, %r14d
cmpl %ebx, %r15d
jl 0x15c7
movq -0x60(%rbp), %rax
addq -0xb0(%rbp), %rax
movq -0x90(%rbp), %rdx
addl -0x78(%rbp), %edx
movq %rax, -0x60(%rbp)
cmpl %eax, -0xb8(%rbp)
jne 0x158c
movl $0x1, %eax
jmp 0x17ee
xorl %eax, %eax
addq $0x98, %rsp
jmp 0x1847
addl %r13d, %r10d
shll $0x3, %r10d
leal (,%r13,8), %r14d
subq $0x8, %rsp
xorl %edx, %edx
leaq 0xd736(%rip), %r11      # 0xef49
movq -0x38(%rbp), %rcx
movl %ebx, %r8d
movq -0x58(%rbp), %r9
xorl %eax, %eax
pushq %r14
pushq %r10
pushq %rbx
pushq %rcx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %r12
pushq %rdx
pushq %rdx
pushq %r11
pushq %rdx
pushq %r13
pushq -0x88(%rbp)
pushq %rdx
callq 0xa06d
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq