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

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x1c(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movq -0x8(%rbp), %rdx
movzwl 0x14(%rdx), %edx
addl %edx, %ecx
imull $0x3, %ecx, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x1c(%rax), %eax
imull $0x3, %eax, %eax
movq -0x10(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movq -0x10(%rbp), %rdx
movzwl 0x14(%rdx), %edx
addl %edx, %ecx
imull $0x9, %ecx, %ecx
addl %ecx, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x1c(%rax), %eax
imull $0x3, %eax, %eax
movq -0x18(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movq -0x18(%rbp), %rdx
movzwl 0x14(%rdx), %edx
addl %edx, %ecx
imull $0x9, %ecx, %ecx
addl %ecx, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x18, %eax
movl $0x31, %ecx
cltd
idivl %ecx
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x8(%rbp), %rax
movzwl 0x1a(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
movq -0x8(%rbp), %rdx
movzwl 0x12(%rdx), %edx
addl %edx, %ecx
imull $0x3, %ecx, %ecx
addl %ecx, %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x1a(%rax), %eax
imull $0x3, %eax, %eax
movq -0x10(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
movq -0x10(%rbp), %rdx
movzwl 0x12(%rdx), %edx
addl %edx, %ecx
imull $0x9, %ecx, %ecx
addl %ecx, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x1a(%rax), %eax
imull $0x3, %eax, %eax
movq -0x18(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
movq -0x18(%rbp), %rdx
movzwl 0x12(%rdx), %edx
addl %edx, %ecx
imull $0x9, %ecx, %ecx
addl %ecx, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
addl $0x18, %eax
movl $0x31, %ecx
cltd
idivl %ecx
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
movq -0x8(%rbp), %rdx
movzwl 0x10(%rdx), %edx
addl %edx, %ecx
imull $0x3, %ecx, %ecx
addl %ecx, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x18(%rax), %eax
imull $0x3, %eax, %eax
movq -0x10(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
movq -0x10(%rbp), %rdx
movzwl 0x10(%rdx), %edx
addl %edx, %ecx
imull $0x9, %ecx, %ecx
addl %ecx, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x18(%rax), %eax
imull $0x3, %eax, %eax
movq -0x18(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
movq -0x18(%rbp), %rdx
movzwl 0x10(%rdx), %edx
addl %edx, %ecx
imull $0x9, %ecx, %ecx
addl %ecx, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addl $0x18, %eax
movl $0x31, %ecx
cltd
idivl %ecx
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, (%rax)
movq -0x8(%rbp), %rax
movzwl 0x1e(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0xe(%rcx), %ecx
movq -0x8(%rbp), %rdx
movzwl 0x16(%rdx), %edx
addl %edx, %ecx
imull $0x3, %ecx, %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x1e(%rax), %eax
imull $0x3, %eax, %eax
movq -0x10(%rbp), %rcx
movzwl 0xe(%rcx), %ecx
movq -0x10(%rbp), %rdx
movzwl 0x16(%rdx), %edx
addl %edx, %ecx
imull $0x9, %ecx, %ecx
addl %ecx, %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x1e(%rax), %eax
imull $0x3, %eax, %eax
movq -0x18(%rbp), %rcx
movzwl 0xe(%rcx), %ecx
movq -0x18(%rbp), %rdx
movzwl 0x16(%rdx), %edx
addl %edx, %ecx
imull $0x9, %ecx, %ecx
addl %ecx, %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
addl $0x18, %eax
movl $0x31, %ecx
cltd
idivl %ecx
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x6(%rax)
popq %rbp
retq
nopw %cs:(%rax,%rax)