// File: /workspace/github_cpp_makefile_star2_O2/alan0201tw[P]RayTracer/include/stb_image_write.h
// Function: stbiw__encode_png_line(unsigned char*, int, int, int, int, int, int, signed char*)
static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int width, int height, int y, int n, int filter_type, signed char *line_buffer)
{
   static int mapping[] = { 0,1,2,3,4 };
   static int firstmap[] = { 0,1,0,5,6 };
   int *mymap = (y != 0) ? mapping : firstmap;
   int i;
   int type = mymap[filter_type];
   unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y);
   int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;
    
   if (type==0) {
      memcpy(line_buffer, z, width*n);
      return;
   }

   // first loop isn't optimized since it's just one pixel    
   for (i = 0; i < n; ++i) {
      switch (type) {
         case 1: line_buffer[i] = z[i]; break;
         case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;
         case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break;
         case 4: line_buffer[i] = (signed char) (z[i] - stbiw__paeth(0,z[i-signed_stride],0)); break;
         case 5: line_buffer[i] = z[i]; break;
         case 6: line_buffer[i] = z[i]; break;
      }
   }
   switch (type) {
      case 1: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-n]; break;
      case 2: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-signed_stride]; break;
      case 3: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break;
      case 4: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break;
      case 5: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - (z[i-n]>>1); break;
      case 6: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break;
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r10
movq 0x78(%rsp), %rdi
movslq 0x70(%rsp), %rax
testl %r8d, %r8d
leaq 0xf012(%rip), %r11      # 0x31d50
leaq 0xefeb(%rip), %rbx      # 0x31d30
cmoveq %r11, %rbx
movl (%rbx,%rax,4), %ebp
movl 0x257da(%rip), %eax     # 0x4852c
movl %r8d, %r11d
notl %r11d
addl %ecx, %r11d
testl %eax, %eax
cmovel %r8d, %r11d
imull %esi, %r11d
movslq %r11d, %rcx
leaq (%r10,%rcx), %r14
testl %ebp, %ebp
je 0x22e6a
movq %rcx, 0x18(%rsp)
movl %edx, 0xc(%rsp)
movq %r10, 0x28(%rsp)
movl %esi, %ecx
negl %ecx
testl %eax, %eax
cmovel %esi, %ecx
movslq %ecx, %rcx
xorl %r12d, %r12d
testl %r9d, %r9d
movl $0x0, %r13d
movl %r9d, 0x8(%rsp)
cmovgl %r9d, %r13d
movq %r14, %r15
movq %rcx, 0x10(%rsp)
subq %rcx, %r15
decl %ebp
leaq 0xe7c9(%rip), %rcx      # 0x31580
movq %rdi, 0x20(%rsp)
movq %r14, 0x30(%rsp)
cmpq %r12, %r13
je 0x22e1d
cmpl $0x5, %ebp
ja 0x22e18
movslq (%rcx,%rbp,4), %rax
addq %rcx, %rax
jmpq *%rax
movb (%r14,%r12), %bl
jmp 0x22e14
movb (%r14,%r12), %bl
movzbl (%r15,%r12), %esi
xorl %edi, %edi
xorl %edx, %edx
movq %rcx, %r14
callq 0x2d29a
movq %r14, %rcx
movq 0x30(%rsp), %r14
movq 0x20(%rsp), %rdi
jmp 0x22e12
movb (%r14,%r12), %bl
subb (%r15,%r12), %bl
jmp 0x22e14
movb (%r14,%r12), %bl
movb (%r15,%r12), %al
shrb %al
subb %al, %bl
movb %bl, (%rdi,%r12)
incq %r12
jmp 0x22dc1
cmpl $0x5, %ebp
movq 0x28(%rsp), %r13
ja 0x22fd3
leaq 0xe766(%rip), %rax      # 0x31598
movslq (%rax,%rbp,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
xorl %edx, %edx
cmpq %rcx, %rax
jge 0x22fd3
movb (%r14,%rax), %sil
subb (%r14,%rdx), %sil
movb %sil, (%rdi,%rax)
incq %rax
incq %rdx
jmp 0x22e4d
imull %edx, %r9d
movslq %r9d, %rdx
movq %r14, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6360
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
xorl %edx, %edx
cmpq %rcx, %rax
jge 0x22fd3
movb (%r14,%rax), %sil
movb (%r14,%rdx), %r8b
shrb %r8b
subb %r8b, %sil
movb %sil, (%rdi,%rax)
incq %rax
incq %rdx
jmp 0x22e99
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
movq %rax, %rdx
subq 0x10(%rsp), %rdx
xorl %esi, %esi
leaq (%rax,%rsi), %r8
cmpq %rcx, %r8
jge 0x22fd3
movb (%r14,%rax), %r10b
movzbl (%r14), %r8d
movzbl (%r14,%rdx), %r9d
addl %r8d, %r9d
shrl %r9d
subb %r9b, %r10b
movb %r10b, (%rdi,%rax)
incq %r14
incq %rdi
incq %rsi
jmp 0x22ed6
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %ecx
imull %ecx, %eax
movslq %ecx, %r15
movslq %eax, %r12
movq 0x18(%rsp), %rax
addq %r15, %rax
addq %rax, %r13
negq 0x10(%rsp)
cmpq %r12, %r15
jge 0x22fd3
movb (%r13), %bl
movzbl (%r14), %edi
movq 0x10(%rsp), %rax
movzbl (%r13,%rax), %esi
movzbl (%r14,%rax), %edx
callq 0x2d29a
subb %al, %bl
movq 0x20(%rsp), %rax
movb %bl, (%rax,%r15)
incq %r15
incq %r13
incq %r14
jmp 0x22f29
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
movq 0x18(%rsp), %rdx
addq %rax, %rdx
addq %rdx, %r13
addq %rax, %rdi
negq 0x10(%rsp)
movq 0x10(%rsp), %rsi
cmpq %rcx, %rax
jge 0x22fd3
movb (%r13), %dl
subb (%r13,%rsi), %dl
movb %dl, (%rdi)
incq %rax
incq %r13
incq %rdi
jmp 0x22f8d
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
xorl %edx, %edx
cmpq %rcx, %rax
jge 0x22fd3
movb (%r14,%rax), %sil
subb (%r14,%rdx), %sil
movb %sil, (%rdi,%rax)
incq %rax
incq %rdx
jmp 0x22fba
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq