// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
movq %r8, 0x38(%rsp)
movl %ecx, %r15d
movl %esi, %ebp
leal -0x2(%r15), %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
movl %edx, %ecx
orl %ebp, %ecx
js 0x2613b
movl %edx, %ebx
movq %rdi, %r12
movb %al, %sil
orl $0x2, %esi
cmpl $0x0, 0x295b1(%rip)     # 0x4f404
je 0x26146
orl $0x8, %esi
addl %r13d, %r10d
shll $0x3, %r10d
leal (,%r13,8), %r11d
xorl %r14d, %r14d
movq %r12, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movl %esi, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %rbx
pushq %rbp
pushq %r14
pushq %r14
pushq %r14
pushq %r14
callq 0x38e85
addq $0x40, %rsp
movl 0x29642(%rip), %ecx     # 0x4f4dc
leal -0x1(%rbx), %edx
testl %ecx, %ecx
cmovnel %r14d, %edx
cmpl $0x1, %ecx
sbbl %r14d, %r14d
orl %ebx, %r14d
movl $0x1, %eax
movq %r14, 0x70(%rsp)
cmpl %r14d, %edx
je 0x2613d
movq %r12, 0x48(%rsp)
testl %ecx, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmoveq %rax, %rcx
movl %r15d, %eax
imull %ebp, %eax
leal -0x1(%rbp), %esi
movl %esi, 0x34(%rsp)
movslq %r15d, %r14
movslq %ebp, %r12
movl %edx, %esi
movq %rsi, 0x8(%rsp)
imull %eax, %edx
movq %rcx, 0x68(%rsp)
movl %eax, 0x2c(%rsp)
imull %eax, %ecx
movl %ecx, 0x30(%rsp)
movq %r13, 0x58(%rsp)
movq %rbp, 0x50(%rsp)
movq %r15, 0x18(%rsp)
movq %r12, 0x60(%rsp)
movslq %edx, %rdx
movq %rdx, 0x40(%rsp)
testl %ebp, %ebp
jle 0x26112
movl 0x2c(%rsp), %eax
imull 0x8(%rsp), %eax
movslq %eax, %rcx
movq 0x38(%rsp), %rax
addq %rax, %rcx
movq %rcx, 0x78(%rsp)
movq 0x40(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
movl %r13d, %eax
imull %r15d, %eax
movslq %eax, %r15
movl $0x1, %eax
cmpl 0x34(%rsp), %r13d
movq %r13, 0x80(%rsp)
jge 0x26056
movq 0x78(%rsp), %rcx
leaq (%rcx,%r15), %rdi
leal 0x1(%r13), %eax
imull 0x18(%rsp), %eax
movslq %eax, %rsi
addq %rcx, %rsi
movq %rdi, %rbx
movq %r14, %rdx
callq 0x6410
leal 0x2(%r13), %ecx
testl %eax, %eax
je 0x25ffb
movl $0x2, %eax
cmpl %ebp, %ecx
jge 0x26056
movslq %ecx, %r13
movq %r14, %rbp
imulq %r13, %rbp
addq 0x10(%rsp), %rbp
incq %r13
movl $0x1, %eax
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %r12
movq %rdi, %rbx
movq %rbp, %rsi
callq 0x6410
testl %eax, %eax
je 0x26053
movq %r12, %rax
incl %eax
movq 0x60(%rsp), %r12
cmpq %r12, %r13
jge 0x25ff7
movq %rbx, %rdi
addq %r14, %rdi
addq %r14, %rbp
incq %r13
cmpl $0x7f, %eax
jb 0x25fc2
incl %eax
jmp 0x26056
movl $0x2, %eax
cmpl %ebp, %ecx
jge 0x260d4
movslq %ecx, %r13
movq %r14, %r15
imulq %r13, %r15
addq 0x10(%rsp), %r15
incq %r13
movl $0x2, %ebp
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6410
testl %eax, %eax
jne 0x260d2
leal 0x1(%rbp), %eax
cmpq %r12, %r13
jge 0x260d4
addq %r14, %r15
incq %r13
cmpl $0x7f, %ebp
movl %eax, %ebp
jb 0x2601f
jmp 0x260d4
movq %r12, %rax
movq %rax, %rbx
decl %eax
movb %al, 0x7(%rsp)
movq 0x48(%rsp), %r13
movq 0x8(%r13), %rdi
leaq 0x7(%rsp), %rsi
movl $0x1, %edx
callq *(%r13)
movq %rbx, 0x20(%rsp)
testl %ebx, %ebx
movq 0x18(%rsp), %rbp
movq 0x58(%rsp), %r12
jle 0x260ac
movl 0x20(%rsp), %ebx
addq 0x10(%rsp), %r15
movq %r13, %rdi
movl %ebp, %esi
movl %r12d, %edx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x38d5a
addq %r14, %r15
decq %rbx
jne 0x26092
movq %rbp, %r15
movq 0x60(%rsp), %r12
movq 0x50(%rsp), %rbp
movq 0x20(%rsp), %rax
addl 0x80(%rsp), %eax
movl %eax, %r13d
cmpl %ebp, %eax
jl 0x25f4e
jmp 0x26112
movl %ebp, %eax
movq %rax, 0x20(%rsp)
addl $0x7f, %eax
movb %al, 0x6(%rsp)
movq 0x48(%rsp), %r15
movq 0x8(%r15), %rdi
leaq 0x6(%rsp), %rsi
movl $0x1, %edx
callq *(%r15)
movq %r15, %rdi
movq 0x18(%rsp), %r15
movl %r15d, %esi
movq 0x58(%rsp), %rdx
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x38d5a
jmp 0x260b4
movq 0x8(%rsp), %rax
addq 0x68(%rsp), %rax
movq 0x40(%rsp), %rdx
addl 0x30(%rsp), %edx
movq %rax, 0x8(%rsp)
cmpl %eax, 0x70(%rsp)
jne 0x25f15
movl $0x1, %eax
jmp 0x2613d
xorl %eax, %eax
addq $0x88, %rsp
jmp 0x26196
addl %r13d, %r10d
shll $0x3, %r10d
leal (,%r13,8), %r14d
subq $0x8, %rsp
xorl %edx, %edx
leaq 0x1a20f(%rip), %r11     # 0x40371
movq %r12, %rdi
movl %ebp, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
xorl %eax, %eax
pushq %r14
pushq %r10
pushq %rbx
pushq %rbp
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rdx
pushq %rsi
pushq %rdx
pushq %rdx
pushq %r11
pushq %rdx
pushq %r13
pushq 0xb8(%rsp)
pushq %rdx
callq 0x38a84
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq