// File: /workspace/github_c_makefile_star2_O0/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 $0x108, %rsp            # imm = 0x108
movq %rdi, -0x38(%rbp)
movl %esi, -0x3c(%rbp)
movl %edx, -0x40(%rbp)
movl %ecx, -0x44(%rbp)
movq %r8, -0x50(%rbp)
movb $0x1, %al
cmpl $0x2, -0x44(%rbp)
movb %al, -0x9b(%rbp)
je 0x1640
cmpl $0x4, -0x44(%rbp)
sete %al
movb %al, -0x9b(%rbp)
movb -0x9b(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0x1662
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x166b
movl -0x44(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %edx
movl $0x2, %eax
movl $0x3, %ecx
cmpl $0x2, %edx
cmovll %ecx, %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x40(%rbp)
jl 0x1696
cmpl $0x0, -0x3c(%rbp)
jge 0x16a2
movl $0x0, -0x2c(%rbp)
jmp 0x1adb
cmpl $0x0, 0x19a6b(%rip)     # 0x1b114
jne 0x1772
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %ecx
movl -0x40(%rbp), %r8d
movl -0x44(%rbp), %r9d
movq -0x50(%rbp), %r13
movl -0x54(%rbp), %r12d
movl -0x5c(%rbp), %r14d
movl -0x3c(%rbp), %ebx
movl -0x40(%rbp), %r11d
movl -0x58(%rbp), %r10d
addl -0x54(%rbp), %r10d
shll $0x3, %r10d
movl -0x54(%rbp), %eax
shll $0x3, %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %esi, %esi
leaq 0x154e9(%rip), %r15     # 0x16bda
movl %edx, %esi
movl $0x0, (%rsp)
movq %r13, 0x8(%rsp)
movl %r12d, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
movl %r14d, 0x38(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x50(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x60(%rsp)
movl %ebx, 0x68(%rsp)
movl %r11d, 0x70(%rsp)
movl %r10d, 0x78(%rsp)
movl %eax, 0x80(%rsp)
movb $0x0, %al
callq 0xd4f0
movl %eax, -0x2c(%rbp)
jmp 0x1adb
movq -0x38(%rbp), %rdi
movl -0x5c(%rbp), %r8d
addl $0x8, %r8d
movl -0x3c(%rbp), %ebx
movl -0x40(%rbp), %r11d
movl -0x58(%rbp), %r10d
addl -0x54(%rbp), %r10d
shll $0x3, %r10d
movl -0x54(%rbp), %eax
shll $0x3, %eax
leaq 0x1543c(%rip), %rsi     # 0x16bda
xorl %r9d, %r9d
movl %r9d, %edx
movl %r9d, %ecx
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movl %ebx, 0x20(%rsp)
movl %r11d, 0x28(%rsp)
movl %r10d, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movb $0x0, %al
callq 0xdb80
cmpl $0x0, 0x19e3e(%rip)     # 0x1b624
je 0x17fe
movl $0x0, -0x64(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x1815
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x64(%rbp)
movl $0xffffffff, -0x6c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x70(%rbp) # imm = 0xFFFFFFFF
jmp 0x1817
movl -0x64(%rbp), %eax
cmpl -0x6c(%rbp), %eax
je 0x1ad2
movq -0x50(%rbp), %rax
movl -0x64(%rbp), %ecx
imull -0x3c(%rbp), %ecx
imull -0x44(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x1ac2
movq -0x78(%rbp), %rax
movl -0x60(%rbp), %ecx
imull -0x44(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movl $0x1, -0x8c(%rbp)
movl $0x1, -0x7c(%rbp)
movl -0x60(%rbp), %eax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x19e7
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movq -0x88(%rbp), %rdi
movq -0x78(%rbp), %rsi
movl -0x60(%rbp), %eax
addl $0x1, %eax
imull -0x44(%rbp), %eax
cltq
addq %rax, %rsi
movslq -0x44(%rbp), %rdx
callq 0x10f0
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
je 0x196f
movq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x60(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %ecx
xorl %eax, %eax
cmpl -0x3c(%rbp), %ecx
movb %al, -0xa1(%rbp)
jge 0x18ff
cmpl $0x80, -0x7c(%rbp)
setl %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x190b
jmp 0x196d
movq -0x98(%rbp), %rdi
movq -0x78(%rbp), %rsi
movl -0x68(%rbp), %eax
imull -0x44(%rbp), %eax
cltq
addq %rax, %rsi
movslq -0x44(%rbp), %rdx
callq 0x10f0
cmpl $0x0, %eax
je 0x1952
movl -0x44(%rbp), %ecx
movq -0x98(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x195d
movl -0x7c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x196d
jmp 0x195f
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x18df
jmp 0x19e5
movl -0x60(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %ecx
xorl %eax, %eax
cmpl -0x3c(%rbp), %ecx
movb %al, -0xa2(%rbp)
jge 0x1998
cmpl $0x80, -0x7c(%rbp)
setl %al
movb %al, -0xa2(%rbp)
movb -0xa2(%rbp), %al
testb $0x1, %al
jne 0x19a4
jmp 0x19e3
movq -0x88(%rbp), %rdi
movq -0x78(%rbp), %rsi
movl -0x68(%rbp), %eax
imull -0x44(%rbp), %eax
cltq
addq %rax, %rsi
movslq -0x44(%rbp), %rdx
callq 0x10f0
cmpl $0x0, %eax
jne 0x19d4
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x19d6
jmp 0x19e3
jmp 0x19d8
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1978
jmp 0x19e5
jmp 0x19e7
cmpl $0x0, -0x8c(%rbp)
je 0x1a64
movl -0x7c(%rbp), %eax
subl $0x1, %eax
andl $0xff, %eax
movb %al, -0x99(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
leaq -0x99(%rbp), %rsi
movl $0x1, %edx
callq *%rax
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x1a62
movq -0x38(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x54(%rbp), %ecx
movq -0x88(%rbp), %r9
movl -0x68(%rbp), %eax
imull -0x44(%rbp), %eax
cltq
addq %rax, %r9
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0xd920
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1a25
jmp 0x1ab2
movl -0x7c(%rbp), %eax
subl $0x81, %eax
andl $0xff, %eax
movb %al, -0x9a(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
leaq -0x9a(%rbp), %rsi
movl $0x1, %edx
callq *%rax
movq -0x38(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x54(%rbp), %ecx
movq -0x88(%rbp), %r9
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0xd920
jmp 0x1ab4
movl -0x7c(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x1843
jmp 0x1ac4
movl -0x70(%rbp), %eax
addl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x1817
jmp 0x1ad4
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq