// File: alan0201tw[P]RayTracer/include/stb_image_write.h
// Function: stbiw__write_pixel(stbi__write_context*, int, int, int, int, unsigned char*)
static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write_alpha, int expand_mono, unsigned char *d)
{
   unsigned char bg[3] = { 255, 0, 255}, px[3];
   int k;

   if (write_alpha < 0)
      s->func(s->context, &d[comp - 1], 1);

   switch (comp) {
      case 2: // 2 pixels = mono + alpha, alpha is written separately, so same as 1-channel case
      case 1:
         if (expand_mono)
            stbiw__write3(s, d[0], d[0], d[0]); // monochrome bmp
         else
            s->func(s->context, d, 1);  // monochrome TGA
         break;
      case 4:
         if (!write_alpha) {
            // composite against pink background
            for (k = 0; k < 3; ++k)
               px[k] = bg[k] + ((d[k] - bg[k]) * d[3]) / 255;
            stbiw__write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]);
            break;
         }
         /* FALLTHROUGH */
      case 3:
         stbiw__write3(s, d[1 - rgb_dir], d[1], d[1 + rgb_dir]);
         break;
   }
   if (write_alpha > 0)
      s->func(s->context, &d[comp - 1], 1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq %r9, -0x20(%rbp)
movw 0xd64c(%rip), %ax       # 0x7f960
movw %ax, -0x23(%rbp)
movb 0xd644(%rip), %al       # 0x7f962
movb %al, -0x21(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x7234d
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x20(%rbp), %rsi
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addq %rcx, %rsi
movl $0x1, %edx
callq *%rax
movl -0x10(%rbp), %eax
movl %eax, -0x30(%rbp)
decl %eax
subl $0x2, %eax
jb 0x72377
jmp 0x7235c
movl -0x30(%rbp), %eax
subl $0x3, %eax
je 0x7245a
jmp 0x7236a
movl -0x30(%rbp), %eax
subl $0x4, %eax
je 0x723c0
jmp 0x72495
cmpl $0x0, -0x18(%rbp)
je 0x723a1
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movb (%rax), %dl
movq -0x20(%rbp), %rax
movb (%rax), %cl
movq -0x20(%rbp), %rax
movzbl %dl, %esi
movzbl %cl, %edx
movzbl (%rax), %ecx
callq 0x724d0
jmp 0x723bb
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x20(%rbp), %rsi
movl $0x1, %edx
callq *%rax
jmp 0x72495
cmpl $0x0, -0x14(%rbp)
jne 0x72458
movl $0x0, -0x2c(%rbp)
cmpl $0x3, -0x2c(%rbp)
jge 0x72429
movslq -0x2c(%rbp), %rax
movzbl -0x23(%rbp,%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movslq -0x2c(%rbp), %rcx
movzbl -0x23(%rbp,%rcx), %ecx
subl %ecx, %eax
movq -0x20(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
imull %ecx, %eax
movl $0xff, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x34(%rbp), %eax
addl %ecx, %eax
movb %al, %cl
movslq -0x2c(%rbp), %rax
movb %cl, -0x26(%rbp,%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x723d1
movq -0x8(%rbp), %rdi
movl $0x1, %eax
subl -0xc(%rbp), %eax
cltq
movb -0x26(%rbp,%rax), %dl
movb -0x25(%rbp), %cl
movl -0xc(%rbp), %eax
addl $0x1, %eax
cltq
movzbl %dl, %esi
movzbl %cl, %edx
movzbl -0x26(%rbp,%rax), %ecx
callq 0x724d0
jmp 0x72495
jmp 0x7245a
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl $0x1, %ecx
subl -0xc(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %sil
movq -0x20(%rbp), %rax
movb 0x1(%rax), %dl
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl %sil, %esi
movzbl %dl, %edx
movzbl (%rax,%rcx), %ecx
callq 0x724d0
cmpl $0x0, -0x14(%rbp)
jle 0x724c1
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x20(%rbp), %rsi
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addq %rcx, %rsi
movl $0x1, %edx
callq *%rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)