// File: /workspace/github_cpp_makefile_star2_O2/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 0x3a3a
movss 0x40(%rbx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x4bb3
ucomiss 0x1768(%rip), %xmm0     # 0x6168
ja 0x4bb3
movq 0x30(%rbx), %rdi
callq 0x38d8
movl %eax, %r14d
movq 0x38(%rbx), %rdi
callq 0x38d8
cmpl %eax, %r14d
jne 0x4c2c
movq 0x30(%rbx), %rdi
callq 0x38e2
movl %eax, %r14d
movq 0x38(%rbx), %rdi
callq 0x38e2
cmpl %eax, %r14d
jne 0x4cbb
movq 0x30(%rbx), %rdi
callq 0x38d8
movl %eax, %r14d
movq 0x30(%rbx), %rdi
callq 0x38e2
movl %eax, %r15d
movq 0x30(%rbx), %rdi
callq 0x38ec
movq %rax, %r12
movq 0x38(%rbx), %rdi
callq 0x38ec
movq %rax, %r13
movl %r15d, %eax
imull %r14d, %eax
cltq
pushq $0x3
popq %rcx
mulq %rcx
pushq $-0x1
popq %rdi
cmovnoq %rax, %rdi
callq 0x3030
movq %rax, %rdi
movss 0x40(%rbx), %xmm0
movss 0x16cb(%rip), %xmm1     # 0x6168
xorl %eax, %eax
testl %r14d, %r14d
movl $0x0, %edx
cmovgl %r14d, %edx
subss %xmm0, %xmm1
movslq %r14d, %rsi
testl %r15d, %r15d
movl %r15d, %ecx
cmovlel %eax, %ecx
leaq (%rdx,%rdx,2), %rdx
addq $0x2, %r12
leaq (%rsi,%rsi,2), %rsi
addq $0x2, %r13
movq %rdi, -0x30(%rbp)
addq $0x2, %rdi
cmpq %rcx, %rax
je 0x4b84
xorl %r8d, %r8d
cmpq %r8, %rdx
je 0x4b73
movzbl -0x2(%r12,%r8), %r9d
cvtsi2ss %r9d, %xmm2
movzbl -0x2(%r13,%r8), %r9d
cvtsi2ss %r9d, %xmm3
mulss %xmm1, %xmm3
mulss %xmm0, %xmm2
addss %xmm3, %xmm2
cvttss2si %xmm2, %r9d
movb %r9b, -0x2(%rdi,%r8)
movzbl -0x1(%r12,%r8), %r9d
cvtsi2ss %r9d, %xmm2
movzbl -0x1(%r13,%r8), %r9d
cvtsi2ss %r9d, %xmm3
mulss %xmm1, %xmm3
mulss %xmm0, %xmm2
addss %xmm3, %xmm2
cvttss2si %xmm2, %r9d
movb %r9b, -0x1(%rdi,%r8)
movzbl (%r12,%r8), %r9d
cvtsi2ss %r9d, %xmm2
movzbl (%r13,%r8), %r9d
cvtsi2ss %r9d, %xmm3
mulss %xmm1, %xmm3
mulss %xmm0, %xmm2
addss %xmm3, %xmm2
cvttss2si %xmm2, %r9d
movb %r9b, (%rdi,%r8)
addq $0x3, %r8
jmp 0x4adf
incq %rax
addq %rsi, %r12
addq %rsi, %r13
addq %rsi, %rdi
jmp 0x4ad3
addq $0x8, %rbx
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x3936
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3942
cvtss2sd %xmm0, %xmm0
leaq 0x1609(%rip), %rsi      # 0x61c7
leaq -0x840(%rbp), %rbx
movq %rbx, %rdi
movb $0x1, %al
callq 0x3050
leaq 0x1610(%rip), %rsi      # 0x61e6
leaq -0x438(%rbp), %rdi
movq %rbx, %rdx
callq 0x5b4c
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq %rax, %rbx
leaq 0x4cb7(%rip), %rax      # 0x98b0
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
leaq -0x430(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x30d0
leaq 0x4c70(%rip), %rsi      # 0x9888
movq 0x53c1(%rip), %rdx      # 0x9fe0
movq %rbx, %rdi
callq 0x31c0
jmp 0x4d45
movq 0x30(%rbx), %rdi
callq 0x38d8
movl %eax, %r14d
movq 0x38(%rbx), %rdi
callq 0x38d8
leaq 0x15a6(%rip), %rsi      # 0x61ee
leaq -0x840(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x3050
leaq 0x1581(%rip), %rsi      # 0x61e6
leaq -0x438(%rbp), %rdi
movq %rbx, %rdx
callq 0x5b4c
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq %rax, %rbx
leaq 0x4c28(%rip), %rax      # 0x98b0
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
leaq -0x430(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x30d0
leaq 0x4be1(%rip), %rsi      # 0x9888
movq 0x5332(%rip), %rdx      # 0x9fe0
movq %rbx, %rdi
callq 0x31c0
jmp 0x4d45
movq 0x30(%rbx), %rdi
callq 0x38e2
movl %eax, %r14d
movq 0x38(%rbx), %rdi
callq 0x38e2
leaq 0x153a(%rip), %rsi      # 0x6211
leaq -0x840(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x3050
leaq 0x14f2(%rip), %rsi      # 0x61e6
leaq -0x438(%rbp), %rdi
movq %rbx, %rdx
callq 0x5b4c
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq %rax, %rbx
leaq 0x4b99(%rip), %rax      # 0x98b0
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
leaq -0x430(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x30d0
leaq 0x4b52(%rip), %rsi      # 0x9888
movq 0x52a3(%rip), %rdx      # 0x9fe0
movq %rbx, %rdi
callq 0x31c0
jmp 0x4d49
jmp 0x4d49
movq %rax, %rbx
leaq -0x438(%rbp), %rdi
callq 0x3208
movq %rbx, %rdi
callq 0x31d0