// File: /workspace/github_c_makefile_star2_O3/georgeweigt[P]eigenmath/eigenmath.c
// Function: normalize_polar_term_double
void
normalize_polar_term_double(struct atom *R)
{
	int n;
	double coeff, r;

	coeff = R->u.d;

	// coeff = coeff mod 2

	coeff = fmod(coeff, 2.0);

	// convert negative rotation to positive

	if (coeff < 0.0)
		coeff += 2.0;

	n = (int) floor(2.0 * coeff); // number of 90 degree turns

	r = coeff - n / 2.0; // remainder

	switch (n % 4) {

	case 0:
		if (r == 0.0)
			push_integer(1);
		else {
			push_symbol(POWER);
			push_symbol(EXP1);
			push_symbol(MULTIPLY);
			push_double(r);
			push(imaginaryunit);
			push_symbol(PI);
			list(4);
			list(3);
		}
		break;

	case 1:
		if (r == 0.0)
			push(imaginaryunit);
		else {
			push_symbol(MULTIPLY);
			push(imaginaryunit);
			push_symbol(POWER);
			push_symbol(EXP1);
			push_symbol(MULTIPLY);
			push_double(r);
			push(imaginaryunit);
			push_symbol(PI);
			list(4);
			list(3);
			list(3);
		}
		break;

	case 2:
		if (r == 0.0)
			push_integer(-1);
		else {
			push_symbol(MULTIPLY);
			push_integer(-1);
			push_symbol(POWER);
			push_symbol(EXP1);
			push_symbol(MULTIPLY);
			push_double(r);
			push(imaginaryunit);
			push_symbol(PI);
			list(4);
			list(3);
			list(3);
		}
		break;

	case 3:
		if (r == 0.0) {
			push_symbol(MULTIPLY);
			push_integer(-1);
			push(imaginaryunit);
			list(3);
		} else {
			push_symbol(MULTIPLY);
			push_integer(-1);
			push(imaginaryunit);
			push_symbol(POWER);
			push_symbol(EXP1);
			push_symbol(MULTIPLY);
			push_double(r);
			push(imaginaryunit);
			push_symbol(PI);
			list(4);
			list(3);
			list(4);
		}
		break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movsd (%rdi), %xmm0
movsd 0xc7fe(%rip), %xmm1     # 0x2a158
callq 0x7160
movsd 0xc7f1(%rip), %xmm3     # 0x2a158
addsd %xmm0, %xmm3
xorpd %xmm1, %xmm1
movapd %xmm0, %xmm2
cmpltsd %xmm1, %xmm2
andpd %xmm2, %xmm3
andnpd %xmm0, %xmm2
orpd %xmm3, %xmm2
movapd %xmm2, -0x10(%rbp)
movapd %xmm2, %xmm0
addsd %xmm2, %xmm0
callq 0x7300
cvttsd2si %xmm0, %eax
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cmpl $0x3, %eax
ja 0x1daf0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd 0xc7d0(%rip), %xmm0     # 0x2a190
movapd -0x10(%rbp), %xmm1
addsd %xmm0, %xmm1
leaq 0xc6b4(%rip), %rcx      # 0x2a084
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x1db10
jp 0x1db10
movq 0xee0e4(%rip), %rdi     # 0x10bad8
jmp 0x1dae6
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x1daf6
jp 0x1daf6
movq 0xf89dc(%rip), %rdi     # 0x1163f0
jmp 0x1dae6
movq 0x2a888(%rip), %rdi     # 0x482a8
movapd %xmm1, -0x10(%rbp)
callq 0x8ba5
movq 0xf89bf(%rip), %rdi     # 0x1163f0
callq 0x8ba5
movq 0xee0a3(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movapd -0x10(%rbp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x1da57
jnp 0x1dbfc
movq 0x2a852(%rip), %rdi     # 0x482b0
callq 0x8ba5
movq 0x2a85e(%rip), %rdi     # 0x482c8
callq 0x8ba5
movq 0x2a832(%rip), %rdi     # 0x482a8
callq 0x8ba5
callq 0x74dc
movb $0x5, 0x10(%rax)
movapd -0x10(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8ba5
movq 0xee044(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x285a8(%rip), %rdi     # 0x46050
callq 0x8ba5
movl $0x4, %edi
callq 0x8b7d
movl $0x3, %edi
callq 0x8b7d
movl $0x4, %edi
jmp 0x1dc01
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x1db75
jp 0x1db75
movq 0xedffa(%rip), %rdi     # 0x10bae0
addq $0x10, %rsp
popq %rbp
jmp 0x8ba5
addq $0x10, %rsp
popq %rbp
retq
movq 0x2a7ab(%rip), %rdi     # 0x482a8
movapd %xmm1, -0x10(%rbp)
callq 0x8ba5
movq 0xf88e2(%rip), %rdi     # 0x1163f0
jmp 0x1db8d
movq 0x2a799(%rip), %rdi     # 0x482b0
movapd %xmm1, -0x10(%rbp)
callq 0x8ba5
movq 0x2a7a0(%rip), %rdi     # 0x482c8
callq 0x8ba5
movq 0x2a774(%rip), %rdi     # 0x482a8
callq 0x8ba5
callq 0x74dc
movb $0x5, 0x10(%rax)
movapd -0x10(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8ba5
movq 0xedf86(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x284ea(%rip), %rdi     # 0x46050
callq 0x8ba5
movl $0x4, %edi
jmp 0x1dbf7
movq 0x2a72c(%rip), %rdi     # 0x482a8
movapd %xmm1, -0x10(%rbp)
callq 0x8ba5
movq 0xedf53(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x2a717(%rip), %rdi     # 0x482b0
callq 0x8ba5
movq 0x2a723(%rip), %rdi     # 0x482c8
callq 0x8ba5
movq 0x2a6f7(%rip), %rdi     # 0x482a8
callq 0x8ba5
callq 0x74dc
movb $0x5, 0x10(%rax)
movapd -0x10(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8ba5
movq 0xedf09(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x2846d(%rip), %rdi     # 0x46050
callq 0x8ba5
movl $0x4, %edi
callq 0x8b7d
movl $0x3, %edi
callq 0x8b7d
movl $0x3, %edi
addq $0x10, %rsp
popq %rbp
jmp 0x8b7d