// File: /workspace/github_c_makefile_star2_O3/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 0x2848
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
movq %rcx, (%rsp)
movq 0x8(%rdx), %r12
addq $0x8, %r14
movl 0x28(%r12), %eax
cmpl $0x5, %eax
jne 0x2859
movq 0x30(%r12), %rax
cmpb $0x21, (%rax)
jne 0x28a2
movl $0xb, 0x28(%r12)
movq 0x8(%r12), %r13
testq %r13, %r13
je 0x285e
movl %ebp, 0xc(%rsp)
movq %r12, 0x38(%rsp)
movl 0x28(%r13), %eax
andl $-0x2, %eax
cmpl $0x8, %eax
je 0x2850
movq %r13, %rbp
movq (%r13), %rax
movq 0x8(%r13), %r13
testq %r13, %r13
je 0x276d
cmpq $0x0, (%r13)
jne 0x276d
movq %rbp, (%r13)
testq %rax, %rax
je 0x2798
movl 0x28(%rax), %eax
decl %eax
cmpl $0xa, %eax
ja 0x2798
leaq 0x1c15(%rip), %rcx      # 0x4398
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x5, 0x28(%rbp)
jmp 0x2834
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 0x2d08
movq %rbx, %rdi
callq 0x3362
movl %eax, 0x28(%rbp)
movq %rdx, 0x30(%rbp)
jmp 0x2834
movq 0x30(%rbp), %r12
movq %r12, %rdi
callq 0x1080
movq %rax, 0x40(%rsp)
movq (%rsp), %rbx
movq 0x10(%rbx), %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2a16
movq %rax, 0x30(%rsp)
movq 0x8(%rbx), %rdi
movq %r12, %rsi
movq 0x38(%rsp), %r12
movq 0x40(%rsp), %rdx
callq 0x2a16
movl 0x28(%rbp), %ecx
cmpl $0xe, %ecx
ja 0x283f
movl $0x500e, %edx           # imm = 0x500E
btl %ecx, %edx
jae 0x283f
movl $0x2, 0x28(%rbp)
testq %r13, %r13
jne 0x2742
jmp 0x2850
orq %rax, 0x30(%rsp)
jne 0x282d
jmp 0x2834
xorl %r12d, %r12d
jmp 0x28fc
movl 0x28(%r12), %eax
movl 0xc(%rsp), %ebp
cmpl $0xb, %eax
jne 0x28a2
xorl %esi, %esi
cmpl $0x1, %ebp
sete %sil
leaq 0x1ca3(%rip), %rcx      # 0x4511
movq %r15, %rdi
movl $0x2, %edx
callq 0x1608
movl $0x1, %edi
movl $0x8, %esi
callq 0x1130
movq %rax, %r12
movq (%r14), %rsi
movq %r15, %rdi
movq (%rsp), %rdx
callq 0x1f71
movq %rax, (%r12)
jmp 0x28fc
movslq %ebp, %rdi
movl $0x8, %esi
callq 0x1130
movq %rax, %r12
testl %ebp, %ebp
jle 0x28fc
movl %ebp, %ebp
movq (%rsp), %r13
xorl %ebx, %ebx
movq (%r14), %r14
xorl %esi, %esi
testq %r14, %r14
setne %sil
movq %r15, %rdi
movl $0x2, %edx
leaq 0x1c7d(%rip), %rcx      # 0x4556
callq 0x1608
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1f71
movq %rax, (%r12,%rbx,8)
addq $0x8, %r14
incq %rbx
cmpq %rbx, %rbp
jne 0x28be
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop