// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x5993a
leaq 0x56d1c(%rip), %rax     # 0xb0650
movq %rax, -0x48(%rbp)
jmp 0x59947
leaq 0x56d2f(%rip), %rax     # 0xb0670
movq %rax, -0x48(%rbp)
jmp 0x59947
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movslq 0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, 0x571ca(%rip)     # 0xb0b3c
je 0x59982
movl -0x14(%rbp), %eax
subl $0x1, %eax
subl -0x18(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0x59988
movl -0x18(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movl -0x4c(%rbp), %ecx
movl -0x5c(%rbp), %edx
imull %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, 0x57196(%rip)     # 0xb0b3c
je 0x599b2
xorl %eax, %eax
subl -0xc(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x599b8
movl -0xc(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x599e0
movq 0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x10(%rbp), %eax
imull -0x1c(%rbp), %eax
movslq %eax, %rdx
callq 0x7400
jmp 0x59d79
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x59b17
movl -0x30(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x68(%rbp)
subl $0x5, %eax
ja 0x59b07
movq -0x68(%rbp), %rax
leaq 0x25836(%rip), %rcx     # 0x7f248
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x59b07
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl -0x3c(%rbp), %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x59b07
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl -0x3c(%rbp), %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
sarl %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x59b07
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x6c(%rbp)
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %esi
xorl %edx, %edx
movl %edx, %edi
callq 0x72c70
movb %al, %cl
movl -0x6c(%rbp), %eax
movzbl %cl, %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x59b07
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x59b07
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x59b09
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x599e7
movl -0x30(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x78(%rbp)
subl $0x5, %eax
ja 0x59d79
movq -0x78(%rbp), %rax
leaq 0x256fa(%rip), %rcx     # 0x7f230
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x10(%rbp), %ecx
imull -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x59b8a
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl -0x1c(%rbp), %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x59b45
jmp 0x59d79
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x10(%rbp), %ecx
imull -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x59bda
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl -0x3c(%rbp), %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x59b95
jmp 0x59d79
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x10(%rbp), %ecx
imull -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x59c3f
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl -0x1c(%rbp), %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
movq -0x38(%rbp), %rdx
movl -0x2c(%rbp), %esi
subl -0x3c(%rbp), %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
addl %edx, %ecx
sarl %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x59be5
jmp 0x59d79
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x10(%rbp), %ecx
imull -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x59cc4
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x7c(%rbp)
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edi
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %esi
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl -0x3c(%rbp), %ecx
subl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
callq 0x72c70
movb %al, %cl
movl -0x7c(%rbp), %eax
movzbl %cl, %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x59c4a
jmp 0x59d79
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x10(%rbp), %ecx
imull -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x59d16
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %edx
subl -0x1c(%rbp), %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
sarl %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x59ccf
jmp 0x59d79
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x10(%rbp), %ecx
imull -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x59d77
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x80(%rbp)
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edi
xorl %edx, %edx
movl %edx, %esi
callq 0x72c70
movb %al, %cl
movl -0x80(%rbp), %eax
movzbl %cl, %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x59d1e
jmp 0x59d79
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)