// File: /workspace/github_c_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movq %r8, -0x80(%rbp)
movl %ecx, %r12d
movl %edx, %r14d
movq %rdi, -0x40(%rbp)
leal -0x2(%r12), %eax
xorl %ecx, %ecx
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
sete %cl
movl %r12d, %eax
movq %rcx, -0x50(%rbp)
subl %ecx, %eax
xorl %r8d, %r8d
cmpl $0x2, %eax
setl %cl
movq %rsi, -0x58(%rbp)
orl %esi, %edx
js 0x180d
movb %cl, %r8b
orl $0x2, %r8d
cmpl $0x0, 0x10be4(%rip)     # 0x12124
je 0x1816
orl $0x8, %r8d
movq -0x50(%rbp), %rcx
addl %ecx, %eax
shll $0x3, %eax
leal (,%rcx,8), %ecx
andl $0x0, 0x18(%rsp)
movl %ecx, 0x38(%rsp)
andl $0x0, 0x10(%rsp)
movl %r14d, 0x28(%rsp)
andl $0x0, 0x8(%rsp)
movq -0x58(%rbp), %r13
movl %r13d, 0x20(%rsp)
andl $0x0, (%rsp)
movl %eax, 0x30(%rsp)
xorl %r15d, %r15d
movq -0x40(%rbp), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x9716
movl 0x10b92(%rip), %eax     # 0x12130
leal -0x1(%r14), %ecx
xorl %edx, %edx
testl %eax, %eax
setne %dl
cmovnel %r15d, %ecx
cmpl $0x1, %eax
sbbl %r15d, %r15d
orl %r14d, %r15d
leaq -0x1(,%rdx,2), %rdx
movl %r12d, %esi
imull %r13d, %esi
leal -0x1(%r13), %eax
movl %eax, -0x78(%rbp)
movslq %r12d, %rbx
movslq %r13d, %rax
movq %rax, -0x88(%rbp)
movslq %ecx, %rcx
movslq %r15d, %rax
movq %rax, -0xa0(%rbp)
movl %ecx, %eax
imull %esi, %eax
movq %rdx, -0x98(%rbp)
movl %esi, -0x74(%rbp)
imull %esi, %edx
movq %rdx, -0x90(%rbp)
pushq $0x1
popq %rdx
movq %r12, -0x48(%rbp)
movq %rbx, -0x70(%rbp)
cmpq -0xa0(%rbp), %rcx
je 0x180f
movq %r12, %r14
movslq %eax, %rsi
movl -0x74(%rbp), %eax
imull %ecx, %eax
movslq %eax, %rdi
movq -0x80(%rbp), %rax
addq %rax, %rdi
movq %rdi, -0xb0(%rbp)
movq %rsi, -0xa8(%rbp)
addq %rax, %rsi
movq %rsi, -0x60(%rbp)
xorl %r12d, %r12d
movq %rcx, -0xb8(%rbp)
cmpl -0x58(%rbp), %r12d
jge 0x17ee
movl %r12d, %eax
imull %r14d, %eax
movslq %eax, %r13
movl %edx, %r15d
cmpl -0x78(%rbp), %r12d
movq %r12, -0xc0(%rbp)
jge 0x1793
movq -0xb0(%rbp), %rcx
leaq (%rcx,%r13), %rdi
leal 0x1(%r12), %eax
imull %r14d, %eax
movslq %eax, %rsi
addq %rcx, %rsi
movq %rdi, -0x68(%rbp)
movq %rbx, %rdx
callq 0x1180
leal 0x2(%r12), %ecx
movslq %ecx, %r14
testl %eax, %eax
je 0x1702
movq %rbx, %r12
imulq %r14, %r12
addq -0x60(%rbp), %r12
pushq $0x2
popq %rax
movq %rax, -0x38(%rbp)
movq -0x68(%rbp), %r15
cmpq -0x88(%rbp), %r14
jge 0x1774
cmpl $0x7f, -0x38(%rbp)
ja 0x1774
movq %r15, %rdi
movq %r12, %rsi
movq -0x70(%rbp), %rbx
movq %rbx, %rdx
callq 0x1180
testl %eax, %eax
je 0x1785
addq %rbx, %r15
movq -0x38(%rbp), %rax
incl %eax
movq %rax, -0x38(%rbp)
incq %r14
addq %rbx, %r12
jmp 0x16bc
movq %rbx, %r12
imulq %r14, %r12
addq -0x60(%rbp), %r12
pushq $0x2
popq %rax
movl %eax, %r15d
cmpq -0x88(%rbp), %r14
jge 0x1740
cmpl $0x7f, %r15d
ja 0x1740
movq -0x68(%rbp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x1180
testl %eax, %eax
jne 0x1740
incl %r15d
incq %r14
addq %rbx, %r12
jmp 0x1713
leal 0x7f(%r15), %eax
movb %al, -0x29(%rbp)
movq -0x40(%rbp), %r14
movq 0x8(%r14), %rdi
leaq -0x29(%rbp), %rsi
pushq $0x1
popq %rdx
callq *(%r14)
movq %r14, %rdi
movq -0x48(%rbp), %rsi
movq %rsi, %r14
movq -0x50(%rbp), %rdx
xorl %ecx, %ecx
movq -0x68(%rbp), %r8
callq 0x960f
jmp 0x17d5
movq -0x48(%rbp), %r14
pushq $0x1
popq %rdx
movq -0x38(%rbp), %r15
movq -0x70(%rbp), %rbx
jmp 0x1793
movq -0x38(%rbp), %r15
decl %r15d
movq -0x48(%rbp), %r14
pushq $0x1
popq %rdx
leal -0x1(%r15), %eax
movb %al, -0x2a(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x2a(%rbp), %rsi
callq *(%rax)
movq %r14, %r12
movl %r15d, %r14d
addq -0x60(%rbp), %r13
subq $0x1, %r14
jb 0x17d2
movq -0x40(%rbp), %rdi
movl %r12d, %esi
movq -0x50(%rbp), %rdx
xorl %ecx, %ecx
movq %r13, %r8
callq 0x960f
addq %rbx, %r13
jmp 0x17b2
movq %r12, %r14
addl -0xc0(%rbp), %r15d
movl %r15d, %r12d
movq -0xb8(%rbp), %rcx
pushq $0x1
popq %rdx
jmp 0x164c
addq -0x98(%rbp), %rcx
movq -0x90(%rbp), %rax
movq -0xa8(%rbp), %rsi
addl %esi, %eax
movq %r14, %r12
jmp 0x160a
xorl %edx, %edx
movl %edx, %eax
jmp 0x1899
movq -0x50(%rbp), %rsi
addl %esi, %eax
shll $0x3, %eax
leal (,%rsi,8), %ecx
movl %ecx, 0x80(%rsp)
movl %r14d, 0x70(%rsp)
andl $0x0, 0x60(%rsp)
movq -0x58(%rbp), %rcx
movl %ecx, 0x68(%rsp)
andl $0x0, 0x58(%rsp)
movl %r8d, 0x38(%rsp)
andl $0x0, 0x50(%rsp)
leaq 0xc6f4(%rip), %rdx      # 0xdf49
andl $0x0, 0x48(%rsp)
movq %rdx, 0x20(%rsp)
andl $0x0, 0x40(%rsp)
movl %esi, 0x10(%rsp)
andl $0x0, 0x30(%rsp)
movq -0x80(%rbp), %rdx
movq %rdx, 0x8(%rsp)
andl $0x0, 0x28(%rsp)
movl %eax, 0x78(%rsp)
andl $0x0, 0x18(%rsp)
andl $0x0, (%rsp)
movq -0x40(%rbp), %rdi
movl %r14d, %r8d
movl %r12d, %r9d
xorl %eax, %eax
callq 0x9384
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq