// File: /workspace/github_cpp_makefile_star2_O3/kebwi[P]Trifid/src/SteerablePyramid.cpp
// Function: SteerablePyramid::getFilterFTIndex()
int SteerablePyramid::getFilterFTIndex()
{
	assert(skFilterDims[0] > 0);
	
	//Search the currently defined filter FTs for one with the appropriate dimensions.
	//If one is found, return its index.
	for (int i = 0; i < skFiltersFTs.size(); i++)
		if (skFiltersFTs[i].width_ == width_ && skFiltersFTs[i].height_ == height_)
			return i;
	
	//No filter FT with the appropriate dimensions was found, so add a new one and return its index.
	FilterFT filterFT;
	skFiltersFTs.push_back(filterFT);
	skFiltersFTs.back().resize(width_, height_);
	
	Float_t *shiftBuffer = new Float_t[width_ * height_];
	for (int i = 0; i < 7; i++)
		for (int lvl = 0 ; lvl < numLevels_; lvl++)
		{	
			int filterDim = skFilterDims[i];
			
			int horDim = width_ / pow(2, lvl);
			int verDim = height_ / pow(2, lvl);
			assert(horDim >= filterDim && verDim >= filterDim);
			
			memset(shiftBuffer, 0, horDim * verDim * sizeof(Float_t));
			
			int xOffset = (horDim - filterDim) / 2;
			int yOffset = (verDim - filterDim) / 2;
			
			//By default, an embedded odd-length signal will be positioned such that the center pixel
			//resides at lower right, but I prefer that it be at upper left, so shift it by one.
			assert(filterDim % 2 == 1);	//All the filters should have odd dimensions
			if (filterDim % 2 == 1)
			{
				xOffset++;
				yOffset++;
			}
			
			//Copy the filter to the temp buffer 
			for (int y = 0; y < filterDim; y++)
				for (int x = 0; x < filterDim; x++)
					shiftBuffer[(y + yOffset) * horDim + (x + xOffset)] =
						skFilters[i][y * filterDim + x];
			
			//Shift (with wrap) the center to the corners
			for (int y = 0; y < verDim; y++)
				for (int x = 0; x < horDim; x++)
					skFiltersFTs.back().filtersFTs[i][lvl][y * horDim + x] =
						shiftBuffer[((y + verDim / 2) % verDim) * horDim + (x + horDim / 2) % horDim];
			
			//Do the Fourier analysis
			assert(doFourierAnalysis(skFiltersFTs.back().filtersFTs[i][lvl],
									skFiltersFTs.back().filtersFTs[i][lvl], horDim, verDim));
			
			//Copy the inverse filter to the temp buffer 
			for (int y = 0; y < filterDim; y++)
				for (int x = 0; x < filterDim; x++)
					shiftBuffer[(y + yOffset) * horDim + (x + xOffset)] =
						skFiltersInv[i][y * filterDim + x];
			
			//Shift (with wrap) the center to the corners
			for (int y = 0; y < verDim; y++)
				for (int x = 0; x < horDim; x++)
					skFiltersFTs.back().filtersInvFTs[i][lvl][y * horDim + x] =
						shiftBuffer[((y + verDim / 2) % verDim) * horDim + (x + horDim / 2) % horDim];
			
			//Do the Fourier analysis
			assert(doFourierAnalysis(skFiltersFTs.back().filtersInvFTs[i][lvl],
									skFiltersFTs.back().filtersInvFTs[i][lvl], horDim, verDim));
		}
	delete [] shiftBuffer;
	
	return skFiltersFTs.size() - 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
cmpl $0x0, 0x1e234(%rip)     # 0x39b00
jle 0x1bdc9
movq %rdi, %r13
movq 0x1e1f4(%rip), %rdx     # 0x39ad0
movq 0x1e1e5(%rip), %rax     # 0x39ac8
subq %rax, %rdx
je 0x1b92c
sarq $0x3, %rdx
movabsq $-0x7d05f417d05f417d, %rcx # imm = 0x82FA0BE82FA0BE83
imulq %rdx, %rcx
movl 0x30(%r13), %edx
movl 0x34(%r13), %esi
cmpq $0x1, %rcx
adcq $0x0, %rcx
addq $0x4, %rax
xorl %r14d, %r14d
cmpl %edx, -0x4(%rax)
jne 0x1b91e
cmpl %esi, (%rax)
je 0x1bd38
incq %r14
addq $0x158, %rax            # imm = 0x158
cmpq %r14, %rcx
jne 0x1b911
leaq 0x50(%rsp), %r14
movl $0x158, %edx            # imm = 0x158
movq %r14, %rdi
xorl %esi, %esi
callq 0x3190
leaq 0x1e181(%rip), %rdi     # 0x39ac8
movq %r14, %rsi
callq 0x218d4
movq 0x1e17a(%rip), %rdi     # 0x39ad0
movq 0x30(%r13), %rax
movq %rax, -0x158(%rdi)
addq $-0x158, %rdi           # imm = 0xFEA8
callq 0x21b40
movslq 0x30(%r13), %rax
movslq 0x34(%r13), %rcx
imulq %rax, %rcx
movq %rcx, %rax
shlq $0x3, %rax
testl %ecx, %ecx
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x3030
movq %rax, %r14
movl 0x38(%r13), %eax
movq $0x0, (%rsp)
movq %r13, 0x40(%rsp)
testl %eax, %eax
jle 0x1bcf5
xorl %ebp, %ebp
movq (%rsp), %rax
leaq 0x1e145(%rip), %rcx     # 0x39b00
movl (%rcx,%rax,4), %ebx
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x8(%rsp)
movss 0x30(%r13), %xmm1
movaps %xmm1, 0x10(%rsp)
callq 0x32a0
movapd %xmm0, 0x30(%rsp)
movups 0x34(%r13), %xmm0
unpcklps 0x10(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
cvtdq2pd %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x32a0
unpcklpd 0x30(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movapd 0x10(%rsp), %xmm1
divpd %xmm0, %xmm1
cvttpd2dq %xmm1, %xmm0
movd %ebx, %xmm1
pshufd $0x50, %xmm0, %xmm2     # xmm2 = xmm0[0,0,1,1]
pshufd $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
pcmpgtd %xmm2, %xmm1
movmskpd %xmm1, %eax
xorl $0x3, %eax
cmpl $0x3, %eax
jne 0x1bd8b
movl %ebx, %r12d
movd %xmm0, %ebx
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %r15d
movl %ebx, %eax
imull %r15d, %eax
movslq %eax, %rdx
shlq $0x3, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x3190
movl %r12d, %eax
andl $0x80000001, %eax       # imm = 0x80000001
cmpl $0x1, %eax
jne 0x1bd6c
movq %rbp, 0x10(%rsp)
movl %ebx, %eax
subl %r12d, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
movl %r15d, %eax
subl %r12d, %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
movq (%rsp), %rax
leaq 0x1e085(%rip), %rsi     # 0x39b20
movq (%rsi,%rax,8), %rax
leaq (,%r12,8), %rbp
incl %ecx
imull %r15d, %ecx
leal (%rdx,%rcx), %r13d
incl %r13d
movl %ebx, %r8d
movl %r15d, %ebx
movq %r13, %rcx
xorl %edx, %edx
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm0
leal (%rcx,%rsi), %edi
movslq %edi, %rdi
movsd %xmm0, (%r14,%rdi,8)
incq %rsi
cmpq %rsi, %r12
jne 0x1bac1
incq %rdx
addq %rbp, %rax
addq %rbx, %rcx
cmpq %r12, %rdx
jne 0x1babf
movq 0x1dfe1(%rip), %rax     # 0x39ad0
movl %r8d, %ecx
movq %rcx, 0x30(%rsp)
testl %r8d, %r8d
movl %r8d, 0x8(%rsp)
jle 0x1bba7
movl %r8d, %ecx
shrl %ecx
movq %rcx, 0x28(%rsp)
movl %r15d, %edi
shrl $0x1f, %edi
addl %r15d, %edi
sarl %edi
movq (%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rax
addq $-0x150, %rax           # imm = 0xFEB0
movq %rax, 0x48(%rsp)
leaq (,%rbx,8), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
testl %r15d, %r15d
jle 0x1bb8e
movq 0x28(%rsp), %rax
addl %r11d, %eax
xorl %edx, %edx
divl 0x8(%rsp)
movl %edx, %ecx
imull %r15d, %ecx
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdx
movq (%rax,%rdx,8), %rsi
addq %r10, %rsi
xorl %r8d, %r8d
leal (%rdi,%r8), %eax
xorl %edx, %edx
divl %r15d
addl %ecx, %edx
movsd (%r14,%rdx,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
incq %r8
cmpq %r8, %rbx
jne 0x1bb6f
incq %r11
addq %r9, %r10
cmpq 0x30(%rsp), %r11
jne 0x1bb3f
movq 0x1df2e(%rip), %rax     # 0x39ad0
movl 0x8(%rsp), %r8d
movq (%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rcx, 0x28(%rsp)
movq -0x150(%rax,%rcx,8), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq %rdi, %rsi
movl %r15d, %edx
movl %r8d, %ecx
callq 0x194c7
testb %al, %al
je 0x1bdaa
movq (%rsp), %rax
leaq 0x1df7a(%rip), %rcx     # 0x39b60
movq (%rcx,%rax,8), %rax
xorl %edi, %edi
movl 0x8(%rsp), %ecx
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm0
leal (%rdx,%r13), %esi
movslq %esi, %rsi
movsd %xmm0, (%r14,%rsi,8)
incq %rdx
cmpq %rdx, %r12
jne 0x1bbf2
incq %rdi
addq %rbp, %rax
addq %rbx, %r13
cmpq %r12, %rdi
jne 0x1bbf0
movq 0x1deaf(%rip), %rax     # 0x39ad0
testl %ecx, %ecx
jle 0x1bcb6
movl %ecx, %esi
shrl %esi
movl %r15d, %edi
shrl $0x1f, %edi
addl %r15d, %edi
sarl %edi
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx,8), %r8
addq $-0xa8, %r8
leaq (,%rbx,8), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
movq 0x10(%rsp), %rbp
testl %r15d, %r15d
jle 0x1bc9c
leal (%rsi,%r11), %eax
xorl %edx, %edx
divl 0x8(%rsp)
movl %edx, %ecx
imull %r15d, %ecx
movq (%r8), %rax
movq (%rax,%rbp,8), %r12
addq %r10, %r12
xorl %r13d, %r13d
leal (%rdi,%r13), %eax
xorl %edx, %edx
divl %r15d
addl %ecx, %edx
movsd (%r14,%rdx,8), %xmm0
movsd %xmm0, (%r12,%r13,8)
incq %r13
cmpq %r13, %rbx
jne 0x1bc7d
incq %r11
addq %r9, %r10
cmpq 0x30(%rsp), %r11
jne 0x1bc5b
movq 0x1de20(%rip), %rax     # 0x39ad0
movl 0x8(%rsp), %ecx
jmp 0x1bcbb
movq 0x10(%rsp), %rbp
movq 0x28(%rsp), %rdx
movq -0xa8(%rax,%rdx,8), %rax
movq (%rax,%rbp,8), %rdi
movq %rdi, %rsi
movl %r15d, %edx
callq 0x194c7
testb %al, %al
je 0x1bd4d
movq 0x10(%rsp), %rbp
incq %rbp
movq 0x40(%rsp), %r13
movslq 0x38(%r13), %rax
cmpq %rax, %rbp
jl 0x1b9b0
movq (%rsp), %rdx
incq %rdx
movq %rdx, (%rsp)
cmpq $0x7, %rdx
jne 0x1b9a6
movq %r14, %rdi
callq 0x33c0
movq 0x1ddb7(%rip), %rax     # 0x39ad0
subq 0x1dda8(%rip), %rax     # 0x39ac8
shrq $0x3, %rax
imull $0x2fa0be83, %eax, %r14d # imm = 0x2FA0BE83
decl %r14d
leaq 0x50(%rsp), %rdi
callq 0x21904
movl %r14d, %eax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11731(%rip), %rdi     # 0x2d485
leaq 0x115c7(%rip), %rsi     # 0x2d322
leaq 0x1165d(%rip), %rcx     # 0x2d3bf
movl $0x194, %edx            # imm = 0x194
callq 0x31c0
leaq 0x11616(%rip), %rdi     # 0x2d389
leaq 0x115a8(%rip), %rsi     # 0x2d322
leaq 0x1163e(%rip), %rcx     # 0x2d3bf
movl $0x16f, %edx            # imm = 0x16F
callq 0x31c0
leaq 0x11656(%rip), %rdi     # 0x2d3e8
leaq 0x11589(%rip), %rsi     # 0x2d322
leaq 0x1161f(%rip), %rcx     # 0x2d3bf
movl $0x166, %edx            # imm = 0x166
callq 0x31c0
leaq 0x11662(%rip), %rdi     # 0x2d413
leaq 0x1156a(%rip), %rsi     # 0x2d322
leaq 0x11600(%rip), %rcx     # 0x2d3bf
movl $0x184, %edx            # imm = 0x184
callq 0x31c0
leaq 0x115db(%rip), %rdi     # 0x2d3ab
leaq 0x1154b(%rip), %rsi     # 0x2d322
leaq 0x115e1(%rip), %rcx     # 0x2d3bf
movl $0x151, %edx            # imm = 0x151
callq 0x31c0
jmp 0x1bdec
jmp 0x1bdec
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x21904
movq %rbx, %rdi
callq 0x3500
nop