// File: /workspace/github_c_makefile_star2_O0/voithos[P]awl/src/eval.c
// Function: awlval_eval
awlval* awlval_eval(awlenv* e, awlval* v) {
    bool recursing = false;

    while (true) {
        // Handle abort
        if (eval_aborted) {
            AWLENV_DEL_RECURSING(e);
            awlval_del(v);

            eval_aborted = false;
            return awlval_err("eval aborted");
        }

        switch (v->type) {
            case AWLVAL_SYM:
            {
                awlval* x = awlenv_get(e, v);
                awlval_del(v);
                AWLENV_DEL_RECURSING(e);
                return x;
                break;
            }

            case AWLVAL_SEXPR:
            {
                awlval* x = awlval_eval_sexpr(e, v);

                /* recursively evaluate results */
                if (x->type == AWLVAL_FN && x->called) {
                    AWLENV_DEL_RECURSING(e);
                    recursing = true;

                    e = awlenv_copy(x->env);
                    v = awlval_copy(x->body);

                    awlval_del(x);
                } else {
                    /* evaluate result in next loop */
                    v = x;
                }
                break;
            }

            case AWLVAL_QEXPR:
            {
                awlval* x = awlval_eval_inside_qexpr(e, v);
                AWLENV_DEL_RECURSING(e);
                return x;
                break;
            }

            case AWLVAL_EEXPR:
            case AWLVAL_CEXPR:
            {
                AWLENV_DEL_RECURSING(e);
                awlval* err = awlval_err("cannot directly evaluate %s; must be contained inside %s",
                        awlval_type_name(v->type), awlval_type_name(AWLVAL_QEXPR));
                awlval_del(v);
                return err;
            }

            default:
                AWLENV_DEL_RECURSING(e);
                return v;
                break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
testb $0x1, 0x1ab56(%rip)     # 0x222e1
je 0x77c3
testb $0x1, -0x19(%rbp)
je 0x779c
movq -0x10(%rbp), %rdi
callq 0x16e00
movq -0x18(%rbp), %rdi
callq 0x16cf0
movb $0x0, 0x1ab35(%rip)     # 0x222e1
leaq 0x12e4d(%rip), %rdi     # 0x1a600
movb $0x0, %al
callq 0x16600
movq %rax, -0x8(%rbp)
jmp 0x7932
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $-0x3, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0xb, %eax
ja 0x7914
movq -0x48(%rbp), %rax
leaq 0x12dea(%rip), %rcx     # 0x1a5d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x18900
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x16cf0
testb $0x1, -0x19(%rbp)
je 0x7818
movq -0x10(%rbp), %rdi
callq 0x16e00
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7932
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x7940
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x8, (%rax)
jne 0x7889
movq -0x30(%rbp), %rax
testb $0x1, 0x30(%rax)
je 0x7889
testb $0x1, -0x19(%rbp)
je 0x7858
movq -0x10(%rbp), %rdi
callq 0x16e00
movb $0x1, -0x19(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x17c20
movq %rax, -0x10(%rbp)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x171d0
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rdi
callq 0x16cf0
jmp 0x7891
movq -0x30(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x792d
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x7a60
movq %rax, -0x38(%rbp)
testb $0x1, -0x19(%rbp)
je 0x78b6
movq -0x10(%rbp), %rdi
callq 0x16e00
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7932
testb $0x1, -0x19(%rbp)
je 0x78cf
movq -0x10(%rbp), %rdi
callq 0x16e00
movq -0x18(%rbp), %rax
movl (%rax), %edi
callq 0x161a0
movq %rax, -0x50(%rbp)
movl $0xc, %edi
callq 0x161a0
movq -0x50(%rbp), %rsi
movq %rax, %rdx
leaq 0x12d17(%rip), %rdi     # 0x1a60d
movb $0x0, %al
callq 0x16600
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
callq 0x16cf0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7932
testb $0x1, -0x19(%rbp)
je 0x7923
movq -0x10(%rbp), %rdi
callq 0x16e00
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7932
jmp 0x7784
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)