// File: /workspace/github_cpp_makefile_star2_O1/CodyNault[P]Image-Filter-Dataflow/src/filters.cpp
// Function: Blender::Execute()
void Blender::Execute()
{
	TwoInputCheck();
	if(this->factor < 0 || this->factor > 1){
		char msg[1028];
		sprintf(msg, "Invalid factor for Blender: %f", this->factor);
		DataFlowException except("Blender", msg);
		throw except;
	}
	if(inputImg1->GetWidth() != inputImg2->GetWidth()){
		char msg[1028];
		sprintf(msg, "Blender: widths must match: %d, %d", inputImg1->GetWidth(), inputImg2->GetWidth());
		DataFlowException except("Blender", msg);
		throw except;
	}
	if(inputImg1->GetHeight() != inputImg2->GetHeight()){

		char msg[1028];
		sprintf(msg, "Blender: heights must match: %d, %d", inputImg1->GetHeight(), inputImg2->GetHeight());
		DataFlowException except("Blender", msg);
		throw except;
	}
	int width = inputImg1->GetWidth();
	int height = inputImg1->GetHeight();
	Pixel *buffer1 = inputImg1->GetBuffer();
	Pixel *buffer2 = inputImg2->GetBuffer();
	Pixel *combinedBuffer = new Pixel[ width * height];
	float factor2 = 1.0 - factor;
	float red = 0.0, green = 0.0, blue = 0.0;
	for(int i = 0; i < height; i++)
	{
		for(int j = 0; j < width; j++)
		{
			red = buffer1[i * width + j].red * factor + buffer2[ i * width + j].red * factor2; 
			combinedBuffer[i * width + j].red = static_cast<int>(red);
			green = buffer1[i * width + j].green * factor + buffer2[ i * width + j].green * factor2; 
			combinedBuffer[i * width + j].green = static_cast<int>(green);
			blue = buffer1[i * width + j].blue * factor + buffer2[ i * width + j].blue * factor2; 
			combinedBuffer[i * width + j].blue = static_cast<int>(blue);
		}
	}
	outputImg.ResetSize(width, height);
	outputImg.SetBuffer(combinedBuffer);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x818, %rsp            # imm = 0x818
movq %rdi, %rbx
addq $0x28, %rdi
callq 0x3aee
movss 0x40(%rbx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x4b54
ucomiss 0x17ce(%rip), %xmm0     # 0x6168
ja 0x4b54
movq 0x30(%rbx), %rdi
callq 0x3978
movl %eax, %r14d
movq 0x38(%rbx), %rdi
callq 0x3978
cmpl %eax, %r14d
jne 0x4bcd
movq 0x30(%rbx), %rdi
callq 0x3982
movl %eax, %r14d
movq 0x38(%rbx), %rdi
callq 0x3982
cmpl %eax, %r14d
jne 0x4c5c
movq 0x30(%rbx), %rdi
callq 0x3978
movl %eax, %r14d
movq 0x30(%rbx), %rdi
callq 0x3982
movl %eax, %r15d
movq 0x30(%rbx), %rdi
callq 0x398c
movq %rax, %r12
movq 0x38(%rbx), %rdi
callq 0x398c
movq %rax, %r13
movl %r15d, %eax
imull %r14d, %eax
cltq
movl $0x3, %ecx
mulq %rcx
movq $-0x1, %rdi
cmovnoq %rax, %rdi
callq 0x3030
testl %r15d, %r15d
jle 0x4b23
movss 0x40(%rbx), %xmm0
movss 0x1725(%rip), %xmm1     # 0x6168
subss %xmm0, %xmm1
movl %r14d, %edx
movl %r15d, %r9d
movq %rax, %rcx
addq $0x2, %rcx
leaq (%rdx,%rdx,2), %rdx
addq $0x2, %r13
addq $0x2, %r12
xorl %esi, %esi
testl %r14d, %r14d
jle 0x4b0e
xorl %edi, %edi
movzbl -0x2(%r12,%rdi), %r8d
xorps %xmm2, %xmm2
cvtsi2ss %r8d, %xmm2
movzbl -0x2(%r13,%rdi), %r8d
xorps %xmm3, %xmm3
cvtsi2ss %r8d, %xmm3
mulss %xmm1, %xmm3
mulss %xmm0, %xmm2
addss %xmm3, %xmm2
cvttss2si %xmm2, %r8d
movb %r8b, -0x2(%rcx,%rdi)
movzbl -0x1(%r12,%rdi), %r8d
xorps %xmm2, %xmm2
cvtsi2ss %r8d, %xmm2
movzbl -0x1(%r13,%rdi), %r8d
xorps %xmm3, %xmm3
cvtsi2ss %r8d, %xmm3
mulss %xmm1, %xmm3
mulss %xmm0, %xmm2
addss %xmm3, %xmm2
cvttss2si %xmm2, %r8d
movb %r8b, -0x1(%rcx,%rdi)
movzbl (%r12,%rdi), %r8d
xorps %xmm2, %xmm2
cvtsi2ss %r8d, %xmm2
movzbl (%r13,%rdi), %r8d
xorps %xmm3, %xmm3
cvtsi2ss %r8d, %xmm3
mulss %xmm1, %xmm3
mulss %xmm0, %xmm2
addss %xmm3, %xmm2
cvttss2si %xmm2, %r8d
movb %r8b, (%rcx,%rdi)
addq $0x3, %rdi
cmpq %rdi, %rdx
jne 0x4a6d
incq %rsi
addq %rdx, %rcx
addq %rdx, %r13
addq %rdx, %r12
cmpq %r9, %rsi
jne 0x4a62
addq $0x8, %rbx
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
movq %rax, %r14
callq 0x39ea
movq %rbx, %rdi
movq %r14, %rsi
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39f6
cvtss2sd %xmm0, %xmm0
leaq 0x1668(%rip), %rsi      # 0x61c7
leaq -0x840(%rbp), %rbx
movq %rbx, %rdi
movb $0x1, %al
callq 0x3050
leaq 0x166f(%rip), %rsi      # 0x61e6
leaq -0x430(%rbp), %rdi
movq %rbx, %rdx
callq 0x5ae8
movl $0x408, %edi            # imm = 0x408
callq 0x3090
movq %rax, %rbx
leaq 0x3d16(%rip), %rax      # 0x88b0
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
leaq -0x428(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x30b0
leaq 0x3ccf(%rip), %rsi      # 0x8888
movq 0x4420(%rip), %rdx      # 0x8fe0
movq %rbx, %rdi
callq 0x31a0
jmp 0x4ce6
movq 0x30(%rbx), %rdi
callq 0x3978
movl %eax, %r14d
movq 0x38(%rbx), %rdi
callq 0x3978
leaq 0x1605(%rip), %rsi      # 0x61ee
leaq -0x840(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x3050
leaq 0x15e0(%rip), %rsi      # 0x61e6
leaq -0x430(%rbp), %rdi
movq %rbx, %rdx
callq 0x5ae8
movl $0x408, %edi            # imm = 0x408
callq 0x3090
movq %rax, %rbx
leaq 0x3c87(%rip), %rax      # 0x88b0
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
leaq -0x428(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x30b0
leaq 0x3c40(%rip), %rsi      # 0x8888
movq 0x4391(%rip), %rdx      # 0x8fe0
movq %rbx, %rdi
callq 0x31a0
jmp 0x4ce6
movq 0x30(%rbx), %rdi
callq 0x3982
movl %eax, %r14d
movq 0x38(%rbx), %rdi
callq 0x3982
leaq 0x1599(%rip), %rsi      # 0x6211
leaq -0x840(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x3050
leaq 0x1551(%rip), %rsi      # 0x61e6
leaq -0x430(%rbp), %rdi
movq %rbx, %rdx
callq 0x5ae8
movl $0x408, %edi            # imm = 0x408
callq 0x3090
movq %rax, %rbx
leaq 0x3bf8(%rip), %rax      # 0x88b0
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
leaq -0x428(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x30b0
leaq 0x3bb1(%rip), %rsi      # 0x8888
movq 0x4302(%rip), %rdx      # 0x8fe0
movq %rbx, %rdi
callq 0x31a0
jmp 0x4cea
jmp 0x4cea
movq %rax, %rbx
leaq -0x430(%rbp), %rdi
callq 0x31e8
movq %rbx, %rdi
callq 0x31b0
nop