// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %edx, %ebx
movl %esi, 0x4(%rsp)
movq %rdi, 0x20(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xc0(%rsp)
movabsq $0x3fc999999999999a, %rax # imm = 0x3FC999999999999A
movq %rax, 0xa0(%rsp)
movabsq $0x3fe3333333333333, %rcx # imm = 0x3FE3333333333333
movq %rcx, 0xa8(%rsp)
movabsq $0x3fe6666666666666, %rdx # imm = 0x3FE6666666666666
movq %rdx, 0xb0(%rsp)
movq %rax, 0xb8(%rsp)
movabsq $-0x402ccccccccccccd, %rdx # imm = 0xBFD3333333333333
movq %rdx, 0xc0(%rsp)
movabsq $0x3fb999999999999a, %rdx # imm = 0x3FB999999999999A
movq %rdx, 0xd0(%rsp)
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x80(%rsp)
movabsq $-0x4046666666666666, %rdx # imm = 0xBFB999999999999A
movq %rdx, 0x60(%rsp)
movabsq $0x3fd3333333333333, %rdx # imm = 0x3FD3333333333333
movq %rdx, 0x70(%rsp)
movq %rax, 0x78(%rsp)
movabsq $-0x401999999999999a, %rax # imm = 0xBFE6666666666666
movq %rax, 0x80(%rsp)
movq %rcx, 0x88(%rsp)
movabsq $-0x4036666666666666, %rax # imm = 0xBFC999999999999A
movq %rax, 0x90(%rsp)
movslq %esi, %rbp
leaq (,%rbp,8), %r13
testl %ebp, %ebp
movq $-0x1, %rax
cmovsq %rax, %r13
movq %r13, %rdi
callq 0x2030
movq %rax, %r14
movq %rax, 0x58(%rsp)
movq %r13, %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
movq %rax, 0x50(%rsp)
movq %r13, %rdi
callq 0x2030
movq %rax, %r15
movq %rax, 0x48(%rsp)
movq %r13, %rdi
callq 0x2030
movq %rax, %r12
movq %rax, 0x40(%rsp)
movl 0x4(%rsp), %r10d
testl %ebp, %ebp
movq %r10, 0x18(%rsp)
jle 0x2720
movslq %ebx, %rax
leaq (,%rax,8), %rbp
testl %eax, %eax
movq $-0x1, %rax
cmovsq %rax, %rbp
xorl %r13d, %r13d
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r14,%r13,8)
movq %rbp, %rdi
callq 0x2030
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r15,%r13,8)
movq %rbp, %rdi
callq 0x2030
movq 0x18(%rsp), %r10
movq %rax, (%r12,%r13,8)
incq %r13
cmpq %r13, %r10
jne 0x26de
movl %ebx, %r13d
movl 0x4(%rsp), %ebp
testl %ebp, %ebp
movq 0x8(%rsp), %r11
jle 0x276b
xorl %eax, %eax
xorl %ecx, %ecx
testl %ebx, %ebx
jle 0x2763
movq (%r14,%rcx,8), %rdx
movq (%r11,%rcx,8), %rsi
movq (%r15,%rcx,8), %rdi
movq (%r12,%rcx,8), %r8
xorl %r9d, %r9d
movq %rax, (%rdx,%r9,8)
movq %rax, (%rsi,%r9,8)
movq %rax, (%rdi,%r9,8)
movq %rax, (%r8,%r9,8)
incq %r9
cmpq %r9, %r13
jne 0x274b
incq %rcx
cmpq %r10, %rcx
jne 0x2734
movq %r12, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movq %r14, 0x10(%rsp)
cmpl $0x2, %ebp
jl 0x283a
movl 0x4(%rsp), %eax
shrl %eax
movl %ebx, %ecx
shrl $0x1f, %ecx
addl %ebx, %ecx
sarl %ecx
movq 0x20(%rsp), %rdx
movq (%rdx), %rdx
movq %rdx, %r15
leaq (%rdx,%rax,8), %rdx
movq %rdx, 0x38(%rsp)
shlq $0x3, %rcx
xorl %edi, %edi
cmpl $0x2, %ebx
jl 0x282e
movq (%r15,%rdi,8), %r8
movq %rdi, %rdx
shlq $0x4, %rdx
movq 0x10(%rsp), %rsi
movq (%rsi,%rdx), %r9
movq 0x38(%rsp), %rsi
movq (%rsi,%rdi,8), %r10
movq 0x28(%rsp), %rsi
movq (%rsi,%rdx), %r11
movq 0x8(%rsp), %rsi
movq (%rsi,%rdx), %rbp
movq 0x30(%rsp), %rsi
movq (%rsi,%rdx), %rsi
leaq (%r8,%rcx), %rdx
leaq (%r10,%rcx), %r12
xorl %r14d, %r14d
movsd (%r8,%r14), %xmm0
movsd %xmm0, (%r9,%r14,2)
movsd (%r10,%r14), %xmm0
movsd %xmm0, (%r11,%r14,2)
movsd (%r12,%r14), %xmm0
movsd %xmm0, (%rbp,%r14,2)
movsd (%rdx,%r14), %xmm0
movsd %xmm0, (%rsi,%r14,2)
addq $0x8, %r14
cmpq %r14, %rcx
jne 0x27f4
incq %rdi
cmpq %rax, %rdi
jne 0x27ac
leaq 0x58(%rsp), %rdi
leaq 0xa0(%rsp), %r15
movl 0x4(%rsp), %r14d
movl %r14d, %esi
movl %ebx, %edx
movq %r15, %rcx
movl $0x7, %r8d
callq 0x23fb
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %rbp
movl %r14d, %esi
movl %ebx, %edx
movq %rbp, %rcx
movl $0x7, %r8d
callq 0x23fb
leaq 0x50(%rsp), %rdi
movl %r14d, %esi
movl %ebx, %edx
movq %rbp, %rcx
movl $0x7, %r8d
callq 0x23fb
leaq 0x40(%rsp), %rdi
movl %r14d, %esi
movl %ebx, %edx
movq %r15, %rcx
movl $0x7, %r8d
callq 0x23fb
testl %r14d, %r14d
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r10
movq 0x28(%rsp), %r15
movq 0x18(%rsp), %r11
movq 0x30(%rsp), %r12
jle 0x2917
xorl %eax, %eax
testl %ebx, %ebx
jle 0x290f
movq (%r9,%rax,8), %rcx
movq (%r15,%rax,8), %rdx
movq (%r10,%rax,8), %rsi
movq (%r12,%rax,8), %rdi
xorl %r8d, %r8d
movsd (%rcx,%r8,8), %xmm0
addsd (%rdx,%r8,8), %xmm0
movsd %xmm0, (%rcx,%r8,8)
movsd (%rsi,%r8,8), %xmm0
addsd (%rdi,%r8,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
incq %r8
cmpq %r8, %r13
jne 0x28e3
incq %rax
cmpq %r11, %rax
jne 0x28cc
testl %r14d, %r14d
jle 0x2966
leaq 0xa0(%rsp), %r15
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %r12
movq %rbp, %rdi
movl %ebx, %esi
movq %r15, %rdx
movl $0x7, %ecx
callq 0x232c
movq %r12, %rdi
movl %ebx, %esi
leaq 0x60(%rsp), %rdx
movl $0x7, %ecx
callq 0x232c
addq $0x8, %r12
addq $0x8, %rbp
decq %r14
jne 0x2933
cmpl $0x0, 0x4(%rsp)
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r10
movq 0x18(%rsp), %r11
jle 0x29c7
movq 0x20(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
movsd 0x167a(%rip), %xmm0     # 0x4008
testl %ebx, %ebx
jle 0x29bf
movq (%r9,%rcx,8), %rdx
movq (%r10,%rcx,8), %rsi
movq (%rax,%rcx,8), %rdi
xorl %r8d, %r8d
movsd (%rdx,%r8,8), %xmm1
addsd (%rsi,%r8,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rdi,%r8,8)
incq %r8
cmpq %r8, %r13
jne 0x29a1
incq %rcx
cmpq %r11, %rcx
jne 0x298e
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq