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

	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]);
			cosfunc();
			p1->u.tensor->elem[i] = pop();
		}
		push(p1);
		return;
	}

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

	// cos(z) = 1/2 exp(i z) + 1/2 exp(-i z)

	if (isdoublez(p1)) {
		push_double(0.5);
		push(imaginaryunit);
		push(p1);
		multiply();
		expfunc();
		push(imaginaryunit);
		negate();
		push(p1);
		multiply();
		expfunc();
		add();
		multiply();
		return;
	}

	// cos(-x) = cos(x)

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

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

	// cos(arctan(y,x)) = x (x^2 + y^2)^(-1/2)

	if (car(p1) == symbol(ARCTAN)) {
		X = caddr(p1);
		Y = cadr(p1);
		push(X);
		push(X);
		push(X);
		multiply();
		push(Y);
		push(Y);
		multiply();
		add();
		push_rational(-1, 2);
		power();
		multiply();
		return;
	}

	// cos(arcsin(x)) = sqrt(1 - x^2)

	if (car(p1) == symbol(ARCSIN)) {
		push_integer(1);
		push(cadr(p1));
		push_integer(2);
		power();
		subtract();
		push_rational(1, 2);
		power();
		return;
	}

	// n pi ?

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

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

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

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

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

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x2f18f(%rip), %eax     # 0x3f2b8
leal -0x186a1(%rax), %ecx
cmpl $0xfffe7960, %ecx       # imm = 0xFFFE7960
jb 0x101b1
leaq 0x38482(%rip), %r14     # 0x485c0
decl %eax
movl %eax, 0x2f172(%rip)     # 0x3f2b8
movq (%r14,%rax,8), %rbx
movzbl 0x10(%rbx), %r12d
cmpl $0x5, %r12d
je 0x1021f
cmpl $0x7, %r12d
je 0x101bd
movq %rbx, %rdi
callq 0xca1c
testl %eax, %eax
jne 0x1025e
movq %rbx, %rdi
callq 0xac49
testl %eax, %eax
je 0x1031c
movq %rbx, %rdi
callq 0x8ba5
movq 0x106262(%rip), %rdi    # 0x1163f0
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl 0x2f115(%rip), %eax     # 0x3f2b8
leal -0x186a1(%rax), %ecx
cmpl $0xfffe7960, %ecx       # imm = 0xFFFE7960
jae 0x1013e
leaq 0x1ed89(%rip), %rdi     # 0x2ef41
callq 0x780b
movq %rbx, %rdi
callq 0x9638
movq %rax, %rbx
movq (%rax), %rax
movslq 0x64(%rax), %r15
testq %r15, %r15
jle 0x1021a
xorl %r12d, %r12d
movl $0xfffe795f, %r13d      # imm = 0xFFFE795F
movq (%rbx), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x8ba5
callq 0x10115
movl 0x2f0c3(%rip), %eax     # 0x3f2b8
leal (%rax,%r13), %ecx
cmpl %r13d, %ecx
jbe 0x101b1
decl %eax
movl %eax, 0x2f0b2(%rip)     # 0x3f2b8
movq (%r14,%rax,8), %rax
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r12,8)
incq %r12
cmpq %r12, %r15
jne 0x101dd
movq %rbx, %rdi
jmp 0x1024b
movq %rbx, %rdi
callq 0x8ba5
callq 0x9128
callq 0x7170
movsd %xmm0, -0x30(%rbp)
callq 0x74dc
movb $0x5, 0x10(%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
callq 0x74dc
movb $0x5, 0x10(%rax)
movabsq $0x3fe0000000000000, %rcx # imm = 0x3FE0000000000000
movq %rcx, (%rax)
movq %rax, %rdi
callq 0x8ba5
movq 0xfb85d(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movq 0x38027(%rip), %rdi     # 0x482c8
callq 0x8ba5
callq 0xb238
callq 0xa573
movq 0xfb829(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x10612d(%rip), %rdi    # 0x1163f0
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movq %rbx, %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movq 0x37fdd(%rip), %rdi     # 0x482c8
callq 0x8ba5
callq 0xb238
callq 0xa573
movl $0x2, %edi
callq 0xadb3
movl $0x2, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xacef
cmpb $0x1, %r12b
leaq 0x356d9(%rip), %r15     # 0x45a00
movq %r15, %rax
cmoveq %rbx, %rax
movq (%rax), %rax
cmpq 0x37f68(%rip), %rax     # 0x482a0
je 0x103c5
cmpq 0x32e53(%rip), %rax     # 0x43198
je 0x103db
cmpq 0x32e36(%rip), %rax     # 0x43188
je 0x10408
movq %rbx, %rdi
callq 0x8ba5
movq 0x35ce9(%rip), %rdi     # 0x46050
callq 0x8ba5
callq 0xe218
movl 0x2ef41(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x101b1
decl %eax
movl %eax, 0x2ef29(%rip)     # 0x3f2b8
movq (%r14,%rax,8), %rdi
movb 0x10(%rdi), %r14b
movl %r14d, %eax
andb $-0x2, %al
cmpb $0x4, %al
jne 0x10651
callq 0x8ba5
cmpb $0x5, %r14b
jne 0x104f9
callq 0x9128
mulsd 0x19d80(%rip), %xmm0    # 0x2a140
jmp 0x1022c
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x106e6
addq $0x8, %rbx
cmpb $0x1, %r12b
cmovneq %r15, %rbx
movq (%rbx), %rax
cmpb $0x1, 0x10(%rax)
jne 0x10484
movq (%rax), %rbx
movq 0x8(%rax), %rax
cmpb $0x1, 0x10(%rax)
cmoveq %rax, %r15
jmp 0x10497
movq 0xfb6c9(%rip), %rdi     # 0x10bad8
callq 0x8ba5
leaq 0x8(%rbx), %rax
cmpb $0x1, 0x10(%rbx)
cmovneq %r15, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmoveq %rax, %r15
movq (%r15), %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xb1be
callq 0xa573
movq 0x105fa7(%rip), %rdi    # 0x1163f0
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl $0x2, %edi
callq 0xadb3
movl $0x1, %edi
movl $0x2, %esi
callq 0xa533
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa573
movq 0x35575(%rip), %rbx     # 0x45a00
cmpb $0x1, 0x10(%rbx)
movq %rbx, %r15
movq %rbx, %r14
jne 0x1049a
movq (%r15), %r14
movq %r14, %rdi
callq 0x8ba5
movq %r14, %rdi
callq 0x8ba5
movq %r14, %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movq %rbx, %rdi
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl $0x2, %edi
callq 0xadb3
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x2, %esi
callq 0xa533
callq 0xa573
jmp 0x10304
movl $0xb4, %edi
callq 0xb1be
movl $0x2, %edi
callq 0xacef
callq 0x8c47
cmpb $0x4, 0x10(%rax)
jne 0x10651
movq 0x8(%rax), %rcx
cmpl $0x1, -0x4(%rcx)
jne 0x10651
cmpl $0x1, (%rcx)
jne 0x10651
movq %rax, %rdi
callq 0x8ba5
movl $0x168, %edi            # imm = 0x168
callq 0xb1be
callq 0x108ee
callq 0xf8e6
cmpl $0xb3, %eax
jg 0x10576
cmpl $0x59, %eax
jg 0x1059f
cmpl $0x2c, %eax
jg 0x105d4
testl %eax, %eax
je 0x106b3
cmpl $0x1e, %eax
je 0x1063b
jmp 0x10651
cmpl $0x10d, %eax            # imm = 0x10D
jg 0x105b9
cmpl $0xe0, %eax
jg 0x105e9
cmpl $0xb4, %eax
je 0x106bf
cmpl $0xd2, %eax
je 0x10626
jmp 0x10651
cmpl $0x86, %eax
jg 0x10618
cmpl $0x5a, %eax
je 0x1067d
cmpl $0x78, %eax
je 0x105fb
jmp 0x10651
cmpl $0x13a, %eax            # imm = 0x13A
jg 0x1062d
cmpl $0x10e, %eax            # imm = 0x10E
je 0x1067d
cmpl $0x12c, %eax            # imm = 0x12C
je 0x105e2
jmp 0x10651
cmpl $0x2d, %eax
je 0x10690
cmpl $0x3c, %eax
jne 0x10651
movl $0x1, %edi
jmp 0x10600
cmpl $0xe1, %eax
je 0x10689
cmpl $0xf0, %eax
jne 0x10651
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x2, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa533
cmpl $0x87, %eax
je 0x10689
cmpl $0x96, %eax
jne 0x10651
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0x10640
cmpl $0x13b, %eax            # imm = 0x13B
je 0x10690
cmpl $0x14a, %eax            # imm = 0x14A
jne 0x10651
movl $0x1, %edi
movl $0x2, %esi
callq 0xa533
movl $0x3, %edi
jmp 0x106a4
movq 0x33198(%rip), %rdi     # 0x437f0
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
movl $0x2, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b7d
movq 0x32abc(%rip), %rdi     # 0x43140
jmp 0x1024b
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0x10695
movl $0x1, %edi
movl $0x2, %esi
callq 0xa533
movl $0x2, %edi
callq 0xb1be
movl $0x1, %edi
jmp 0x104e5
movq 0xfb41e(%rip), %rdi     # 0x10bad8
jmp 0x1024b
movq 0x105d2a(%rip), %rdi    # 0x1163f0
jmp 0x1024b