// File: /workspace/github_c_makefile_star2_O1/theandrew168[P]squeaky/src/mce.c
// Function: mce_eval
struct value*
mce_eval(struct vm* vm, struct value* exp, struct value* env)
{
tailcall:

    if (is_self_evaluating(exp)) {
        return exp;
    } else if (is_variable(exp)) {
        return env_lookup(vm, exp, env);
    } else if (is_quoted(exp)) {
        return text_of_quotation(exp);
    } else if (is_assignment(exp)) {
        return eval_assignment(vm, exp, env);
    } else if (is_definition(exp)) {
        return eval_definition(vm, exp, env);
    } else if (is_if(exp)) {
        exp = eval_if(vm, exp, env);
        goto tailcall;
    } else if (is_environment(exp)) {
        return env;
    } else if (is_load(exp)) {
        return load(vm, load_args(exp), env);
    } else if (is_gc(exp)) {
        vm_gc(vm, env);
        return vm_make_empty_list(vm);
    } else if (is_lambda(exp)) {
        // TODO: check for the three different lambda forms:
        // (lambda (x) (* x x))
        // (lambda x x)
        // (lambda (x . rest) (append x rest))
        return vm_make_lambda(vm, lambda_params(exp), lambda_body(exp), env);
    } else if (is_application(exp)) {
        // 'apply' is evalutaed inline for TCO
        struct value* proc = mce_eval(vm, operator(exp), env);
        struct value* args = list_of_values(vm, operands(exp), env);

        // handle builtin 'eval' specifically for TCO
        if (is_primitive_proc(proc) && proc->as.builtin == mce_builtin_eval) {
            ASSERT_ARITY("eval", args, 2);
            ASSERT_TYPE("eval", args, 1, VALUE_PAIR);
            env = eval_env(args);
            exp = eval_exp(args);
            goto tailcall;
        }

        // handle builtin 'apply' specifically for TCO
        if (is_primitive_proc(proc) && proc->as.builtin == mce_builtin_apply) {
            proc = apply_operator(args);
            args = apply_operands(args);
        }

        if (is_primitive_proc(proc)) {
            return proc->as.builtin(vm, args);
        } else if (is_compound_proc(proc)) {
            // evaluate the lambda's body in the current stack frame (for TCO)
            env = env_extend(vm, proc->as.lambda.params, args, proc->as.lambda.env);
            exp = proc->as.lambda.body;
            while (!is_last_exp(exp)) {
                mce_eval(vm, first_exp(exp), env);
                exp = rest_exps(exp);
            }
            exp = first_exp(exp);
            goto tailcall;
        } else {
            fprintf(stderr, "runtime error (invalid proc) at: TODO\n");
            exit(EXIT_FAILURE);
        }
    }

    fprintf(stderr, "runtime error (invalid expr) at: TODO\n");
    exit(EXIT_FAILURE);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %rbx
leaq 0x303a(%rip), %r15      # 0x8bbc
leaq 0x2d3b(%rip), %r12      # 0x88c4
movq %rax, 0x8(%rsp)
movl (%rbp), %eax
leal -0x2(%rax), %ecx
cmpl $0x4, %ecx
jb 0x5e7e
cmpl $0x6, %eax
je 0x5e58
movq %rbp, %rdi
movq %r15, %rsi
callq 0x611c
testb %al, %al
jne 0x5e74
movq %rbp, %rdi
movq %r12, %rsi
callq 0x611c
movq %rbp, %rdi
testb %al, %al
jne 0x5e90
leaq 0x2cf3(%rip), %rsi      # 0x88c9
callq 0x611c
movq %rbp, %rdi
testb %al, %al
jne 0x5ee5
leaq 0x2ce3(%rip), %rsi      # 0x88d0
callq 0x611c
movq %rbp, %rdi
testb %al, %al
je 0x5c7f
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x5b64
movq %rax, %rdi
callq 0x6a14
movl %eax, %r13d
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5ad4
testb %r13b, %r13b
jne 0x5c6f
movq %rax, %rdi
callq 0x5ad4
cmpl $0x1, (%rax)
jne 0x5c57
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7096
movq %rax, %rbp
jmp 0x5b8e
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
movq %rax, %rbp
jmp 0x5b8e
leaq 0x2c4d(%rip), %rsi      # 0x88d3
callq 0x611c
testb %al, %al
jne 0x5fec
movq %rbp, %rdi
leaq 0x2c50(%rip), %rsi      # 0x88ed
callq 0x611c
testb %al, %al
jne 0x5fec
movq %rbp, %rdi
leaq 0x2c4a(%rip), %rsi      # 0x88fe
callq 0x611c
testb %al, %al
jne 0x5fec
movq %rbp, %rdi
leaq 0x2525(%rip), %rsi      # 0x81f0
callq 0x611c
testb %al, %al
jne 0x5ff4
movq %rbp, %rdi
leaq 0x2c34(%rip), %rsi      # 0x8916
callq 0x611c
testb %al, %al
jne 0x6083
movq %rbp, %rdi
leaq 0x2c20(%rip), %rsi      # 0x8919
callq 0x611c
testb %al, %al
jne 0x60a4
cmpl $0x7, (%rbp)
jne 0x60e6
movq %rbp, %rdi
callq 0x5b51
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x5b64
movq %rax, %r13
movq %rbp, %rdi
callq 0x5ad4
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x6140
movq %r13, %rdx
movq %rax, %r13
movl (%rdx), %eax
cmpl $0x8, %eax
jne 0x5d8c
leaq 0x45a(%rip), %rcx       # 0x61ad
cmpq %rcx, 0x10(%rdx)
je 0x5e01
cmpl $0x8, %eax
jne 0x5d8c
leaq 0x46f(%rip), %rax       # 0x61d8
cmpq %rax, 0x10(%rdx)
jne 0x5d8c
movq %r13, %rdi
callq 0x5b51
movq %rax, 0x10(%rsp)
movq %r13, %rdi
callq 0x5ad4
movq 0x10(%rsp), %rdx
movq %rax, %r13
movl (%rdx), %eax
cmpl $0x9, %eax
je 0x5dac
cmpl $0x8, %eax
jne 0x60eb
movq %rbx, %rdi
movq %r13, %rsi
callq *0x10(%rdx)
xorl %ecx, %ecx
jmp 0x5e4e
movq 0x10(%rdx), %rsi
movq 0x20(%rdx), %rcx
movq %rbx, %rdi
movq %rdx, %rbp
movq %r13, %rdx
callq 0x568d
movq %rax, %r14
movq 0x18(%rbp), %rbp
movq %rbp, %rdi
callq 0x5ad4
cmpl $0x1, (%rax)
je 0x5dfc
movq %rbp, %rdi
callq 0x5b51
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x5b64
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rbp
movq %rax, %rdi
jmp 0x5dcc
movq %rbp, %rdi
jmp 0x5e3f
movq %r13, %rdi
callq 0x5ab0
cmpq $0x2, %rax
jne 0x60f0
movl $0x1, %esi
movq %r13, %rdi
callq 0x5ae4
cmpl $0x7, (%rax)
jne 0x60f8
movq %r13, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
movq %rax, %r14
movq %r13, %rdi
callq 0x5b51
movq %rax, %rbp
movb $0x1, %cl
movq 0x8(%rsp), %rax
testb %cl, %cl
jne 0x5b89
jmp 0x5e81
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x56fe
cmpl $0x1, (%rbp)
jne 0x5f48
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
movq %rax, %r15
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x5b64
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %r14, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x582f
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
movl (%rax), %r12d
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
movq %rax, %r15
cmpl $0x6, %r12d
je 0x5f19
movq %r15, %rdi
callq 0x5b51
movq %rax, %r15
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
cmpl $0x6, (%rax)
jne 0x5f66
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
jmp 0x5fbf
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5b51
leaq 0x29ac(%rip), %rsi      # 0x8919
movq %rbx, %rdi
callq 0x71a1
movq %rax, %r12
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
movq %rax, %rdi
callq 0x5ad4
movq %rax, %r13
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5ad4
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x7205
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x7205
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x5b64
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %r14, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x59a9
movq %r14, %rax
jmp 0x5e81
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %r15
movq %rax, %rdi
callq 0x5ab0
cmpq $0x1, %rax
jne 0x6100
movq %r15, %rdi
xorl %esi, %esi
callq 0x5ae4
cmpl $0x5, (%rax)
jne 0x6108
movq %r15, %rdi
xorl %esi, %esi
callq 0x5ae4
movq %rax, %r12
movq 0x10(%rax), %rdi
leaq 0x229f(%rip), %rsi      # 0x82db
callq 0x1190
testq %rax, %rax
je 0x6110
movq %rax, %r15
movq %r15, %rdi
callq 0x1230
testl %eax, %eax
jne 0x6079
movq %rbx, %rdi
movq %r15, %rsi
callq 0x67a6
cmpl $0xe, (%rax)
je 0x6079
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x5b64
jmp 0x604d
movq %r15, %rdi
callq 0x1160
jmp 0x608e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6ec4
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7044
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5b51
movq %rax, %r15
movq %rbp, %rdi
callq 0x5ad4
movq %rax, %rdi
callq 0x5ad4
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %r14, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7287
callq 0x2ca2
callq 0x2cc7
movq %r13, %rdi
callq 0x2cec
movq %r13, %rdi
callq 0x2d22
movq %r15, %rdi
callq 0x2d7b
movq %r15, %rdi
callq 0x2db4
addq $0x10, %r12
movq %r12, %rdi
callq 0x2e0a