// File: kebwi[P]Trifid/src/FFT/fftext.cpp
// Function: fftInit(long)
int fftInit(long M){
// malloc and init cosine and bit reversed tables for a given size fft, ifft, rfft, rifft
/* INPUTS */
/* M = log2 of fft size	(ex M=10 for 1024 point fft) */
/* OUTPUTS */
/* private cosine and bit reversed tables	*/

int theError = 1;
/*** I did NOT test cases with M>27 ***/
if ((M >= 0) && (M < 8*sizeof(long))){
	theError = 0;
	if (UtblArray[M] == 0){	// have we not inited this size fft yet?
		// init cos table
		UtblArray[M] = (Float_t *) malloc( (POW2(M)/4+1)*sizeof(Float_t) );
		if (UtblArray[M] == 0)
			theError = 2;
		else{
			fftCosInit(M, UtblArray[M]);
		}
		if (M > 1){
			if (BRLowArray[M/2] == 0){	// init bit reversed table for cmplx fft
				BRLowArray[M/2] = (short *) malloc( POW2(M/2-1)*sizeof(short) );
				if (BRLowArray[M/2] == 0)
					theError = 2;
				else{
					fftBRInit(M, BRLowArray[M/2]);
				}
			}
		}
		if (M > 2){
			if (BRLowArray[(M-1)/2] == 0){	// init bit reversed table for real fft
				BRLowArray[(M-1)/2] = (short *) malloc( POW2((M-1)/2-1)*sizeof(short) );
				if (BRLowArray[(M-1)/2] == 0)
					theError = 2;
				else{
					fftBRInit(M-1, BRLowArray[(M-1)/2]);
				}
			}
		}
	}
};
return theError;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl $0x1, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
jl 0x3a6e4
cmpq $0x40, -0x8(%rbp)
jae 0x3a6e4
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rcx
leaq 0x229f5(%rip), %rax     # 0x5cec0
cmpq $0x0, (%rax,%rcx,8)
jne 0x3a6e2
movq -0x8(%rbp), %rcx
movl $0x1, %edi
shlq %cl, %rdi
shrq $0x2, %rdi
addq $0x1, %rdi
shlq $0x3, %rdi
callq 0x44e0
movq %rax, %rdx
movq -0x8(%rbp), %rcx
leaq 0x229bf(%rip), %rax     # 0x5cec0
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rcx
leaq 0x229b0(%rip), %rax     # 0x5cec0
cmpq $0x0, (%rax,%rcx,8)
jne 0x3a520
movl $0x2, -0xc(%rbp)
jmp 0x3a538
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rcx
leaq 0x22991(%rip), %rax     # 0x5cec0
movq (%rax,%rcx,8), %rsi
callq 0x3a9c0
cmpq $0x1, -0x8(%rbp)
jle 0x3a600
movq -0x8(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
leaq 0x22b65(%rip), %rax     # 0x5d0c0
cmpq $0x0, (%rax,%rcx,8)
jne 0x3a5fe
movq -0x8(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
subq $0x1, %rcx
movl $0x1, %edi
shlq %cl, %rdi
shlq %rdi
callq 0x44e0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq -0x18(%rbp), %rdx
movq %rax, %rcx
leaq 0x22b15(%rip), %rax     # 0x5d0c0
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
leaq 0x22af9(%rip), %rax     # 0x5d0c0
cmpq $0x0, (%rax,%rcx,8)
jne 0x3a5d7
movl $0x2, -0xc(%rbp)
jmp 0x3a5fc
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
leaq 0x22acd(%rip), %rax     # 0x5d0c0
movq (%rax,%rcx,8), %rsi
callq 0x3aaa0
jmp 0x3a5fe
jmp 0x3a600
cmpq $0x2, -0x8(%rbp)
jle 0x3a6e0
movq -0x8(%rbp), %rax
subq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
leaq 0x22a99(%rip), %rax     # 0x5d0c0
cmpq $0x0, (%rax,%rcx,8)
jne 0x3a6de
movq -0x8(%rbp), %rax
subq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
subq $0x1, %rcx
movl $0x1, %edi
shlq %cl, %rdi
shlq %rdi
callq 0x44e0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
subq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq -0x20(%rbp), %rdx
movq %rax, %rcx
leaq 0x22a41(%rip), %rax     # 0x5d0c0
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
subq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
leaq 0x22a21(%rip), %rax     # 0x5d0c0
cmpq $0x0, (%rax,%rcx,8)
jne 0x3a6af
movl $0x2, -0xc(%rbp)
jmp 0x3a6dc
movq -0x8(%rbp), %rdi
subq $0x1, %rdi
movq -0x8(%rbp), %rax
subq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
leaq 0x229ed(%rip), %rax     # 0x5d0c0
movq (%rax,%rcx,8), %rsi
callq 0x3aaa0
jmp 0x3a6de
jmp 0x3a6e0
jmp 0x3a6e2
jmp 0x3a6e4
movl -0xc(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)