// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
testl %esi, %esi
je 0x28f3
movq %rdx, %r14
movq %rdi, %r15
movq %rcx, 0x8(%rsp)
movl %esi, 0x4(%rsp)
movq 0x8(%rdx), %r12
cmpl $0x5, 0x28(%r12)
jne 0x28a0
movq 0x30(%r12), %rax
cmpb $0x21, (%rax)
jne 0x28a0
movl $0xb, 0x28(%r12)
movq 0x8(%r12), %r13
testq %r13, %r13
je 0x28a0
movq %r12, 0x30(%rsp)
movl 0x28(%r13), %eax
andl $-0x2, %eax
cmpl $0x8, %eax
je 0x28a0
movq %r13, %rbp
movq (%r13), %rax
movq 0x8(%r13), %r13
testq %r13, %r13
je 0x27bc
cmpq $0x0, (%r13)
jne 0x27bc
movq %rbp, (%r13)
testq %rax, %rax
je 0x27e4
movl 0x28(%rax), %eax
decl %eax
cmpl $0xa, %eax
ja 0x27e4
leaq 0x1bc6(%rip), %rcx      # 0x4398
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x5, 0x28(%rbp)
jmp 0x2826
movq 0x30(%rbp), %rdx
movq %rdx, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movl 0x20(%rbp), %eax
movl %eax, 0x1c(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movups %xmm0, (%rax)
movq %r15, %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x2ccd
movq %rbx, %rdi
callq 0x3319
movl %eax, 0x28(%rbp)
movq %rdx, 0x30(%rbp)
testq %r13, %r13
jne 0x2791
jmp 0x28a0
movq 0x30(%rbp), %r12
movq %r12, %rdi
callq 0x1080
movq %rax, 0x40(%rsp)
movq 0x8(%rsp), %rbx
movq 0x10(%rbx), %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2a5e
movq %rax, 0x38(%rsp)
movq 0x8(%rbx), %rdi
movq %r12, %rsi
movq 0x30(%rsp), %r12
movq 0x40(%rsp), %rdx
callq 0x2a5e
movl 0x28(%rbp), %ecx
cmpl $0xf, %ecx
setae %dl
movl $0x2ff1, %esi           # imm = 0x2FF1
shrl %cl, %esi
orb %dl, %sil
testb $0x1, %sil
je 0x2897
cmpq $0x0, 0x38(%rsp)
jne 0x2897
testq %rax, %rax
je 0x2826
movl $0x2, 0x28(%rbp)
jmp 0x2826
addq $0x8, %r14
cmpl $0xb, 0x28(%r12)
jne 0x28f8
xorl %esi, %esi
cmpl $0x1, 0x4(%rsp)
sete %sil
leaq 0x1c53(%rip), %rcx      # 0x4511
movq %r15, %rdi
movl $0x2, %edx
callq 0x1600
movl $0x1, %edi
movl $0x8, %esi
callq 0x1130
movq %rax, %r12
movq (%r14), %rsi
movq %r15, %rdi
movq 0x8(%rsp), %rdx
callq 0x1f69
movq %rax, (%r12)
jmp 0x2957
xorl %r12d, %r12d
jmp 0x2957
movl 0x4(%rsp), %ebp
movslq %ebp, %rdi
movl $0x8, %esi
callq 0x1130
movq %rax, %r12
testl %ebp, %ebp
jle 0x2957
movl %ebp, %ebp
movq 0x8(%rsp), %r13
xorl %ebx, %ebx
movq (%r14), %r14
xorl %esi, %esi
testq %r14, %r14
setne %sil
movq %r15, %rdi
movl $0x2, %edx
leaq 0x1c22(%rip), %rcx      # 0x4556
callq 0x1600
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1f69
movq %rax, (%r12,%rbx,8)
addq $0x8, %r14
incq %rbx
cmpq %rbx, %rbp
jne 0x2919
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)