// File: /workspace/github_c_makefile_star2_O3/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 0x8ba5
movl $0x2, %edi
callq 0xb1be
callq 0x108ee
movl 0x21c75(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x1d93a
decl %eax
movl %eax, 0x21c5d(%rip)     # 0x3f2b8
leaq 0x2af5e(%rip), %r15     # 0x485c0
movq (%r15,%rax,8), %rbx
cmpb $0x1, 0x12(%rbx)
jne 0x1d6aa
movq %rbx, %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xb1be
movl $0x2, %edi
callq 0xadb3
movl 0x21c2a(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x1d93a
decl %eax
movl %eax, 0x21c12(%rip)     # 0x3f2b8
movq (%r15,%rax,8), %rbx
movq %rbx, %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xb1be
movl $0x2, %edi
callq 0xacef
callq 0x15584
callq 0xf8e6
movl %eax, %r14d
movq %rbx, %rdi
callq 0x8ba5
movl %r14d, %edi
callq 0xb1be
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x2, %esi
callq 0xa533
movl $0x2, %edi
callq 0xacef
movl $0x2, %edi
callq 0xadb3
movl 0x21bac(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x1d93a
decl %eax
leal 0x3(%r14), %ecx
testl %r14d, %r14d
cmovnsl %r14d, %ecx
movl %eax, 0x21b89(%rip)     # 0x3f2b8
andl $-0x4, %ecx
subl %ecx, %r14d
cmpl $0x3, %r14d
ja 0x1d84b
movq (%r15,%rax,8), %rbx
leaq 0xc92a(%rip), %rax      # 0x2a074
movslq (%rax,%r14,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rbx, %rdi
callq 0xb477
testl %eax, %eax
je 0x1d86b
movq 0xee36e(%rip), %rdi     # 0x10bad8
jmp 0x1d83c
movq %rbx, %rdi
callq 0xb477
testl %eax, %eax
je 0x1d856
movq 0xf8c6a(%rip), %rdi     # 0x1163f0
jmp 0x1d83c
movq %rbx, %rdi
callq 0xb477
movl %eax, %r14d
movq 0x2ab0b(%rip), %rdi     # 0x482a8
callq 0x8ba5
movq 0xf8c47(%rip), %rdi     # 0x1163f0
callq 0x8ba5
movq 0xee32b(%rip), %rdi     # 0x10bae0
callq 0x8ba5
testl %r14d, %r14d
jne 0x1d926
movq 0x2aae6(%rip), %rdi     # 0x482b0
callq 0x8ba5
movq 0x2aaf2(%rip), %rdi     # 0x482c8
callq 0x8ba5
movq 0x2aac6(%rip), %rdi     # 0x482a8
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
movq 0xee2ea(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x2884e(%rip), %rdi     # 0x46050
callq 0x8ba5
movl $0x4, %edi
callq 0x8b7d
movl $0x3, %edi
callq 0x8b7d
movl $0x4, %edi
jmp 0x1d92b
movq %rbx, %rdi
callq 0xb477
testl %eax, %eax
je 0x1d8b6
movq 0xee2a4(%rip), %rdi     # 0x10bae0
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x2aa4b(%rip), %rdi     # 0x482a8
callq 0x8ba5
movq 0xf8b87(%rip), %rdi     # 0x1163f0
jmp 0x1d8c9
movq 0x2aa3e(%rip), %rdi     # 0x482b0
callq 0x8ba5
movq 0x2aa4a(%rip), %rdi     # 0x482c8
callq 0x8ba5
movq 0x2aa1e(%rip), %rdi     # 0x482a8
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
movq 0xee242(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x287a6(%rip), %rdi     # 0x46050
callq 0x8ba5
movl $0x4, %edi
jmp 0x1d921
movq 0x2a9eb(%rip), %rdi     # 0x482a8
callq 0x8ba5
movq 0xee217(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x2a9db(%rip), %rdi     # 0x482b0
callq 0x8ba5
movq 0x2a9e7(%rip), %rdi     # 0x482c8
callq 0x8ba5
movq 0x2a9bb(%rip), %rdi     # 0x482a8
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
movq 0xee1df(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x28743(%rip), %rdi     # 0x46050
callq 0x8ba5
movl $0x4, %edi
callq 0x8b7d
movl $0x3, %edi
callq 0x8b7d
movl $0x3, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x8b7d
leaq 0x11600(%rip), %rdi     # 0x2ef41
callq 0x780b