// File: /workspace/github_cpp_makefile_star2_O2/kebwi[P]Trifid/src/FFT/fftlib.cpp
// Function: scbitrevR2(double*, long, short*, double)
inline void scbitrevR2(Float_t *ioptr, long M, short *BRLow, Float_t scale){
/*** scaled bit reverse and first radix 2 stage forward or inverse fft ***/
Float_t	f0r;
Float_t	f0i;
Float_t	f1r;
Float_t	f1i;
Float_t	f2r;
Float_t	f2i;
Float_t	f3r;
Float_t	f3i;
Float_t	f4r;
Float_t	f4i;
Float_t	f5r;
Float_t	f5i;
Float_t	f6r;
Float_t	f6i;
Float_t	f7r;
Float_t	f7i;
Float_t	t0r;
Float_t	t0i;
Float_t	t1r;
Float_t	t1i;
Float_t	*p0r;
Float_t	*p1r;
Float_t	*IOP;
Float_t 	*iolimit;
long 	Colstart;
long 	iCol;
unsigned long 	posA;
unsigned long 	posAi;
unsigned long 	posB;
unsigned long 	posBi;

const unsigned long Nrems2 = POW2((M+3)/2);
const unsigned long Nroot_1_ColInc = POW2(M)-Nrems2;
const unsigned long Nroot_1 = POW2(M/2-1)-1;
const unsigned long ColstartShift = (M+1)/2 +1;
posA = POW2(M);		// 1/2 of POW2(M) complexes
posAi = posA + 1;
posB = posA + 2;
posBi = posB + 1;

iolimit = ioptr + Nrems2;
for (; ioptr < iolimit; ioptr += POW2(M/2+1)){
	for (Colstart = Nroot_1; Colstart >= 0; Colstart--){
		iCol = Nroot_1;
		p0r = ioptr+ Nroot_1_ColInc + BRLow[Colstart]*4;
		IOP = ioptr + (Colstart << ColstartShift);
		p1r = IOP + BRLow[iCol]*4;
		f0r = *(p0r);
		f0i = *(p0r+1);
		f1r = *(p0r+posA);
		f1i = *(p0r+posAi);
		for (; iCol > Colstart;){
			f2r = *(p0r+2);
			f2i = *(p0r+(2+1));
			f3r = *(p0r+posB);
			f3i = *(p0r+posBi);
			f4r = *(p1r);
			f4i = *(p1r+1);
			f5r = *(p1r+posA);
			f5i = *(p1r+posAi);
			f6r = *(p1r+2);
			f6i = *(p1r+(2+1));
			f7r = *(p1r+posB);
			f7i = *(p1r+posBi);
			
			t0r	= f0r + f1r;
			t0i	= f0i + f1i;
			f1r = f0r - f1r;
			f1i = f0i - f1i;
			t1r = f2r + f3r;
			t1i = f2i + f3i;
			f3r = f2r - f3r;
			f3i = f2i - f3i;
			f0r = f4r + f5r;
			f0i = f4i + f5i;
			f5r = f4r - f5r;
			f5i = f4i - f5i;
			f2r = f6r + f7r;
			f2i = f6i + f7i;
			f7r = f6r - f7r;
			f7i = f6i - f7i;

			*(p1r) = scale*t0r;
			*(p1r+1) = scale*t0i;
			*(p1r+2) = scale*f1r;
			*(p1r+(2+1)) = scale*f1i;
			*(p1r+posA) = scale*t1r;
			*(p1r+posAi) = scale*t1i;
			*(p1r+posB) = scale*f3r;
			*(p1r+posBi) = scale*f3i;
			*(p0r) = scale*f0r;
			*(p0r+1) = scale*f0i;
			*(p0r+2) = scale*f5r;
			*(p0r+(2+1)) = scale*f5i;
			*(p0r+posA) = scale*f2r;
			*(p0r+posAi) = scale*f2i;
			*(p0r+posB) = scale*f7r;
			*(p0r+posBi) = scale*f7i;

			p0r -= Nrems2;
			f0r = *(p0r);
			f0i = *(p0r+1);
			f1r = *(p0r+posA);
			f1i = *(p0r+posAi);
			iCol -= 1;
			p1r = IOP + BRLow[iCol]*4;
		};
		f2r = *(p0r+2);
		f2i = *(p0r+(2+1));
		f3r = *(p0r+posB);
		f3i = *(p0r+posBi);

		t0r   = f0r + f1r;
		t0i   = f0i + f1i;
		f1r = f0r - f1r;
		f1i = f0i - f1i;
		t1r   = f2r + f3r;
		t1i   = f2i + f3i;
		f3r = f2r - f3r;
		f3i = f2i - f3i;

		*(p0r) = scale*t0r;
		*(p0r+1) = scale*t0i;
		*(p0r+2) = scale*f1r;
		*(p0r+(2+1)) = scale*f1i;
		*(p0r+posA) = scale*t1r;
		*(p0r+posAi) = scale*t1i;
		*(p0r+posB) = scale*f3r;
		*(p0r+posBi) = scale*f3i;

	};
};
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r8
leaq 0x3(%rsi), %rax
movabsq $0x2, %r10
cqto
idivq %r10
movabsq $0x1, %r14
movq %r14, %r11
movl %eax, %ecx
shlq %cl, %r11
movq %r14, %rbx
movl %esi, %ecx
shlq %cl, %rbx
movq %rsi, %rax
cqto
idivq %r10
movq %rax, %r9
leal -0x1(%rax), %ecx
movabsq $-0x1, %rax
shlq %cl, %rax
notq %rax
movq %rax, -0x30(%rsp)
leaq 0x1(%rsi), %rax
cqto
idivq %r10
incb %r9b
movl %r9d, %ecx
shlq %cl, %r14
incq %rax
movq %rax, -0x8(%rsp)
leaq (%rdi,%r11,8), %rax
movq %rax, -0x18(%rsp)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
leaq (,%rbx,8), %rax
movq %rax, -0x10(%rsp)
shlq $0x3, %r11
movq %rdi, %r9
subq %r11, %r9
addq $0x10, %r9
movq %r14, -0x20(%rsp)
leaq (,%r14,8), %rax
movq %rax, -0x28(%rsp)
negq %r11
movq %rbx, %r12
shlq $0x4, %r12
cmpq -0x18(%rsp), %rdi
jae 0x20533
movq -0x30(%rsp), %r13
testq %r13, %r13
js 0x20520
movswl (%r8,%r13,2), %ecx
shll $0x2, %ecx
movslq %ecx, %r14
movq %r13, %rdx
movq -0x8(%rsp), %rcx
shlq %cl, %rdx
movq %rdi, %rsi
leaq (%rdi,%rdx,8), %rdx
movq -0x10(%rsp), %rax
leaq (%rax,%r14,8), %r10
leaq (%r12,%r14,8), %rcx
movq %r9, %rbp
movq -0x30(%rsp), %r14
movupd -0x10(%rbp,%r10), %xmm1
movupd -0x10(%rbp,%rcx), %xmm3
movapd %xmm1, %xmm2
addpd %xmm3, %xmm2
cmpq %r13, %r14
jle 0x204ce
movswq (%r8,%r14,2), %r15
shlq $0x5, %r15
leaq (%rdx,%r15), %rax
movupd (%rbp,%r10), %xmm4
movupd (%rbp,%rcx), %xmm5
movapd %xmm4, %xmm6
addpd %xmm5, %xmm6
mulpd %xmm0, %xmm2
subpd %xmm3, %xmm1
mulpd %xmm0, %xmm1
mulpd %xmm0, %xmm6
subpd %xmm5, %xmm4
mulpd %xmm0, %xmm4
movupd (%rdx,%r15), %xmm3
movupd 0x10(%rdx,%r15), %xmm5
movupd (%rax,%rbx,8), %xmm7
movupd 0x10(%rax,%rbx,8), %xmm8
movapd %xmm5, %xmm9
addpd %xmm8, %xmm9
movapd %xmm3, %xmm10
addpd %xmm7, %xmm10
mulpd %xmm0, %xmm10
movupd %xmm2, (%rdx,%r15)
movupd %xmm1, 0x10(%rdx,%r15)
movupd %xmm6, (%rax,%rbx,8)
movupd %xmm4, 0x10(%rax,%rbx,8)
movupd %xmm10, -0x10(%rbp,%r10)
subpd %xmm7, %xmm3
mulpd %xmm0, %xmm3
movupd %xmm3, (%rbp,%r10)
mulpd %xmm0, %xmm9
movupd %xmm9, -0x10(%rbp,%rcx)
subpd %xmm8, %xmm5
mulpd %xmm0, %xmm5
movupd %xmm5, (%rbp,%rcx)
decq %r14
addq %r11, %rbp
jmp 0x203f0
movupd (%rbp,%r10), %xmm4
movupd (%rbp,%rcx), %xmm5
movapd %xmm4, %xmm6
addpd %xmm5, %xmm6
mulpd %xmm0, %xmm2
movupd %xmm2, -0x10(%rbp,%r10)
subpd %xmm3, %xmm1
mulpd %xmm0, %xmm1
movupd %xmm1, (%rbp,%r10)
mulpd %xmm0, %xmm6
movupd %xmm6, -0x10(%rbp,%rcx)
subpd %xmm5, %xmm4
mulpd %xmm0, %xmm4
movupd %xmm4, (%rbp,%rcx)
decq %r13
movq %rsi, %rdi
jmp 0x203b5
movq -0x20(%rsp), %rax
leaq (%rdi,%rax,8), %rdi
addq -0x28(%rsp), %r9
jmp 0x203a5
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq