// File: /workspace/github_c_makefile_star2_O1/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 0xa8e8(%rip), %xmm1     # 0x26138
callq 0x7160
movsd 0xa8db(%rip), %xmm3     # 0x26138
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 0x1b9e6
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd 0xa8ba(%rip), %xmm0     # 0x26170
movapd -0x10(%rbp), %xmm1
addsd %xmm0, %xmm1
leaq 0xa7a2(%rip), %rcx      # 0x26068
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x1ba06
jp 0x1ba06
movq 0xeb1ee(%rip), %rdi     # 0x106ad8
jmp 0x1b9dc
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x1b9ec
jp 0x1b9ec
movq 0xf5ae6(%rip), %rdi     # 0x1113f0
jmp 0x1b9dc
movq 0x27992(%rip), %rdi     # 0x432a8
movapd %xmm1, -0x10(%rbp)
callq 0x8b01
movq 0xf5ac9(%rip), %rdi     # 0x1113f0
callq 0x8b01
movq 0xeb1ad(%rip), %rdi     # 0x106ae0
callq 0x8b01
movapd -0x10(%rbp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x1b94d
jnp 0x1baf2
movq 0x2795c(%rip), %rdi     # 0x432b0
callq 0x8b01
movq 0x27968(%rip), %rdi     # 0x432c8
callq 0x8b01
movq 0x2793c(%rip), %rdi     # 0x432a8
callq 0x8b01
callq 0x74ec
movb $0x5, 0x10(%rax)
movapd -0x10(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8b01
movq 0xeb14e(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq 0x256b2(%rip), %rdi     # 0x41050
callq 0x8b01
movl $0x4, %edi
callq 0x8ad9
movl $0x3, %edi
callq 0x8ad9
movl $0x4, %edi
jmp 0x1baf7
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x1ba6b
jp 0x1ba6b
movq 0xeb104(%rip), %rdi     # 0x106ae0
addq $0x10, %rsp
popq %rbp
jmp 0x8b01
addq $0x10, %rsp
popq %rbp
retq
movq 0x278b5(%rip), %rdi     # 0x432a8
movapd %xmm1, -0x10(%rbp)
callq 0x8b01
movq 0xf59ec(%rip), %rdi     # 0x1113f0
jmp 0x1ba83
movq 0x278a3(%rip), %rdi     # 0x432b0
movapd %xmm1, -0x10(%rbp)
callq 0x8b01
movq 0x278aa(%rip), %rdi     # 0x432c8
callq 0x8b01
movq 0x2787e(%rip), %rdi     # 0x432a8
callq 0x8b01
callq 0x74ec
movb $0x5, 0x10(%rax)
movapd -0x10(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8b01
movq 0xeb090(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq 0x255f4(%rip), %rdi     # 0x41050
callq 0x8b01
movl $0x4, %edi
jmp 0x1baed
movq 0x27836(%rip), %rdi     # 0x432a8
movapd %xmm1, -0x10(%rbp)
callq 0x8b01
movq 0xeb05d(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq 0x27821(%rip), %rdi     # 0x432b0
callq 0x8b01
movq 0x2782d(%rip), %rdi     # 0x432c8
callq 0x8b01
movq 0x27801(%rip), %rdi     # 0x432a8
callq 0x8b01
callq 0x74ec
movb $0x5, 0x10(%rax)
movapd -0x10(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8b01
movq 0xeb013(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq 0x25577(%rip), %rdi     # 0x41050
callq 0x8b01
movl $0x4, %edi
callq 0x8ad9
movl $0x3, %edi
callq 0x8ad9
movl $0x3, %edi
addq $0x10, %rsp
popq %rbp
jmp 0x8ad9