// File: /workspace/github_c_makefile_star2_O1/georgeweigt[P]eigenmath/eigenmath.c
// Function: normalize_polar_term_rational
void
normalize_polar_term_rational(struct atom *R)
{
	int n;

	// R = R mod 2

	push(R);
	push_integer(2);
	modfunc();
	R = pop();

	// convert negative rotation to positive

	if (R->sign == MMINUS) {
		push(R);
		push_integer(2);
		add();
		R = pop();
	}

	push(R);
	push_integer(2);
	multiply();
	floorfunc();
	n = pop_integer(); // number of 90 degree turns

	push(R);
	push_integer(n);
	push_rational(-1, 2);
	multiply();
	add();
	R = pop(); // remainder

	switch (n % 4) {

	case 0:
		if (iszero(R))
			push_integer(1);
		else {
			push_symbol(POWER);
			push_symbol(EXP1);
			push_symbol(MULTIPLY);
			push(R);
			push(imaginaryunit);
			push_symbol(PI);
			list(4);
			list(3);
		}
		break;

	case 1:
		if (iszero(R))
			push(imaginaryunit);
		else {
			push_symbol(MULTIPLY);
			push(imaginaryunit);
			push_symbol(POWER);
			push_symbol(EXP1);
			push_symbol(MULTIPLY);
			push(R);
			push(imaginaryunit);
			push_symbol(PI);
			list(4);
			list(3);
			list(3);
		}
		break;

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

	case 3:
		if (iszero(R)) {
			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(R);
			push(imaginaryunit);
			push_symbol(PI);
			list(4);
			list(3);
			list(4);
		}
		break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
callq 0x8b01
movl $0x2, %edi
callq 0xacbe
callq 0xf98a
callq 0x8b78
movq %rax, %rbx
cmpb $0x1, 0x12(%rax)
jne 0x1b5dc
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xacbe
movl $0x2, %edi
callq 0xa975
callq 0x8b78
movq %rax, %rbx
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xacbe
movl $0x2, %edi
callq 0xa8bb
callq 0x13eac
callq 0xeb5b
movl %eax, %r14d
movq %rbx, %rdi
callq 0x8b01
movl %r14d, %edi
callq 0xacbe
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x2, %esi
callq 0xa1f4
movl $0x2, %edi
callq 0xa8bb
movl $0x2, %edi
callq 0xa975
callq 0x8b78
leal 0x3(%r14), %ecx
testl %r14d, %r14d
cmovnsl %r14d, %ecx
andl $-0x4, %ecx
subl %ecx, %r14d
cmpl $0x3, %r14d
ja 0x1b759
movq %rax, %rbx
leaq 0xa9f6(%rip), %rax      # 0x26058
movslq (%rax,%r14,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rbx, %rdi
callq 0xaece
testl %eax, %eax
je 0x1b773
movq 0xeb456(%rip), %rdi     # 0x106ad8
jmp 0x1b750
movq %rbx, %rdi
callq 0xaece
testl %eax, %eax
je 0x1b75e
movq 0xf5d52(%rip), %rdi     # 0x1113f0
jmp 0x1b750
movq %rbx, %rdi
callq 0xaece
movl %eax, %r14d
movq 0x27bf3(%rip), %rdi     # 0x432a8
callq 0x8b01
movq 0xf5d2f(%rip), %rdi     # 0x1113f0
callq 0x8b01
movq 0xeb413(%rip), %rdi     # 0x106ae0
callq 0x8b01
testl %r14d, %r14d
jne 0x1b82e
movq 0x27bce(%rip), %rdi     # 0x432b0
callq 0x8b01
movq 0x27bda(%rip), %rdi     # 0x432c8
callq 0x8b01
movq 0x27bae(%rip), %rdi     # 0x432a8
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movq 0xeb3d2(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq 0x25936(%rip), %rdi     # 0x41050
callq 0x8b01
movl $0x4, %edi
callq 0x8ad9
movl $0x3, %edi
callq 0x8ad9
movl $0x4, %edi
jmp 0x1b833
movq %rbx, %rdi
callq 0xaece
testl %eax, %eax
je 0x1b7be
movq 0xeb390(%rip), %rdi     # 0x106ae0
popq %rbx
popq %r14
popq %rbp
jmp 0x8b01
popq %rbx
popq %r14
popq %rbp
retq
movq 0x27b43(%rip), %rdi     # 0x432a8
callq 0x8b01
movq 0xf5c7f(%rip), %rdi     # 0x1113f0
jmp 0x1b7d1
movq 0x27b36(%rip), %rdi     # 0x432b0
callq 0x8b01
movq 0x27b42(%rip), %rdi     # 0x432c8
callq 0x8b01
movq 0x27b16(%rip), %rdi     # 0x432a8
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movq 0xeb33a(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq 0x2589e(%rip), %rdi     # 0x41050
callq 0x8b01
movl $0x4, %edi
jmp 0x1b829
movq 0x27ae3(%rip), %rdi     # 0x432a8
callq 0x8b01
movq 0xeb30f(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq 0x27ad3(%rip), %rdi     # 0x432b0
callq 0x8b01
movq 0x27adf(%rip), %rdi     # 0x432c8
callq 0x8b01
movq 0x27ab3(%rip), %rdi     # 0x432a8
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movq 0xeb2d7(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq 0x2583b(%rip), %rdi     # 0x41050
callq 0x8b01
movl $0x4, %edi
callq 0x8ad9
movl $0x3, %edi
callq 0x8ad9
movl $0x3, %edi
popq %rbx
popq %r14
popq %rbp
jmp 0x8ad9