// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movq %rdi, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, 0xa0(%rsp)
movaps 0x20f3(%rip), %xmm1     # 0x5020
movaps %xmm1, 0xb0(%rsp)
movaps 0x20f4(%rip), %xmm1     # 0x5030
movaps %xmm1, 0xc0(%rsp)
movabsq $0x3fc999999999999a, %rax # imm = 0x3FC999999999999A
movq %rax, 0xd0(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps 0x20db(%rip), %xmm0     # 0x5040
movaps %xmm0, 0x60(%rsp)
movaps 0x20df(%rip), %xmm0     # 0x5050
movaps %xmm0, 0x70(%rsp)
movabsq $0x3fd3333333333333, %rax # imm = 0x3FD3333333333333
movq %rax, 0x80(%rsp)
movabsq $-0x4046666666666666, %rax # imm = 0xBFB999999999999A
movq %rax, 0x90(%rsp)
movl %esi, %r13d
shlq $0x3, %r13
xorl %ebx, %ebx
testl %esi, %esi
pushq $-0x1
popq %rax
cmovsq %rax, %r13
movl $0x0, %eax
movl %esi, 0x1c(%rsp)
cmovgl %esi, %eax
movq %rax, 0x28(%rsp)
movq %r13, %rdi
callq 0x2030
movq %rax, %r12
movq %rax, 0x58(%rsp)
movq %r13, %rdi
callq 0x2030
movq %rax, %r14
movq %rax, 0x50(%rsp)
movq %r13, %rdi
callq 0x2030
movq %rax, %r15
movq %rax, 0x48(%rsp)
movq %r13, %rdi
callq 0x2030
movq %rax, %r13
movq %rax, 0x40(%rsp)
movl %ebp, %eax
movl %ebp, %ebp
shlq $0x3, %rbp
movl %eax, 0xc(%rsp)
testl %eax, %eax
pushq $-0x1
popq %rax
cmovsq %rax, %rbp
cmpq %rbx, 0x28(%rsp)
je 0x304f
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r12,%rbx,8)
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r14,%rbx,8)
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r15,%rbx,8)
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r13,%rbx,8)
incq %rbx
jmp 0x3012
xorl %eax, %eax
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
movl $0x0, %ebx
cmovgl %ecx, %ebx
movq 0x28(%rsp), %rbp
cmpq %rbp, %rax
je 0x309d
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
xorl %edx, %edx
cmpq %rdx, %rbx
je 0x3098
movq (%rcx,%rax,8), %rsi
movsd (%rsi,%rdx,8), %xmm0
movq (%r12,%rax,8), %rsi
movsd %xmm0, (%rsi,%rdx,8)
movq (%r14,%rax,8), %rsi
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
jmp 0x3073
incq %rax
jmp 0x3064
movq %r12, %rax
movq %r14, 0x30(%rsp)
movq %rbp, %rcx
subq $0x1, %rcx
jb 0x3105
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movl 0xc(%rsp), %esi
leaq 0xa0(%rsp), %rdx
pushq $0x7
popq %rax
movq %rcx, 0x38(%rsp)
movl %eax, %ecx
callq 0x2ce7
movq 0x30(%rsp), %rbp
movq %rbp, %rdi
movl 0xc(%rsp), %esi
leaq 0x60(%rsp), %rdx
pushq $0x7
popq %rcx
callq 0x2ce7
movq 0x38(%rsp), %rcx
movq 0x20(%rsp), %rax
addq $0x8, %rbp
movq %rbp, 0x30(%rsp)
addq $0x8, %rax
jmp 0x30a8
xorl %eax, %eax
movq 0x28(%rsp), %rsi
cmpq %rsi, %rax
je 0x3147
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x3142
movq (%r12,%rax,8), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq (%r15,%rax,8), %rdx
movsd %xmm0, (%rdx,%rcx,8)
movq (%r14,%rax,8), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq (%r13,%rax,8), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x3113
incq %rax
jmp 0x310c
leaq 0x58(%rsp), %rdi
leaq 0xa0(%rsp), %rcx
pushq $0x7
popq %r8
movl 0x1c(%rsp), %ebx
movl %ebx, %esi
movl 0xc(%rsp), %ebp
movl %ebp, %edx
callq 0x2da9
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %rcx
movl %ebx, %esi
movl %ebp, %edx
pushq $0x7
popq %r8
callq 0x2da9
leaq 0x50(%rsp), %rdi
movl %ebx, %esi
movl %ebp, %edx
leaq 0x60(%rsp), %rcx
pushq $0x7
popq %r8
callq 0x2da9
leaq 0x40(%rsp), %rdi
movl %ebx, %esi
movl %ebp, %edx
leaq 0xa0(%rsp), %rcx
pushq $0x7
popq %r8
callq 0x2da9
pushq $0x2
popq %rsi
movl %ebx, %eax
cltd
idivl %esi
movl %eax, %ecx
movl %ebp, %eax
cltd
idivl %esi
xorl %edi, %edi
testl %eax, %eax
movl $0x0, %esi
cmovgl %eax, %esi
cltq
movslq %ebp, %rdx
testl %ecx, %ecx
movl $0x0, %r8d
movl %ecx, 0x20(%rsp)
cmovgl %ecx, %r8d
leaq (,%rsi,8), %r9
cmpq %r8, %rdi
je 0x324e
leaq (%rdi,%rdi), %r10
movq 0x10(%rsp), %rcx
movq (%rcx), %r11
xorl %ebx, %ebx
cmpq %rbx, %r9
je 0x321b
movq (%r12,%r10,8), %rbp
movsd (%rbp,%rbx,2), %xmm0
movq (%r11,%rdi,8), %rbp
movsd %xmm0, (%rbp,%rbx)
addq $0x8, %rbx
jmp 0x31fc
movq 0x10(%rsp), %rcx
movq (%rcx), %r11
xorl %ebx, %ebx
movq %rax, %rbp
cmpq %rdx, %rbp
jge 0x3249
movq (%r13,%r10,8), %rcx
movsd (%rcx,%rbx), %xmm0
movq (%r11,%rdi,8), %rcx
movsd %xmm0, (%rcx,%rbp,8)
incq %rbp
addq $0x10, %rbx
jmp 0x3228
incq %rdi
jmp 0x31e9
movslq 0x20(%rsp), %rcx
movslq 0x1c(%rsp), %rdi
movl %esi, %esi
shlq $0x3, %rsi
movq %rcx, %r8
cmpq %rdi, %r8
jge 0x32ce
movq %r8, %r9
subq %rcx, %r9
addq %r9, %r9
movq 0x10(%rsp), %r10
movq (%r10), %r10
xorl %r11d, %r11d
cmpq %r11, %rsi
je 0x3299
movq (%r15,%r9,8), %rbx
movsd (%rbx,%r11,2), %xmm0
movq (%r10,%r8,8), %rbx
movsd %xmm0, (%rbx,%r11)
addq $0x8, %r11
jmp 0x327a
movq 0x10(%rsp), %r10
movq (%r10), %r10
xorl %r11d, %r11d
movq %rax, %rbx
cmpq %rdx, %rbx
jge 0x32c9
movq (%r14,%r9,8), %r12
movsd (%r12,%r11), %xmm0
movq (%r10,%r8,8), %r12
movsd %xmm0, (%r12,%rbx,8)
incq %rbx
addq $0x10, %r11
jmp 0x32a7
incq %r8
jmp 0x3261
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq