// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
cvtsi2sdl 0x30(%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movl -0xc(%rbp), %esi
movl $0x2, %edi
callq 0x1d7f0
movq -0x68(%rbp), %rax
movaps %xmm0, %xmm1
movsd -0x60(%rbp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x24(%rbp)
cvtsi2sdl 0x34(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0xc(%rbp), %esi
movl $0x2, %edi
callq 0x1d7f0
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
imull -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x2d694
movq -0x68(%rbp), %rax
movl -0x30(%rbp), %edx
imull -0x24(%rbp), %edx
movq 0x40(%rax), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2d66b
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x2d6db
movslq -0x2c(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4030
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x2c(%rbp), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x41e0
movq -0x68(%rbp), %rcx
movl -0xc(%rbp), %eax
movl 0x38(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2d715
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
jmp 0x2d71d
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x28(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x6c(%rbp), %eax
cmpl %ecx, %eax
jge 0x2d7c8
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
shll %ecx
imull -0x24(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x24(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x70(%rbp), %eax
cmpl %ecx, %eax
jge 0x2d7b8
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x40(%rbp)
movsd 0x1eaab(%rip), %xmm0    # 0x4c240
mulsd (%rax), %xmm0
movq -0x48(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x48(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x48(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x2d764
jmp 0x2d7ba
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2d724
movq -0x68(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movq 0x2f463(%rip), %r8      # 0x5cc40
movl 0x2f3f4(%rip), %r9d     # 0x5cbd8
movq -0x18(%rbp), %rax
movq %rax, (%rsp)
movl $0x1, 0x8(%rsp)
callq 0x2bc90
movq -0x68(%rbp), %rdi
movq 0x8(%rdi), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movq 0x2f432(%rip), %r8      # 0x5cc48
movl 0x2f3bf(%rip), %r9d     # 0x5cbdc
movq -0x18(%rbp), %rax
xorl %r10d, %r10d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x2bc90
movq -0x68(%rbp), %rdi
movq 0x10(%rdi), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movq 0x2f3fe(%rip), %r8      # 0x5cc50
movl 0x2f387(%rip), %r9d     # 0x5cbe0
movq -0x18(%rbp), %rax
xorl %r10d, %r10d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x2bc90
movq -0x68(%rbp), %rdi
movq 0x18(%rdi), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movq 0x2f3ca(%rip), %r8      # 0x5cc58
movl 0x2f34f(%rip), %r9d     # 0x5cbe4
movq -0x18(%rbp), %rax
xorl %r10d, %r10d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x2bc90
movq -0x68(%rbp), %rdi
movq 0x20(%rdi), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movq 0x2f396(%rip), %r8      # 0x5cc60
movl 0x2f317(%rip), %r9d     # 0x5cbe8
movq -0x18(%rbp), %rax
xorl %r10d, %r10d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x2bc90
cmpl $0x0, -0xc(%rbp)
jne 0x2d953
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movq 0x2f334(%rip), %r8      # 0x5cc38
movl 0x2f2c9(%rip), %r9d     # 0x5cbd4
movq -0x38(%rbp), %rax
movq %rax, (%rsp)
movl $0x1, 0x8(%rsp)
callq 0x2bc90
movq -0x68(%rbp), %rdi
movq (%rdi), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movq 0x2f2fc(%rip), %r8      # 0x5cc30
movl 0x2f295(%rip), %r9d     # 0x5cbd0
movq -0x38(%rbp), %rax
xorl %r10d, %r10d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x2bc90
cmpl $0x0, -0xc(%rbp)
jne 0x2d96e
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0x2c(%rbp), %rdx
shlq $0x3, %rdx
callq 0x4300
cmpl $0x0, -0xc(%rbp)
jne 0x2d98d
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0x2d98b
movq -0x78(%rbp), %rdi
callq 0x44d0
jmp 0x2d98d
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)