// File: /workspace/github_cpp_makefile_star2_O1/kylegranger[P]ImageScaling/filter16.cpp
// Function: DownfilterRight(color_t*, color_t*, color_t*, color_t*, color_t*)
void DownfilterRight(color_t *src1, color_t *src2, color_t *src3, color_t *src4, color_t *dst)
{
	// we mix 16 source pixels into one destination pixel
	int r = (src1[0].r)     + 3 * (src1[1].r + src1[2].r);
	r    += (src2[0].r) * 3 + 9 * (src2[1].r + src2[2].r);
	r    += (src3[0].r) * 3 + 9 * (src3[1].r + src3[2].r);
	r    += (src4[0].r)     + 3 * (src4[1].r + src4[2].r);
	dst->r = ((r+28)/56);
	int g = (src1[0].g)     + 3 * (src1[1].g + src1[2].g);
	g    += (src2[0].g) * 3 + 9 * (src2[1].g + src2[2].g);
	g    += (src3[0].g) * 3 + 9 * (src3[1].g + src3[2].g);
	g    += (src4[0].g)     + 3 * (src4[1].g + src4[2].g);
	dst->g = ((g+28)/56);
	int b = (src1[0].b)     + 3 * (src1[1].b + src1[2].b);
	b    += (src2[0].b) * 3 + 9 * (src2[1].b + src2[2].b);
	b    += (src3[0].b) * 3 + 9 * (src3[1].b + src3[2].b);
	b    += (src4[0].b)     + 3 * (src4[1].b + src4[2].b);
	dst->b = ((b+28)/56);
	int a = (src1[0].a)     + 3 * (src1[1].a + src1[2].a);
	a    += (src2[0].a) * 3 + 9 * (src2[1].a + src2[2].a);
	a    += (src3[0].a) * 3 + 9 * (src3[1].a + src3[2].a);
	a    += (src4[0].a)     + 3 * (src4[1].a + src4[2].a);
	dst->a = ((a+28)/56);
}

// Assembly:
pushq %rbx
movzwl 0x4(%rdi), %eax
movzwl 0xc(%rdi), %r9d
movzwl 0x14(%rdi), %r10d
addl %r9d, %r10d
movzwl 0x4(%rsi), %r9d
movzwl 0xc(%rsi), %r11d
movzwl 0x14(%rsi), %ebx
addl %r11d, %ebx
movzwl 0x4(%rdx), %r11d
addl %r9d, %r11d
addl %r10d, %r11d
movzwl 0xc(%rdx), %r9d
movzwl 0x14(%rdx), %r10d
addl %r9d, %r10d
addl %ebx, %r10d
movzwl 0x4(%rcx), %r9d
addl %eax, %r9d
movzwl 0xc(%rcx), %eax
movzwl 0x14(%rcx), %ebx
addl %eax, %ebx
addl %r11d, %ebx
leal (%rbx,%rbx,2), %eax
leal (%r10,%r10,8), %r10d
addl %r9d, %r10d
addl %r10d, %eax
addl $0x1c, %eax
shrl $0x3, %eax
imulq $0x24924925, %rax, %rax # imm = 0x24924925
shrq $0x20, %rax
movw %ax, 0x4(%r8)
movzwl 0x2(%rdi), %eax
movzwl 0xa(%rdi), %r9d
movzwl 0x12(%rdi), %r10d
addl %r9d, %r10d
movzwl 0x2(%rsi), %r9d
movzwl 0xa(%rsi), %r11d
movzwl 0x12(%rsi), %ebx
addl %r11d, %ebx
movzwl 0x2(%rdx), %r11d
addl %r9d, %r11d
addl %r10d, %r11d
movzwl 0xa(%rdx), %r9d
movzwl 0x12(%rdx), %r10d
addl %r9d, %r10d
addl %ebx, %r10d
movzwl 0x2(%rcx), %r9d
addl %eax, %r9d
movzwl 0xa(%rcx), %eax
movzwl 0x12(%rcx), %ebx
addl %eax, %ebx
addl %r11d, %ebx
leal (%rbx,%rbx,2), %eax
leal (%r10,%r10,8), %r10d
addl %r9d, %r10d
addl %r10d, %eax
addl $0x1c, %eax
shrl $0x3, %eax
imulq $0x24924925, %rax, %rax # imm = 0x24924925
shrq $0x20, %rax
movw %ax, 0x2(%r8)
movzwl (%rdi), %eax
movzwl 0x8(%rdi), %r9d
movzwl 0x10(%rdi), %r10d
addl %r9d, %r10d
movzwl (%rsi), %r9d
movzwl 0x8(%rsi), %r11d
movzwl 0x10(%rsi), %ebx
addl %r11d, %ebx
movzwl (%rdx), %r11d
addl %r9d, %r11d
addl %r10d, %r11d
movzwl 0x8(%rdx), %r9d
movzwl 0x10(%rdx), %r10d
addl %r9d, %r10d
addl %ebx, %r10d
movzwl (%rcx), %r9d
addl %eax, %r9d
movzwl 0x8(%rcx), %eax
movzwl 0x10(%rcx), %ebx
addl %eax, %ebx
addl %r11d, %ebx
leal (%rbx,%rbx,2), %eax
leal (%r10,%r10,8), %r10d
addl %r9d, %r10d
addl %r10d, %eax
addl $0x1c, %eax
shrl $0x3, %eax
imulq $0x24924925, %rax, %rax # imm = 0x24924925
shrq $0x20, %rax
movw %ax, (%r8)
movzwl 0x6(%rdi), %eax
movzwl 0xe(%rdi), %r9d
movzwl 0x16(%rdi), %edi
addl %r9d, %edi
movzwl 0x6(%rsi), %r9d
movzwl 0xe(%rsi), %r10d
movzwl 0x16(%rsi), %esi
addl %r10d, %esi
movzwl 0x6(%rdx), %r10d
addl %r9d, %r10d
addl %edi, %r10d
movzwl 0xe(%rdx), %edi
movzwl 0x16(%rdx), %edx
addl %edi, %edx
addl %esi, %edx
movzwl 0x6(%rcx), %esi
addl %eax, %esi
movzwl 0xe(%rcx), %eax
movzwl 0x16(%rcx), %ecx
addl %eax, %ecx
addl %r10d, %ecx
leal (%rcx,%rcx,2), %eax
leal (%rdx,%rdx,8), %ecx
addl %esi, %ecx
addl %ecx, %eax
addl $0x1c, %eax
shrl $0x3, %eax
imulq $0x24924925, %rax, %rax # imm = 0x24924925
shrq $0x20, %rax
movw %ax, 0x6(%r8)
popq %rbx
retq