// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: eval_user_function
void
eval_user_function(struct atom *p1)
{
	int h, i;
	struct atom *FUNC_NAME, *FUNC_ARGS, *FUNC_DEFN;

	FUNC_NAME = car(p1);
	FUNC_ARGS = cdr(p1);

	FUNC_DEFN = get_usrfunc(FUNC_NAME);

	// undefined function?

	if (FUNC_DEFN == symbol(NIL)) {
		if (FUNC_NAME == symbol(D_LOWER)) {
			expanding++;
			eval_derivative(p1);
			expanding--;
			return;
		}
		h = tos;
		push(FUNC_NAME);
		while (iscons(FUNC_ARGS)) {
			push(car(FUNC_ARGS));
			evalg();
			FUNC_ARGS = cdr(FUNC_ARGS);
		}
		list(tos - h);
		return;
	}

	save_symbol(symbol(ARG1));
	save_symbol(symbol(ARG2));
	save_symbol(symbol(ARG3));
	save_symbol(symbol(ARG4));
	save_symbol(symbol(ARG5));
	save_symbol(symbol(ARG6));
	save_symbol(symbol(ARG7));
	save_symbol(symbol(ARG8));
	save_symbol(symbol(ARG9));

	push(FUNC_DEFN); // make visible to garbage collector

	// eval all args before changing bindings

	for (i = 0; i < 9; i++) {
		push(car(FUNC_ARGS));
		evalg();
		FUNC_ARGS = cdr(FUNC_ARGS);
	}

	set_symbol(symbol(ARG9), pop(), symbol(NIL));
	set_symbol(symbol(ARG8), pop(), symbol(NIL));
	set_symbol(symbol(ARG7), pop(), symbol(NIL));
	set_symbol(symbol(ARG6), pop(), symbol(NIL));
	set_symbol(symbol(ARG5), pop(), symbol(NIL));
	set_symbol(symbol(ARG4), pop(), symbol(NIL));
	set_symbol(symbol(ARG3), pop(), symbol(NIL));
	set_symbol(symbol(ARG2), pop(), symbol(NIL));
	set_symbol(symbol(ARG1), pop(), symbol(NIL));

	evalg(); // eval FUNC_DEFN

	p1 = pop();
	restore_symbol();
	restore_symbol();
	restore_symbol();
	restore_symbol();
	restore_symbol();
	restore_symbol();
	restore_symbol();
	restore_symbol();
	restore_symbol();
	push(p1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
leaq 0x8(%rdi), %rax
cmpb $0x1, 0x10(%rdi)
leaq 0x35913(%rip), %r12     # 0x3e9f0
movq %r12, %rcx
cmoveq %rdi, %rcx
movq (%rcx), %r15
cmovneq %r12, %rax
movq (%rax), %r13
movq %r15, %rdi
callq 0x13c81
cmpq 0x358f3(%rip), %rax     # 0x3e9f0
je 0x930b
movq %rax, %rbx
movq 0x381cb(%rip), %rdi     # 0x412d8
callq 0xd63f
movq 0x381c7(%rip), %rdi     # 0x412e0
callq 0xd63f
movq 0x381c3(%rip), %rdi     # 0x412e8
callq 0xd63f
movq 0x381bf(%rip), %rdi     # 0x412f0
callq 0xd63f
movq 0x381bb(%rip), %rdi     # 0x412f8
callq 0xd63f
movq 0x381b7(%rip), %rdi     # 0x41300
callq 0xd63f
movq 0x381b3(%rip), %rdi     # 0x41308
callq 0xd63f
movq 0x381af(%rip), %rdi     # 0x41310
callq 0xd63f
movq 0x381ab(%rip), %rdi     # 0x41318
callq 0xd63f
movq %rbx, %rdi
callq 0x861b
pushq $0x9
popq %rbx
subl $0x1, %ebx
jb 0x91ad
cmpb $0x1, 0x10(%r13)
movq %r12, %rax
cmoveq %r13, %rax
movq (%rax), %rdi
callq 0x861b
callq 0x8f7d
cmpb $0x1, 0x10(%r13)
leaq 0x8(%r13), %rax
cmovneq %r12, %rax
movq (%rax), %r13
jmp 0x917d
movq 0x38164(%rip), %rbx     # 0x41318
callq 0x868d
movq 0x35830(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
movq 0x3813e(%rip), %rbx     # 0x41310
callq 0x868d
movq 0x35812(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
movq 0x38118(%rip), %rbx     # 0x41308
callq 0x868d
movq 0x357f4(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
movq 0x380f2(%rip), %rbx     # 0x41300
callq 0x868d
movq 0x357d6(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
movq 0x380cc(%rip), %rbx     # 0x412f8
callq 0x868d
movq 0x357b8(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
movq 0x380a6(%rip), %rbx     # 0x412f0
callq 0x868d
movq 0x3579a(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
movq 0x38080(%rip), %rbx     # 0x412e8
callq 0x868d
movq 0x3577c(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
movq 0x3805a(%rip), %rbx     # 0x412e0
callq 0x868d
movq 0x3575e(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
movq 0x38034(%rip), %rbx     # 0x412d8
callq 0x868d
movq 0x35740(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
callq 0x8f7d
callq 0x868d
movq %rax, %rbx
callq 0xd684
callq 0xd684
callq 0xd684
callq 0xd684
callq 0xd684
callq 0xd684
callq 0xd684
callq 0xd684
callq 0xd684
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
cmpq 0x337a6(%rip), %r15     # 0x3cab8
je 0x9364
movl 0x2ef8e(%rip), %ebx     # 0x382a8
movq %r15, %rdi
callq 0x861b
cmpb $0x1, 0x10(%r13)
jne 0x9349
movq (%r13), %rdi
callq 0x861b
callq 0x8f7d
cmpb $0x1, 0x10(%r13)
leaq 0x8(%r13), %rax
cmovneq %r12, %rax
movq (%rax), %r13
jmp 0x9322
movl 0x2ef59(%rip), %edi     # 0x382a8
subl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x85eb
incl 0xfb756(%rip)           # 0x104ac0
movq %r14, %rdi
callq 0xf087
decl 0xfb748(%rip)           # 0x104ac0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq