// File: /workspace/github_cpp_makefile_star2_O1/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, 0x20(%rsp)
movl %esi, %ebx
movq %rdi, %r14
cvtsi2sdl 0x30(%rdi), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0xd396(%rip), %xmm0     # 0x2b058
movl %esi, %edi
callq 0x3410
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r15d
xorps %xmm0, %xmm0
cvtsi2sdl 0x34(%r14), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0xd369(%rip), %xmm0     # 0x2b058
movl %ebx, %edi
callq 0x3410
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %ebp
movl %ebp, %eax
imull %r15d, %eax
testl %ebp, %ebp
jle 0x1dd26
movq 0x40(%r14), %rcx
movl %ebp, %edx
xorl %esi, %esi
xorl %edi, %edi
movl %esi, (%rcx,%rdi,4)
incq %rdi
addl %r15d, %esi
cmpq %rdi, %rdx
jne 0x1dd18
movslq %eax, %rdx
testl %ebx, %ebx
je 0x1dd38
movq $0x0, 0x10(%rsp)
jmp 0x1dd5d
leaq (,%rdx,8), %rax
testl %edx, %edx
movq $-0x1, %rdi
cmovnsq %rax, %rdi
movq %rdx, %r12
callq 0x3030
movq %r12, %rdx
movq %rax, 0x10(%rsp)
shlq $0x3, %rdx
movq %r13, %rdi
xorl %esi, %esi
movq %rdx, 0x18(%rsp)
callq 0x3190
movl 0x38(%r14), %ecx
decl %ecx
movl %ebx, %edx
movslq %ebx, %rbx
movq 0x20(%rsp), %r12
movq %r12, %rax
movl %edx, 0x8(%rsp)
cmpl %edx, %ecx
jne 0x1dd93
movq 0x28(%r14), %rax
movq (%rax,%rbx,8), %rax
cmpl $0x2, %ebp
jl 0x1ddf5
movl %ebp, %ecx
shrl %ecx
leal (%r15,%r15), %edx
movl %r15d, %esi
shrl $0x1f, %esi
addl %r15d, %esi
sarl %esi
xorl %edi, %edi
movsd 0x103db(%rip), %xmm0    # 0x2e190
cmpl $0x2, %r15d
jl 0x1dded
movl %edx, %r8d
imull %edi, %r8d
movslq %r8d, %r8
leaq (,%r8,8), %r8
addq %r13, %r8
movl %esi, %r9d
movsd (%rax), %xmm1
mulsd %xmm0, %xmm1
addq $0x8, %rax
movsd %xmm1, (%r8)
addq $0x10, %r8
decl %r9d
jne 0x1ddd3
incq %rdi
cmpq %rcx, %rdi
jne 0x1ddb5
movq 0x1bd74(%rip), %r8      # 0x39b70
movl 0x1bd05(%rip), %r9d     # 0x39b08
movq %r14, %rdi
movq %r13, %rsi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x1
pushq %r12
callq 0x1c96c
addq $0x10, %rsp
movq 0x8(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq 0x1bd4e(%rip), %r8      # 0x39b78
movl 0x1bcdb(%rip), %r9d     # 0x39b0c
xorl %r13d, %r13d
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq %r13
pushq %r12
callq 0x1c96c
addq $0x10, %rsp
movq 0x10(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq 0x1bd28(%rip), %r8      # 0x39b80
movl 0x1bcb1(%rip), %r9d     # 0x39b10
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq %r13
pushq %r12
callq 0x1c96c
addq $0x10, %rsp
movq 0x18(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq 0x1bd05(%rip), %r8      # 0x39b88
movl 0x1bc8a(%rip), %r9d     # 0x39b14
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq %r13
pushq %r12
callq 0x1c96c
addq $0x10, %rsp
movq 0x20(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq 0x1bce2(%rip), %r8      # 0x39b90
movl 0x1bc63(%rip), %r9d     # 0x39b18
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq %r13
pushq %r12
callq 0x1c96c
addq $0x10, %rsp
cmpl $0x0, 0x8(%rsp)
je 0x1dee0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1bc81(%rip), %r8      # 0x39b68
movl 0x1bc16(%rip), %r9d     # 0x39b04
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x1
movq 0x18(%rsp), %rbx
pushq %rbx
callq 0x1c96c
addq $0x10, %rsp
movq (%r14), %rsi
movq 0x1bc4c(%rip), %r8      # 0x39b60
movl 0x1bbe5(%rip), %r9d     # 0x39b00
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq $0x0
pushq %rbx
callq 0x1c96c
addq $0x10, %rsp
movq %r12, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
callq 0x3260
testq %rbx, %rbx
je 0x1ded1
movq 0x10(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x33c0