// File: /workspace/github_c_makefile_star2_O2/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
subq $0x38, %rsp
movq %rdi, %r10
movq 0x18(%rbp), %rdi
movslq 0x10(%rbp), %rax
testl %r8d, %r8d
leaq 0x9872(%rip), %r11      # 0xc220
leaq 0x984b(%rip), %rbx      # 0xc200
cmoveq %r11, %rbx
movl (%rbx,%rax,4), %r13d
movl 0xf76d(%rip), %eax      # 0x12130
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 %r13d, %r13d
je 0x2adb
movq %rcx, -0x40(%rbp)
movl %edx, -0x30(%rbp)
movq %r10, -0x50(%rbp)
movl %esi, %ecx
negl %ecx
testl %eax, %eax
cmovel %esi, %ecx
movslq %ecx, %rcx
xorl %r12d, %r12d
testl %r9d, %r9d
movl $0x0, %r15d
movl %r9d, -0x2c(%rbp)
cmovgl %r9d, %r15d
movq %r14, %rdx
movq %rcx, -0x38(%rbp)
subq %rcx, %rdx
decl %r13d
leaq 0x95eb(%rip), %rcx      # 0xc010
movq %rdi, -0x48(%rbp)
movq %r14, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
cmpq %r12, %r15
je 0x2a90
cmpl $0x5, %r13d
ja 0x2a8b
movslq (%rcx,%r13,4), %rax
addq %rcx, %rax
jmpq *%rax
movb (%r14,%r12), %bl
jmp 0x2a87
movb (%r14,%r12), %bl
movzbl (%rdx,%r12), %esi
xorl %edi, %edi
xorl %edx, %edx
movq %rcx, %r14
callq 0x983e
movq %r14, %rcx
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %r14
movq -0x48(%rbp), %rdi
jmp 0x2a85
movb (%r14,%r12), %bl
subb (%rdx,%r12), %bl
jmp 0x2a87
movb (%r14,%r12), %bl
movb (%rdx,%r12), %al
shrb %al
subb %al, %bl
movb %bl, (%rdi,%r12)
incq %r12
jmp 0x2a31
cmpl $0x5, %r13d
movq -0x50(%rbp), %rsi
ja 0x2c33
leaq 0x9583(%rip), %rax      # 0xc028
movslq (%rax,%r13,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
xorl %edx, %edx
cmpq %rcx, %rax
jge 0x2c33
movb (%r14,%rax), %sil
subb (%r14,%rdx), %sil
movb %sil, (%rdi,%rax)
incq %rax
incq %rdx
jmp 0x2abe
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 0x1150
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
xorl %edx, %edx
cmpq %rcx, %rax
jge 0x2c33
movb (%r14,%rax), %sil
movb (%r14,%rdx), %r8b
shrb %r8b
subb %r8b, %sil
movb %sil, (%rdi,%rax)
incq %rax
incq %rdx
jmp 0x2b08
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
movq %rax, %rdx
subq -0x38(%rbp), %rdx
xorl %esi, %esi
leaq (%rax,%rsi), %r8
cmpq %rcx, %r8
jge 0x2c33
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 0x2b42
movl -0x30(%rbp), %eax
movl -0x2c(%rbp), %ecx
imull %ecx, %eax
movslq %ecx, %rbx
movslq %eax, %r15
movq -0x40(%rbp), %rax
addq %rbx, %rax
addq %rax, %rsi
negq -0x38(%rbp)
cmpq %r15, %rbx
jge 0x2c33
movq %rsi, %r13
movb (%rsi), %r12b
movzbl (%r14), %edi
movq -0x38(%rbp), %rax
movzbl (%rsi,%rax), %esi
movzbl (%r14,%rax), %edx
callq 0x983e
subb %al, %r12b
movq -0x48(%rbp), %rax
movb %r12b, (%rax,%rbx)
movq %r13, %rsi
incq %rbx
incq %rsi
incq %r14
jmp 0x2b91
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
movq -0x40(%rbp), %rdx
addq %rax, %rdx
addq %rdx, %rsi
addq %rax, %rdi
negq -0x38(%rbp)
movq -0x38(%rbp), %r8
cmpq %rcx, %rax
jge 0x2c33
movb (%rsi), %dl
subb (%rsi,%r8), %dl
movb %dl, (%rdi)
incq %rax
incq %rsi
incq %rdi
jmp 0x2bf2
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %eax
imull %eax, %ecx
cltq
movslq %ecx, %rcx
xorl %edx, %edx
cmpq %rcx, %rax
jge 0x2c33
movb (%r14,%rax), %sil
subb (%r14,%rdx), %sil
movb %sil, (%rdi,%rax)
incq %rax
incq %rdx
jmp 0x2c1a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq