// File: /workspace/github_cpp_makefile_star2_O3/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, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, 0xa0(%rsp)
movaps 0x2ae6(%rip), %xmm1     # 0x60c0
movaps %xmm1, 0xb0(%rsp)
movaps 0x2ae7(%rip), %xmm1     # 0x60d0
movaps %xmm1, 0xc0(%rsp)
movabsq $0x3fc999999999999a, %rax # imm = 0x3FC999999999999A
movq %rax, 0xd0(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps 0x2ace(%rip), %xmm0     # 0x60e0
movaps %xmm0, 0x60(%rsp)
movaps 0x2ad2(%rip), %xmm0     # 0x60f0
movaps %xmm0, 0x70(%rsp)
movabsq $0x3fd3333333333333, %rax # imm = 0x3FD3333333333333
movq %rax, 0x80(%rsp)
movabsq $-0x4046666666666666, %rax # imm = 0xBFB999999999999A
movq %rax, 0x90(%rsp)
movl %esi, %r12d
leaq (,%r12,8), %r14
testl %esi, %esi
movq $-0x1, %r13
cmovsq %r13, %r14
movq %r14, %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
movq %rax, 0x58(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x10(%rsp)
movq %rax, 0x50(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, %rbp
movq %rax, 0x48(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x20(%rsp)
movq %rax, 0x40(%rsp)
movl %r15d, 0x4(%rsp)
testl %r15d, %r15d
movq %rbp, 0x30(%rsp)
jle 0x3832
movl %ebx, %r15d
movq %r12, 0x28(%rsp)
leaq (,%r15,8), %rbp
movl %ebx, 0x3c(%rsp)
testl %ebx, %ebx
cmovsq %r13, %rbp
xorl %r14d, %r14d
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rbx
movq 0x20(%rsp), %r12
movq %rbp, %rdi
callq 0x2030
movq %rax, (%rbx,%r14,8)
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r13,%r14,8)
movq %rbp, %rdi
callq 0x2030
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r12,%r14,8)
incq %r14
cmpq %r14, 0x28(%rsp)
jne 0x36e4
cmpl $0x0, 0x4(%rsp)
movq 0x28(%rsp), %r12
movl 0x3c(%rsp), %ebx
jle 0x3832
movq 0x18(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r10
testl %ebx, %ebx
jle 0x3779
movq (%rax,%rcx,8), %rdx
movq (%r10,%rcx,8), %rsi
movq (%r9,%rcx,8), %rdi
xorl %r8d, %r8d
movsd (%rdx,%r8,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %r15
jne 0x375f
incq %rcx
cmpq %r12, %rcx
jne 0x374c
cmpl $0x0, 0x4(%rsp)
jle 0x3832
leaq 0x60(%rsp), %rbp
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %r14
movq %r13, %rdi
movl %ebx, %esi
leaq 0xa0(%rsp), %rdx
movl $0x7, %ecx
callq 0x3373
movq %r14, %rdi
movl %ebx, %esi
movq %rbp, %rdx
movl $0x7, %ecx
callq 0x3373
addq $0x8, %r14
addq $0x8, %r13
decq %r12
jne 0x379b
cmpl $0x0, 0x4(%rsp)
movq 0x28(%rsp), %r12
movq 0x30(%rsp), %r9
jle 0x3832
xorl %eax, %eax
testl %ebx, %ebx
jle 0x382a
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq (%r9,%rax,8), %rdx
movq 0x10(%rsp), %rsi
movq (%rsi,%rax,8), %rsi
movq 0x20(%rsp), %rdi
movq (%rdi,%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, %r15
jne 0x380a
incq %rax
cmpq %r12, %rax
jne 0x37e4
leaq 0x58(%rsp), %rdi
leaq 0xa0(%rsp), %rbp
movl 0x4(%rsp), %r15d
movl %r15d, %esi
movl %ebx, %edx
movq %rbp, %rcx
movl $0x7, %r8d
callq 0x343c
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %r14
movl %r15d, %esi
movl %ebx, %edx
movq %r14, %rcx
movl $0x7, %r8d
callq 0x343c
leaq 0x50(%rsp), %rdi
movl %r15d, %esi
movl %ebx, %edx
movq %r14, %rcx
movl $0x7, %r8d
callq 0x343c
leaq 0x40(%rsp), %rdi
movl %r15d, %esi
movl %ebx, %edx
movq %rbp, %rcx
movl $0x7, %r8d
callq 0x343c
movl %r15d, %ecx
shrl $0x1f, %ecx
addl %r15d, %ecx
sarl %ecx
movslq %ebx, %rax
movl %ecx, %ecx
cmpl $0x2, %r15d
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r15
movq 0x20(%rsp), %r13
jl 0x3944
movl %ebx, %edx
shrl $0x1f, %edx
addl %ebx, %edx
sarl %edx
movq 0x18(%rsp), %rsi
movq (%rsi), %rsi
movslq %edx, %rdi
xorl %r8d, %r8d
cmpl $0x2, %ebx
jl 0x390e
movq %r8, %r9
shlq $0x4, %r9
movq (%r15,%r9), %r9
movq (%rsi,%r8,8), %r10
xorl %r11d, %r11d
movsd (%r9), %xmm0
movsd %xmm0, (%r10,%r11,8)
incq %r11
addq $0x10, %r9
cmpq %r11, %rdx
jne 0x38f7
testl %ebx, %ebx
jle 0x393c
movq %r8, %r9
shlq $0x4, %r9
movq (%r13,%r9), %r9
movq (%rsi,%r8,8), %r10
movq %rdi, %r11
movsd (%r9), %xmm0
movsd %xmm0, (%r10,%r11,8)
incq %r11
addq $0x10, %r9
cmpq %rax, %r11
jl 0x3925
incq %r8
cmpq %rcx, %r8
jne 0x38e0
cmpl $0x0, 0x4(%rsp)
movq 0x30(%rsp), %r15
jle 0x39d4
movl %ebx, %edx
shrl $0x1f, %edx
addl %ebx, %edx
sarl %edx
movq 0x18(%rsp), %rsi
movq (%rsi), %rsi
movslq %edx, %rdi
movq %rcx, %r8
cmpl $0x2, %ebx
jl 0x399c
movq %r8, %r9
subq %rcx, %r9
shlq $0x4, %r9
movq (%r15,%r9), %r9
movq (%rsi,%r8,8), %r10
xorl %r11d, %r11d
movsd (%r9), %xmm0
movsd %xmm0, (%r10,%r11,8)
incq %r11
addq $0x10, %r9
cmpq %r11, %rdx
jne 0x3985
testl %ebx, %ebx
jle 0x39cc
movq %r8, %r9
subq %rcx, %r9
shlq $0x4, %r9
movq (%r14,%r9), %r9
movq (%rsi,%r8,8), %r10
movq %rdi, %r11
movsd (%r9), %xmm0
movsd %xmm0, (%r10,%r11,8)
incq %r11
addq $0x10, %r9
cmpq %rax, %r11
jl 0x39b5
incq %r8
cmpq %r12, %r8
jb 0x396b
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq