// File: /workspace/github_c_makefile_star2_O3/nilesr[P]dotter/./stb/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;

      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);

      for (j = y - 1; j >= 0; --j) {
          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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r8, 0x48(%rsp)
leal -0x2(%rcx), %eax
xorl %ebp, %ebp
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
sete %bpl
movq %rcx, 0x10(%rsp)
movl %ecx, %r10d
subl %ebp, %r10d
xorl %r14d, %r14d
cmpl $0x2, %r10d
setl %al
movl %edx, %ecx
orl %esi, %ecx
js 0x1715
movl %edx, %r12d
movq %rdi, %r13
movq %rsi, 0x30(%rsp)
movb %al, %r14b
orl $0x2, %r14d
cmpl $0x0, 0xdc8a(%rip)      # 0xf0f0
je 0x1720
orl $0x8, %r14d
addl %ebp, %r10d
shll $0x3, %r10d
leal (,%rbp,8), %r11d
xorl %ebx, %ebx
movq %r13, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movl %r14d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %r12
movq 0x48(%rsp), %r15
pushq %r15
pushq %rbx
pushq %rbx
pushq %rbx
pushq %rbx
callq 0x5810
addq $0x40, %rsp
testl %r12d, %r12d
jle 0x170e
movq %r13, 0x58(%rsp)
movq 0x10(%rsp), %rax
movl %eax, %ecx
imull %r15d, %ecx
leal -0x1(%r15), %edx
movl %edx, 0x44(%rsp)
movslq %eax, %r14
movslq %r15d, %r13
movl %r12d, %eax
movq %rax, 0x20(%rsp)
decl %r12d
movl %ecx, 0x1c(%rsp)
imull %ecx, %r12d
movq %rbp, 0x60(%rsp)
movq %r15, %rbx
movq %r13, 0x68(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x70(%rsp)
decq %rax
movq %rax, 0x20(%rsp)
movslq %r12d, %r12
movq %r12, 0x50(%rsp)
testl %ebx, %ebx
movq 0x10(%rsp), %r12
jle 0x16f8
movl 0x1c(%rsp), %eax
imull 0x20(%rsp), %eax
movslq %eax, %rcx
movq 0x48(%rsp), %rax
addq %rax, %rcx
movq %rcx, 0x78(%rsp)
movq 0x50(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
movl %ebp, %eax
imull %r12d, %eax
movslq %eax, %r15
movl $0x1, %eax
cmpl 0x44(%rsp), %ebp
movq %rbp, 0x80(%rsp)
jge 0x1641
movq 0x78(%rsp), %rcx
leaq (%rcx,%r15), %rdi
leal 0x1(%rbp), %eax
imull 0x10(%rsp), %eax
movslq %eax, %rsi
addq %rcx, %rsi
movq %rdi, %r12
movq %r14, %rdx
callq 0x1110
leal 0x2(%rbp), %ecx
testl %eax, %eax
je 0x15e9
movl $0x2, %eax
cmpl %ebx, %ecx
jge 0x1641
movslq %ecx, %rbp
movq %r14, %rbx
imulq %rbp, %rbx
addq 0x28(%rsp), %rbx
incq %rbp
movl $0x1, %eax
movq %r12, %rdi
movq %r14, %rdx
movq %rax, %r13
movq %rdi, %r12
movq %rbx, %rsi
callq 0x1110
testl %eax, %eax
je 0x163e
movq %r13, %rax
incl %eax
movq 0x68(%rsp), %r13
cmpq %r13, %rbp
jge 0x15e5
movq %r12, %rdi
addq %r14, %rdi
addq %r14, %rbx
incq %rbp
cmpl $0x7f, %eax
jb 0x15b0
incl %eax
jmp 0x1641
movl $0x2, %eax
cmpl %ebx, %ecx
jge 0x16bb
movslq %ecx, %r15
movq %r14, %rbx
imulq %r15, %rbx
addq 0x28(%rsp), %rbx
incq %r15
movl $0x2, %ebp
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1110
testl %eax, %eax
jne 0x16b9
leal 0x1(%rbp), %eax
cmpq %r13, %r15
jge 0x16bb
addq %r14, %rbx
incq %r15
cmpl $0x7f, %ebp
movl %eax, %ebp
jb 0x160d
jmp 0x16bb
movq %r13, %rax
movq %rax, %rbx
decl %eax
movb %al, 0xf(%rsp)
movq 0x58(%rsp), %rbp
movq 0x8(%rbp), %rdi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq *(%rbp)
movq %rbx, 0x38(%rsp)
testl %ebx, %ebx
movq 0x10(%rsp), %r12
movq 0x60(%rsp), %r13
jle 0x1697
movl 0x38(%rsp), %ebx
addq 0x28(%rsp), %r15
movq %rbp, %rdi
movl %r12d, %esi
movl %r13d, %edx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x56e5
addq %r14, %r15
decq %rbx
jne 0x167c
movq 0x68(%rsp), %r13
movq 0x38(%rsp), %rax
addl 0x80(%rsp), %eax
movl %eax, %ebp
movq 0x30(%rsp), %rbx
cmpl %ebx, %eax
jl 0x1540
jmp 0x16f8
movl %ebp, %eax
movq %rax, 0x38(%rsp)
addl $0x7f, %eax
movb %al, 0xe(%rsp)
movq 0x58(%rsp), %rbx
movq 0x8(%rbx), %rdi
leaq 0xe(%rsp), %rsi
movl $0x1, %edx
callq *(%rbx)
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq 0x60(%rsp), %rdx
xorl %ecx, %ecx
movq %r12, %r8
movq %rsi, %r12
callq 0x56e5
jmp 0x169c
movq 0x50(%rsp), %r12
subl 0x1c(%rsp), %r12d
cmpq $0x2, 0x70(%rsp)
jge 0x14f1
movl $0x1, %eax
jmp 0x1717
xorl %eax, %eax
addq $0x88, %rsp
jmp 0x1774
addl %ebp, %r10d
shll $0x3, %r10d
leal (,%rbp,8), %ebx
subq $0x8, %rsp
xorl %edx, %edx
leaq 0x9b91(%rip), %r11      # 0xb2cc
movq %r13, %rdi
movq 0x38(%rsp), %rcx
movl %r12d, %r8d
movq 0x18(%rsp), %r9
xorl %eax, %eax
pushq %rbx
pushq %r10
pushq %r12
pushq %rcx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %r14
pushq %rdx
pushq %rdx
pushq %r11
pushq %rdx
pushq %rbp
pushq 0xc8(%rsp)
pushq %rdx
callq 0x543d
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq