// File: kylegranger[P]ImageScaling/filter16.cpp
// Function: UpfilterLeft(color_t*, color_t*, color_t*, color_t*, color_t*)
void UpfilterLeft(color_t *src1, color_t *src2, color_t *src3, color_t *dst1, color_t *dst2)
{
	// we mix 9 source pixels to four destination pixels
	dst1[0].r = (3 * src1[1].r + src2[1].r * 9 + 6) / 12;
	dst1[1].r = ((src1[2].r + 3 * (src1[1].r + src2[2].r) + src2[1].r * 9 + 8) >> 4);
	dst2[0].r = (3 * src3[1].r + src2[1].r * 9 + 6) / 12;
	dst2[1].r = ((src3[2].r + 3 * (src3[1].r + src2[2].r) + src2[1].r * 9 + 8) >> 4);

	dst1[0].g = (3 * src1[1].g + src2[1].g * 9 + 6) / 12;
	dst1[1].g = ((src1[2].g + 3 * (src1[1].g + src2[2].g) + src2[1].g * 9 + 8) >> 4);
	dst2[0].g = (3 * src3[1].g + src2[1].g * 9 + 6) / 12;
	dst2[1].g = ((src3[2].g + 3 * (src3[1].g + src2[2].g) + src2[1].g * 9 + 8) >> 4);

	dst1[0].b = (3 * src1[1].b + src2[1].b * 9 + 6) / 12;
	dst1[1].b = ((src1[2].b + 3 * (src1[1].b + src2[2].b) + src2[1].b * 9 + 8) >> 4);
	dst2[0].b = (3 * src3[1].b + src2[1].b * 9 + 6) / 12;
	dst2[1].b = ((src3[2].b + 3 * (src3[1].b + src2[2].b) + src2[1].b * 9 + 8) >> 4);

	dst1[0].a = (3 * src1[1].a + src2[1].a * 9 + 6) / 12;
	dst1[1].a = ((src1[2].a + 3 * (src1[1].a + src2[2].a) + src2[1].a * 9 + 8) >> 4);
	dst2[0].a = (3 * src3[1].a + src2[1].a * 9 + 6) / 12;
	dst2[1].a = ((src3[2].a + 3 * (src3[1].a + src2[2].a) + src2[1].a * 9 + 8) >> 4);
}

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