// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: s7_let_ref
inline s7_pointer s7_let_ref(s7_scheme *sc, s7_pointer env, s7_pointer symbol)
    {
        s7_pointer x, y;
        /* (let ((a 1)) ((curlet) 'a))
         * ((rootlet) 'abs)
         */
        if (!is_let(env))
            return(wrong_type_argument_with_type(sc, sc->let_ref_symbol, 1, env, a_let_string));

        if (!is_symbol(symbol))
        {
#if S7_DEBUGGING
            if ((env != sc->rootlet) && (has_let_ref_fallback(env)))
#else
                if (has_let_ref_fallback(env))
#endif
                    return(call_let_ref_fallback(sc, env, symbol));
            return(wrong_type_argument_with_type(sc, sc->let_ref_symbol, 2, symbol, a_symbol_string));
        }

        check_method_uncopied(sc, env, sc->let_ref_symbol, list_2(sc, env, symbol));
        /* a let-ref method is almost impossible to write without creating an infinite loop:
         *   any reference to the let will probably call let-ref somewhere, calling us again, and looping.
         *   This is not a problem in c-objects and funclets because c-object-ref and funclet-ref don't exist.
         *   After much wasted debugging, I decided to make let-ref and let-set! immutable.
         */

        if (is_keyword(symbol))
            symbol = keyword_symbol(symbol);

        if (env == sc->rootlet)
        {
            y = global_slot(symbol);
            if (is_slot(y))
                return(slot_value(y));
            return(sc->undefined);
        }

        if (let_id(env) == symbol_id(symbol))
            return(slot_value(local_slot(symbol))); /* this obviously has to follow the global-env check */

        for (x = env; is_let(x); x = outlet(x))
            for (y = let_slots(x); tis_slot(y); y = next_slot(y))
                if (slot_symbol(y) == symbol)
                    return(slot_value(y));

        if (has_methods(env)) /* this is not a redundant check -- if has_methods, don't check global slot */
        {
            /* If a let is a mock-hash-table (for example), implicit
             *   indexing of the hash-table collides with the same thing for the let (field names
             *   versus keys), and we can't just try again here because that makes it too easy to
             *   get into infinite recursion.  So, 'let-ref-fallback...
             */
            if (has_let_ref_fallback(env))
                return(call_let_ref_fallback(sc, env, symbol));
        }
        else
        {
            y = global_slot(symbol);  /* (let () ((curlet) 'pi)) */
            if (is_slot(y))
                return(slot_value(y));
        }
        return(sc->undefined);
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
cmpb $0x1c, (%rsi)
jne 0xa928
movq %rdx, %r15
cmpb $0xa, (%rdx)
movq (%r14), %r13
jne 0xa95c
btl $0x1e, %r13d
jae 0xa97f
cmpb $0x1, 0x24c(%rbx)
jne 0xa97f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x88f3
movq 0x1230(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x888f
cmpq 0x128(%rbx), %rax
je 0xa97f
movq %rax, %r12
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r13
cmpq 0x98(%rbx), %rax
ja 0xa8d4
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movl $0x200001, %ecx         # imm = 0x200001
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
movq %r13, 0x10(%rax)
movq 0x90(%rbx), %rdx
leaq -0x8(%rdx), %rsi
movq %rsi, 0x90(%rbx)
movq -0x8(%rdx), %rdx
movq %rcx, (%rdx)
movq %r14, 0x8(%rdx)
movq %rax, 0x10(%rdx)
movq %rbx, %rdi
movq %r12, %rsi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xa34c
movq 0x1230(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x10b01e(%rip), %rdx    # 0x115958
movq 0x140(%rbx), %r8
movq 0x10f010(%rip), %r9     # 0x119958
movq %rbx, %rdi
movq %r14, %rcx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x9bbb
notl %r13d
testl $0x44000000, %r13d      # imm = 0x44000000
jne 0xa9ab
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xaa3e
testb $-0x80, 0x6(%r15)
je 0xa992
movq 0x8(%r15), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %r15
cmpq %r14, 0x150(%rbx)
je 0xaa0e
movq 0x18(%r14), %rax
cmpq 0x20(%r15), %rax
jne 0xa9d6
movq 0x18(%r15), %rax
jmp 0xaa17
movq 0x1230(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x10afa3(%rip), %rdx    # 0x115960
movq 0x140(%rbx), %r8
movq 0x10ef95(%rip), %r9     # 0x119960
movq %rbx, %rdi
movq %r15, %rcx
jmp 0xa94e
movl %r13d, %ecx
movq %r14, %rax
cmpb $0x1c, %cl
jne 0xaa07
leaq 0x8(%rax), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0xa9f9
cmpq %r15, 0x8(%rcx)
je 0xaa01
addq $0x18, %rcx
jmp 0xa9e5
movq 0x10(%rax), %rax
movb (%rax), %cl
jmp 0xa9dc
movq 0x10(%rcx), %rax
jmp 0xaa34
btl $0x1e, %r13d
jb 0xaa1d
movq 0x10(%r15), %rax
cmpb $0x20, (%rax)
jne 0xaa2d
movq 0x10(%rax), %rax
jmp 0xaa34
notl %r13d
testl $0x44000000, %r13d      # imm = 0x44000000
je 0xa968
movq 0x128(%rbx), %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq