// File: /workspace/github_cpp_makefile_star2_O2/kebwi[P]Trifid/src/SteerablePyramid.cpp
// Function: SteerablePyramid::DoOneStepWaveletSynthesis(int, double*, double*)
void SteerablePyramid::DoOneStepWaveletSynthesis(int level, Float_t* pixelValues, Float_t *upsampledThumbnail)
{
	int horDim = width_ / pow(2, level);
	int verDim = height_ / pow(2, level);
	int totalPixels = horDim * verDim;
	
	for (int i = 0; i < verDim; i++)
		yLookup_[i] = i * horDim;
	
	Float_t *finalImage = NULL;
	Float_t *pixelPtr = NULL;
	Float_t *coeffPtr = NULL;
	
	if (level == 0)
		finalImage = new Float_t[totalPixels];
	
	//Is this necessary or did new clear out the allocated memory?
	memset(upsampledThumbnail, 0, totalPixels * sizeof(Float_t));
	
	//Upsample the growing thumbnail from the base thumbnail (lowest level) or the previous iteration's thumbnail
	
	if (level == numLevels_ - 1)	//Lowest level, upsample actual stored thumbnail
		pixelPtr = l1Coeffs_[level];
	else	//Intermediate level, upsample growing thumbnail from previous iteration
		pixelPtr = pixelValues;
	
	for (int y = 0; y < verDim / 2; y++)
	{
		coeffPtr = &upsampledThumbnail[(y * 2) * horDim];
		for (int x = 0; x < horDim / 2; x++)
		{
			*coeffPtr = *pixelPtr++ * 4;
			coeffPtr += 2;
		}
	}
	
	ConvolveImage(upsampledThumbnail, horDim, verDim, skFiltersInv[2], skFilterDims[2], pixelValues, true);
	ConvolveImage(b1Coeffs_[level], horDim, verDim, skFiltersInv[3], skFilterDims[3], pixelValues, false);
	ConvolveImage(b2Coeffs_[level], horDim, verDim, skFiltersInv[4], skFilterDims[4], pixelValues, false);
	ConvolveImage(b3Coeffs_[level], horDim, verDim, skFiltersInv[5], skFilterDims[5], pixelValues, false);
	ConvolveImage(b4Coeffs_[level], horDim, verDim, skFiltersInv[6], skFilterDims[6], pixelValues, false);
	
	if (level == 0)
	{
		ConvolveImage(pixelValues, horDim, verDim, skFiltersInv[1], skFilterDims[1], finalImage, true);
		ConvolveImage(h0Coeffs_, horDim, verDim, skFiltersInv[0], skFilterDims[0], finalImage, false);
	}
	
	if (level == 0)
		memcpy(pixelValues, finalImage, totalPixels * sizeof(Float_t));
	
	if (level == 0)
		delete [] finalImage;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r13
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
cvtsi2sdl 0x30(%rdi), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0xa5e6(%rip), %xmm0     # 0x22058
movl %esi, %edi
callq 0x33f0
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r15d
cvtsi2sdl 0x34(%r14), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0xa5bc(%rip), %xmm0     # 0x22058
movl %ebp, 0x10(%rsp)
movl %ebp, %edi
callq 0x33f0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %ebp
movq 0x40(%r14), %rax
xorl %ecx, %ecx
testl %ebp, %ebp
movl $0x0, %edx
cmovgl %ebp, %edx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x17ad7
movl %ecx, (%rax,%rsi,4)
incq %rsi
addl %r15d, %ecx
jmp 0x17ac7
movl %ebp, %eax
imull %r15d, %eax
movslq %eax, %rdx
cmpl $0x0, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
je 0x17afb
shlq $0x3, %rdx
movq $0x0, 0x8(%rsp)
jmp 0x17b19
leaq (,%rdx,8), %rbx
testl %edx, %edx
pushq $-0x1
popq %rdi
cmovnsq %rbx, %rdi
callq 0x3030
movq %rax, 0x8(%rsp)
movq %rbx, %rdx
xorl %r12d, %r12d
movq %r13, %rdi
xorl %esi, %esi
movq %rdx, 0x20(%rsp)
callq 0x3170
movl 0x38(%r14), %eax
decl %eax
movl 0x10(%rsp), %ecx
movslq %ecx, %rbx
movq 0x18(%rsp), %rsi
cmpl %ecx, %eax
jne 0x17b49
movq 0x28(%r14), %rax
movq (%rax,%rbx,8), %rsi
pushq $0x2
popq %rdi
movl %ebp, %eax
cltd
idivl %edi
movl %eax, %ecx
movl %r15d, %eax
cltd
idivl %edi
testl %eax, %eax
cmovlel %r12d, %eax
testl %ecx, %ecx
cmovlel %r12d, %ecx
leal (%r15,%r15), %edx
addl %eax, %eax
movsd 0xd625(%rip), %xmm0     # 0x25198
xorl %edi, %edi
cmpq %rcx, %rdi
je 0x17bb0
movslq %r12d, %r8
leaq (,%r8,8), %r8
addq %r13, %r8
xorl %r9d, %r9d
cmpl %r9d, %eax
je 0x17ba8
movsd (%rsi), %xmm1
mulsd %xmm0, %xmm1
addq $0x8, %rsi
movsd %xmm1, (%r8,%r9,8)
addq $0x2, %r9
jmp 0x17b8b
incq %rdi
addl %edx, %r12d
jmp 0x17b75
movq 0x1afa9(%rip), %r8      # 0x32b60
movl 0x1af3a(%rip), %r9d     # 0x32af8
movq %r14, %rdi
movq %r13, %rsi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x1
movq 0x20(%rsp), %r12
pushq %r12
callq 0x16882
popq %rax
popq %rcx
movq 0x8(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq 0x1af80(%rip), %r8      # 0x32b68
movl 0x1af0d(%rip), %r9d     # 0x32afc
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x0
pushq %r12
callq 0x16882
popq %rax
popq %rcx
movq 0x10(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq 0x1af5f(%rip), %r8      # 0x32b70
movl 0x1aee8(%rip), %r9d     # 0x32b00
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x0
pushq %r12
callq 0x16882
popq %rax
popq %rcx
movq 0x18(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq 0x1af3e(%rip), %r8      # 0x32b78
movl 0x1aec3(%rip), %r9d     # 0x32b04
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x0
pushq %r12
callq 0x16882
popq %rax
popq %rcx
movq 0x20(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq 0x1af1d(%rip), %r8      # 0x32b80
movl 0x1ae9e(%rip), %r9d     # 0x32b08
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x0
pushq %r12
callq 0x16882
popq %rax
popq %rcx
cmpl $0x0, 0x10(%rsp)
je 0x17c93
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1aebe(%rip), %r8      # 0x32b58
movl 0x1ae53(%rip), %r9d     # 0x32af4
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x1
movq 0x10(%rsp), %rbx
pushq %rbx
callq 0x16882
popq %rax
popq %rcx
movq (%r14), %rsi
movq 0x1ae8b(%rip), %r8      # 0x32b50
movl 0x1ae24(%rip), %r9d     # 0x32af0
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x0
pushq %rbx
callq 0x16882
popq %rax
popq %rcx
movq %r12, %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %rdx
callq 0x3240
testq %rbx, %rbx
je 0x17c84
movq 0x8(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3380
nop