// File: /workspace/github_c_makefile_star2_O1/georgeweigt[P]eigenmath/eigenmath.c
// Function: tanfunc
void
tanfunc(void)
{
	int i, n;
	double d;
	struct atom *p1, *p2;

	p1 = pop();

	if (istensor(p1)) {
		p1 = copy_tensor(p1);
		n = p1->u.tensor->nelem;
		for (i = 0; i < n; i++) {
			push(p1->u.tensor->elem[i]);
			tanfunc();
			p1->u.tensor->elem[i] = pop();
		}
		push(p1);
		return;
	}

	if (isdouble(p1)) {
		push(p1);
		d = pop_double();
		d = tan(d);
		push_double(d);
		return;
	}

	if (isdoublez(p1)) {
		push(p1);
		sinfunc();
		push(p1);
		cosfunc();
		divide();
		return;
	}

	// tan(-x) = -tan(x)

	if (isnegativeterm(p1)) {
		push(p1);
		negate();
		tanfunc();
		negate();
		return;
	}

	if (car(p1) == symbol(ADD)) {
		tanfunc_sum(p1);
		return;
	}

	if (car(p1) == symbol(ARCTAN)) {
		push(cadr(p1));
		push(caddr(p1));
		divide();
		return;
	}

	// n pi ?

	push(p1);
	push_symbol(PI);
	divide();
	p2 = pop();

	if (!isnum(p2)) {
		push_symbol(TAN);
		push(p1);
		list(2);
		return;
	}

	if (isdouble(p2)) {
		push(p2);
		d = pop_double();
		d = tan(d * M_PI);
		push_double(d);
		return;
	}

	push(p2); // nonnegative by tan(-x) = -tan(x) above
	push_integer(180);
	multiply();
	p2 = pop();

	if (!isinteger(p2)) {
		push_symbol(TAN);
		push(p1);
		list(2);
		return;
	}

	push(p2);
	push_integer(360);
	modfunc();
	n = pop_integer();

	switch (n) {
	case 0:
	case 180:
		push_integer(0);
		break;
	case 30:
	case 210:
		push_rational(1, 3);
		push_integer(3);
		push_rational(1, 2);
		power();
		multiply();
		break;
	case 150:
	case 330:
		push_rational(-1, 3);
		push_integer(3);
		push_rational(1, 2);
		power();
		multiply();
		break;
	case 45:
	case 225:
		push_integer(1);
		break;
	case 135:
	case 315:
		push_integer(-1);
		break;
	case 60:
	case 240:
		push_integer(3);
		push_rational(1, 2);
		power();
		break;
	case 120:
	case 300:
		push_integer(3);
		push_rational(1, 2);
		power();
		negate();
		break;
	default:
		push_symbol(TAN);
		push(p1);
		list(2);
		break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
callq 0x8b78
movq %rax, %rbx
movzbl 0x10(%rax), %r15d
cmpl $0x5, %r15d
je 0x1f89c
cmpl $0x7, %r15d
jne 0x1f8d9
movq %rbx, %rdi
callq 0x953d
movq %rax, %rbx
movq (%rax), %rax
movslq 0x64(%rax), %r14
testq %r14, %r14
jle 0x1f897
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x68(%rax,%r15,8), %rdi
callq 0x8b01
callq 0x1f82a
callq 0x8b78
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x1f870
movq %rbx, %rdi
jmp 0x1f8c8
movq %rbx, %rdi
callq 0x8b01
callq 0x9086
callq 0x7290
movsd %xmm0, -0x28(%rbp)
callq 0x74ec
movb $0x5, 0x10(%rax)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
movq %rbx, %rdi
callq 0xc3a9
movq %rbx, %rdi
testl %eax, %eax
je 0x1f910
callq 0x8b01
callq 0xfade
movq %rbx, %rdi
callq 0x8b01
callq 0xf2ab
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xd9a4
callq 0xa813
testl %eax, %eax
je 0x1f95e
movq %rbx, %rdi
callq 0x8b01
movq 0xf1ac8(%rip), %rdi     # 0x1113f0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
callq 0x1f82a
movq 0xf1aad(%rip), %rdi     # 0x1113f0
callq 0x8b01
movl $0x2, %edi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa8bb
cmpb $0x1, %r15b
leaq 0x21097(%rip), %r14     # 0x40a00
movq %r14, %rax
cmoveq %rbx, %rax
movq (%rax), %rax
cmpq 0x23926(%rip), %rax     # 0x432a0
je 0x1f9da
cmpq 0x1e815(%rip), %rax     # 0x3e198
je 0x1f9ee
movq %rbx, %rdi
callq 0x8b01
movq 0x216bc(%rip), %rdi     # 0x41050
callq 0x8b01
callq 0xd9a4
callq 0x8b78
movb 0x10(%rax), %r14b
movl %r14d, %ecx
andb $-0x2, %cl
cmpb $0x4, %cl
jne 0x1fb79
movq %rax, %rdi
callq 0x8b01
cmpb $0x5, %r14b
jne 0x1fa57
callq 0x9086
mulsd 0x674b(%rip), %xmm0     # 0x26120
jmp 0x1f8a9
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1fc2c
movq %rbx, %r12
addq $0x8, %r12
cmpb $0x1, %r15b
movq %r14, %rax
cmoveq %r12, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %r14, %rax
movq (%rax), %rdi
callq 0x8b01
cmpb $0x1, 0x10(%rbx)
cmovneq %r14, %r12
movq (%r12), %rax
movb 0x10(%rax), %cl
addq $0x8, %rax
cmpb $0x1, %cl
movq %r14, %rdx
cmoveq %rax, %rdx
movq (%rdx), %rdx
cmpb $0x1, 0x10(%rdx)
jne 0x1fa4a
cmpb $0x1, %cl
leaq 0x20fbd(%rip), %rcx     # 0x40a00
cmoveq %rax, %rcx
movq (%rcx), %r14
movq (%r14), %rdi
callq 0x8b01
jmp 0x1f8ff
movl $0xb4, %edi
callq 0xacbe
movl $0x2, %edi
callq 0xa8bb
callq 0x8b78
cmpb $0x4, 0x10(%rax)
jne 0x1fb79
movq 0x8(%rax), %rcx
cmpl $0x1, -0x4(%rcx)
jne 0x1fb79
cmpl $0x1, (%rcx)
jne 0x1fb79
movq %rax, %rdi
callq 0x8b01
movl $0x168, %edi            # imm = 0x168
callq 0xacbe
callq 0xf98a
callq 0xeb5b
cmpl $0xb3, %eax
jg 0x1fad7
cmpl $0x3b, %eax
jle 0x1fb2a
cmpl $0x86, %eax
jg 0x1fb6b
cmpl $0x3c, %eax
je 0x1fbb8
cmpl $0x78, %eax
je 0x1fafb
jmp 0x1fb79
cmpl $0xef, %eax
jle 0x1fb42
cmpl $0x13a, %eax            # imm = 0x13A
jg 0x1fba3
cmpl $0xf0, %eax
je 0x1fbb8
cmpl $0x12c, %eax            # imm = 0x12C
jne 0x1fb79
movl $0x3, %edi
callq 0xacbe
movl $0x1, %edi
movl $0x2, %esi
callq 0xa1f4
callq 0xa234
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9ec9
testl %eax, %eax
je 0x1fbee
cmpl $0x1e, %eax
je 0x1fbfa
cmpl $0x2d, %eax
je 0x1fb5f
jmp 0x1fb79
cmpl $0xb4, %eax
je 0x1fbee
cmpl $0xd2, %eax
je 0x1fbfa
cmpl $0xe1, %eax
jne 0x1fb79
movq 0xe6f72(%rip), %rdi     # 0x106ad8
jmp 0x1f8c8
cmpl $0x87, %eax
je 0x1fbe2
cmpl $0x96, %eax
je 0x1fbb1
movq 0x22150(%rip), %rdi     # 0x41cd0
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x8ad9
cmpl $0x13b, %eax            # imm = 0x13B
je 0x1fbe2
cmpl $0x14a, %eax            # imm = 0x14A
jne 0x1fb79
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0x1fbff
movl $0x3, %edi
callq 0xacbe
movl $0x1, %edi
movl $0x2, %esi
callq 0xa1f4
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa234
movq 0xf1807(%rip), %rdi     # 0x1113f0
jmp 0x1f8c8
movq 0x1e54b(%rip), %rdi     # 0x3e140
jmp 0x1f8c8
movl $0x1, %edi
movl $0x3, %esi
callq 0xa1f4
movl $0x3, %edi
callq 0xacbe
movl $0x1, %edi
movl $0x2, %esi
callq 0xa1f4
callq 0xa234
jmp 0x1f948