// File: /workspace/github_c_makefile_star2_O2/qpfiffer[P]lair/src/eval.c
// Function: get_function_args
static const struct _lair_type **_get_function_args(
		struct _lair_runtime *r,
		const int argc,
		const struct _lair_ast *ast_node,
		struct _lair_env *env) {
	if (argc == 0)
		return NULL;

	const struct _lair_ast *next_node = ast_node->next;
	if (next_node->atom.type == LR_FUNCTION_ARG &&
			strncmp(next_node->atom.value.str, "!", 1) == 0) {
		/* I guess we're building a JIT now. */
		/* Evalue at the RHS: */
		ast_node->next->atom.type = LR_CALL;

		/* This one is a function, the next one is a call, so we evaluate the
		 * one after that:
		 */
		_reevaluate_until_break(r, env, ast_node->next->next);
	}

	if (next_node->atom.type == LR_CALL) {
		check(r, argc == 1, ERR_RUNTIME, "Function takes more than one argument, but RHS is only one argument.");
		/* We need to evaluate the RHS before we can pass it to the function
		 * as arguments.
		 */
		const struct _lair_type **args = calloc(1, sizeof(struct _lair_type *));
		args[0] = _lair_env_eval(r, ast_node->next, env);
		return args;
	}

	const struct _lair_type **args = calloc(argc, sizeof(struct _lair_type *));
	const struct _lair_ast *cur_node = ast_node->next;
	int i = 0;
	/* XXX: Bug here. You could have a function like this:
	 * ! print ! add_two x ! add_two 2 2
	 * Which would do something weird. Need to be able to see how far
	 * the eval went.
	 */
	for (;i < argc; i++) {
		check(r, cur_node != NULL, ERR_RUNTIME, "Not enough arguments to function.");
		args[i] = _lair_env_eval(r, cur_node, env);
		cur_node = cur_node->next;
	}
	return args;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq %rsi, 0x18(%rsp)
testl %esi, %esi
je 0x2776
movq %rdx, %r15
movq 0x8(%rdx), %rcx
addq $0x8, %r15
movl 0x28(%rcx), %eax
cmpl $0x5, %eax
jne 0x2783
movq 0x30(%rcx), %rax
cmpb $0x21, (%rax)
jne 0x27de
movl $0xb, 0x28(%rcx)
movq %rcx, 0x40(%rsp)
movq 0x8(%rcx), %r13
leaq 0x30(%rsp), %r12
leaq 0x20(%rsp), %r14
leaq 0x1d3a(%rip), %rbp      # 0x4398
testq %r13, %r13
je 0x277b
movq %r13, %rbx
movl 0x28(%r13), %eax
andl $-0x2, %eax
cmpl $0x8, %eax
je 0x277b
movq (%rbx), %rax
movq 0x8(%rbx), %r13
testq %r13, %r13
je 0x2691
cmpq $0x0, (%r13)
jne 0x2691
movq %rbx, (%r13)
testq %rax, %rax
je 0x26b3
movl 0x28(%rax), %eax
decl %eax
cmpl $0xa, %eax
ja 0x26b3
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
movl $0x5, 0x28(%rbx)
jmp 0x265e
movq 0x30(%rbx), %rdx
movq %rdx, 0x20(%rsp)
andl $0x0, 0x28(%rsp)
movl 0x20(%rbx), %eax
movl %eax, 0x2c(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x2b62
movq %r14, %rdi
callq 0x3111
movl %eax, 0x28(%rbx)
movq %rdx, 0x30(%rbx)
jmp 0x265e
movq 0x30(%rbx), %rbp
movq %rbp, %rdi
callq 0x1080
movq %rax, 0x50(%rsp)
movq %r12, %r14
movq 0x10(%rsp), %r12
movq 0x10(%r12), %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x293c
movq %rax, 0x48(%rsp)
movq 0x8(%r12), %rdi
movq %r14, %r12
leaq 0x20(%rsp), %r14
movq %rbp, %rsi
leaq 0x1c62(%rip), %rbp      # 0x4398
movq 0x50(%rsp), %rdx
callq 0x293c
movl 0x28(%rbx), %ecx
cmpl $0xf, %ecx
setae %dl
movl $0x2ff1, %esi           # imm = 0x2FF1
shrl %cl, %esi
orb %dl, %sil
testb $0x1, %sil
je 0x276a
cmpq $0x0, 0x48(%rsp)
jne 0x276a
testq %rax, %rax
je 0x265e
movl $0x2, 0x28(%rbx)
jmp 0x265e
xorl %r13d, %r13d
jmp 0x27cc
movq 0x40(%rsp), %rax
movl 0x28(%rax), %eax
cmpl $0xb, %eax
jne 0x27de
xorl %esi, %esi
cmpl $0x1, 0x18(%rsp)
sete %sil
leaq 0x1d77(%rip), %rcx      # 0x4511
pushq $0x2
popq %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x15c8
pushq $0x1
popq %rdi
pushq $0x8
popq %rsi
callq 0x1130
movq %rax, %r13
movq (%r15), %rsi
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
callq 0x1eb9
movq %rax, (%r13)
movq %r13, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %r14
movslq %r14d, %rdi
pushq $0x8
popq %rsi
callq 0x1130
movq %rax, %r13
xorl %r12d, %r12d
testl %r14d, %r14d
cmovlel %r12d, %r14d
pushq $0x2
popq %rbx
movq 0x8(%rsp), %rbp
cmpq %r12, %r14
je 0x27cc
movq (%r15), %r15
xorl %esi, %esi
testq %r15, %r15
setne %sil
movq %rbp, %rdi
movl %ebx, %edx
leaq 0x1d36(%rip), %rcx      # 0x4556
callq 0x15c8
movq %rbp, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x1eb9
movq %rax, (%r13,%r12,8)
addq $0x8, %r15
incq %r12
jmp 0x2803
nop