// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: eval_rotate
void
eval_rotate(struct atom *p1)
{
	int m, n;
	uint32_t c;
	struct atom *PSI, *OPCODE, *PHASE;

	push(cadr(p1));
	evalf();
	PSI = pop();

	if (!istensor(PSI) || PSI->u.tensor->ndim > 1 || PSI->u.tensor->nelem > 32768 || !POWEROF2(PSI->u.tensor->nelem))
		stopf("rotate error 1 first argument is not a vector or dimension error");

	c = 0;

	p1 = cddr(p1);

	while (iscons(p1)) {

		if (!iscons(cdr(p1)))
			stopf("rotate error 2 unexpected end of argument list");

		OPCODE = car(p1);
		push(cadr(p1));
		evalf();
		n = pop_integer();

		if (n > 14 || (1 << n) >= PSI->u.tensor->nelem)
			stopf("rotate error 3 qubit number format or range");

		p1 = cddr(p1);

		if (OPCODE == symbol(C_UPPER)) {
			c |= 1 << n;
			continue;
		}

		if (OPCODE == symbol(H_UPPER)) {
			rotate_h(PSI, c, n);
			c = 0;
			continue;
		}

		if (OPCODE == symbol(P_UPPER)) {
			if (!iscons(p1))
				stopf("rotate error 2 unexpected end of argument list");
			push(car(p1));
			p1 = cdr(p1);
			evalf();
			push(imaginaryunit);
			multiply();
			expfunc();
			PHASE = pop();
			rotate_p(PSI, PHASE, c, n);
			c = 0;
			continue;
		}

		if (OPCODE == symbol(Q_UPPER)) {
			rotate_q(PSI, n);
			c = 0;
			continue;
		}

		if (OPCODE == symbol(V_UPPER)) {
			rotate_v(PSI, n);
			c = 0;
			continue;
		}

		if (OPCODE == symbol(W_UPPER)) {
			m = n;
			if (!iscons(p1))
				stopf("rotate error 2 unexpected end of argument list");
			push(car(p1));
			p1 = cdr(p1);
			evalf();
			n = pop_integer();
			if (n > 14 || (1 << n) >= PSI->u.tensor->nelem)
				stopf("rotate error 3 qubit number format or range");
			rotate_w(PSI, c, m, n);
			c = 0;
			continue;
		}

		if (OPCODE == symbol(X_UPPER)) {
			rotate_x(PSI, c, n);
			c = 0;
			continue;
		}

		if (OPCODE == symbol(Y_UPPER)) {
			rotate_y(PSI, c, n);
			c = 0;
			continue;
		}

		if (OPCODE == symbol(Z_UPPER)) {
			rotate_z(PSI, c, n);
			c = 0;
			continue;
		}

		stopf("rotate error 4 unknown rotation code");
	}

	push(PSI);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
leaq 0x8(%rdi), %r15
cmpb $0x1, 0x10(%rdi)
leaq 0x24320(%rip), %rcx     # 0x3e9f0
movq %rcx, %rax
cmoveq %r15, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %rcx, %rax
movq (%rax), %rdi
callq 0x861b
callq 0x8fbb
callq 0x868d
cmpb $0x7, 0x10(%rax)
jne 0x1a9ba
movq %rax, %rbx
movq (%rax), %rax
cmpl $0x1, (%rax)
jg 0x1a9ba
movl 0x64(%rax), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jg 0x1a9ba
movl %eax, %ecx
shrl %ecx
andl $0x55555555, %ecx       # imm = 0x55555555
subl %ecx, %eax
movl $0x33333333, %ecx       # imm = 0x33333333
movl %eax, %edx
andl %ecx, %edx
shrl $0x2, %eax
andl %ecx, %eax
addl %edx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
addl %eax, %ecx
andl $0xf0f0f0f, %ecx        # imm = 0xF0F0F0F
imull $0x1010101, %ecx, %eax  # imm = 0x1010101
shrl $0x18, %eax
cmpl $0x2, %eax
jae 0x1a9ba
cmpb $0x1, 0x10(%r14)
leaq 0x2428e(%rip), %rdx     # 0x3e9f0
cmovneq %rdx, %r15
movq (%r15), %rax
leaq 0x8(%rax), %rcx
cmpb $0x1, 0x10(%rax)
cmovneq %rdx, %rcx
movq (%rcx), %r13
xorl %r14d, %r14d
cmpb $0x1, 0x10(%r13)
jne 0x1a98c
movq 0x8(%r13), %rax
cmpb $0x1, 0x10(%rax)
jne 0x1a9ae
movq (%r13), %r12
movq (%rax), %rdi
callq 0x861b
callq 0x8fbb
callq 0xd9d9
cmpl $0xe, %eax
jg 0x1a9a2
movl %eax, %r15d
pushq $0x1
popq %rax
movl %r15d, %ecx
shll %cl, %eax
movq (%rbx), %rcx
cmpl 0x64(%rcx), %eax
jge 0x1a9a2
leaq 0x8(%r13), %rcx
cmpb $0x1, 0x10(%r13)
leaq 0x24216(%rip), %rsi     # 0x3e9f0
cmovneq %rsi, %rcx
movq (%rcx), %rcx
leaq 0x8(%rcx), %rdx
cmpb $0x1, 0x10(%rcx)
cmovneq %rsi, %rdx
movq (%rdx), %r13
cmpq 0x21f99(%rip), %r12     # 0x3c790
jne 0x1a801
orl %eax, %r14d
jmp 0x1a77b
cmpq 0x22f28(%rip), %r12     # 0x3d730
je 0x1a874
cmpq 0x2481f(%rip), %r12     # 0x3f030
je 0x1a887
cmpq 0x24b36(%rip), %r12     # 0x3f350
je 0x1a8e8
cmpq 0x25ac9(%rip), %r12     # 0x402f0
je 0x1a8f8
cmpq 0x25ddc(%rip), %r12     # 0x40610
je 0x1a908
cmpq 0x260ef(%rip), %r12     # 0x40930
je 0x1a966
cmpq 0x26402(%rip), %r12     # 0x40c50
je 0x1a979
cmpq 0x26715(%rip), %r12     # 0x40f70
jne 0x1a9c6
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x1af1f
jmp 0x1a778
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x1a9d2
jmp 0x1a778
cmpb $0x1, 0x10(%r13)
jne 0x1a9ae
movq (%r13), %rdi
callq 0x861b
cmpb $0x1, 0x10(%r13)
leaq 0x8(%r13), %rax
leaq 0x24145(%rip), %rcx     # 0x3e9f0
cmovneq %rcx, %rax
movq (%rax), %r13
callq 0x8fbb
movq 0xea212(%rip), %rdi     # 0x104ad0
callq 0x861b
callq 0x9fae
callq 0xe4ce
callq 0x868d
movq %rbx, %rdi
movq %rax, %rsi
movl %r14d, %edx
movl %r15d, %ecx
callq 0x1aac9
jmp 0x1a778
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1ab3e
jmp 0x1a778
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1ac37
jmp 0x1a778
cmpb $0x1, 0x10(%r13)
jne 0x1a9ae
movq (%r13), %rdi
callq 0x861b
cmpb $0x1, 0x10(%r13)
leaq 0x8(%r13), %rax
leaq 0x240c4(%rip), %rcx     # 0x3e9f0
cmovneq %rcx, %rax
movq (%rax), %r13
callq 0x8fbb
callq 0xd9d9
cmpl $0xe, %eax
jg 0x1a9a2
pushq $0x1
popq %rdx
movl %eax, %ecx
shll %cl, %edx
movq (%rbx), %rcx
cmpl 0x64(%rcx), %edx
jge 0x1a9a2
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
movl %eax, %ecx
callq 0x1ad25
jmp 0x1a778
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x1add4
jmp 0x1a778
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x1ae61
jmp 0x1a778
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
leaq 0xd063(%rip), %rdi      # 0x27a0c
callq 0x7756
leaq 0xd028(%rip), %rdi      # 0x279dd
callq 0x7756
leaq 0xcfdb(%rip), %rdi      # 0x2799c
callq 0x7756
leaq 0xd06b(%rip), %rdi      # 0x27a38
callq 0x7756