// File: /workspace/github_c_makefile_star2_O2/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
pushq %rbx
subq $0x18, %rsp
movsd (%rdi), %xmm0
movsd 0xa45e(%rip), %xmm1     # 0x23178
callq 0x7160
movsd 0xa451(%rip), %xmm3     # 0x23178
addsd %xmm0, %xmm3
xorpd %xmm1, %xmm1
movapd %xmm0, %xmm2
cmpltsd %xmm1, %xmm2
andpd %xmm2, %xmm3
andnpd %xmm0, %xmm2
orpd %xmm3, %xmm2
movapd %xmm2, -0x20(%rbp)
movapd %xmm2, %xmm0
addsd %xmm2, %xmm0
callq 0x72f0
cvttsd2si %xmm0, %eax
pushq $0x4
popq %rcx
cltd
idivl %ecx
cmpl $0x3, %edx
ja 0x18e84
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd 0xa3d7(%rip), %xmm0     # 0x23150
movapd -0x20(%rbp), %xmm1
addsd %xmm0, %xmm1
leaq 0xa2fb(%rip), %rax      # 0x23084
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x18ea6
jp 0x18ea6
pushq $0x1
jmp 0x18dc0
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x18e8b
jp 0x18e8b
pushq $-0x1
popq %rdi
addq $0x18, %rsp
popq %rbx
popq %rbp
jmp 0xa426
movq 0x284c5(%rip), %rdi     # 0x41298
movapd %xmm1, -0x20(%rbp)
callq 0x861b
pushq $-0x1
popq %rdi
callq 0xa426
movq 0xebce4(%rip), %rdi     # 0x104ad0
callq 0x861b
movapd -0x20(%rbp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x18e06
jnp 0x18ef9
movq 0x28493(%rip), %rdi     # 0x412a0
callq 0x861b
movq 0x2849f(%rip), %rdi     # 0x412b8
callq 0x861b
movq 0x28473(%rip), %rdi     # 0x41298
callq 0x861b
movapd -0x20(%rbp), %xmm0
callq 0xaf59
movq 0xebc95(%rip), %rdi     # 0x104ad0
callq 0x861b
movq 0x261f9(%rip), %rdi     # 0x3f040
callq 0x861b
pushq $0x4
popq %rbx
movl %ebx, %edi
callq 0x85eb
pushq $0x3
popq %rdi
jmp 0x18f6e
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x18efe
jp 0x18efe
movq 0xebc57(%rip), %rdi     # 0x104ad0
addq $0x18, %rsp
popq %rbx
popq %rbp
jmp 0x861b
addq $0x18, %rsp
popq %rbx
popq %rbp
retq
movq 0x28406(%rip), %rdi     # 0x41298
movapd %xmm1, -0x20(%rbp)
callq 0x861b
pushq $-0x1
popq %rdi
callq 0xa426
jmp 0x18f1b
movq 0x283f3(%rip), %rdi     # 0x412a0
movapd %xmm1, -0x20(%rbp)
callq 0x861b
movq 0x283fa(%rip), %rdi     # 0x412b8
callq 0x861b
movq 0x283ce(%rip), %rdi     # 0x41298
callq 0x861b
movapd -0x20(%rbp), %xmm0
callq 0xaf59
movq 0xebbf0(%rip), %rdi     # 0x104ad0
callq 0x861b
movq 0x26154(%rip), %rdi     # 0x3f040
callq 0x861b
pushq $0x4
popq %rdi
callq 0x85eb
pushq $0x3
popq %rdi
jmp 0x18f75
movq 0x28393(%rip), %rdi     # 0x41298
movapd %xmm1, -0x20(%rbp)
callq 0x861b
movq 0xebbba(%rip), %rdi     # 0x104ad0
callq 0x861b
movq 0x2837e(%rip), %rdi     # 0x412a0
callq 0x861b
movq 0x2838a(%rip), %rdi     # 0x412b8
callq 0x861b
movq 0x2835e(%rip), %rdi     # 0x41298
callq 0x861b
movapd -0x20(%rbp), %xmm0
callq 0xaf59
movq 0xebb80(%rip), %rdi     # 0x104ad0
callq 0x861b
movq 0x260e4(%rip), %rdi     # 0x3f040
callq 0x861b
pushq $0x4
popq %rdi
callq 0x85eb
pushq $0x3
popq %rbx
movl %ebx, %edi
callq 0x85eb
movl %ebx, %edi
addq $0x18, %rsp
popq %rbx
popq %rbp
jmp 0x85eb