// File: /workspace/github_c_makefile_star2_O3/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
movl 0x326c1(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0xd089
decl %eax
movl %eax, 0x326a9(%rip)     # 0x3f2b8
leaq 0x3b9aa(%rip), %r14     # 0x485c0
movq (%r14,%rax,8), %rbx
cmpb $0x7, 0x10(%rbx)
jne 0xcc97
movq %rbx, %rdi
callq 0x9638
movq %rax, %rbx
movq (%rax), %rax
movslq 0x64(%rax), %r15
testq %r15, %r15
jle 0xcc81
xorl %r12d, %r12d
movl $0xfffe795f, %r13d      # imm = 0xFFFE795F
movq (%rbx), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x8ba5
callq 0xcbe3
movl 0x32660(%rip), %eax     # 0x3f2b8
leal (%rax,%r13), %ecx
cmpl %r13d, %ecx
jbe 0xd089
decl %eax
movl %eax, 0x3264b(%rip)     # 0x3f2b8
movq (%r14,%rax,8), %rax
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r12,8)
incq %r12
cmpq %r12, %r15
jne 0xcc40
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
movq %rbx, %rdi
callq 0xed67
testl %eax, %eax
je 0xccd2
movq %rbx, %rdi
callq 0x8ba5
callq 0xac30
movl 0x32602(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0xd089
decl %eax
movl %eax, 0x325ea(%rip)     # 0x3f2b8
movq (%r14,%rax,8), %rbx
movq %rbx, %rdi
callq 0xb477
testl %eax, %eax
je 0xcd0e
movq 0x386eb(%rip), %rdi     # 0x453d0
callq 0x8ba5
movq 0x3644f(%rip), %rdi     # 0x43140
callq 0x8ba5
movl $0x2, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b7d
movb 0x10(%rbx), %r15b
cmpb $0x5, %r15b
jne 0xcd5d
movq %rbx, %rdi
callq 0x8ba5
callq 0x9128
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xcd53
callq 0x7150
movsd %xmm0, -0x30(%rbp)
callq 0x74dc
movb $0x5, 0x10(%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
jmp 0xcc84
movb 0x10(%rbx), %r15b
cmpb $0x5, %r15b
je 0xcd69
movq %rbx, %rdi
callq 0xca1c
testl %eax, %eax
je 0xcdb6
movq %rbx, %rdi
callq 0x8ba5
callq 0xf5df
callq 0xcbe3
movq %rbx, %rdi
callq 0x8ba5
callq 0xe743
movq 0xfed51(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl $0x2, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xadb3
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xd1c4
testl %eax, %eax
je 0xcdd8
movq 0x3636d(%rip), %rdi     # 0x43140
jmp 0xcc84
cmpq 0x3b4e9(%rip), %rbx     # 0x482c8
je 0xce38
movq %rbx, %rax
cmpb $0x1, %r15b
je 0xce4b
movzbl %r15b, %eax
cmpl $0x4, %eax
jne 0xce44
cmpb $0x1, 0x12(%rbx)
jne 0xceb9
movq %rbx, %rdi
callq 0x8ba5
movq 0x1095e4(%rip), %rdi    # 0x1163f0
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
callq 0xcbe3
movq 0xfecb9(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movq 0x3921d(%rip), %rdi     # 0x46050
jmp 0xcd8f
movq 0xfec99(%rip), %rdi     # 0x10bad8
jmp 0xcc84
leaq 0x38bb5(%rip), %rax     # 0x45a00
movq (%rax), %rax
cmpq 0x3b45b(%rip), %rax     # 0x482b0
je 0xce8d
cmpb $0x1, %r15b
leaq 0x38b9e(%rip), %r14     # 0x45a00
movq %r14, %rax
cmoveq %rbx, %rax
movq (%rax), %rax
cmpq 0x3b435(%rip), %rax     # 0x482a8
je 0xcfe6
movq 0x38550(%rip), %rdi     # 0x453d0
callq 0x8ba5
movq %rbx, %rdi
jmp 0xccf1
leaq 0x8(%rbx), %r12
cmpb $0x1, %r15b
leaq 0x38b64(%rip), %r14     # 0x45a00
movq %r14, %rax
cmoveq %r12, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
jne 0xd035
movq 0x8(%rax), %rax
jmp 0xd03c
movslq 0x323f8(%rip), %r15     # 0x3f2b8
movq %rbx, %rdi
callq 0x8ba5
callq 0x190c2
movl 0x323e5(%rip), %edi     # 0x3f2b8
movq %r15, -0x30(%rbp)
cmpl %edi, %r15d
jge 0xcfde
movq -0x30(%rbp), %r15
leaq (%r14,%r15,8), %r12
leaq 0x38b11(%rip), %r13     # 0x45a00
movq (%r12), %rbx
movb 0x10(%rbx), %al
cmpb $0x1, %al
movq %r13, %rcx
cmoveq %rbx, %rcx
movq (%rcx), %rcx
cmpq 0x3b3a7(%rip), %rcx     # 0x482b0
je 0xcf2b
movq 0x384be(%rip), %rdi     # 0x453d0
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0x8b7d
jmp 0xcfa8
movq %r13, %rcx
leaq 0x8(%rbx), %r13
cmpb $0x1, %al
movq %rcx, %rax
cmoveq %r13, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
jne 0xcf4a
movq 0x8(%rax), %rax
jmp 0xcf51
movq 0x38aaf(%rip), %rax     # 0x45a00
cmpb $0x1, 0x10(%rax)
jne 0xcf5a
movq %rax, %rcx
movq (%rcx), %rdi
callq 0x8ba5
movq 0x38467(%rip), %rdi     # 0x453d0
callq 0x8ba5
cmpb $0x1, 0x10(%rbx)
leaq 0x38a87(%rip), %rcx     # 0x45a00
cmovneq %rcx, %r13
movq (%r13), %rax
movq %rcx, %r13
cmpb $0x1, 0x10(%rax)
cmovneq %rcx, %rax
movq (%rax), %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0x8b7d
movl $0x2, %edi
callq 0xacef
movl 0x3230a(%rip), %edi     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rdi,%rcx), %eax
cmpl %ecx, %eax
jbe 0xd089
decl %edi
movl %edi, 0x322f2(%rip)     # 0x3f2b8
movq (%r14,%rdi,8), %rax
movq %rax, (%r12)
incq %r15
addq $0x8, %r12
cmpq %rdi, %r15
jl 0xceef
subl -0x30(%rbp), %edi
jmp 0xcda3
addq $0x8, %rbx
cmpb $0x1, %r15b
movl 0x322c3(%rip), %r15d    # 0x3f2b8
cmovneq %r14, %rbx
movq (%rbx), %rbx
cmpb $0x1, 0x10(%rbx)
movl %r15d, %edi
jne 0xd02d
movq (%rbx), %rdi
callq 0x8ba5
callq 0xcbe3
leaq 0x8(%rbx), %rax
cmpb $0x1, 0x10(%rbx)
cmovneq %r14, %rax
movq (%rax), %rbx
cmpb $0x1, 0x10(%rbx)
je 0xd005
movl 0x3228b(%rip), %edi     # 0x3f2b8
subl %r15d, %edi
jmp 0xcda3
movq 0x389c4(%rip), %rax     # 0x45a00
cmpb $0x1, 0x10(%rax)
movq %r14, %rcx
jne 0xd048
movq %rax, %rcx
movq (%rcx), %rdi
callq 0x8ba5
cmpb $0x1, 0x10(%rbx)
cmovneq %r14, %r12
movq (%r12), %rax
cmpb $0x1, 0x10(%rax)
cmoveq %rax, %r14
movq (%r14), %rdi
callq 0x8ba5
callq 0xcbe3
movl $0x2, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xacef
leaq 0x21eb1(%rip), %rdi     # 0x2ef41
callq 0x780b