// File: /workspace/github_cpp_makefile_star2_O1/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 $0x98, %rsp
movq %r8, 0x60(%rsp)
movl %edx, %ebx
movl %esi, %r15d
leal -0x2(%rcx), %eax
xorl %r13d, %r13d
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
sete %r13b
movl %ecx, %r10d
subl %r13d, %r10d
xorl %esi, %esi
cmpl $0x2, %r10d
setl %al
orl %r15d, %edx
js 0x26aa3
movq %rdi, %rbp
movq %rcx, 0x30(%rsp)
movb %al, %sil
orl $0x2, %esi
cmpl $0x0, 0x28cce(%rip)     # 0x4f404
je 0x26aae
orl $0x8, %esi
addl %r13d, %r10d
shll $0x3, %r10d
leal (,%r13,8), %r11d
xorl %r14d, %r14d
movq %rbp, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movl %esi, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %rbx
pushq %r15
pushq %r14
pushq %r14
pushq %r14
pushq %r14
callq 0x39186
addq $0x40, %rsp
movl 0x28d7e(%rip), %ecx     # 0x4f4fc
leal -0x1(%rbx), %edx
testl %ecx, %ecx
cmovnel %r14d, %edx
cmpl $0x1, %ecx
sbbl %r14d, %r14d
orl %ebx, %r14d
movl $0x1, %eax
movq %r14, 0x80(%rsp)
cmpl %r14d, %edx
je 0x26aa5
testl %ecx, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmoveq %rax, %rcx
movq 0x30(%rsp), %r14
movl %r14d, %eax
imull %r15d, %eax
leal -0x1(%r15), %esi
movl %esi, 0x5c(%rsp)
movslq %r14d, %rsi
movq %rsi, 0x38(%rsp)
movslq %r15d, %rsi
movq %rsi, 0x70(%rsp)
movl %edx, %esi
movq %rsi, 0x40(%rsp)
imull %eax, %edx
movq %rcx, 0x78(%rsp)
movl %eax, 0x54(%rsp)
imull %eax, %ecx
movl %ecx, 0x58(%rsp)
movq %r13, 0x20(%rsp)
movq %r15, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
movslq %edx, %rdx
movq %rdx, 0x68(%rsp)
testl %r15d, %r15d
jle 0x26a77
movl 0x54(%rsp), %eax
imull 0x40(%rsp), %eax
movslq %eax, %rdx
movq 0x60(%rsp), %rax
addq %rax, %rdx
movq 0x68(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
xorl %ecx, %ecx
movq %rdx, 0x88(%rsp)
movl %ecx, %eax
imull %r14d, %eax
movslq %eax, %rbx
leaq (%rdx,%rbx), %r12
cmpl 0x5c(%rsp), %ecx
movq %rcx, 0x90(%rsp)
jge 0x268fb
leal 0x1(%rcx), %eax
imull %r14d, %eax
movslq %eax, %rsi
addq %rdx, %rsi
movq %r12, %rdi
movq 0x38(%rsp), %rdx
movq %rcx, %r14
callq 0x6410
leal 0x2(%r14), %ecx
testl %eax, %eax
je 0x26902
cmpl %r15d, %ecx
jge 0x26975
movslq %ecx, %r13
movq 0x38(%rsp), %r15
movq %r15, %rbp
imulq %r13, %rbp
addq 0x48(%rsp), %rbp
incq %r13
movl $0x1, %edx
movq %r12, 0x28(%rsp)
movq %r12, %r14
movq %rdx, %r12
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x6410
testl %eax, %eax
je 0x26a3d
movq %r12, %rdx
incl %edx
cmpq 0x70(%rsp), %r13
jge 0x268e3
addq %r15, %r14
addq %r15, %rbp
incq %r13
cmpl $0x7f, %edx
jb 0x268b0
incl %edx
xorl %eax, %eax
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rbp
jmp 0x26a51
movl $0x1, %edx
jmp 0x2697a
movb $0x1, %al
movl $0x2, %edx
cmpl %r15d, %ecx
jge 0x2697c
movq %r12, %r14
movslq %ecx, %r13
movq 0x38(%rsp), %r15
movq %r15, %rbp
imulq %r13, %rbp
addq 0x48(%rsp), %rbp
incq %r13
movl $0x2, %r12d
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x6410
testl %eax, %eax
jne 0x26a5b
leal 0x1(%r12), %eax
cmpq 0x70(%rsp), %r13
jge 0x2695f
addq %r15, %rbp
incq %r13
cmpl $0x7f, %r12d
movl %eax, %r12d
jb 0x2692e
movl %eax, %edx
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rbp
jmp 0x26a6d
movl $0x2, %edx
xorl %eax, %eax
testb %al, %al
je 0x269b5
leal 0x7f(%rdx), %eax
movb %al, 0xe(%rsp)
movq 0x8(%rbp), %rdi
leaq 0xe(%rsp), %rsi
movq %rdx, %rbx
movl $0x1, %edx
callq *(%rbp)
movq %rbp, %rdi
movq 0x30(%rsp), %r14
movl %r14d, %esi
movl %r13d, %edx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x39076
jmp 0x26a21
leal -0x1(%rdx), %eax
movb %al, 0xf(%rsp)
movq 0x8(%rbp), %rdi
leaq 0xf(%rsp), %rsi
movq %rdx, %r14
movl $0x1, %edx
callq *(%rbp)
movq %r14, 0x28(%rsp)
testl %r14d, %r14d
movq %r13, %r15
movq %rbp, %r13
movq 0x30(%rsp), %rbp
movq 0x38(%rsp), %r12
jle 0x26a0e
movl 0x28(%rsp), %r14d
addq 0x48(%rsp), %rbx
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x39076
addq %r12, %rbx
decq %r14
jne 0x269f4
movq %rbp, %r14
movq %r13, %rbp
movq %r15, %r13
movq 0x10(%rsp), %r15
movq 0x28(%rsp), %rbx
addl 0x90(%rsp), %ebx
movl %ebx, %ecx
cmpl %r15d, %ebx
movq 0x88(%rsp), %rdx
jl 0x2683f
jmp 0x26a77
xorl %eax, %eax
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rbp
movq %r12, %rdx
movq 0x28(%rsp), %r12
jmp 0x2697c
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rbp
movq %r12, %rdx
movq %r14, %r12
movb $0x1, %al
jmp 0x2697c
movq 0x40(%rsp), %rax
addq 0x78(%rsp), %rax
movq 0x68(%rsp), %rdx
addl 0x58(%rsp), %edx
movq %rax, 0x40(%rsp)
cmpl %eax, 0x80(%rsp)
jne 0x26803
movl $0x1, %eax
jmp 0x26aa5
xorl %eax, %eax
addq $0x98, %rsp
jmp 0x26b02
addl %r13d, %r10d
shll $0x3, %r10d
leal (,%r13,8), %r14d
subq $0x8, %rsp
xorl %edx, %edx
leaq 0x19643(%rip), %r11     # 0x4010d
movq %rbp, %rdi
movl %r15d, %ecx
movl %ebx, %r8d
movq 0x38(%rsp), %r9
xorl %eax, %eax
pushq %r14
pushq %r10
pushq %rbx
pushq %r15
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rsi
pushq %rdx
pushq %rdx
pushq %r11
pushq %rdx
pushq %r13
pushq 0xe0(%rsp)
pushq %rdx
callq 0x38d9d
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq