// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, %rax
movq 0x40(%rsp), %rdi
movslq 0x38(%rsp), %r10
testl %r8d, %r8d
leaq 0x15d64(%rip), %r11     # 0x3dbe0
leaq 0x15d3d(%rip), %rbx     # 0x3dbc0
cmoveq %r11, %rbx
movl (%rbx,%r10,4), %r11d
movl %r8d, %ebx
notl %ebx
addl %ecx, %ebx
movl %esi, %r10d
negl %r10d
cmpl $0x0, 0x2765d(%rip)     # 0x4f4fc
cmovel %r8d, %ebx
cmovel %esi, %r10d
imull %esi, %ebx
movslq %ebx, %rcx
leaq (%rax,%rcx), %rsi
testl %r11d, %r11d
je 0x27f62
testl %r9d, %r9d
jle 0x27f16
movslq %r10d, %r14
movl %r9d, %r8d
movq %rcx, %rbx
subq %r14, %rbx
addq %rax, %rbx
xorl %r14d, %r14d
leal -0x1(%r11), %r15d
leaq 0x15544(%rip), %r12     # 0x3d420
cmpl $0x5, %r15d
ja 0x27f0e
movslq (%r12,%r15,4), %r13
addq %r12, %r13
jmpq *%r13
movb (%rsi,%r14), %bpl
jmp 0x27f0a
movb (%rsi,%r14), %bpl
subb (%rbx,%r14), %bpl
jmp 0x27f0a
movb (%rsi,%r14), %bpl
movb (%rbx,%r14), %r13b
shrb %r13b
subb %r13b, %bpl
movb %bpl, (%rdi,%r14)
incq %r14
cmpq %r14, %r8
jne 0x27edc
decl %r11d
cmpl $0x5, %r11d
ja 0x280f3
leaq 0x1550e(%rip), %r8      # 0x3d438
movslq (%r8,%r11,4), %r11
addq %r8, %r11
jmpq *%r11
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x280f3
movslq %r9d, %rax
movslq %edx, %rcx
movb (%rsi,%rax), %dl
subb (%rsi), %dl
movb %dl, (%rdi,%rax)
incq %rsi
incq %rdi
decq %rcx
cmpq %rcx, %rax
jne 0x27f47
jmp 0x280f3
imull %edx, %r9d
movslq %r9d, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6330
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x280f3
movslq %r9d, %rax
movslq %edx, %rcx
movb (%rsi,%rax), %dl
movb (%rsi), %r8b
shrb %r8b
subb %r8b, %dl
movb %dl, (%rdi,%rax)
incq %rsi
incq %rdi
decq %rcx
cmpq %rcx, %rax
jne 0x27f8b
jmp 0x280f3
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x280f3
movslq %r9d, %r9
movslq %r10d, %r8
movslq %edx, %rdx
negq %r8
addq %r9, %rcx
addq %rcx, %rax
addq %r9, %rdi
subq %r9, %rdx
xorl %ecx, %ecx
movb (%rax), %r9b
movzbl (%rsi,%rcx), %r10d
movzbl (%rax,%r8), %r11d
addl %r10d, %r11d
shrl %r11d
subb %r11b, %r9b
movb %r9b, (%rdi,%rcx)
incq %rax
incq %rcx
cmpq %rcx, %rdx
jne 0x27fd4
jmp 0x280f3
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x280f3
movslq %r9d, %r9
movslq %r10d, %r10
movslq %edx, %rdx
leaq (%r9,%rcx), %r11
subq %r10, %rcx
addq %rax, %rcx
movq %r11, %r8
subq %r10, %r8
addq %rax, %r8
addq %r11, %rax
addq %r9, %rdi
subq %r9, %rdx
xorl %r9d, %r9d
movzbl (%rsi,%r9), %r10d
movzbl (%r8,%r9), %ebx
movzbl (%rcx,%r9), %r11d
leal (%rbx,%r10), %r12d
subl %r11d, %r12d
movl %r12d, %r14d
subl %r10d, %r14d
movl %r14d, %ebp
negl %ebp
cmovsl %r14d, %ebp
movl %r12d, %r15d
subl %ebx, %r15d
movl %r15d, %r14d
negl %r14d
cmovsl %r15d, %r14d
subl %r11d, %r12d
movl %r12d, %r15d
negl %r15d
cmovsl %r12d, %r15d
cmpl %r15d, %r14d
ja 0x2807d
movl %ebx, %r11d
movb (%rax,%r9), %bl
cmpl %r15d, %ebp
cmoval %r11d, %r10d
cmpl %r14d, %ebp
cmoval %r11d, %r10d
subb %r10b, %bl
movb %bl, (%rdi,%r9)
incq %r9
cmpq %r9, %rdx
jne 0x28033
jmp 0x280f3
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x280f3
movslq %r9d, %r8
movslq %r10d, %r9
movslq %edx, %rdx
subq %r9, %rcx
addq %rcx, %rax
movb (%rsi,%r8), %cl
subb (%rax,%r8), %cl
movb %cl, (%rdi,%r8)
incq %r8
cmpq %r8, %rdx
jne 0x280b8
jmp 0x280f3
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x280f3
movslq %r9d, %rax
movslq %edx, %rcx
movb (%rsi,%rax), %dl
subb (%rsi), %dl
movb %dl, (%rdi,%rax)
incq %rsi
incq %rdi
decq %rcx
cmpq %rcx, %rax
jne 0x280dd
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq