// File: kchan1[P]helloworld_test1/main.cpp
// Function: subband_decomp(double**&, int, int)
void subband_decomp(double** &image_data, int height, int width){
        //Our filters (yay)
	double low_pass_filter[7] = {.1,0,-.3,.2,.7,.6,.2};
	double high_pass_filter[7] = {-.2,.6,-.7,.2,.3,0,-.1};
	
	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];
	}

	//put copies of the whole image into round1_low and round1_high
	for(int i = 0; i<height; i++){
		for (int j = 0; j<width; j++){
			round1_low[i][j]=(double)image_data[i][j];
			round1_high[i][j] = (double)image_data[i][j];
		}
	}
	
	//horizontal low and high pass
	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);
	}

	//copy the buffers into round 2s
	for(int i =0; i<height; i++){
		for(int j = 0; j<width; j++){
			round2_low[i][j]=round1_low[i][j];
			round2_high[i][j]=round1_high[i][j];
		}
	}

	//vertical low pass on round1_low and round2_high
	//veritcal high pass on round2_low and round1_high
	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);
	//at this point: 
        //round1_low has been through low and low
	//round2_low has been through low and high
	//round1_high has been through high and high
	//round2_high has been through high and low


	//for (int i = 0; i <10 ; i++){
	//	std::cout<<round2_high[i][1]<<" ";
	//}
	//std::cout<<std::endl;

	//fill the top of the of the image
	for (int i = 0; i<height/2; i++){
	        //fill the left quarter
		for(int j = 0; j<width/2; j++){
			image_data[i][j] = round1_low[i*2][j*2];
		}
		//fill the right quarter
		for(int j =width/2; j<width; j++){
			image_data[i][j] = round2_high[i*2][(j-width/2)*2];
		}
	}

	//fill the bottom half of the image
	for (int i = height/2; i<height; i++){
	        //fill the left quarter
		for(int j = 0; j<width/2; j++){
			image_data[i][j] = round2_low[(i-height/2)*2][j*2];
		}
                //fill the right quarter
		for(int j =width/2; j<width; j++){
			image_data[i][j] = round1_high[(i-height/2)*2][(j-width/2)*2];
		}
	}

	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
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 0x3a0b(%rip), %xmm0     # 0x7078
movsd %xmm0, -0x50(%rbp)
movsd 0x39f6(%rip), %xmm0     # 0x7070
movsd %xmm0, -0x40(%rbp)
movsd 0x39c1(%rip), %xmm0     # 0x7048
movsd %xmm0, -0x38(%rbp)
movsd 0x39d4(%rip), %xmm0     # 0x7068
movsd %xmm0, -0x30(%rbp)
movsd 0x39b7(%rip), %xmm0     # 0x7058
movsd %xmm0, -0x28(%rbp)
movsd 0x399a(%rip), %xmm0     # 0x7048
movsd %xmm0, -0x20(%rbp)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x20d0
movsd 0x3992(%rip), %xmm0     # 0x7060
movsd %xmm0, -0x90(%rbp)
movsd 0x397a(%rip), %xmm0     # 0x7058
movsd %xmm0, -0x88(%rbp)
movsd 0x3962(%rip), %xmm0     # 0x7050
movsd %xmm0, -0x80(%rbp)
movsd 0x394d(%rip), %xmm0     # 0x7048
movsd %xmm0, -0x78(%rbp)
movsd 0x3938(%rip), %xmm0     # 0x7040
movsd %xmm0, -0x70(%rbp)
movsd 0x3923(%rip), %xmm0     # 0x7038
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 0x38df
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 0x37d4
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x39b3
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x399d
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xbc(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x98(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xbc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xbc(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xa0(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xbc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x3902
jmp 0x399f
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x38e9
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x3a28
movq -0x98(%rbp), %rdi
movslq -0xc0(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl -0x10(%rbp), %esi
leaq -0x50(%rbp), %rdx
movl $0x7, %ecx
callq 0x3330
movq -0xa0(%rbp), %rdi
movslq -0xc0(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl -0x10(%rbp), %esi
leaq -0x90(%rbp), %rdx
movl $0x7, %ecx
callq 0x3330
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x39bd
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x3afc
movl $0x0, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x3ae6
movq -0x98(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xa8(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0xa0(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xb0(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x3a4b
jmp 0x3ae8
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x3a32
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
leaq -0x50(%rbp), %rcx
leaq -0x98(%rbp), %rdi
movl $0x7, %r8d
callq 0x3470
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
leaq -0x90(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
movl $0x7, %r8d
callq 0x3470
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
leaq -0x90(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
movl $0x7, %r8d
callq 0x3470
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
leaq -0x50(%rbp), %rcx
leaq -0xb0(%rbp), %rdi
movl $0x7, %r8d
callq 0x3470
movl $0x0, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0xe4(%rbp)
movl -0xc(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xe4(%rbp), %eax
cmpl %ecx, %eax
jge 0x3cc9
movl $0x0, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
movl %eax, -0xe8(%rbp)
movl -0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xe8(%rbp), %eax
cmpl %ecx, %eax
jge 0x3c25
movq -0x98(%rbp), %rax
movl -0xcc(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0xd0(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xcc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xd0(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x3bad
movl -0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x3cb3
movq -0xb0(%rbp), %rax
movl -0xcc(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xf0(%rbp)
movl -0xd4(%rbp), %ecx
movl -0x10(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0xf0(%rbp), %rax
subl %edx, %ecx
shll %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xcc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xd4(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x3c36
jmp 0x3cb5
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x3b7c
movl -0xc(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0xd8(%rbp)
movl -0xd8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x3e53
movl $0x0, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
movl %eax, -0xf4(%rbp)
movl -0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xf4(%rbp), %eax
cmpl %ecx, %eax
jge 0x3d8b
movq -0xa8(%rbp), %rax
movq %rax, -0x100(%rbp)
movl -0xd8(%rbp), %ecx
movl -0xc(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0x100(%rbp), %rax
subl %edx, %ecx
shll %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0xdc(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xd8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xdc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x3cf3
movl -0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0xe0(%rbp)
movl -0xe0(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x3e3d
movq -0xa0(%rbp), %rax
movq %rax, -0x110(%rbp)
movl -0xd8(%rbp), %ecx
movl -0xc(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0x110(%rbp), %rax
subl %edx, %ecx
shll %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x108(%rbp)
movl -0xe0(%rbp), %ecx
movl -0x10(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0x108(%rbp), %rax
subl %edx, %ecx
shll %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xd8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xe0(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xe0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe0(%rbp)
jmp 0x3d9c
jmp 0x3e3f
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd8(%rbp)
jmp 0x3cda
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax)