// File: /workspace/github_c_makefile_star2_O1/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 %rbx
pushq %rax
callq 0x8b78
movq %rax, %rbx
movzbl 0x10(%rax), %r15d
cmpl $0x5, %r15d
je 0xf358
cmpl $0x7, %r15d
je 0xf312
movq %rbx, %rdi
callq 0xc3a9
testl %eax, %eax
jne 0xf393
movq %rbx, %rdi
callq 0xa813
testl %eax, %eax
je 0xf44d
movq %rbx, %rdi
callq 0x8b01
movq 0x1020ef(%rip), %rdi    # 0x1113f0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
jmp 0xf2b5
movq %rbx, %rdi
callq 0x953d
movq %rax, %rbx
movq (%rax), %rax
movslq 0x64(%rax), %r14
testq %r14, %r14
jle 0xf353
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x68(%rax,%r15,8), %rdi
callq 0x8b01
callq 0xf2ab
callq 0x8b78
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0xf32c
movq %rbx, %rdi
jmp 0xf384
movq %rbx, %rdi
callq 0x8b01
callq 0x9086
callq 0x7170
movsd %xmm0, -0x20(%rbp)
callq 0x74ec
movb $0x5, 0x10(%rax)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
callq 0x74ec
movb $0x5, 0x10(%rax)
movabsq $0x3fe0000000000000, %rcx # imm = 0x3FE0000000000000
movq %rcx, (%rax)
movq %rax, %rdi
callq 0x8b01
movq 0xf7728(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
movq 0x33ef2(%rip), %rdi     # 0x432c8
callq 0x8b01
callq 0xad38
callq 0xa234
movq 0xf76f4(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq 0x101ff8(%rip), %rdi    # 0x1113f0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
movq 0x33ea8(%rip), %rdi     # 0x432c8
callq 0x8b01
callq 0xad38
callq 0xa234
movl $0x2, %edi
callq 0xa975
movl $0x2, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xa8bb
cmpb $0x1, %r15b
leaq 0x315a8(%rip), %r14     # 0x40a00
movq %r14, %rax
cmoveq %rbx, %rax
movq (%rax), %rax
cmpq 0x33e37(%rip), %rax     # 0x432a0
je 0xf4d6
cmpq 0x2ed26(%rip), %rax     # 0x3e198
je 0xf4e8
cmpq 0x2ed0d(%rip), %rax     # 0x3e188
je 0xf591
movq %rbx, %rdi
callq 0x8b01
movq 0x31bc0(%rip), %rdi     # 0x41050
callq 0x8b01
callq 0xd9a4
callq 0x8b78
movb 0x10(%rax), %r14b
movl %r14d, %ecx
andb $-0x2, %cl
cmpb $0x4, %cl
jne 0xf74f
movq %rax, %rdi
callq 0x8b01
cmpb $0x5, %r14b
jne 0xf5fb
callq 0x9086
mulsd 0x16c4f(%rip), %xmm0    # 0x26120
jmp 0xf365
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xf7e0
addq $0x8, %rbx
cmpb $0x1, %r15b
cmovneq %r14, %rbx
movq (%rbx), %rax
movb 0x10(%rax), %cl
leaq 0x8(%rax), %rdx
cmpb $0x1, %cl
movq %r14, %rsi
cmoveq %rdx, %rsi
movq (%rsi), %rsi
cmpb $0x1, 0x10(%rsi)
movq %r14, %rsi
jne 0xf525
cmpb $0x1, %cl
leaq 0x314e2(%rip), %rsi     # 0x40a00
cmoveq %rdx, %rsi
movq (%rsi), %rsi
cmpb $0x1, %cl
movq (%rsi), %rbx
cmoveq %rax, %r14
movq (%r14), %r14
movq %rbx, %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
movq %r14, %rdi
callq 0x8b01
movq %r14, %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
movl $0x2, %edi
callq 0xa975
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x2, %esi
callq 0xa1f4
callq 0xa234
jmp 0xf439
movq 0xf7540(%rip), %rdi     # 0x106ad8
callq 0x8b01
movq %rbx, %rax
addq $0x8, %rax
cmpb $0x1, 0x10(%rbx)
cmovneq %r14, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmoveq %rax, %r14
movq (%r14), %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xacbe
callq 0xa234
callq 0x9ec9
movl $0x2, %edi
callq 0xa975
movl $0x1, %edi
movl $0x2, %esi
callq 0xa1f4
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xa234
movl $0xb4, %edi
callq 0xacbe
movl $0x2, %edi
callq 0xa8bb
callq 0x8b78
cmpb $0x4, 0x10(%rax)
jne 0xf74f
movq 0x8(%rax), %rcx
cmpl $0x1, -0x4(%rcx)
jne 0xf74f
cmpl $0x1, (%rcx)
jne 0xf74f
movq %rax, %rdi
callq 0x8b01
movl $0x168, %edi            # imm = 0x168
callq 0xacbe
callq 0xf98a
callq 0xeb5b
cmpl $0xb3, %eax
jg 0xf678
cmpl $0x59, %eax
jg 0xf6a1
cmpl $0x2c, %eax
jg 0xf6d6
testl %eax, %eax
je 0xf7ad
cmpl $0x1e, %eax
je 0xf739
jmp 0xf74f
cmpl $0x10d, %eax            # imm = 0x10D
jg 0xf6bb
cmpl $0xe0, %eax
jg 0xf6eb
cmpl $0xb4, %eax
je 0xf7b9
cmpl $0xd2, %eax
je 0xf724
jmp 0xf74f
cmpl $0x86, %eax
jg 0xf716
cmpl $0x5a, %eax
je 0xf777
cmpl $0x78, %eax
je 0xf6fd
jmp 0xf74f
cmpl $0x13a, %eax            # imm = 0x13A
jg 0xf72b
cmpl $0x10e, %eax            # imm = 0x10E
je 0xf777
cmpl $0x12c, %eax            # imm = 0x12C
je 0xf6e4
jmp 0xf74f
cmpl $0x2d, %eax
je 0xf78a
cmpl $0x3c, %eax
jne 0xf74f
movl $0x1, %edi
jmp 0xf702
cmpl $0xe1, %eax
je 0xf783
cmpl $0xf0, %eax
jne 0xf74f
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x2, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xa1f4
cmpl $0x87, %eax
je 0xf783
cmpl $0x96, %eax
jne 0xf74f
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0xf73e
cmpl $0x13b, %eax            # imm = 0x13B
je 0xf78a
cmpl $0x14a, %eax            # imm = 0x14A
jne 0xf74f
movl $0x1, %edi
movl $0x2, %esi
callq 0xa1f4
movl $0x3, %edi
jmp 0xf79e
movq 0x2f09a(%rip), %rdi     # 0x3e7f0
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x8ad9
movq 0x2e9c2(%rip), %rdi     # 0x3e140
jmp 0xf384
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0xf78f
movl $0x1, %edi
movl $0x2, %esi
callq 0xa1f4
movl $0x2, %edi
callq 0xacbe
movl $0x1, %edi
jmp 0xf57d
movq 0xf7324(%rip), %rdi     # 0x106ad8
jmp 0xf384
movq 0x101c30(%rip), %rdi    # 0x1113f0
jmp 0xf384