// File: /workspace/github_cpp_makefile_star2_O1/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 $0x198, %rsp            # imm = 0x198
cmpl $0x0, 0x1dd3c(%rip)     # 0x39b00
jle 0x1c2c5
movq %rdi, %rbx
movq 0x1dcfc(%rip), %rsi     # 0x39ad0
movq 0x1dced(%rip), %rax     # 0x39ac8
subq %rax, %rsi
setne %cl
je 0x1be35
sarq $0x3, %rsi
movabsq $-0x7d05f417d05f417d, %rdx # imm = 0x82FA0BE82FA0BE83
imulq %rsi, %rdx
movl 0x30(%rbx), %esi
movl 0x34(%rbx), %edi
cmpq $0x1, %rdx
movq %rdx, %r8
adcq $0x0, %r8
addq $0x4, %rax
xorl %r14d, %r14d
cmpl %esi, -0x4(%rax)
jne 0x1be16
cmpl %edi, (%rax)
je 0x1be2c
incq %r14
cmpq %r14, %rdx
seta %cl
addq $0x158, %rax            # imm = 0x158
cmpq %r14, %r8
jne 0x1be0d
jmp 0x1be35
testb $0x1, %cl
jne 0x1c234
leaq 0x40(%rsp), %r14
movl $0x158, %edx            # imm = 0x158
movq %r14, %rdi
xorl %esi, %esi
callq 0x3190
leaq 0x1dc78(%rip), %rdi     # 0x39ac8
movq %r14, %rsi
callq 0x21b44
movq 0x1dc71(%rip), %rdi     # 0x39ad0
movq 0x30(%rbx), %rax
movq %rax, -0x158(%rdi)
addq $-0x158, %rdi           # imm = 0xFEA8
callq 0x21db4
movslq 0x30(%rbx), %rax
movslq 0x34(%rbx), %rcx
imulq %rax, %rcx
movq %rcx, %rax
shlq $0x3, %rax
testl %ecx, %ecx
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x3030
movq %rax, %r14
movq $0x0, 0x18(%rsp)
movq %rbx, 0x28(%rsp)
cmpl $0x0, 0x38(%rbx)
jle 0x1c1ef
xorl %r15d, %r15d
movq 0x18(%rsp), %rax
leaq 0x1dc3b(%rip), %rcx     # 0x39b00
movl (%rcx,%rax,4), %r12d
xorps %xmm0, %xmm0
cvtsi2sdl 0x30(%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x32a0
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %ebp
xorps %xmm0, %xmm0
cvtsi2sdl 0x34(%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x32a0
cmpl %r12d, %ebp
jl 0x1c287
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r13d
cmpl %r12d, %r13d
jl 0x1c287
movl %r13d, %eax
imull %ebp, %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 0x1c268
movq %r15, 0x10(%rsp)
movl %r13d, %eax
subl %r12d, %eax
movl %eax, %r9d
shrl $0x1f, %r9d
addl %eax, %r9d
sarl %r9d
movl %ebp, %eax
subl %r12d, %eax
movl %eax, %r10d
shrl $0x1f, %r10d
addl %eax, %r10d
sarl %r10d
movl %ebp, %ebx
testl %r12d, %r12d
jle 0x1bfdb
movq 0x18(%rsp), %rax
leaq 0x1db89(%rip), %rcx     # 0x39b20
movq (%rcx,%rax,8), %rax
leaq (,%r12,8), %rcx
leal 0x1(%r9), %edx
imull %ebp, %edx
addl %r10d, %edx
incl %edx
xorl %esi, %esi
xorl %edi, %edi
movsd (%rax,%rdi,8), %xmm0
leal (%rdx,%rdi), %r8d
movslq %r8d, %r8
movsd %xmm0, (%r14,%r8,8)
incq %rdi
cmpq %rdi, %r12
jne 0x1bfb3
incq %rsi
addq %rcx, %rax
addq %rbx, %rdx
cmpq %r12, %rsi
jne 0x1bfb1
movq %r10, 0x30(%rsp)
movq %r9, 0x38(%rsp)
movl %r13d, %eax
movl %r13d, %r13d
movl %eax, 0x8(%rsp)
testl %eax, %eax
jle 0x1c084
movl 0x8(%rsp), %eax
shrl %eax
movq %rax, 0x20(%rsp)
movl %ebp, %edi
shrl $0x1f, %edi
addl %ebp, %edi
sarl %edi
movq 0x1dabe(%rip), %rax     # 0x39ad0
movq 0x18(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r8
addq $-0x150, %r8            # imm = 0xFEB0
leaq (,%rbx,8), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
testl %ebp, %ebp
jle 0x1c079
movq 0x20(%rsp), %rax
addl %r11d, %eax
xorl %edx, %edx
divl 0x8(%rsp)
movl %edx, %ecx
imull %ebp, %ecx
movq (%r8), %rax
movq 0x10(%rsp), %rdx
movq (%rax,%rdx,8), %r15
addq %r10, %r15
xorl %esi, %esi
leal (%rdi,%rsi), %eax
xorl %edx, %edx
divl %ebp
addl %ecx, %edx
movsd (%r14,%rdx,8), %xmm0
movsd %xmm0, (%r15,%rsi,8)
incq %rsi
cmpq %rsi, %rbx
jne 0x1c05c
incq %r11
addq %r9, %r10
cmpq %r13, %r11
jne 0x1c034
movq 0x1da45(%rip), %rax     # 0x39ad0
movq 0x18(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rcx, 0x20(%rsp)
movq -0x150(%rax,%rcx,8), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq %rdi, %rsi
movl %ebp, %edx
movl 0x8(%rsp), %ecx
callq 0x1995b
testb %al, %al
je 0x1c2a6
testl %r12d, %r12d
jle 0x1c11c
movq 0x18(%rsp), %rax
leaq 0x1da8f(%rip), %rcx     # 0x39b60
movq (%rcx,%rax,8), %rax
leaq (,%r12,8), %rcx
movq 0x38(%rsp), %rdx
incl %edx
imull %ebp, %edx
movq 0x30(%rsp), %rsi
addl %esi, %edx
incl %edx
xorl %esi, %esi
xorl %edi, %edi
movsd (%rax,%rdi,8), %xmm0
leal (%rdx,%rdi), %r8d
movslq %r8d, %r8
movsd %xmm0, (%r14,%r8,8)
incq %rdi
cmpq %rdi, %r12
jne 0x1c0f4
incq %rsi
addq %rcx, %rax
addq %rbx, %rdx
cmpq %r12, %rsi
jne 0x1c0f2
cmpl $0x0, 0x8(%rsp)
jle 0x1c1ab
movl 0x8(%rsp), %eax
movl %eax, %esi
shrl %esi
movl %ebp, %edi
shrl $0x1f, %edi
addl %ebp, %edi
sarl %edi
movq 0x1d991(%rip), %rax     # 0x39ad0
movq 0x20(%rsp), %rcx
leaq (%rax,%rcx,8), %r8
addq $-0xa8, %r8
leaq (,%rbx,8), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
testl %ebp, %ebp
jle 0x1c1a0
leal (%rsi,%r11), %eax
xorl %edx, %edx
divl 0x8(%rsp)
movl %edx, %ecx
imull %ebp, %ecx
movq (%r8), %rax
movq 0x10(%rsp), %rdx
movq (%rax,%rdx,8), %r15
addq %r10, %r15
xorl %r12d, %r12d
leal (%rdi,%r12), %eax
xorl %edx, %edx
divl %ebp
addl %ecx, %edx
movsd (%r14,%rdx,8), %xmm0
movsd %xmm0, (%r15,%r12,8)
incq %r12
cmpq %r12, %rbx
jne 0x1c182
incq %r11
addq %r9, %r10
cmpq %r13, %r11
jne 0x1c15d
movq 0x1d91e(%rip), %rax     # 0x39ad0
movq 0x20(%rsp), %rcx
movq -0xa8(%rax,%rcx,8), %rax
movq 0x10(%rsp), %r15
movq (%rax,%r15,8), %rdi
movq %rdi, %rsi
movl %ebp, %edx
movl 0x8(%rsp), %ecx
callq 0x1995b
testb %al, %al
je 0x1c249
incq %r15
movq 0x28(%rsp), %rbx
movslq 0x38(%rbx), %rax
cmpq %rax, %r15
jl 0x1beb9
movq 0x18(%rsp), %rcx
incq %rcx
movq %rcx, 0x18(%rsp)
cmpq $0x7, %rcx
jne 0x1beac
movq %r14, %rdi
callq 0x33c0
movq 0x1d8bb(%rip), %rax     # 0x39ad0
subq 0x1d8ac(%rip), %rax     # 0x39ac8
shrq $0x3, %rax
imull $0x2fa0be83, %eax, %r14d # imm = 0x2FA0BE83
decl %r14d
leaq 0x40(%rsp), %rdi
callq 0x21b74
movl %r14d, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x121cd(%rip), %rdi     # 0x2e41d
leaq 0x12063(%rip), %rsi     # 0x2e2ba
leaq 0x120f9(%rip), %rcx     # 0x2e357
movl $0x194, %edx            # imm = 0x194
callq 0x31c0
leaq 0x120b2(%rip), %rdi     # 0x2e321
leaq 0x12044(%rip), %rsi     # 0x2e2ba
leaq 0x120da(%rip), %rcx     # 0x2e357
movl $0x16f, %edx            # imm = 0x16F
callq 0x31c0
leaq 0x120f2(%rip), %rdi     # 0x2e380
leaq 0x12025(%rip), %rsi     # 0x2e2ba
leaq 0x120bb(%rip), %rcx     # 0x2e357
movl $0x166, %edx            # imm = 0x166
callq 0x31c0
leaq 0x120fe(%rip), %rdi     # 0x2e3ab
leaq 0x12006(%rip), %rsi     # 0x2e2ba
leaq 0x1209c(%rip), %rcx     # 0x2e357
movl $0x184, %edx            # imm = 0x184
callq 0x31c0
leaq 0x12077(%rip), %rdi     # 0x2e343
leaq 0x11fe7(%rip), %rsi     # 0x2e2ba
leaq 0x1207d(%rip), %rcx     # 0x2e357
movl $0x151, %edx            # imm = 0x151
callq 0x31c0
jmp 0x1c2e8
jmp 0x1c2e8
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x21b74
movq %rbx, %rdi
callq 0x3500
nop