// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/compile.c
// Function: janetc_resolve
JanetSlot janetc_resolve(
    JanetCompiler *c,
    const uint8_t *sym) {

    JanetSlot ret = janetc_cslot(janet_wrap_nil());
    JanetScope *scope = c->scope;
    SymPair *pair;
    int foundlocal = 1;
    int unused = 0;

    /* Search scopes for symbol, starting from top */
    while (scope) {
        int32_t i, len;
        if (scope->flags & JANET_SCOPE_UNUSED)
            unused = 1;
        len = janet_v_count(scope->syms);
        /* Search in reverse order */
        for (i = len - 1; i >= 0; i--) {
            pair = scope->syms + i;
            if (pair->sym == sym) {
                ret = pair->slot;
                goto found;
            }
        }
        if (scope->flags & JANET_SCOPE_FUNCTION)
            foundlocal = 0;
        scope = scope->parent;
    }

    /* Symbol not found - check for global */
    {
        JanetBinding binding = janet_resolve_ext(c->env, sym);
        if (binding.type == JANET_BINDING_NONE) {
            Janet handler = janet_table_get(c->env, janet_ckeywordv("missing-symbol"));
            switch (janet_type(handler)) {
                case JANET_NIL:
                    break;
                case JANET_FUNCTION:
                    if (!lookup_missing(c, sym, janet_unwrap_function(handler), &binding))
                        return janetc_cslot(janet_wrap_nil());
                    break;
                default:
                    janetc_error(c, janet_formatc("invalid lookup handler %V", handler));
                    return janetc_cslot(janet_wrap_nil());
            }
        }

        switch (binding.type) {
            default:
            case JANET_BINDING_NONE:
                janetc_error(c, janet_formatc("unknown symbol %q", janet_wrap_symbol(sym)));
                return janetc_cslot(janet_wrap_nil());
            case JANET_BINDING_DEF:
            case JANET_BINDING_MACRO: /* Macro should function like defs when not in calling pos */
                ret = janetc_cslot(binding.value);
                break;
            case JANET_BINDING_DYNAMIC_DEF:
            case JANET_BINDING_DYNAMIC_MACRO:
                ret = janetc_cslot(binding.value);
                ret.flags |= JANET_SLOT_REF | JANET_SLOT_NAMED | JANET_SLOTTYPE_ANY;
                ret.flags &= ~JANET_SLOT_CONSTANT;
                break;
            case JANET_BINDING_VAR: {
                ret = janetc_cslot(binding.value);
                ret.flags |= JANET_SLOT_REF | JANET_SLOT_NAMED | JANET_SLOT_MUTABLE | JANET_SLOTTYPE_ANY;
                ret.flags &= ~JANET_SLOT_CONSTANT;
                break;
            }
        }
        JanetCompileLintLevel depLevel = JANET_C_LINT_RELAXED;
        switch (binding.deprecation) {
            case JANET_BINDING_DEP_NONE:
                break;
            case JANET_BINDING_DEP_RELAXED:
                depLevel = JANET_C_LINT_RELAXED;
                break;
            case JANET_BINDING_DEP_NORMAL:
                depLevel = JANET_C_LINT_NORMAL;
                break;
            case JANET_BINDING_DEP_STRICT:
                depLevel = JANET_C_LINT_STRICT;
                break;
        }
        if (binding.deprecation != JANET_BINDING_DEP_NONE) {
            janetc_lintf(c, depLevel, "%q is deprecated", janet_wrap_symbol(sym));
        }
        return ret;
    }

    /* Symbol was found */
found:

    /* Constants can be returned immediately (they are stateless) */
    if (ret.flags & (JANET_SLOT_CONSTANT | JANET_SLOT_REF))
        return ret;

    /* Unused references and locals shouldn't add captured envs. */
    if (unused || foundlocal) {
        ret.envindex = -1;
        return ret;
    }

    /* non-local scope needs to expose its environment */
    JanetScope *original_scope = scope;
    pair->keep = 1;
    while (scope && !(scope->flags & JANET_SCOPE_FUNCTION))
        scope = scope->parent;
    janet_assert(scope, "invalid scopes");
    scope->flags |= JANET_SCOPE_ENV;

    /* In the function scope, allocate the slot as an upvalue */
    janetc_regalloc_touch(&scope->ua, ret.index);

    /* Iterate through child scopes and make sure environment is propagated */
    scope = scope->child;

    /* Propagate env up to current scope */
    int32_t envindex = -1;
    while (scope) {
        if (scope->flags & JANET_SCOPE_FUNCTION) {
            int32_t j, len;
            int scopefound = 0;
            /* Check if scope already has env. If so, break */
            len = janet_v_count(scope->envs);
            for (j = 0; j < len; j++) {
                if (scope->envs[j].envindex == envindex) {
                    scopefound = 1;
                    envindex = j;
                    break;
                }
            }
            /* Add the environment if it is not already referenced */
            if (!scopefound) {
                len = janet_v_count(scope->envs);
                JanetEnvRef ref;
                ref.envindex = envindex;
                ref.scope = original_scope;
                janet_v_push(scope->envs, ref);
                envindex = len;
            }
        }
        scope = scope->child;
    }

    ret.envindex = envindex;
    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x128(%rbp)
movq %rdi, -0x120(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x1ff40
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x1, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x20a14
movq -0x38(%rbp), %rax
movl 0x6c(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x2095b
movl $0x1, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x20979
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4(%rax), %eax
movl %eax, -0x12c(%rbp)
jmp 0x20983
xorl %eax, %eax
movl %eax, -0x12c(%rbp)
jmp 0x20983
movl -0x12c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jl 0x209ed
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x209e0
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x28(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x20dc8
jmp 0x209e2
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x20995
movq -0x38(%rbp), %rax
movl 0x6c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x20a03
movl $0x0, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x2093a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x6cf90
cmpl $0x0, -0x68(%rbp)
jne 0x20b91
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x138(%rbp)
leaq 0x60b21(%rip), %rdi     # 0x8156a
callq 0x68d90
movq %rax, %rdi
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
callq 0x7b550
movq -0x138(%rbp), %rdi
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rsi
callq 0x69420
movq %rax, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x20a8a
jmp 0x20a9e
movq -0x70(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
movl %eax, -0x13c(%rbp)
jmp 0x20aa8
xorl %eax, %eax
movl %eax, -0x13c(%rbp)
jmp 0x20aa8
movl -0x13c(%rbp), %eax
movl %eax, -0x140(%rbp)
subl $0x1, %eax
je 0x20ac8
jmp 0x20abb
movl -0x140(%rbp), %eax
subl $0xc, %eax
je 0x20acd
jmp 0x20b35
jmp 0x20b8f
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x70(%rbp), %rdi
callq 0x7b260
movq -0x150(%rbp), %rdi
movq -0x148(%rbp), %rsi
movq %rax, %rdx
leaq -0x68(%rbp), %rcx
callq 0x210f0
cmpl $0x0, %eax
jne 0x20b33
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0x128(%rbp), %rdi
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rsi
callq 0x1ff40
jmp 0x210db
jmp 0x20b8f
movq -0x8(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x70(%rbp), %rsi
leaq 0x60a2e(%rip), %rdi     # 0x81579
movb $0x0, %al
callq 0x5bdd0
movq -0x158(%rbp), %rdi
movq %rax, %rsi
callq 0x1ffb0
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0x128(%rbp), %rdi
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rsi
callq 0x1ff40
jmp 0x210db
jmp 0x20b91
movl -0x68(%rbp), %eax
movq %rax, -0x160(%rbp)
subq $0x5, %rax
ja 0x20bb8
movq -0x160(%rbp), %rax
leaq 0x60781(%rip), %rcx     # 0x81330
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x20bba
movq -0x8(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x10(%rbp), %rdi
movabsq $-0x5800000000000, %rsi # imm = 0xFFFA800000000000
callq 0x7b550
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rsi
leaq 0x609a6(%rip), %rdi     # 0x81593
movb $0x0, %al
callq 0x5bdd0
movq -0x168(%rbp), %rdi
movq %rax, %rsi
callq 0x1ffb0
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0x128(%rbp), %rdi
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rsi
callq 0x1ff40
jmp 0x210db
movq -0x60(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x1ff40
movq -0xb0(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x20cf7
movq -0x60(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x1ff40
movq -0xc8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x18(%rbp), %eax
orl $0xaffff, %eax          # imm = 0xAFFFF
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
andl $0xfffeffff, %eax       # imm = 0xFFFEFFFF
movl %eax, -0x18(%rbp)
jmp 0x20cf7
movq -0x60(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x1ff40
movq -0xe0(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x18(%rbp), %eax
orl $0xeffff, %eax          # imm = 0xEFFFF
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
andl $0xfffeffff, %eax       # imm = 0xFFFEFFFF
movl %eax, -0x18(%rbp)
movl $0x0, -0xe4(%rbp)
movl -0x58(%rbp), %eax
movq %rax, -0x170(%rbp)
subq $0x3, %rax
ja 0x20d4c
movq -0x170(%rbp), %rax
leaq 0x60629(%rip), %rcx     # 0x81348
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x20d4c
movl $0x0, -0xe4(%rbp)
jmp 0x20d4c
movl $0x1, -0xe4(%rbp)
jmp 0x20d4c
movl $0x2, -0xe4(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x20da5
movq -0x8(%rbp), %rax
movq %rax, -0x180(%rbp)
movl -0xe4(%rbp), %eax
movl %eax, -0x174(%rbp)
movq -0x10(%rbp), %rdi
movabsq $-0x5800000000000, %rsi # imm = 0xFFFA800000000000
callq 0x7b550
movq -0x180(%rbp), %rdi
movl -0x174(%rbp), %esi
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rcx
leaq 0x60807(%rip), %rdx     # 0x815a5
movb $0x0, %al
callq 0x20030
movq -0x128(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x210db
movl -0x18(%rbp), %eax
andl $0x90000, %eax          # imm = 0x90000
cmpl $0x0, %eax
je 0x20df8
movq -0x128(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x210db
cmpl $0x0, -0x48(%rbp)
jne 0x20e04
cmpl $0x0, -0x44(%rbp)
je 0x20e2e
movq -0x128(%rbp), %rax
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x210db
movq -0x38(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x40(%rbp), %rax
movl $0x1, 0x28(%rax)
xorl %eax, %eax
cmpq $0x0, -0x38(%rbp)
movb %al, -0x181(%rbp)
je 0x20e6b
movq -0x38(%rbp), %rax
movl 0x6c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x181(%rbp)
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0x20e77
jmp 0x20e85
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x20e44
jmp 0x20e87
cmpq $0x0, -0x38(%rbp)
jne 0x20ec0
jmp 0x20e90
movq 0x8f159(%rip), %rax     # 0xafff0
movq (%rax), %rdi
leaq 0x60173(%rip), %rsi     # 0x81014
movl $0x15f, %edx            # imm = 0x15F
leaq 0x60709(%rip), %rcx     # 0x815b6
leaq 0x60715(%rip), %r8      # 0x815c9
movb $0x0, %al
callq 0x125f0
callq 0x12100
jmp 0x20ec2
movq -0x38(%rbp), %rax
movl 0x6c(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x6c(%rax)
movq -0x38(%rbp), %rdi
addq $0x48, %rdi
movl -0x20(%rbp), %esi
callq 0x5ded0
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0xffffffff, -0xfc(%rbp) # imm = 0xFFFFFFFF
cmpq $0x0, -0x38(%rbp)
je 0x210b4
movq -0x38(%rbp), %rax
movl 0x6c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x210a3
movl $0x0, -0x108(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x20f3b
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x4(%rax), %eax
movl %eax, -0x188(%rbp)
jmp 0x20f45
xorl %eax, %eax
movl %eax, -0x188(%rbp)
jmp 0x20f45
movl -0x188(%rbp), %eax
movl %eax, -0x104(%rbp)
movl $0x0, -0x100(%rbp)
movl -0x100(%rbp), %eax
cmpl -0x104(%rbp), %eax
jge 0x20fb4
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x100(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0xfc(%rbp), %eax
jne 0x20fa1
movl $0x1, -0x108(%rbp)
movl -0x100(%rbp), %eax
movl %eax, -0xfc(%rbp)
jmp 0x20fb4
jmp 0x20fa3
movl -0x100(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x100(%rbp)
jmp 0x20f5b
cmpl $0x0, -0x108(%rbp)
jne 0x210a1
movq -0x38(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x20fdf
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x4(%rax), %eax
movl %eax, -0x18c(%rbp)
jmp 0x20fe9
xorl %eax, %eax
movl %eax, -0x18c(%rbp)
jmp 0x20fe9
movl -0x18c(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0xfc(%rbp), %eax
movl %eax, -0x118(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x21035
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x4(%rax), %eax
addl $0x1, %eax
movq -0x38(%rbp), %rcx
movq 0x60(%rcx), %rcx
cmpl -0x8(%rcx), %eax
jl 0x21059
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rdi
movl $0x1, %esi
movl $0x10, %edx
callq 0x70760
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x60(%rax)
jmp 0x2105b
jmp 0x2105b
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x60(%rcx), %rdx
movl -0x4(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x4(%rdx)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x118(%rbp), %rcx
movq %rcx, (%rax)
movq -0x110(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x104(%rbp), %eax
movl %eax, -0xfc(%rbp)
jmp 0x210a3
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x20ef5
movq -0x128(%rbp), %rax
movl -0xfc(%rbp), %ecx
movl %ecx, -0x1c(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x120(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopl (%rax,%rax)