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

	// R = EXPO mod 2

	push(EXPO);
	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) {

	case 0:
		if (iszero(R))
			push_integer(1);
		else {
			push_symbol(POWER);
			push_integer(-1);
			push(R);
			list(3);
		}
		break;

	case 1:
		if (iszero(R))
			push(imaginaryunit);
		else {
			push_symbol(MULTIPLY);
			push_integer(-1);
			push_symbol(POWER);
			push_integer(-1);
			push(R);
			push_rational(-1, 2);
			add();
			list(3);
			list(3);
		}
		break;

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

	case 3:
		if (iszero(R)) {
			push_symbol(MULTIPLY);
			push_integer(-1);
			push(imaginaryunit);
			list(3);
		} else {
			push_symbol(POWER);
			push_integer(-1);
			push(R);
			push_rational(-1, 2);
			add();
			list(3);
		}
		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 0x182ed
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 %r15
movl %r15d, %edi
callq 0xa426
callq 0x9fae
callq 0x122e1
callq 0xd9d9
movl %eax, %r14d
movq %rbx, %rdi
callq 0x861b
movl %r14d, %edi
callq 0xa426
pushq $-0x1
popq %rdi
movl %r15d, %esi
callq 0x9a47
callq 0x9fae
callq 0xa1f6
callq 0x868d
cmpl $0x3, %r14d
ja 0x183e5
movq %rax, %rbx
movl %r14d, %eax
leaq 0xad00(%rip), %rcx      # 0x23054
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0xa641
testl %eax, %eax
je 0x1845b
pushq $0x1
jmp 0x1837f
movq %rbx, %rdi
callq 0xa641
testl %eax, %eax
je 0x183f0
pushq $-0x1
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xa426
movq %rbx, %rdi
callq 0xa641
testl %eax, %eax
je 0x18429
movq 0x28ef2(%rip), %rdi     # 0x41298
callq 0x861b
pushq $-0x1
popq %rdi
callq 0xa426
movq 0xec716(%rip), %rdi     # 0x104ad0
jmp 0x18472
movq %rbx, %rdi
callq 0xa641
testl %eax, %eax
je 0x1847c
movq 0xec6fa(%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 0x28ea1(%rip), %rdi     # 0x41298
callq 0x861b
pushq $-0x1
popq %r14
movl %r14d, %edi
callq 0xa426
movq 0x28e91(%rip), %rdi     # 0x412a0
callq 0x861b
movl %r14d, %edi
callq 0xa426
movq %rbx, %rdi
callq 0x861b
jmp 0x184c0
movq 0x28e70(%rip), %rdi     # 0x412a0
callq 0x861b
pushq $-0x1
popq %r14
movl %r14d, %edi
callq 0xa426
movq %rbx, %rdi
callq 0x861b
pushq $0x2
popq %rsi
movl %r14d, %edi
callq 0x9a47
callq 0xa1f6
jmp 0x18477
movq 0x28e3e(%rip), %rdi     # 0x412a0
callq 0x861b
pushq $-0x1
popq %rdi
callq 0xa426
movq %rbx, %rdi
callq 0x861b
pushq $0x3
popq %rdi
jmp 0x184cc
movq 0x28e15(%rip), %rdi     # 0x41298
callq 0x861b
pushq $-0x1
popq %r14
movl %r14d, %edi
callq 0xa426
movq 0x28e05(%rip), %rdi     # 0x412a0
callq 0x861b
movl %r14d, %edi
callq 0xa426
movq %rbx, %rdi
callq 0x861b
pushq $0x2
popq %rsi
movl %r14d, %edi
callq 0x9a47
callq 0xa1f6
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