// File: /workspace/github_cpp_makefile_star2_O2/kebwi[P]Trifid/src/FFT/fftlib.cpp
// Function: rffts1(double*, long, long, double*, short*)
void rffts1(Float_t *ioptr, long M, long Rows, Float_t *Utbl, short *BRLow){
/* Compute in-place real fft on the rows of the input array	*/
/* The result is the complex spectra of the positive frequencies */
/* except the location for the first complex number contains the real */
/* values for DC and Nyquest */
/* INPUTS */
/* *ioptr = real input data array	*/
/* M = log2 of fft size	*/
/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array)	*/
/* *Utbl = cosine table	*/
/* *BRLow = bit reversed counter table	*/
/* OUTPUTS */
/* *ioptr = output data array	in the following order */
/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */

Float_t	scale;
long 	StageCnt;
long 	NDiffU;

M=M-1;
switch (M){
case -1:
	break;
case 0:
	for (;Rows>0;Rows--){
		rfft1pt(ioptr);				/* a 2 pt fft */
		ioptr += 2*POW2(M);
	}
case 1:
	for (;Rows>0;Rows--){
		rfft2pt(ioptr);				/* a 4 pt fft */
		ioptr += 2*POW2(M);
	}
	break;
case 2:
	for (;Rows>0;Rows--){
		rfft4pt(ioptr);				/* an 8 pt fft */
		ioptr += 2*POW2(M);
	}
	break;
case 3:
	for (;Rows>0;Rows--){
		rfft8pt(ioptr);				/* a 16 pt fft */
		ioptr += 2*POW2(M);
	}
	break;
default:
	scale = 0.5;
	for (;Rows>0;Rows--){

		scbitrevR2(ioptr, M, BRLow, scale);						/* bit reverse and first radix 2 stage */
		
		StageCnt = (M-1) / 3;		// number of radix 8 stages
		NDiffU = 2;				// one radix 2 stage already complete

		if ( (M-1-(StageCnt * 3)) == 1 ){
			bfR2(ioptr, M, NDiffU);			/* 1 radix 2 stage */
			NDiffU *= 2;
		}

		if ( (M-1-(StageCnt * 3)) == 2 ){
			bfR4(ioptr, M, NDiffU);			/* 1 radix 4 stage */
			NDiffU *= 4;
		}

		if (M <= MCACHE){
			bfstages(ioptr, M, Utbl, 2, NDiffU, StageCnt);		/*  RADIX 8 Stages	*/
			frstage(ioptr, M+1, Utbl);
		}

		else{
			fftrecurs(ioptr, M, Utbl, 2, NDiffU, StageCnt);		/*  RADIX 8 Stages	*/
			frstage(ioptr, M+1, Utbl);
		}

		ioptr += 2*POW2(M);
	}
}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rdi, %r14
cmpq $0x4, %rsi
ja 0x1de39
leaq 0x8c68(%rip), %rax      # 0x269d8
movq %rsi, %rcx
movslq (%rax,%rsi,4), %rdx
addq %rax, %rdx
jmpq *%rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %r12
shlq %cl, %r12
shlq $0x3, %r12
testq %rbx, %rbx
jle 0x1dd7c
movq %r14, %rdi
callq 0x20a6e
decq %rbx
addq %r12, %r14
jmp 0x1dd96
pushq $0x4
popq %r12
jmp 0x1de1c
pushq $0x1
popq %r12
shlq %cl, %r12
shlq $0x3, %r12
testq %rbx, %rbx
jle 0x1dd7c
movq %r14, %rdi
callq 0x20984
decq %rbx
addq %r12, %r14
jmp 0x1ddbc
pushq $0x1
popq %r12
shlq %cl, %r12
leaq (,%r12,8), %rax
movq %rbx, %rcx
testq %rcx, %rcx
jle 0x1de12
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movapd %xmm0, %xmm2
addsd %xmm1, %xmm2
subsd %xmm1, %xmm0
movsd %xmm2, (%r14)
movsd %xmm0, 0x8(%r14)
decq %rcx
addq %rax, %r14
jmp 0x1dde3
movq %rbx, %rax
sarq $0x3f, %rax
andq %rax, %rbx
shlq $0x3, %r12
testq %rbx, %rbx
jle 0x1dd7c
movq %r14, %rdi
callq 0x2093a
decq %rbx
addq %r12, %r14
jmp 0x1de20
movq %rcx, %r13
leaq -0x1(%rsi), %rbp
leaq -0x2(%rsi), %rax
pushq $0x3
popq %rcx
cqto
idivq %rcx
movq %rax, (%rsp)
imulq $-0x3, %rax, %rax
movq %rsi, 0x10(%rsp)
leaq (%rax,%rsi), %r12
addq $-0x2, %r12
pushq $0x2
popq %rax
movl %ebp, %ecx
shlq %cl, %rax
shlq $0x3, %rax
movq %rax, 0x8(%rsp)
testq %rbx, %rbx
jle 0x1dd7c
movq %r14, %rdi
movq %rbp, %rsi
movq %r8, %r15
movq %r8, %rdx
movsd 0x41b9(%rip), %xmm0     # 0x22048
callq 0x202ea
cmpq $0x2, %r12
je 0x1deb6
pushq $0x2
popq %r8
cmpq $0x1, %r12
jne 0x1dec8
movq %r14, %rdi
movq %rbp, %rsi
pushq $0x2
popq %rdx
callq 0x1f1c7
pushq $0x4
jmp 0x1dec6
movq %r14, %rdi
movq %rbp, %rsi
pushq $0x2
popq %rdx
callq 0x1f2df
pushq $0x8
popq %r8
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
pushq $0x2
popq %rcx
cmpq $0xa, %rbp
ja 0x1dee5
movq (%rsp), %r9
callq 0x1e112
jmp 0x1deee
movq (%rsp), %r9
callq 0x1d961
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0x20dd8
decq %rbx
addq 0x8(%rsp), %r14
movq %r15, %r8
jmp 0x1de72