// File: /workspace/github_c_makefile_star2_O3/ggerganov[P]font-rasterizer/./stb_image_write.h
// Function: stbiw__encode_png_line
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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rax
movq 0x18(%rbp), %rdi
movslq 0x10(%rbp), %r10
testl %r8d, %r8d
leaq 0xa815(%rip), %r11      # 0xd220
leaq 0xa7ee(%rip), %rbx      # 0xd200
cmoveq %r11, %rbx
movl (%rbx,%r10,4), %r11d
movl %r8d, %ebx
notl %ebx
addl %ecx, %ebx
movl %esi, %r10d
negl %r10d
cmpl $0x0, 0xf702(%rip)      # 0x12130
cmovel %r8d, %ebx
cmovel %esi, %r10d
imull %esi, %ebx
movslq %ebx, %rcx
movq %rcx, -0x30(%rbp)
leaq (%rax,%rcx), %rsi
testl %r11d, %r11d
je 0x2af5
testl %r9d, %r9d
jle 0x2aa9
movslq %r10d, %r14
movl %r9d, %r8d
movq -0x30(%rbp), %rbx
subq %r14, %rbx
addq %rax, %rbx
xorl %r14d, %r14d
leal -0x1(%r11), %r15d
leaq 0xa5a0(%rip), %r12      # 0xd010
cmpl $0x5, %r15d
ja 0x2aa1
movslq (%r12,%r15,4), %r13
addq %r12, %r13
jmpq *%r13
movb (%rsi,%r14), %r13b
jmp 0x2a9d
movb (%rsi,%r14), %r13b
subb (%rbx,%r14), %r13b
jmp 0x2a9d
movb (%rsi,%r14), %r13b
movb (%rbx,%r14), %cl
shrb %cl
subb %cl, %r13b
movb %r13b, (%rdi,%r14)
incq %r14
cmpq %r14, %r8
jne 0x2a70
decl %r11d
cmpl $0x5, %r11d
ja 0x2c94
leaq 0xa56b(%rip), %rcx      # 0xd028
movslq (%rcx,%r11,4), %r8
addq %rcx, %r8
jmpq *%r8
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x2c94
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 0x2ada
jmp 0x2c94
imull %edx, %r9d
movslq %r9d, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1150
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x2c94
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 0x2b1e
jmp 0x2c94
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x2c94
movslq %r9d, %rcx
movslq %r10d, %r8
movslq %edx, %rdx
negq %r8
movq -0x30(%rbp), %r9
addq %rcx, %r9
addq %r9, %rax
addq %rcx, %rdi
subq %rcx, %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 0x2b6b
jmp 0x2c94
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x2c94
movslq %r9d, %rcx
movslq %r10d, %r9
movslq %edx, %rdx
movq -0x30(%rbp), %r13
leaq (%rcx,%r13), %r10
subq %r9, %r13
addq %rax, %r13
movq %r10, %r8
subq %r9, %r8
addq %rax, %r8
addq %r10, %rax
addq %rcx, %rdi
subq %rcx, %rdx
xorl %r9d, %r9d
movzbl (%rsi,%r9), %r10d
movzbl (%r8,%r9), %ebx
movzbl (%r13,%r9), %r11d
leal (%rbx,%r10), %ecx
subl %r11d, %ecx
movl %ecx, %r15d
subl %r10d, %r15d
movl %r15d, %r14d
negl %r14d
cmovsl %r15d, %r14d
movl %ecx, %r12d
subl %ebx, %r12d
movl %r12d, %r15d
negl %r15d
cmovsl %r12d, %r15d
subl %r11d, %ecx
movl %ecx, %r12d
negl %r12d
cmovsl %ecx, %r12d
cmpl %r12d, %r15d
ja 0x2c1a
movl %ebx, %r11d
movb (%rax,%r9), %cl
cmpl %r12d, %r14d
cmoval %r11d, %r10d
cmpl %r15d, %r14d
cmoval %r11d, %r10d
subb %r10b, %cl
movb %cl, (%rdi,%r9)
incq %r9
cmpq %r9, %rdx
jne 0x2bce
jmp 0x2c94
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x2c94
movslq %r9d, %r8
movslq %r10d, %rcx
movslq %edx, %rdx
movq -0x30(%rbp), %r9
subq %rcx, %r9
addq %r9, %rax
movb (%rsi,%r8), %cl
subb (%rax,%r8), %cl
movb %cl, (%rdi,%r8)
incq %r8
cmpq %r8, %rdx
jne 0x2c59
jmp 0x2c94
imull %r9d, %edx
cmpl %r9d, %edx
jle 0x2c94
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 0x2c7e
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq