// File: /workspace/github_c_makefile_star2_O3/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 0xb631
movq %rdx, %r15
cmpb $0xa, (%rdx)
movq (%r14), %r13
jne 0xb665
btl $0x1e, %r13d
jae 0xb688
cmpb $0x1, 0x24c(%rbx)
jne 0xb688
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8a63
movq 0x1230(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x89ff
cmpq 0x128(%rbx), %rax
je 0xb688
movq %rax, %r12
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r13
cmpq 0x98(%rbx), %rax
ja 0xb5dd
movq %rbx, %rdi
callq 0xa550
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 0xaee6
movq 0x1230(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x13b315(%rip), %rdx    # 0x146958
movq 0x140(%rbx), %r8
movq 0x13f307(%rip), %r9     # 0x14a958
movq %rbx, %rdi
movq %r14, %rcx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xa4e4
notl %r13d
testl $0x44000000, %r13d      # imm = 0x44000000
jne 0xb6b4
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xb743
testb $-0x80, 0x6(%r15)
je 0xb69b
movq 0x8(%r15), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %r15
cmpq %r14, 0x150(%rbx)
je 0xb70d
movq 0x18(%r14), %rax
cmpq 0x20(%r15), %rax
jne 0xb6df
movq 0x18(%r15), %rax
jmp 0xb716
movq 0x1230(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x13b29a(%rip), %rdx    # 0x146960
movq 0x140(%rbx), %r8
movq 0x13f28c(%rip), %r9     # 0x14a960
movq %rbx, %rdi
movq %r15, %rcx
jmp 0xb657
cmpb $0x1c, %r13b
jne 0xb706
movq %r14, %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
je 0xb6fd
cmpq %r15, 0x8(%rcx)
je 0xb71c
movq 0x18(%rcx), %rcx
jmp 0xb6ec
movq 0x10(%rax), %rax
cmpb $0x1c, (%rax)
je 0xb6e8
btl $0x1e, %r13d
jb 0xb722
movq 0x10(%r15), %rax
cmpb $0x20, (%rax)
jne 0xb732
movq 0x10(%rax), %rax
jmp 0xb739
movq 0x10(%rcx), %rax
jmp 0xb739
notl %r13d
testl $0x44000000, %r13d      # imm = 0x44000000
je 0xb671
movq 0x128(%rbx), %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq