// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %edx, %ebx
movl %esi, %r15d
movq %rdi, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, 0xa0(%rsp)
movabsq $-0x402ccccccccccccd, %rax # imm = 0xBFD3333333333333
movq %rax, 0xb0(%rsp)
movabsq $0x3fc999999999999a, %rax # imm = 0x3FC999999999999A
movq %rax, 0xb8(%rsp)
movabsq $0x3fe6666666666666, %rcx # imm = 0x3FE6666666666666
movq %rcx, 0xc0(%rsp)
movabsq $0x3fe3333333333333, %rcx # imm = 0x3FE3333333333333
movq %rcx, 0xc8(%rsp)
movq %rax, 0xd0(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movabsq $-0x4036666666666666, %rdx # imm = 0xBFC999999999999A
movq %rdx, 0x60(%rsp)
movq %rcx, 0x68(%rsp)
movabsq $-0x401999999999999a, %rcx # imm = 0xBFE6666666666666
movq %rcx, 0x70(%rsp)
movq %rax, 0x78(%rsp)
movabsq $0x3fd3333333333333, %rax # imm = 0x3FD3333333333333
movq %rax, 0x80(%rsp)
movabsq $-0x4046666666666666, %rax # imm = 0xBFB999999999999A
movq %rax, 0x90(%rsp)
movslq %esi, %rbp
leaq (,%rbp,8), %r14
testl %ebp, %ebp
movq $-0x1, %rax
cmovsq %rax, %r14
movq %r14, %rdi
callq 0x2030
movq %rax, 0x10(%rsp)
movq %rax, 0x58(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x18(%rsp)
movq %rax, 0x50(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x30(%rsp)
movq %rax, 0x48(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, %r13
movq %rax, 0x40(%rsp)
movslq %ebx, %r12
movl %r15d, 0xc(%rsp)
movl %r15d, %r15d
testl %ebp, %ebp
jle 0x3137
leaq (,%r12,8), %rbp
testl %r12d, %r12d
movq $-0x1, %rax
cmovsq %rax, %rbp
xorl %r14d, %r14d
movq %rbp, %rdi
callq 0x2030
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
movq %rbp, %rdi
callq 0x2030
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
movq %rbp, %rdi
callq 0x2030
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r13,%r14,8)
incq %r14
cmpq %r14, %r15
jne 0x30ef
movq %r13, 0x38(%rsp)
movl %ebx, %ebp
cmpl $0x0, 0xc(%rsp)
movq 0x10(%rsp), %r9
movq 0x18(%rsp), %r10
jle 0x3194
movq 0x20(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
testl %ebx, %ebx
jle 0x318c
movq (%rax,%rcx,8), %rdx
movq (%r9,%rcx,8), %rsi
movq (%r10,%rcx,8), %rdi
xorl %r8d, %r8d
movsd (%rdx,%r8,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
movsd (%rdx,%r8,8), %xmm0
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rbp
jne 0x316c
incq %rcx
cmpq %r15, %rcx
jne 0x3159
movq %r15, 0x28(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x31e7
movq 0x28(%rsp), %r15
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %r14
movq %r13, %rdi
movl %ebx, %esi
leaq 0xa0(%rsp), %rdx
movl $0x7, %ecx
callq 0x2d45
movq %r14, %rdi
movl %ebx, %esi
leaq 0x60(%rsp), %rdx
movl $0x7, %ecx
callq 0x2d45
addq $0x8, %r14
addq $0x8, %r13
decq %r15
jne 0x31af
cmpl $0x0, 0xc(%rsp)
movq 0x18(%rsp), %r15
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %r10
movq 0x10(%rsp), %r11
movq 0x38(%rsp), %r14
jle 0x3248
xorl %eax, %eax
testl %ebx, %ebx
jle 0x3240
movq (%r11,%rax,8), %rcx
movq (%r9,%rax,8), %rdx
movq (%r15,%rax,8), %rsi
movq (%r14,%rax,8), %rdi
xorl %r8d, %r8d
movsd (%rcx,%r8,8), %xmm0
movsd %xmm0, (%rdx,%r8,8)
movsd (%rsi,%r8,8), %xmm0
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rbp
jne 0x3220
incq %rax
cmpq %r10, %rax
jne 0x3209
leaq 0x58(%rsp), %rdi
leaq 0xa0(%rsp), %r13
movl 0xc(%rsp), %ebp
movl %ebp, %esi
movl %ebx, %edx
movq %r13, %rcx
movl $0x7, %r8d
callq 0x2e14
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %r14
movl %ebp, %esi
movl %ebx, %edx
movq %r14, %rcx
movl $0x7, %r8d
callq 0x2e14
leaq 0x50(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
movq %r14, %rcx
movl $0x7, %r8d
callq 0x2e14
leaq 0x40(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
movq %r13, %rcx
movq 0x38(%rsp), %r13
movq 0x10(%rsp), %r14
movl $0x7, %r8d
callq 0x2e14
movl %ebp, %eax
shrl $0x1f, %eax
addl %ebp, %eax
sarl %eax
movl %eax, %eax
cmpl $0x2, %ebp
jl 0x3362
movl %ebx, %ecx
shrl $0x1f, %ecx
addl %ebx, %ecx
sarl %ecx
movq 0x20(%rsp), %rdx
movq (%rdx), %rdx
movslq %ecx, %rsi
movq %rsi, %rdi
shlq $0x4, %rdi
movq %rcx, %r8
shlq $0x4, %r8
subq %r8, %rdi
xorl %r8d, %r8d
cmpl $0x2, %ebx
jl 0x3329
movq %r8, %r9
shlq $0x4, %r9
movq (%r14,%r9), %r9
movq (%rdx,%r8,8), %r10
xorl %r11d, %r11d
movsd (%r9), %xmm0
movsd %xmm0, (%r10,%r11,8)
incq %r11
addq $0x10, %r9
cmpq %r11, %rcx
jne 0x3312
testl %ebx, %ebx
jle 0x335a
movq %r8, %r10
shlq $0x4, %r10
movq (%rdx,%r8,8), %r9
movq (%r13,%r10), %r10
addq %rdi, %r10
movq %rsi, %r11
movsd (%r10), %xmm0
movsd %xmm0, (%r9,%r11,8)
incq %r11
addq $0x10, %r10
cmpq %r12, %r11
jl 0x3343
incq %r8
cmpq %rax, %r8
jne 0x32fb
cmpl $0x0, 0xc(%rsp)
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r13
jle 0x340b
movl %ebx, %ecx
shrl $0x1f, %ecx
addl %ebx, %ecx
sarl %ecx
movq 0x20(%rsp), %rdx
movq (%rdx), %rdx
movslq %ecx, %rsi
movq %rsi, %rdi
shlq $0x4, %rdi
movq %rcx, %r8
shlq $0x4, %r8
subq %r8, %rdi
movq %rax, %r8
cmpl $0x2, %ebx
jl 0x33d0
movq %r8, %r9
subq %rax, %r9
shlq $0x4, %r9
movq (%r14,%r9), %r9
movq (%rdx,%r8,8), %r10
xorl %r11d, %r11d
movsd (%r9), %xmm0
movsd %xmm0, (%r10,%r11,8)
incq %r11
addq $0x10, %r9
cmpq %r11, %rcx
jne 0x33b9
testl %ebx, %ebx
jle 0x3403
movq %r8, %r10
subq %rax, %r10
shlq $0x4, %r10
movq (%rdx,%r8,8), %r9
movq (%r15,%r10), %r10
addq %rdi, %r10
movq %rsi, %r11
movsd (%r10), %xmm0
movsd %xmm0, (%r9,%r11,8)
incq %r11
addq $0x10, %r10
cmpq %r12, %r11
jl 0x33ec
incq %r8
cmpq %r13, %r8
jb 0x339f
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq