// File: hdlguy[P]fft_demo/fft.cpp
// Function: Fft::transformBluestein(std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&)
void Fft::transformBluestein(vector<double> &real, vector<double> &imag) {
	// Find a power-of-2 convolution length m such that m >= n * 2 + 1
	if (real.size() != imag.size())
		throw "Mismatched lengths";
	size_t n = real.size();
	size_t m;
	{
		size_t target;
		if (n > (SIZE_MAX - 1) / 2)
			throw "Vector too large";
		target = n * 2 + 1;
		for (m = 1; m < target; m *= 2) {
			if (SIZE_MAX / 2 < m)
				throw "Vector too large";
		}
	}
	
	// Trignometric tables
	vector<double> cosTable(n), sinTable(n);
	for (size_t i = 0; i < n; i++) {
		double temp = M_PI * (size_t)((unsigned long long)i * i % ((unsigned long long)n * 2)) / n;
		// Less accurate version if long long is unavailable: double temp = M_PI * i * i / n;
		cosTable[i] = cos(temp);
		sinTable[i] = sin(temp);
	}
	
	// Temporary vectors and preprocessing
	vector<double> areal(m), aimag(m);
	for (size_t i = 0; i < n; i++) {
		areal[i] =  real[i] * cosTable[i] + imag[i] * sinTable[i];
		aimag[i] = -real[i] * sinTable[i] + imag[i] * cosTable[i];
	}
	vector<double> breal(m), bimag(m);
	breal[0] = cosTable[0];
	bimag[0] = sinTable[0];
	for (size_t i = 1; i < n; i++) {
		breal[i] = breal[m - i] = cosTable[i];
		bimag[i] = bimag[m - i] = sinTable[i];
	}
	
	// Convolution
	vector<double> creal(m), cimag(m);
	convolve(areal, aimag, breal, bimag, creal, cimag);
	
	// Postprocessing
	for (size_t i = 0; i < n; i++) {
		real[i] =  creal[i] * cosTable[i] + cimag[i] * sinTable[i];
		imag[i] = -creal[i] * sinTable[i] + cimag[i] * cosTable[i];
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2e00
movq %rax, -0x168(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2e00
movq %rax, %rcx
movq -0x168(%rbp), %rax
cmpq %rcx, %rax
je 0x1be2
movl $0x8, %edi
callq 0x10a0
movq %rax, %rdi
leaq 0x4471(%rip), %rax      # 0x6040
movq %rax, (%rdi)
movq 0x73ef(%rip), %rsi      # 0x8fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x1170
movq -0x8(%rbp), %rdi
callq 0x2e00
movq %rax, -0x18(%rbp)
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
cmpq %rax, -0x18(%rbp)
jbe 0x1c26
movl $0x8, %edi
callq 0x10a0
movq %rax, %rdi
leaq 0x445b(%rip), %rax      # 0x606e
movq %rax, (%rdi)
movq 0x73ab(%rip), %rsi      # 0x8fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x1170
movq -0x18(%rbp), %rax
shlq %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq $0x1, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x1c8d
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
cmpq -0x20(%rbp), %rax
jae 0x1c7e
movl $0x8, %edi
callq 0x10a0
movq %rax, %rdi
leaq 0x4403(%rip), %rax      # 0x606e
movq %rax, (%rdi)
movq 0x7353(%rip), %rsi      # 0x8fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x1170
jmp 0x1c80
movq -0x20(%rbp), %rax
shlq %rax
movq %rax, -0x20(%rbp)
jmp 0x1c3d
movq -0x18(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x2e20
movq -0x178(%rbp), %rsi
movq -0x170(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x2e40
jmp 0x1cc1
leaq -0x41(%rbp), %rdi
callq 0x2eb0
movq -0x18(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x2e20
movq -0x188(%rbp), %rsi
movq -0x180(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x2e40
jmp 0x1cfe
leaq -0x71(%rbp), %rdi
callq 0x2eb0
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x1e37
movq -0x80(%rbp), %rax
imulq %rax, %rax
movq -0x18(%rbp), %rcx
movq %rcx, -0x1a0(%rbp)
addq %rcx, %rcx
xorl %edx, %edx
divq %rcx
movq -0x1a0(%rbp), %rax
movq %rdx, %xmm0
movaps 0x42c5(%rip), %xmm3     # 0x6010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x42c9(%rip), %xmm2     # 0x6020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x42ca(%rip), %xmm1     # 0x6038
mulsd %xmm1, %xmm0
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
callq 0x11c0
movsd %xmm0, -0x198(%rbp)
movq -0x80(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x2ed0
movsd -0x198(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x88(%rbp), %xmm0
callq 0x1040
movsd %xmm0, -0x190(%rbp)
movq -0x80(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x2ed0
movsd -0x190(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1d0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x2eb0
jmp 0x2631
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x2eb0
jmp 0x2628
movq -0x20(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x2e20
movq -0x1b0(%rbp), %rsi
movq -0x1a8(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x2e40
jmp 0x1e71
leaq -0xa1(%rbp), %rdi
callq 0x2eb0
movq -0x20(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x2e20
movq -0x1c0(%rbp), %rsi
movq -0x1b8(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x2e40
jmp 0x1eb7
leaq -0xc1(%rbp), %rdi
callq 0x2eb0
movq $0x0, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x20a5
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x1f8(%rbp)
movq -0xd0(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x1f0(%rbp)
movq -0x10(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x200(%rbp)
movq -0xd0(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x2ed0
movsd -0x200(%rbp), %xmm1
movsd -0x1f8(%rbp), %xmm0
movsd -0x1f0(%rbp), %xmm2
mulsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x1e8(%rbp)
movq -0xd0(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x2ed0
movsd -0x1e8(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x2ed0
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x1d8(%rbp)
movq -0xd0(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x1d0(%rbp)
movq -0x10(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x1e0(%rbp)
movq -0xd0(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x2ed0
movsd -0x1e0(%rbp), %xmm1
movsd -0x1d8(%rbp), %xmm0
movsd -0x1d0(%rbp), %xmm2
mulsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x1c8(%rbp)
movq -0xd0(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x2ed0
movsd -0x1c8(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0xd0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd0(%rbp)
jmp 0x1ece
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa1(%rbp), %rdi
callq 0x2eb0
jmp 0x261f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc1(%rbp), %rdi
callq 0x2eb0
jmp 0x2613
movq -0x20(%rbp), %rax
movq %rax, -0x210(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x2e20
movq -0x210(%rbp), %rsi
movq -0x208(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x2e40
jmp 0x20df
leaq -0xe9(%rbp), %rdi
callq 0x2eb0
movq -0x20(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x2e20
movq -0x220(%rbp), %rsi
movq -0x218(%rbp), %rdx
leaq -0x108(%rbp), %rdi
callq 0x2e40
jmp 0x2125
leaq -0x109(%rbp), %rdi
callq 0x2eb0
leaq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x230(%rbp)
leaq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2ed0
movsd -0x230(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x228(%rbp)
leaq -0x108(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2ed0
movsd -0x228(%rbp), %xmm0
movsd %xmm0, (%rax)
movq $0x1, -0x118(%rbp)
movq -0x118(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x22c4
movq -0x118(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x240(%rbp)
movq -0x20(%rbp), %rsi
subq -0x118(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x2ed0
movsd -0x240(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x118(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x2ed0
movsd -0x240(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x118(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x238(%rbp)
movq -0x20(%rbp), %rsi
subq -0x118(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0x2ed0
movsd -0x238(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x118(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0x2ed0
movsd -0x238(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x118(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x118(%rbp)
jmp 0x21a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe9(%rbp), %rdi
callq 0x2eb0
jmp 0x2607
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x109(%rbp), %rdi
callq 0x2eb0
jmp 0x25fb
movq -0x20(%rbp), %rax
movq %rax, -0x250(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x2e20
movq -0x250(%rbp), %rsi
movq -0x248(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x2e40
jmp 0x22fe
leaq -0x131(%rbp), %rdi
callq 0x2eb0
movq -0x20(%rbp), %rax
movq %rax, -0x260(%rbp)
leaq -0x151(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x2e20
movq -0x260(%rbp), %rsi
movq -0x258(%rbp), %rdx
leaq -0x150(%rbp), %rdi
callq 0x2e40
jmp 0x2344
leaq -0x151(%rbp), %rdi
callq 0x2eb0
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
leaq -0x108(%rbp), %rcx
leaq -0x130(%rbp), %r8
leaq -0x150(%rbp), %r9
callq 0x26d0
jmp 0x2381
movq $0x0, -0x160(%rbp)
movq -0x160(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x2580
movq -0x160(%rbp), %rsi
leaq -0x130(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x298(%rbp)
movq -0x160(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x290(%rbp)
movq -0x160(%rbp), %rsi
leaq -0x150(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x2a0(%rbp)
movq -0x160(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x2ed0
movsd -0x2a0(%rbp), %xmm1
movsd -0x298(%rbp), %xmm0
movsd -0x290(%rbp), %xmm2
mulsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x288(%rbp)
movq -0x8(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0x2ed0
movsd -0x288(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x160(%rbp), %rsi
leaq -0x130(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x278(%rbp)
movq -0x160(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x270(%rbp)
movq -0x160(%rbp), %rsi
leaq -0x150(%rbp), %rdi
callq 0x2ed0
movsd (%rax), %xmm0
movsd %xmm0, -0x280(%rbp)
movq -0x160(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x2ed0
movsd -0x280(%rbp), %xmm1
movsd -0x278(%rbp), %xmm0
movsd -0x270(%rbp), %xmm2
mulsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x268(%rbp)
movq -0x10(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0x2ed0
movsd -0x268(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x160(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x160(%rbp)
jmp 0x238c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x131(%rbp), %rdi
callq 0x2eb0
jmp 0x25ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x151(%rbp), %rdi
callq 0x2eb0
jmp 0x25e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x2ef0
jmp 0x25e3
leaq -0x150(%rbp), %rdi
callq 0x2ef0
leaq -0x130(%rbp), %rdi
callq 0x2ef0
leaq -0x108(%rbp), %rdi
callq 0x2ef0
leaq -0xe8(%rbp), %rdi
callq 0x2ef0
leaq -0xc0(%rbp), %rdi
callq 0x2ef0
leaq -0xa0(%rbp), %rdi
callq 0x2ef0
leaq -0x70(%rbp), %rdi
callq 0x2ef0
leaq -0x40(%rbp), %rdi
callq 0x2ef0
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
leaq -0x130(%rbp), %rdi
callq 0x2ef0
leaq -0x108(%rbp), %rdi
callq 0x2ef0
leaq -0xe8(%rbp), %rdi
callq 0x2ef0
leaq -0xc0(%rbp), %rdi
callq 0x2ef0
leaq -0xa0(%rbp), %rdi
callq 0x2ef0
leaq -0x70(%rbp), %rdi
callq 0x2ef0
leaq -0x40(%rbp), %rdi
callq 0x2ef0
movq -0x50(%rbp), %rdi
callq 0x11a0
nopw (%rax,%rax)