// File: kchan1[P]helloworld_test1/main2.cpp
// Function: subband_recomp(double**&, int, int)
void subband_recomp(double** &image_data, int height, int width){
	double low_pass_filter[7] = {.2,.6,.7,.2,-.3,0,.1};
	double high_pass_filter[7] = {-.1,0,.3,.2,-.7,.6,-.2};

	double** round1_low = new double*[height];
	double** round1_high = new double*[height];
	double** round2_low = new double*[height];
	double** round2_high = new double*[height];

	for (int i = 0; i<height; i++){
		round1_low[i] = new double[width];
		round1_high[i] = new double[width];
		round2_low[i] = new double[width];
		round2_high[i] = new double[width];
	}

	for (int i=0; i <height; i++){
		for(int j=0; j<width; j++){
			round1_low[i][j] = 0;
			round1_high[i][j] = 0;
			round2_low[i][j] = 0;
			round2_high[i][j] = 0;
		}		
	}

	//cout<<height/2<<" "<<width/2<<endl;

	for (int i=0; i<(int)(height/2); i++){
		for(int j=0; j<(int)(width/2);j++){
			round1_low[i*2][j*2]=(double)image_data[i][j];
			round2_low[i*2][j*2]=(double)image_data[i+height/2][j];
			round1_high[i*2][j*2]=(double)image_data[i+height/2][j+width/2];
			round2_high[i*2][j*2]=(double)image_data[i][j+width/2];
		}
	}

	/*for (int i = 0; i<height; i++){
		for(int j =0; j<width;j++){
			cout<<(int)round1_low[i][j]<<" ";
		}
		cout<<endl;
	}*/

	vertical_convolution(round1_low,height,width,low_pass_filter,7);
	vertical_convolution(round2_low,height,width,high_pass_filter,7);
	vertical_convolution(round1_high,height,width,high_pass_filter,7);
	vertical_convolution(round2_high,height,width,low_pass_filter,7);

	//COMBINATION SECTION GO!

	for (int i=0; i<height; i++){
		for(int j=0; j<width; j++){
			round1_low[i][j] = round1_low[i][j]+round2_low[i][j];
			//round1_low[i][j] = round2_low[i][j];
			round1_high[i][j] = round1_high[i][j]+round2_high[i][j];
			//round1_high[i][j] = round2_high[i][j];
		}
	}	

	for(int i=0; i<height; i++){
		horizontal_convolution(round1_low[i],width,low_pass_filter,7);
		horizontal_convolution(round1_high[i],width,high_pass_filter,7);
	}

	for (int i=0; i<height; i++){
		for(int j=0; j<width; j++){
			image_data[i][j] = round1_low[i][j]+round1_high[i][j];
			image_data[i][j]*=.80;
			//image_data[i][j];
		}
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x20d0
movsd 0x28d3(%rip), %xmm0     # 0x5020
movsd %xmm0, -0x50(%rbp)
movsd 0x28b6(%rip), %xmm0     # 0x5010
movsd %xmm0, -0x48(%rbp)
movsd 0x28e1(%rip), %xmm0     # 0x5048
movsd %xmm0, -0x40(%rbp)
movsd 0x28ac(%rip), %xmm0     # 0x5020
movsd %xmm0, -0x38(%rbp)
movsd 0x28bf(%rip), %xmm0     # 0x5040
movsd %xmm0, -0x30(%rbp)
movsd 0x28aa(%rip), %xmm0     # 0x5038
movsd %xmm0, -0x20(%rbp)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x20d0
movsd 0x2882(%rip), %xmm0     # 0x5030
movsd %xmm0, -0x90(%rbp)
movsd 0x286a(%rip), %xmm0     # 0x5028
movsd %xmm0, -0x80(%rbp)
movsd 0x2855(%rip), %xmm0     # 0x5020
movsd %xmm0, -0x78(%rbp)
movsd 0x2840(%rip), %xmm0     # 0x5018
movsd %xmm0, -0x70(%rbp)
movsd 0x282b(%rip), %xmm0     # 0x5010
movsd %xmm0, -0x68(%rbp)
movsd 0x2816(%rip), %xmm0     # 0x5008
movsd %xmm0, -0x60(%rbp)
movslq -0xc(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x98(%rbp)
movslq -0xc(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0xa0(%rbp)
movslq -0xc(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0xa8(%rbp)
movslq -0xc(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0xb0(%rbp)
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x29bc
movslq -0x10(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rdx
movq -0x98(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq -0x10(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rdx
movq -0xa0(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq -0x10(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rdx
movq -0xa8(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq -0x10(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rdx
movq -0xb0(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x28b1
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2a9c
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2a86
movq -0x98(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xbc(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0xa0(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xbc(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0xa8(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xbc(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0xb0(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xbc(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x29df
jmp 0x2a88
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x29c6
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
movl %eax, -0xdc(%rbp)
movl -0xc(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xdc(%rbp), %eax
cmpl %ecx, %eax
jge 0x2cb4
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0xe0(%rbp)
movl -0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xe0(%rbp), %eax
cmpl %ecx, %eax
jge 0x2c9e
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xc0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc4(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x98(%rbp), %rax
movl -0xc0(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0xc4(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x100(%rbp)
movl -0xc0(%rbp), %ecx
movl -0xc(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0x100(%rbp), %rax
addl %edx, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc4(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xa8(%rbp), %rax
movl -0xc0(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0xc4(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
movl -0xc0(%rbp), %ecx
movl -0xc(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0xf8(%rbp), %rax
addl %edx, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xf0(%rbp)
movl -0xc4(%rbp), %ecx
movl -0x10(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0xf0(%rbp), %rax
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xa0(%rbp), %rax
movl -0xc0(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0xc4(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xc0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xe8(%rbp)
movl -0xc4(%rbp), %ecx
movl -0x10(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0xe8(%rbp), %rax
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xb0(%rbp), %rax
movl -0xc0(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0xc4(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x2ad7
jmp 0x2ca0
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x2aa6
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
leaq -0x50(%rbp), %rcx
leaq -0x98(%rbp), %rdi
movl $0x7, %r8d
callq 0x2550
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
leaq -0x90(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
movl $0x7, %r8d
callq 0x2550
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
leaq -0x90(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
movl $0x7, %r8d
callq 0x2550
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
leaq -0x50(%rbp), %rcx
leaq -0xb0(%rbp), %rdi
movl $0x7, %r8d
callq 0x2550
movl $0x0, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2e3a
movl $0x0, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2e24
movq -0x98(%rbp), %rax
movslq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xcc(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xa8(%rbp), %rax
movslq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xcc(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movq -0x98(%rbp), %rax
movslq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xcc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0xa0(%rbp), %rax
movslq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xcc(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xb0(%rbp), %rax
movslq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xcc(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movq -0xa0(%rbp), %rax
movslq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xcc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x2d4d
jmp 0x2e26
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x2d34
movl $0x0, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2eaf
movq -0x98(%rbp), %rdi
movslq -0xd0(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl -0x10(%rbp), %esi
leaq -0x50(%rbp), %rdx
movl $0x7, %ecx
callq 0x2410
movq -0xa0(%rbp), %rdi
movslq -0xd0(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl -0x10(%rbp), %esi
leaq -0x90(%rbp), %rdx
movl $0x7, %ecx
callq 0x2410
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x2e44
movl $0x0, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2f90
movl $0x0, -0xd8(%rbp)
movl -0xd8(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2f7a
movq -0x98(%rbp), %rax
movslq -0xd4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xd8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xa0(%rbp), %rax
movslq -0xd4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xd8(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xd4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xd8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xd4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xd8(%rbp), %rcx
movsd 0x20f4(%rip), %xmm0     # 0x5050
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd8(%rbp)
jmp 0x2ed2
jmp 0x2f7c
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x2eb9
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)