// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdi, %r14
leaq 0x8(%rdi), %rbx
cmpb $0x1, 0x10(%rdi)
leaq 0x234f6(%rip), %rcx     # 0x40a00
movq %rcx, %rax
cmoveq %rbx, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %rcx, %rax
movq (%rax), %rdi
callq 0x8b01
callq 0x95e2
callq 0x8b78
cmpb $0x7, 0x10(%rax)
jne 0x1d84c
movq (%rax), %rcx
cmpl $0x1, (%rcx)
jg 0x1d84c
movl 0x64(%rcx), %esi
cmpl $0x8000, %esi           # imm = 0x8000
jg 0x1d84c
movl %esi, %ecx
shrl %ecx
andl $0x55555555, %ecx       # imm = 0x55555555
subl %ecx, %esi
movl $0x33333333, %ecx       # imm = 0x33333333
movl %esi, %edx
andl %ecx, %edx
shrl $0x2, %esi
andl %ecx, %esi
addl %edx, %esi
movl %esi, %ecx
shrl $0x4, %ecx
addl %esi, %ecx
andl $0xf0f0f0f, %ecx        # imm = 0xF0F0F0F
imull $0x1010101, %ecx, %ecx  # imm = 0x1010101
shrl $0x18, %ecx
cmpl $0x2, %ecx
jae 0x1d84c
movq %rax, -0x38(%rbp)
cmpb $0x1, 0x10(%r14)
leaq 0x23462(%rip), %rdx     # 0x40a00
cmovneq %rdx, %rbx
movq (%rbx), %rax
leaq 0x8(%rax), %rcx
cmpb $0x1, 0x10(%rax)
cmovneq %rdx, %rcx
movq (%rcx), %r13
cmpb $0x1, 0x10(%r13)
jne 0x1d81d
leaq 0x10(%r13), %r14
xorl %eax, %eax
movl %eax, -0x2c(%rbp)
movq 0x8(%r13), %rax
cmpb $0x1, 0x10(%rax)
jne 0x1d840
leaq 0x8(%r13), %r12
cmpb $0x1, (%r14)
leaq 0x2341b(%rip), %rcx     # 0x40a00
cmovneq %rcx, %r13
movq %rcx, %rax
cmoveq %r12, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
movq (%r13), %rbx
cmovneq %rcx, %rax
movq (%rax), %rdi
callq 0x8b01
callq 0x95e2
callq 0xeb5b
cmpl $0xe, %eax
movq -0x38(%rbp), %rdi
jg 0x1d834
movl %eax, %r15d
movl $0x1, %eax
movl %r15d, %ecx
shll %cl, %eax
movq (%rdi), %rcx
cmpl 0x64(%rcx), %eax
jge 0x1d834
cmpb $0x1, (%r14)
leaq 0x233be(%rip), %rdx     # 0x40a00
cmovneq %rdx, %r12
movq (%r12), %rax
leaq 0x8(%rax), %rcx
cmpb $0x1, 0x10(%rax)
cmovneq %rdx, %rcx
movq (%rcx), %r13
cmpq 0x21140(%rip), %rbx     # 0x3e7a0
je 0x1d6d2
cmpq 0x220d7(%rip), %rbx     # 0x3f740
je 0x1d6de
cmpq 0x239ce(%rip), %rbx     # 0x41040
je 0x1d6ee
cmpq 0x23ce5(%rip), %rbx     # 0x41360
je 0x1d771
cmpq 0x24c78(%rip), %rbx     # 0x42300
je 0x1d77e
cmpq 0x24f8b(%rip), %rbx     # 0x42620
je 0x1d78b
cmpq 0x2529e(%rip), %rbx     # 0x42940
je 0x1d7f4
cmpq 0x255b1(%rip), %rbx     # 0x42c60
je 0x1d801
cmpq 0x258c4(%rip), %rbx     # 0x42f80
jne 0x1d858
movl -0x2c(%rbp), %esi
movl %r15d, %edx
callq 0x1de89
jmp 0x1d80c
movl -0x2c(%rbp), %eax
btsl %r15d, %eax
jmp 0x1d80e
movl -0x2c(%rbp), %esi
movl %r15d, %edx
callq 0x1d864
jmp 0x1d80c
cmpb $0x1, 0x10(%r13)
jne 0x1d840
cmpb $0x1, 0x10(%r13)
leaq 0x232fb(%rip), %rbx     # 0x40a00
movq %rbx, %rax
cmoveq %r13, %rax
movq (%rax), %rdi
callq 0x8b01
cmpb $0x1, 0x10(%r13)
leaq 0x8(%r13), %rax
cmovneq %rbx, %rax
movq (%rax), %r13
callq 0x95e2
movq 0xe93b0(%rip), %rdi     # 0x106ae0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
movq 0x25b82(%rip), %rdi     # 0x432c8
callq 0x8b01
callq 0xad38
callq 0xa234
callq 0x8b78
movq -0x38(%rbp), %rdi
movq %rax, %rsi
movl -0x2c(%rbp), %edx
movl %r15d, %ecx
callq 0x1d989
jmp 0x1d80c
movl %r15d, %esi
callq 0x1da0c
jmp 0x1d80c
movl %r15d, %esi
callq 0x1db15
jmp 0x1d80c
cmpb $0x1, 0x10(%r13)
jne 0x1d840
cmpb $0x1, 0x10(%r13)
leaq 0x2325e(%rip), %rbx     # 0x40a00
movq %rbx, %rax
cmoveq %r13, %rax
movq (%rax), %rdi
callq 0x8b01
cmpb $0x1, 0x10(%r13)
leaq 0x8(%r13), %rax
cmovneq %rbx, %rax
movq (%rax), %r13
callq 0x95e2
callq 0xeb5b
cmpl $0xe, %eax
movq -0x38(%rbp), %rdi
jg 0x1d834
movl $0x1, %edx
movl %eax, %ecx
shll %cl, %edx
movq (%rdi), %rcx
cmpl 0x64(%rcx), %edx
jge 0x1d834
movl -0x2c(%rbp), %esi
movl %r15d, %edx
movl %eax, %ecx
callq 0x1dc59
jmp 0x1d80c
movl -0x2c(%rbp), %esi
movl %r15d, %edx
callq 0x1dd10
jmp 0x1d80c
movl -0x2c(%rbp), %esi
movl %r15d, %edx
callq 0x1dda6
xorl %eax, %eax
leaq 0x10(%r13), %r14
cmpb $0x1, 0x10(%r13)
je 0x1d5c5
movq -0x38(%rbp), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
leaq 0xd179(%rip), %rdi      # 0x2a9b4
callq 0x77c8
leaq 0xd13e(%rip), %rdi      # 0x2a985
callq 0x77c8
leaq 0xd0f1(%rip), %rdi      # 0x2a944
callq 0x77c8
leaq 0xd181(%rip), %rdi      # 0x2a9e0
callq 0x77c8