// File: /workspace/github_cpp_makefile_star2_O2/alan0201tw[P]RayTracer/include/stb_image_write.h
// Function: stbi_write_tga_core(stbi__write_context*, int, int, int, void*)
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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r8, 0xc0(%rsp)
movl %ecx, %ebp
movl %edx, %r14d
movq %rdi, 0x90(%rsp)
leal -0x2(%rbp), %eax
xorl %ecx, %ecx
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
sete %cl
movl %ebp, %eax
movq %rcx, 0xa0(%rsp)
subl %ecx, %eax
xorl %r8d, %r8d
cmpl $0x2, %eax
setl %cl
orl %esi, %edx
js 0x21bbb
movl %esi, %r15d
movb %cl, %r8b
orl $0x2, %r8d
cmpl $0x0, 0x26b71(%rip)     # 0x48434
je 0x21bc4
orl $0x8, %r8d
movq 0xa0(%rsp), %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)
movl %r15d, 0x20(%rsp)
andl $0x0, (%rsp)
movl %eax, 0x30(%rsp)
xorl %ebx, %ebx
movq 0x90(%rsp), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x2d16d
movl 0x26c08(%rip), %eax     # 0x4852c
leal -0x1(%r14), %ecx
xorl %edx, %edx
testl %eax, %eax
setne %dl
cmovnel %ebx, %ecx
cmpl $0x1, %eax
sbbl %ebx, %ebx
orl %r14d, %ebx
leaq -0x1(,%rdx,2), %rdx
movl %ebp, %esi
imull %r15d, %esi
leal -0x1(%r15), %eax
movl %eax, 0xbc(%rsp)
movslq %ebp, %r13
movslq %r15d, %rax
movq %rax, 0xd0(%rsp)
movslq %ecx, %rcx
movslq %ebx, %rax
movq %rax, 0xe8(%rsp)
movl %ecx, %eax
imull %esi, %eax
movq %rdx, 0xe0(%rsp)
movl %esi, 0xb8(%rsp)
imull %esi, %edx
movq %rdx, 0xd8(%rsp)
pushq $0x1
popq %rdx
movq %rbp, 0xa8(%rsp)
movq %r15, 0x98(%rsp)
cmpq 0xe8(%rsp), %rcx
je 0x21bbd
movslq %eax, %rsi
movl 0xb8(%rsp), %eax
imull %ecx, %eax
movslq %eax, %rdi
movq 0xc0(%rsp), %rax
addq %rax, %rdi
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
addq %rax, %rsi
movq %rsi, 0xb0(%rsp)
xorl %esi, %esi
movq %rcx, 0x100(%rsp)
cmpl %r15d, %esi
jge 0x21b9c
movl %esi, %eax
imull %ebp, %eax
movslq %eax, %r12
movl %edx, %ebx
movq %rsi, 0xc8(%rsp)
cmpl 0xbc(%rsp), %esi
jge 0x21b4a
movq 0xf8(%rsp), %rcx
leaq (%rcx,%r12), %r14
movq 0xc8(%rsp), %rbx
leal 0x1(%rbx), %eax
imull %ebp, %eax
movslq %eax, %rsi
addq %rcx, %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x6460
leal 0x2(%rbx), %ecx
movslq %ecx, %r15
testl %eax, %eax
je 0x21a9a
movq %r13, %rbp
imulq %r15, %rbp
addq 0xb0(%rsp), %rbp
pushq $0x2
popq %rax
movl %eax, %ebx
cmpq 0xd0(%rsp), %r15
jge 0x21b37
cmpl $0x7f, %ebx
ja 0x21b37
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x6460
testl %eax, %eax
je 0x21b35
addq %r13, %r14
incl %ebx
incq %r15
addq %r13, %rbp
jmp 0x21a60
movq %r13, %r12
imulq %r15, %r12
addq 0xb0(%rsp), %r12
pushq $0x2
popq %rax
movl %eax, %ebx
cmpq 0xd0(%rsp), %r15
jge 0x21ad9
cmpl $0x7f, %ebx
ja 0x21ad9
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x6460
testl %eax, %eax
jne 0x21ad9
incl %ebx
incq %r15
addq %r13, %r12
jmp 0x21aae
leal 0x7f(%rbx), %eax
movb %al, 0x8e(%rsp)
movq 0x90(%rsp), %r15
movq 0x8(%r15), %rdi
leaq 0x8e(%rsp), %rsi
pushq $0x1
popq %rdx
callq *(%r15)
movq %r15, %rdi
movl %ebp, %esi
movq 0xa0(%rsp), %rdx
xorl %ecx, %ecx
movq %r14, %r8
callq 0x2d076
movq 0x98(%rsp), %r15
addl 0xc8(%rsp), %ebx
movl %ebx, %esi
movq 0x100(%rsp), %rcx
pushq $0x1
popq %rdx
jmp 0x219ef
decl %ebx
movq 0xa8(%rsp), %rbp
movq 0x98(%rsp), %r15
pushq $0x1
popq %rdx
leal -0x1(%rbx), %eax
movb %al, 0x8f(%rsp)
movq 0x90(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x8f(%rsp), %rsi
callq *(%rax)
movl %ebx, %r14d
addq 0xb0(%rsp), %r12
subq $0x1, %r14
jb 0x21b1c
movq 0x90(%rsp), %rdi
movl %ebp, %esi
movq 0xa0(%rsp), %rdx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x2d076
addq %r13, %r12
jmp 0x21b75
addq 0xe0(%rsp), %rcx
movq 0xd8(%rsp), %rax
movq 0xf0(%rsp), %rsi
addl %esi, %eax
jmp 0x219a1
xorl %edx, %edx
movl %edx, %eax
jmp 0x21c53
movq 0xa0(%rsp), %rdx
addl %edx, %eax
shll $0x3, %eax
leal (,%rdx,8), %ecx
movl %ecx, 0x80(%rsp)
movl %r14d, 0x70(%rsp)
andl $0x0, 0x60(%rsp)
movl %r15d, 0x68(%rsp)
andl $0x0, 0x58(%rsp)
movl %r8d, 0x38(%rsp)
andl $0x0, 0x50(%rsp)
leaq 0x12675(%rip), %rcx     # 0x34279
andl $0x0, 0x48(%rsp)
movq %rcx, 0x20(%rsp)
andl $0x0, 0x40(%rsp)
movl %edx, 0x10(%rsp)
andl $0x0, 0x30(%rsp)
movq 0xc0(%rsp), %rcx
movq %rcx, 0x8(%rsp)
andl $0x0, 0x28(%rsp)
movl %eax, 0x78(%rsp)
andl $0x0, 0x18(%rsp)
andl $0x0, (%rsp)
movq 0x90(%rsp), %rdi
movl %r15d, %ecx
movl %r14d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x2cdb8
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq