// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x2aa1(%rip), %r15      # 0x7bbc
leaq 0x27a2(%rip), %r12      # 0x78c4
movl (%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x4, %ecx
jb 0x53d3
cmpl $0x6, %eax
je 0x53ad
movq %r14, %rdi
movq %r15, %rsi
callq 0x57b4
testb %al, %al
jne 0x53c9
movq %r14, %rdi
movq %r12, %rsi
callq 0x57b4
movq %r14, %rdi
testb %al, %al
jne 0x53e5
leaq 0x275f(%rip), %rsi      # 0x78c9
callq 0x57b4
movq %r14, %rdi
testb %al, %al
jne 0x543a
leaq 0x274f(%rip), %rsi      # 0x78d0
callq 0x57b4
movq %r14, %rdi
testb %al, %al
je 0x5213
callq 0x5046
movq %rax, %rdi
callq 0x50ce
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x5100
movq %rax, %rdi
callq 0x6158
movl %eax, %r13d
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x5046
testb %r13b, %r13b
jne 0x5203
movq %rax, %rdi
callq 0x5046
cmpl $0x1, (%rax)
jne 0x51eb
movq %rbx, %rdi
xorl %esi, %esi
callq 0x676a
movq %rax, %r14
jmp 0x5122
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x50ce
movq %rax, %r14
jmp 0x5122
leaq 0x26b9(%rip), %rsi      # 0x78d3
callq 0x57b4
testb %al, %al
jne 0x5541
movq %r14, %rdi
leaq 0x26bc(%rip), %rsi      # 0x78ed
callq 0x57b4
testb %al, %al
jne 0x5541
movq %r14, %rdi
leaq 0x26b6(%rip), %rsi      # 0x78fe
callq 0x57b4
testb %al, %al
jne 0x5541
movq %r14, %rdi
leaq 0x1f91(%rip), %rsi      # 0x71f0
callq 0x57b4
testb %al, %al
jne 0x5549
movq %r14, %rdi
leaq 0x26a0(%rip), %rsi      # 0x7916
callq 0x57b4
testb %al, %al
jne 0x55d8
movq %r14, %rdi
leaq 0x268c(%rip), %rsi      # 0x7919
callq 0x57b4
testb %al, %al
jne 0x55f9
cmpl $0x7, (%r14)
jne 0x565a
movq %r14, %rdi
callq 0x50ce
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x5100
movq %rax, %r13
movq %r14, %rdi
callq 0x5046
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x57d8
movq %rax, %r14
movl (%r13), %eax
cmpl $0x8, %eax
jne 0x5319
movq 0x10(%r13), %rax
leaq 0x55b(%rip), %rcx       # 0x5845
cmpq %rcx, %rax
je 0x536c
leaq 0x574(%rip), %rcx       # 0x586a
cmpq %rcx, %rax
jne 0x5640
movq %r14, %rdi
callq 0x50ce
movq %rax, %r13
movq %r14, %rdi
callq 0x5046
movq %rax, %r14
movl (%r13), %eax
cmpl $0x9, %eax
jne 0x563b
movq 0x10(%r13), %rsi
movq 0x20(%r13), %rcx
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4bf9
movq %rax, %rbp
movq 0x18(%r13), %r14
movq %r14, %rdi
callq 0x5046
cmpl $0x1, (%rax)
je 0x53a5
movq %r14, %rdi
callq 0x50ce
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x5100
movq %r14, %rdi
callq 0x5046
movq %rax, %r14
jmp 0x533c
movq %r14, %rdi
callq 0x502c
cmpq $0x2, %rax
jne 0x5691
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x5075
cmpl $0x7, (%rax)
jne 0x56c3
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x50ce
movq %rax, %rbp
movq %r14, %rdi
jmp 0x5206
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4c68
cmpl $0x1, (%r14)
jne 0x549d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5046
movq %rax, %rdi
callq 0x50ce
movq %rax, %r15
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x50ce
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x5100
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %rbp, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4da6
callq 0x5046
movq %rax, %rdi
callq 0x50ce
movl (%rax), %r12d
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x50ce
movq %rax, %r15
cmpl $0x6, %r12d
je 0x546e
movq %r15, %rdi
callq 0x50ce
movq %rax, %r15
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x50ce
cmpl $0x6, (%rax)
jne 0x54bb
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x50ce
jmp 0x5514
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x50ce
leaq 0x2457(%rip), %rsi      # 0x7919
movq %rbx, %rdi
callq 0x6875
movq %rax, %r12
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x50ce
movq %rax, %rdi
callq 0x5046
movq %rax, %r13
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x5046
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x68d9
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x68d9
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x5100
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %rbp, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4f30
movq %rbp, %r14
jmp 0x53d3
movq %r14, %rdi
callq 0x5046
movq %rax, %r14
movq %rax, %rdi
callq 0x502c
cmpq $0x1, %rax
jne 0x5714
movq %r14, %rdi
xorl %esi, %esi
callq 0x5075
cmpl $0x5, (%rax)
jne 0x5748
movq %r14, %rdi
xorl %esi, %esi
callq 0x5075
movq %rax, %r15
movq 0x10(%rax), %rdi
leaq 0x1d4a(%rip), %rsi      # 0x72db
callq 0x1190
testq %rax, %rax
je 0x5793
movq %rax, %r14
movq %r14, %rdi
callq 0x1230
testl %eax, %eax
jne 0x55ce
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5ed2
cmpl $0xe, (%rax)
je 0x55ce
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x5100
jmp 0x55a2
movq %r14, %rdi
callq 0x1160
jmp 0x55e3
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x65b3
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x66fc
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x50ce
movq %rax, %r15
movq %r14, %rdi
callq 0x5046
movq %rax, %rdi
callq 0x5046
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %rbp, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x695b
cmpl $0x8, %eax
jne 0x566d
movq 0x10(%r13), %rax
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
movq 0x697f(%rip), %rax      # 0xbfe0
movq (%rax), %rcx
leaq 0x22dc(%rip), %rdi      # 0x7947
jmp 0x567e
movq 0x696c(%rip), %rax      # 0xbfe0
movq (%rax), %rcx
leaq 0x22a2(%rip), %rdi      # 0x7920
pushq $0x26
popq %rsi
pushq $0x1
popq %rdx
callq 0x1260
pushq $0x1
popq %rdi
callq 0x11b0
movq 0x6948(%rip), %rax      # 0xbfe0
movq (%rax), %rbx
movq %r14, %rdi
callq 0x502c
leaq 0x1b5a(%rip), %rsi      # 0x7204
leaq 0x1a01(%rip), %rdx      # 0x70b2
pushq $0x2
popq %rcx
movq %rbx, %rdi
movq %rax, %r8
xorl %eax, %eax
callq 0x1220
jmp 0x5689
movq 0x6916(%rip), %rax      # 0xbfe0
movq (%rax), %rbx
pushq $0x7
popq %rdi
callq 0x6409
movq %rax, %r15
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5075
movl (%rax), %edi
callq 0x6409
leaq 0x1b92(%rip), %rsi      # 0x7283
leaq 0x19ba(%rip), %rdx      # 0x70b2
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %ecx
movq %r15, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x1220
movl %ebp, %edi
callq 0x11b0
movq 0x68c5(%rip), %rax      # 0xbfe0
movq (%rax), %rbx
movq %r14, %rdi
callq 0x502c
leaq 0x1ad7(%rip), %rsi      # 0x7204
leaq 0x1abc(%rip), %rdx      # 0x71f0
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x1220
jmp 0x570d
movq 0x6891(%rip), %rax      # 0xbfe0
movq (%rax), %rbx
pushq $0x5
popq %rdi
callq 0x6409
movq %rax, %r15
movq %r14, %rdi
xorl %esi, %esi
callq 0x5075
movl (%rax), %edi
callq 0x6409
leaq 0x1b0e(%rip), %rsi      # 0x7283
leaq 0x1a74(%rip), %rdx      # 0x71f0
movq %rbx, %rdi
xorl %ecx, %ecx
movq %r15, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x1220
jmp 0x5689
movq 0x6846(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movq 0x10(%r15), %rdx
leaq 0x222f(%rip), %rsi      # 0x79d7
xorl %eax, %eax
callq 0x1220
jmp 0x5689