// File: CodyNault[P]Image-Filter-Dataflow/src/filters.cpp
// Function: TBConcat::Execute()
void TBConcat::Execute()
{
	TwoInputCheck();
	if(inputImg1->GetWidth() != inputImg2->GetWidth()){
		char msg[1028];
		sprintf(msg, "TBConcat: widths must match: %d, %d", inputImg1->GetWidth(), inputImg2->GetWidth());
		DataFlowException except("TBConcat", msg);
		throw except;
	}
	int topHeight = inputImg1->GetHeight();
	int bottomHeight = inputImg2->GetHeight();
	int newWidth = inputImg1->GetWidth();
	int newHeight = topHeight + bottomHeight;
	Pixel *topBuffer = inputImg1->GetBuffer();
	Pixel *bottomBuffer = inputImg2->GetBuffer();
	Pixel *combinedBuffer = new Pixel[ newWidth * newHeight];
	for(int i = 0; i < newHeight; i++)
	{
		for(int j = 0; j < newWidth; j++)
		{
			if( i < topHeight)
			{
				combinedBuffer[i*newWidth + j] = topBuffer[i * newWidth + j];	
			}else{
				combinedBuffer[i*newWidth + j] = bottomBuffer[(i - topHeight) * newWidth + j];	
			}
		}
	}
	outputImg.ResetSize(newWidth, newHeight);
	outputImg.SetBuffer(combinedBuffer);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x890, %rsp            # imm = 0x890
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x868(%rbp)
addq $0x28, %rdi
callq 0x4070
movq -0x868(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movq -0x868(%rbp), %rax
movl %ecx, -0x85c(%rbp)
movq 0x38(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movl -0x85c(%rbp), %eax
cmpl %ecx, %eax
je 0x645a
movq -0x868(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movq -0x868(%rbp), %rax
movl %ecx, -0x884(%rbp)
movq 0x38(%rax), %rdi
callq 0x3db0
movl -0x884(%rbp), %edx
movl %eax, %ecx
leaq 0x2dc4(%rip), %rsi      # 0x9186
xorl %eax, %eax
leaq -0x410(%rbp), %rdi
movq %rdi, -0x880(%rbp)
callq 0x3050
movq -0x880(%rbp), %rdx
leaq 0x2dc5(%rip), %rsi      # 0x91aa
leaq -0x818(%rbp), %rdi
movq %rdi, -0x878(%rbp)
callq 0x8420
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq -0x878(%rbp), %rsi
movq %rax, %rdi
movq %rdi, -0x870(%rbp)
callq 0x4240
movq -0x870(%rbp), %rdi
leaq 0x6462(%rip), %rsi      # 0xc888
leaq -0x219d(%rip), %rdx     # 0x4290
callq 0x31c0
jmp 0x6684
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x820(%rbp)
movl %eax, -0x824(%rbp)
leaq -0x818(%rbp), %rdi
callq 0x4290
jmp 0x6678
movq -0x868(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3dd0
movl %eax, %ecx
movq -0x868(%rbp), %rax
movl %ecx, -0x828(%rbp)
movq 0x38(%rax), %rdi
callq 0x3dd0
movl %eax, %ecx
movq -0x868(%rbp), %rax
movl %ecx, -0x82c(%rbp)
movq 0x30(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movq -0x868(%rbp), %rax
movl %ecx, -0x830(%rbp)
movl -0x828(%rbp), %ecx
addl -0x82c(%rbp), %ecx
movl %ecx, -0x834(%rbp)
movq 0x30(%rax), %rdi
callq 0x3df0
movq %rax, %rcx
movq -0x868(%rbp), %rax
movq %rcx, -0x840(%rbp)
movq 0x38(%rax), %rdi
callq 0x3df0
movq %rax, -0x848(%rbp)
movl -0x830(%rbp), %eax
imull -0x834(%rbp), %eax
cltq
movl $0x3, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, -0x850(%rbp)
movl $0x0, -0x854(%rbp)
movl -0x854(%rbp), %eax
cmpl -0x834(%rbp), %eax
jge 0x663c
movl $0x0, -0x858(%rbp)
movl -0x858(%rbp), %eax
cmpl -0x830(%rbp), %eax
jge 0x6626
movl -0x854(%rbp), %eax
cmpl -0x828(%rbp), %eax
jge 0x65b7
movq -0x840(%rbp), %rcx
movl -0x854(%rbp), %eax
imull -0x830(%rbp), %eax
addl -0x858(%rbp), %eax
cltq
imulq $0x3, %rax, %rax
addq %rax, %rcx
movq -0x850(%rbp), %rax
movl -0x854(%rbp), %edx
imull -0x830(%rbp), %edx
addl -0x858(%rbp), %edx
movslq %edx, %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rax
movw (%rcx), %dx
movw %dx, (%rax)
movb 0x2(%rcx), %cl
movb %cl, 0x2(%rax)
jmp 0x6610
movq -0x848(%rbp), %rcx
movl -0x854(%rbp), %eax
subl -0x828(%rbp), %eax
imull -0x830(%rbp), %eax
addl -0x858(%rbp), %eax
cltq
imulq $0x3, %rax, %rax
addq %rax, %rcx
movq -0x850(%rbp), %rax
movl -0x854(%rbp), %edx
imull -0x830(%rbp), %edx
addl -0x858(%rbp), %edx
movslq %edx, %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rax
movw (%rcx), %dx
movw %dx, (%rax)
movb 0x2(%rcx), %cl
movb %cl, 0x2(%rax)
jmp 0x6612
movl -0x858(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x858(%rbp)
jmp 0x6542
jmp 0x6628
movl -0x854(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x854(%rbp)
jmp 0x6526
movq -0x868(%rbp), %rdi
addq $0x8, %rdi
movl -0x830(%rbp), %esi
movl -0x834(%rbp), %edx
callq 0x3e90
movq -0x868(%rbp), %rdi
addq $0x8, %rdi
movq -0x850(%rbp), %rsi
callq 0x3eb0
addq $0x890, %rsp            # imm = 0x890
popq %rbp
retq
movq -0x820(%rbp), %rdi
callq 0x31d0
nopw %cs:(%rax,%rax)