// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
decq %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
incq %rax
movq %rax, -0x48(%rbp)
subq $0x4, %rax
ja 0x3b332
movq -0x48(%rbp), %rax
leaq 0x127d9(%rip), %rcx     # 0x4da00
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x3b480
jmp 0x3b237
cmpq $0x0, -0x18(%rbp)
jle 0x3b270
movq -0x8(%rbp), %rdi
callq 0x44f00
movq -0x10(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
shlq %rax
shlq $0x3, %rax
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x3b237
jmp 0x3b272
jmp 0x3b274
cmpq $0x0, -0x18(%rbp)
jle 0x3b2ad
movq -0x8(%rbp), %rdi
callq 0x44f60
movq -0x10(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
shlq %rax
shlq $0x3, %rax
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x3b274
jmp 0x3b480
jmp 0x3b2b4
cmpq $0x0, -0x18(%rbp)
jle 0x3b2ed
movq -0x8(%rbp), %rdi
callq 0x45040
movq -0x10(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
shlq %rax
shlq $0x3, %rax
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x3b2b4
jmp 0x3b480
jmp 0x3b2f4
cmpq $0x0, -0x18(%rbp)
jle 0x3b32d
movq -0x8(%rbp), %rdi
callq 0x45380
movq -0x10(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
shlq %rax
shlq $0x3, %rax
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x3b2f4
jmp 0x3b480
movsd 0xdcd6(%rip), %xmm0     # 0x49010
movsd %xmm0, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
jle 0x3b47e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movsd -0x30(%rbp), %xmm0
callq 0x43240
movq -0x10(%rbp), %rax
subq $0x1, %rax
movl $0x3, %ecx
cqto
idivq %rcx
movq %rax, -0x38(%rbp)
movq $0x2, -0x40(%rbp)
movq -0x10(%rbp), %rax
subq $0x1, %rax
imulq $0x3, -0x38(%rbp), %rcx
subq %rcx, %rax
cmpq $0x1, %rax
jne 0x3b3b0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x3ee70
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
subq $0x1, %rax
imulq $0x3, -0x38(%rbp), %rcx
subq %rcx, %rax
cmpq $0x2, %rax
jne 0x3b3e3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x3f350
movq -0x40(%rbp), %rax
shlq $0x2, %rax
movq %rax, -0x40(%rbp)
cmpq $0xa, -0x10(%rbp)
ja 0x3b41f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %r8
movq -0x38(%rbp), %r9
movl $0x2, %ecx
callq 0x3b750
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x1, %rsi
movq -0x20(%rbp), %rdx
callq 0x45e40
jmp 0x3b452
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %r8
movq -0x38(%rbp), %r9
movl $0x2, %ecx
callq 0x3ab80
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x1, %rsi
movq -0x20(%rbp), %rdx
callq 0x45e40
movq -0x10(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
shlq %rax
shlq $0x3, %rax
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x3b33f
jmp 0x3b480
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)