// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: logfunc
void
logfunc(void)
{
	int h, 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]);
			logfunc();
			p1->u.tensor->elem[i] = pop();
		}
		push(p1);
		return;
	}

	if (hasdouble(p1)) {
		push(p1);
		floatfunc();
		p1 = pop();
	}

	if (iszero(p1)) {
		push_symbol(LOG);
		push_integer(0);
		list(2);
		return;
	}

	if (isdouble(p1)) {
		push(p1);
		d = pop_double();
		if (d > 0.0) {
			push_double(log(d));
			return;
		}
	}

	// log(z) -> log(mag(z)) + i arg(z)

	if (isdouble(p1) || isdoublez(p1)) {
		push(p1);
		magfunc();
		logfunc();
		push(p1);
		argfunc();
		push(imaginaryunit);
		multiply();
		add();
		return;
	}

	// log(1) -> 0

	if (isplusone(p1)) {
		push_integer(0);
		return;
	}

	// log(e) -> 1

	if (p1 == symbol(EXP1)) {
		push_integer(1);
		return;
	}

	if (isnegativenumber(p1)) {
		push(p1);
		negate();
		logfunc();
		push(imaginaryunit);
		push_symbol(PI);
		multiply();
		add();
		return;
	}

	// log(10) -> log(2) + log(5)

	if (isrational(p1)) {
		h = tos;
		push(p1);
		factor_factor();
		for (i = h; i < tos; i++) {
			p2 = stack[i];
			if (car(p2) == symbol(POWER)) {
				push(caddr(p2)); // exponent
				push_symbol(LOG);
				push(cadr(p2)); // base
				list(2);
				multiply();
			} else {
				push_symbol(LOG);
				push(p2);
				list(2);
			}
			stack[i] = pop();
		}
		add_terms(tos - h);
		return;
	}

	// log(a ^ b) -> b log(a)

	if (car(p1) == symbol(POWER)) {
		push(caddr(p1));
		push(cadr(p1));
		logfunc();
		multiply();
		return;
	}

	// log(a * b) -> log(a) + log(b)

	if (car(p1) == symbol(MULTIPLY)) {
		h = tos;
		p1 = cdr(p1);
		while (iscons(p1)) {
			push(car(p1));
			logfunc();
			p1 = cdr(p1);
		}
		add_terms(tos - h);
		return;
	}

	push_symbol(LOG);
	push(p1);
	list(2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x868d
movq %rax, %rbx
cmpb $0x7, 0x10(%rax)
jne 0xba7c
movq %rbx, %rdi
callq 0x8f1b
movq %rax, %rbx
movq (%rax), %rax
movl 0x64(%rax), %r14d
xorl %r15d, %r15d
testl %r14d, %r14d
cmovlel %r15d, %r14d
cmpq %r15, %r14
je 0xbad2
movq (%rbx), %rax
movq 0x68(%rax,%r15,8), %rdi
callq 0x861b
callq 0xba1b
callq 0x868d
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r15,8)
incq %r15
jmp 0xba53
movq %rbx, %rdi
callq 0xd1c9
testl %eax, %eax
je 0xba9d
movq %rbx, %rdi
callq 0x861b
callq 0x9fbd
callq 0x868d
movq %rax, %rbx
movq %rbx, %rdi
callq 0xa641
testl %eax, %eax
je 0xbae8
movq 0x32910(%rip), %rdi     # 0x3e3c0
callq 0x861b
xorl %edi, %edi
callq 0xa426
pushq $0x2
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x85eb
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
movb 0x10(%rbx), %r14b
cmpb $0x5, %r14b
jne 0xbb2b
movq %rbx, %rdi
callq 0x861b
callq 0x8ae1
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xbb21
callq 0x7150
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xaf59
movb 0x10(%rbx), %r14b
cmpb $0x5, %r14b
je 0xbb37
movq %rbx, %rdi
callq 0xb876
testl %eax, %eax
je 0xbb7a
movq %rbx, %rdi
callq 0x861b
callq 0xd79d
callq 0xba1b
movq %rbx, %rdi
callq 0x861b
callq 0xcd92
movq 0xf8f73(%rip), %rdi     # 0x104ad0
callq 0x861b
callq 0x9fae
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa1f6
movq %rbx, %rdi
callq 0xa95a
testl %eax, %eax
je 0xbb9b
xorl %edi, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa426
cmpq 0x35716(%rip), %rbx     # 0x412b8
je 0xbbd7
movq %rbx, %rdi
callq 0x8c2a
testl %eax, %eax
je 0xbbdc
movq %rbx, %rdi
callq 0x861b
callq 0x975f
callq 0xba1b
movq 0xf8f07(%rip), %rdi     # 0x104ad0
callq 0x861b
movq 0x3346b(%rip), %rdi     # 0x3f040
jmp 0xbb5d
pushq $0x1
popq %rdi
jmp 0xbb88
movq %rbx, %rax
cmpb $0x1, %r14b
je 0xbd0d
movzbl %r14b, %eax
cmpl $0x4, %eax
jne 0xbd06
movslq 0x2c6ab(%rip), %r15     # 0x382a8
movq %rbx, %rdi
callq 0x861b
callq 0x1540f
leaq 0x3599f(%rip), %rax     # 0x415b0
leaq (%rax,%r15,8), %r12
leaq 0x32dd4(%rip), %rdx     # 0x3e9f0
pushq $0x2
popq %r13
movq %r15, -0x30(%rbp)
movslq 0x2c67d(%rip), %rdi     # 0x382a8
cmpq %rdi, %r15
jge 0xbcfe
movq (%r12), %r14
movb 0x10(%r14), %al
cmpb $0x1, %al
movq %rdx, %rcx
cmoveq %r14, %rcx
movq (%rcx), %rcx
cmpq 0x35651(%rip), %rcx     # 0x412a0
je 0xbc6f
movq 0x32768(%rip), %rdi     # 0x3e3c0
callq 0x861b
movq %r14, %rdi
callq 0x861b
movl %r13d, %edi
callq 0x85eb
jmp 0xbce2
leaq 0x8(%r14), %rbx
cmpb $0x1, %al
movq %rdx, %rax
cmoveq %rbx, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
jne 0xbc8b
movq 0x8(%rax), %rax
jmp 0xbc92
movq 0x32d5e(%rip), %rax     # 0x3e9f0
cmpb $0x1, 0x10(%rax)
movq %rdx, %rcx
jne 0xbc9e
movq %rax, %rcx
movq (%rcx), %rdi
callq 0x861b
movq 0x32713(%rip), %rdi     # 0x3e3c0
callq 0x861b
cmpb $0x1, 0x10(%r14)
leaq 0x32d32(%rip), %rcx     # 0x3e9f0
cmovneq %rcx, %rbx
movq (%rbx), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %rcx, %rax
movq (%rax), %rdi
callq 0x861b
movl %r13d, %edi
callq 0x85eb
callq 0x9fae
callq 0x868d
movq %rax, (%r12)
incq %r15
addq $0x8, %r12
leaq 0x32cf7(%rip), %rdx     # 0x3e9f0
jmp 0xbc24
subl -0x30(%rbp), %edi
jmp 0xbdb5
leaq 0x32ce3(%rip), %rax     # 0x3e9f0
movq (%rax), %rcx
cmpb $0x1, %r14b
sete %al
cmpq 0x35582(%rip), %rcx     # 0x412a0
je 0xbd57
cmpb $0x1, %r14b
leaq 0x32cc5(%rip), %r14     # 0x3e9f0
movq %r14, %rcx
cmoveq %rbx, %rcx
movq (%rcx), %rcx
cmpq 0x3555c(%rip), %rcx     # 0x41298
je 0xbd7c
movq 0x3267b(%rip), %rdi     # 0x3e3c0
callq 0x861b
movq %rbx, %rdi
callq 0x861b
jmp 0xbabc
leaq 0x8(%rbx), %r15
cmpb $0x1, %r14b
leaq 0x32c8a(%rip), %r14     # 0x3e9f0
movq %r14, %rax
cmoveq %r15, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
jne 0xbdc8
movq 0x8(%rax), %rax
jmp 0xbdcf
movl 0x2c525(%rip), %r15d    # 0x382a8
addq $0x8, %rbx
testb $0x1, %al
cmoveq %r14, %rbx
movq (%rbx), %rbx
cmpb $0x1, 0x10(%rbx)
jne 0xbdac
movq (%rbx), %rdi
callq 0x861b
callq 0xba1b
cmpb $0x1, 0x10(%rbx)
sete %al
jmp 0xbd83
movl 0x2c4f6(%rip), %edi     # 0x382a8
subl %r15d, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0fd
movq 0x32c21(%rip), %rax     # 0x3e9f0
cmpb $0x1, 0x10(%rax)
movq %r14, %rcx
jne 0xbddb
movq %rax, %rcx
movq (%rcx), %rdi
callq 0x861b
cmpb $0x1, 0x10(%rbx)
cmovneq %r14, %r15
movq (%r15), %rax
cmpb $0x1, 0x10(%rax)
cmoveq %rax, %r14
movq (%r14), %rdi
callq 0x861b
callq 0xba1b
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9fae