// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
pushq %rax
callq 0x861b
pushq $0x2
popq %rdi
callq 0xa426
callq 0xe617
callq 0x868d
movq %rax, %rbx
cmpb $0x1, 0x12(%rax)
jne 0x18ab9
movq %rbx, %rdi
callq 0x861b
pushq $0x2
popq %rdi
callq 0xa426
callq 0xa1f6
callq 0x868d
movq %rax, %rbx
movq %rbx, %rdi
callq 0x861b
pushq $0x2
popq %r14
movl %r14d, %edi
callq 0xa426
callq 0x9fae
callq 0x122e1
callq 0xd9d9
movl %eax, %r15d
movq %rbx, %rdi
callq 0x861b
movl %r15d, %edi
callq 0xa426
pushq $-0x1
popq %rdi
movl %r14d, %esi
callq 0x9a47
callq 0x9fae
callq 0xa1f6
callq 0x868d
movq %rax, %rbx
pushq $0x4
popq %rcx
movl %r15d, %eax
cltd
idivl %ecx
cmpl $0x3, %edx
ja 0x18c14
leaq 0xa54f(%rip), %rax      # 0x23074
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rbx, %rdi
callq 0xa641
testl %eax, %eax
je 0x18c35
pushq $0x1
jmp 0x18b54
movq %rbx, %rdi
callq 0xa641
testl %eax, %eax
je 0x18c1f
pushq $-0x1
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xa426
movq %rbx, %rdi
callq 0xa641
movl %eax, %r14d
movq 0x28722(%rip), %rdi     # 0x41298
callq 0x861b
pushq $-0x1
popq %rdi
callq 0xa426
movq 0xebf46(%rip), %rdi     # 0x104ad0
callq 0x861b
testl %r14d, %r14d
jne 0x18c81
movq 0x28701(%rip), %rdi     # 0x412a0
callq 0x861b
movq 0x2870d(%rip), %rdi     # 0x412b8
callq 0x861b
movq 0x286e1(%rip), %rdi     # 0x41298
callq 0x861b
movq %rbx, %rdi
callq 0x861b
movq 0xebf05(%rip), %rdi     # 0x104ad0
callq 0x861b
movq 0x26469(%rip), %rdi     # 0x3f040
callq 0x861b
pushq $0x4
popq %rbx
movl %ebx, %edi
callq 0x85eb
pushq $0x3
popq %rdi
jmp 0x18cef
movq %rbx, %rdi
callq 0xa641
testl %eax, %eax
je 0x18c86
movq 0xebecb(%rip), %rdi     # 0x104ad0
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x861b
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x28672(%rip), %rdi     # 0x41298
callq 0x861b
pushq $-0x1
popq %rdi
callq 0xa426
jmp 0x18c9e
movq 0x28664(%rip), %rdi     # 0x412a0
callq 0x861b
movq 0x28670(%rip), %rdi     # 0x412b8
callq 0x861b
movq 0x28644(%rip), %rdi     # 0x41298
callq 0x861b
movq %rbx, %rdi
callq 0x861b
movq 0xebe68(%rip), %rdi     # 0x104ad0
callq 0x861b
movq 0x263cc(%rip), %rdi     # 0x3f040
callq 0x861b
pushq $0x4
popq %rdi
callq 0x85eb
pushq $0x3
popq %rdi
jmp 0x18cf6
movq 0x2860b(%rip), %rdi     # 0x41298
callq 0x861b
movq 0xebe37(%rip), %rdi     # 0x104ad0
callq 0x861b
movq 0x285fb(%rip), %rdi     # 0x412a0
callq 0x861b
movq 0x28607(%rip), %rdi     # 0x412b8
callq 0x861b
movq 0x285db(%rip), %rdi     # 0x41298
callq 0x861b
movq %rbx, %rdi
callq 0x861b
movq 0xebdff(%rip), %rdi     # 0x104ad0
callq 0x861b
movq 0x26363(%rip), %rdi     # 0x3f040
callq 0x861b
pushq $0x4
popq %rdi
callq 0x85eb
pushq $0x3
popq %rbx
movl %ebx, %edi
callq 0x85eb
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x85eb