// File: /workspace/github_cpp_makefile_star2_O1/kylegranger[P]ImageScaling/filter16.cpp
// Function: Downfilter(color_t*, color_t*, color_t*, color_t*, color_t*)
void Downfilter(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 + src1[3].r)     + 3 * (src1[1].r + src1[2].r);
	r    += (src2[0].r + src2[3].r) * 3 + 9 * (src2[1].r + src2[2].r);
	r    += (src3[0].r + src3[3].r) * 3 + 9 * (src3[1].r + src3[2].r);
	r    += (src4[0].r + src4[3].r)     + 3 * (src4[1].r + src4[2].r);
	dst->r = ((r+32)>>6);
	int g = (src1[0].g + src1[3].g)     + 3 * (src1[1].g + src1[2].g);
	g    += (src2[0].g + src2[3].g) * 3 + 9 * (src2[1].g + src2[2].g);
	g    += (src3[0].g + src3[3].g) * 3 + 9 * (src3[1].g + src3[2].g);
	g    += (src4[0].g + src4[3].g)     + 3 * (src4[1].g + src4[2].g);
	dst->g = ((g+32)>>6);
	int b = (src1[0].b + src1[3].b)     + 3 * (src1[1].b + src1[2].b);
	b    += (src2[0].b + src2[3].b) * 3 + 9 * (src2[1].b + src2[2].b);
	b    += (src3[0].b + src3[3].b) * 3 + 9 * (src3[1].b + src3[2].b);
	b    += (src4[0].b + src4[3].b)     + 3 * (src4[1].b + src4[2].b);
	dst->b = ((b+32)>>6);
	int a = (src1[0].a + src1[3].a)     + 3 * (src1[1].a + src1[2].a);
	a    += (src2[0].a + src2[3].a) * 3 + 9 * (src2[1].a + src2[2].a);
	a    += (src3[0].a + src3[3].a) * 3 + 9 * (src3[1].a + src3[2].a);
	a    += (src4[0].a + src4[3].a)     + 3 * (src4[1].a + src4[2].a);
	dst->a = ((a+32)>>6);
}

// Assembly:
pushq %r14
pushq %rbx
movzwl 0x4(%rdi), %r9d
movzwl 0x1c(%rdi), %eax
addl %r9d, %eax
movzwl 0xc(%rdi), %r9d
movzwl 0x14(%rdi), %r10d
addl %r9d, %r10d
movzwl 0x4(%rsi), %r9d
movzwl 0x1c(%rsi), %r11d
addl %r9d, %r11d
addl %r10d, %r11d
movzwl 0xc(%rsi), %r9d
movzwl 0x14(%rsi), %r10d
addl %r9d, %r10d
movzwl 0x4(%rdx), %r9d
movzwl 0x1c(%rdx), %ebx
addl %r9d, %ebx
movzwl 0xc(%rdx), %r9d
movzwl 0x14(%rdx), %r14d
addl %r9d, %r14d
addl %r10d, %r14d
movzwl 0x4(%rcx), %r9d
movzwl 0x1c(%rcx), %r10d
addl %r9d, %r10d
addl %eax, %r10d
movzwl 0xc(%rcx), %eax
addl %ebx, %eax
addl %r11d, %eax
movzwl 0x14(%rcx), %r9d
addl %eax, %r9d
leal (%r9,%r9,2), %eax
leal (%r14,%r14,8), %r9d
addl %r10d, %r9d
addl %r9d, %eax
addl $0x20, %eax
shrl $0x6, %eax
movw %ax, 0x4(%r8)
movzwl 0x2(%rdi), %r9d
movzwl 0x1a(%rdi), %eax
addl %r9d, %eax
movzwl 0xa(%rdi), %r9d
movzwl 0x12(%rdi), %r10d
addl %r9d, %r10d
movzwl 0x2(%rsi), %r9d
movzwl 0x1a(%rsi), %r11d
addl %r9d, %r11d
addl %r10d, %r11d
movzwl 0xa(%rsi), %r9d
movzwl 0x12(%rsi), %r10d
addl %r9d, %r10d
movzwl 0x2(%rdx), %r9d
movzwl 0x1a(%rdx), %ebx
addl %r9d, %ebx
movzwl 0xa(%rdx), %r9d
movzwl 0x12(%rdx), %r14d
addl %r9d, %r14d
addl %r10d, %r14d
movzwl 0x2(%rcx), %r9d
movzwl 0x1a(%rcx), %r10d
addl %r9d, %r10d
addl %eax, %r10d
movzwl 0xa(%rcx), %eax
addl %ebx, %eax
addl %r11d, %eax
movzwl 0x12(%rcx), %r9d
addl %eax, %r9d
leal (%r9,%r9,2), %eax
leal (%r14,%r14,8), %r9d
addl %r10d, %r9d
addl %r9d, %eax
addl $0x20, %eax
shrl $0x6, %eax
movw %ax, 0x2(%r8)
movzwl (%rdi), %r9d
movzwl 0x18(%rdi), %eax
addl %r9d, %eax
movzwl 0x8(%rdi), %r9d
movzwl 0x10(%rdi), %r10d
addl %r9d, %r10d
movzwl (%rsi), %r9d
movzwl 0x18(%rsi), %r11d
addl %r9d, %r11d
addl %r10d, %r11d
movzwl 0x8(%rsi), %r9d
movzwl 0x10(%rsi), %r10d
addl %r9d, %r10d
movzwl (%rdx), %r9d
movzwl 0x18(%rdx), %ebx
addl %r9d, %ebx
movzwl 0x8(%rdx), %r9d
movzwl 0x10(%rdx), %r14d
addl %r9d, %r14d
addl %r10d, %r14d
movzwl (%rcx), %r9d
movzwl 0x18(%rcx), %r10d
addl %r9d, %r10d
addl %eax, %r10d
movzwl 0x8(%rcx), %eax
addl %ebx, %eax
addl %r11d, %eax
movzwl 0x10(%rcx), %r9d
addl %eax, %r9d
leal (%r9,%r9,2), %eax
leal (%r14,%r14,8), %r9d
addl %r10d, %r9d
addl %r9d, %eax
addl $0x20, %eax
shrl $0x6, %eax
movw %ax, (%r8)
movzwl 0x6(%rdi), %r9d
movzwl 0x1e(%rdi), %eax
addl %r9d, %eax
movzwl 0xe(%rdi), %r9d
movzwl 0x16(%rdi), %edi
addl %r9d, %edi
movzwl 0x6(%rsi), %r9d
movzwl 0x1e(%rsi), %r10d
addl %r9d, %r10d
addl %edi, %r10d
movzwl 0xe(%rsi), %edi
movzwl 0x16(%rsi), %esi
addl %edi, %esi
movzwl 0x6(%rdx), %edi
movzwl 0x1e(%rdx), %r9d
addl %edi, %r9d
movzwl 0xe(%rdx), %edi
movzwl 0x16(%rdx), %edx
addl %edi, %edx
addl %esi, %edx
movzwl 0x6(%rcx), %esi
movzwl 0x1e(%rcx), %edi
addl %esi, %edi
addl %eax, %edi
movzwl 0xe(%rcx), %eax
addl %r9d, %eax
addl %r10d, %eax
movzwl 0x16(%rcx), %ecx
addl %eax, %ecx
leal (%rcx,%rcx,2), %eax
leal (%rdx,%rdx,8), %ecx
addl %edi, %ecx
addl %ecx, %eax
addl $0x20, %eax
shrl $0x6, %eax
movw %ax, 0x6(%r8)
popq %rbx
popq %r14
retq