// File: /workspace/github_c_makefile_star2_O3/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, -0x80(%rbp)
movl %edx, %ebx
leal -0x2(%rcx), %eax
xorl %edx, %edx
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
sete %dl
movq %rcx, -0x40(%rbp)
movl %ecx, %r10d
subl %edx, %r10d
xorl %r15d, %r15d
cmpl $0x2, %r10d
setl %al
movl %ebx, %ecx
movq %rsi, -0x58(%rbp)
orl %esi, %ecx
js 0x17db
movq %rdi, %r13
movb %al, %r15b
orl $0x2, %r15d
cmpl $0x0, 0x10c68(%rip)     # 0x12124
je 0x17e6
orl $0x8, %r15d
addl %edx, %r10d
shll $0x3, %r10d
leal (,%rdx,8), %r11d
xorl %r12d, %r12d
movq %r13, %rdi
movq %rdx, -0x90(%rbp)
xorl %edx, %edx
xorl %ecx, %ecx
movl %r15d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %rbx
movq -0x58(%rbp), %r14
pushq %r14
pushq %r12
pushq %r12
pushq %r12
pushq %r12
callq 0xa09f
addq $0x40, %rsp
movl 0x10c20(%rip), %ecx     # 0x12130
leal -0x1(%rbx), %edx
testl %ecx, %ecx
cmovnel %r12d, %edx
cmpl $0x1, %ecx
sbbl %r12d, %r12d
orl %ebx, %r12d
movl $0x1, %eax
movq %r12, -0xa8(%rbp)
cmpl %r12d, %edx
je 0x17dd
movq %r13, -0x68(%rbp)
testl %ecx, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmoveq %rax, %rcx
movq -0x40(%rbp), %r8
movl %r8d, %eax
imull %r14d, %eax
leal -0x1(%r14), %esi
movl %esi, -0x74(%rbp)
movslq %r8d, %rsi
movq %rsi, -0x38(%rbp)
movslq %r14d, %r13
movl %edx, %esi
movq %rsi, -0x48(%rbp)
imull %eax, %edx
movq %rcx, -0xa0(%rbp)
movl %eax, -0x6c(%rbp)
imull %eax, %ecx
movl %ecx, -0x70(%rbp)
movq %r14, %rbx
movq %r13, -0x98(%rbp)
movslq %edx, %rdx
movq %rdx, -0x88(%rbp)
testl %ebx, %ebx
jle 0x17af
movl -0x6c(%rbp), %eax
imull -0x48(%rbp), %eax
movslq %eax, %rcx
movq -0x80(%rbp), %rax
addq %rax, %rcx
movq %rcx, -0xb0(%rbp)
movq -0x88(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
xorl %r12d, %r12d
movl %r12d, %eax
imull %r8d, %eax
movslq %eax, %r14
movl $0x1, %eax
cmpl -0x74(%rbp), %r12d
movq %r12, -0xb8(%rbp)
jge 0x16e2
movq -0xb0(%rbp), %rcx
leaq (%rcx,%r14), %rdi
leal 0x1(%r12), %eax
imull -0x40(%rbp), %eax
movslq %eax, %rsi
addq %rcx, %rsi
movq %rdi, %r15
movq -0x38(%rbp), %rdx
callq 0x1180
leal 0x2(%r12), %ecx
testl %eax, %eax
je 0x167e
movl $0x2, %eax
cmpl %ebx, %ecx
jge 0x16e2
movslq %ecx, %r12
movq -0x38(%rbp), %rdx
movq %rdx, %rbx
imulq %r12, %rbx
addq -0x50(%rbp), %rbx
incq %r12
movl $0x1, %eax
movq %r15, %rdi
movq %rax, %r13
movq %rdi, %r15
movq %rbx, %rsi
callq 0x1180
testl %eax, %eax
je 0x16df
movq %r13, %rax
incl %eax
movq -0x98(%rbp), %r13
cmpq %r13, %r12
movq -0x38(%rbp), %rdx
jge 0x167a
movq %r15, %rdi
addq %rdx, %rdi
addq %rdx, %rbx
incq %r12
cmpl $0x7f, %eax
jb 0x163e
incl %eax
jmp 0x16e2
movl $0x2, %eax
cmpl %ebx, %ecx
movq -0x38(%rbp), %rdx
jge 0x1772
movslq %ecx, %r14
movq %rdx, %rbx
imulq %r14, %rbx
addq -0x50(%rbp), %rbx
incq %r14
movl $0x2, %r12d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1180
testl %eax, %eax
jne 0x176f
leal 0x1(%r12), %eax
cmpq %r13, %r14
jge 0x1772
movq -0x38(%rbp), %rdx
addq %rdx, %rbx
incq %r14
cmpl $0x7f, %r12d
movl %eax, %r12d
jb 0x16a6
jmp 0x1772
movq %r13, %rax
movq %rax, %rbx
decl %eax
movb %al, -0x2a(%rbp)
movq -0x68(%rbp), %r15
movq 0x8(%r15), %rdi
leaq -0x2a(%rbp), %rsi
movl $0x1, %edx
callq *(%r15)
movq %rbx, -0x60(%rbp)
testl %ebx, %ebx
movq -0x40(%rbp), %r8
movq -0x90(%rbp), %r13
movq -0x38(%rbp), %rax
jle 0x174d
movl -0x60(%rbp), %ebx
addq -0x50(%rbp), %r14
movq %r15, %rdi
movl %r8d, %esi
movl %r13d, %edx
xorl %ecx, %ecx
movq %r8, %r12
movq %r14, %r8
movq %r14, %r15
movq %rax, %r14
callq 0x9f67
movq %r14, %rax
movq %r15, %r14
movq %r12, %r8
movq -0x68(%rbp), %r15
addq %rax, %r14
decq %rbx
jne 0x171c
movq -0x98(%rbp), %r13
movq -0x60(%rbp), %rax
addl -0xb8(%rbp), %eax
movl %eax, %r12d
movq -0x58(%rbp), %rbx
cmpl %ebx, %eax
jl 0x15c5
jmp 0x17af
movl %r12d, %eax
movq %rax, -0x60(%rbp)
addl $0x7f, %eax
movb %al, -0x29(%rbp)
movq -0x68(%rbp), %rbx
movq 0x8(%rbx), %rdi
leaq -0x29(%rbp), %rsi
movl $0x1, %edx
callq *(%rbx)
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
movq -0x90(%rbp), %rdx
xorl %ecx, %ecx
movq %r15, %r8
movq %rsi, %rbx
callq 0x9f67
movq %rbx, %r8
jmp 0x1754
movq -0x48(%rbp), %rax
addq -0xa0(%rbp), %rax
movq -0x88(%rbp), %rdx
addl -0x70(%rbp), %edx
movq %rax, -0x48(%rbp)
cmpl %eax, -0xa8(%rbp)
jne 0x158a
movl $0x1, %eax
jmp 0x17dd
xorl %eax, %eax
addq $0x98, %rsp
jmp 0x1838
addl %edx, %r10d
shll $0x3, %r10d
leal (,%rdx,8), %r14d
subq $0x8, %rsp
movq %rdx, %rsi
xorl %edx, %edx
leaq 0xd744(%rip), %r11      # 0xef49
movq %r13, %rdi
movq -0x58(%rbp), %rcx
movl %ebx, %r8d
movq -0x40(%rbp), %r9
xorl %eax, %eax
pushq %r14
pushq %r10
pushq %rbx
pushq %rcx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %r15
pushq %rdx
pushq %rdx
pushq %r11
pushq %rdx
pushq %rsi
pushq -0x80(%rbp)
pushq %rdx
callq 0x9cab
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq