// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
cmpb $0x1c, (%rsi)
jne 0xc491
movq %rdx, %r14
cmpb $0xa, (%rdx)
movq (%r15), %rax
jne 0xc4ca
movb $0x1, %bpl
btl $0x1e, %eax
jae 0xc4ef
cmpb $0x1, 0x24c(%rbx)
jne 0xc4ef
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9a55
movq 0x1230(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x99ef
cmpq 0x128(%rbx), %rax
je 0xc4ef
movq %rax, %r12
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r13
cmpq 0x98(%rbx), %rax
ja 0xc43b
movq %rbx, %rdi
callq 0xb389
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 %r14, 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 %r15, 0x8(%rdx)
movq %rax, 0x10(%rdx)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xbd41
xorl %ebp, %ebp
jmp 0xc4ef
movq 0x1230(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x1424b5(%rip), %rdx    # 0x14e958
movq 0x140(%rbx), %r8
movq 0x1464a7(%rip), %r9     # 0x152958
movq %rbx, %rdi
movq %r15, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb31d
notl %eax
testl $0x44000000, %eax       # imm = 0x44000000
jne 0xc524
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc5b7
testb %bpl, %bpl
je 0xc5a8
testb $-0x80, 0x6(%r14)
je 0xc50b
movq 0x8(%r14), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %r14
cmpq %r15, 0x150(%rbx)
je 0xc57f
movq 0x18(%r15), %rax
cmpq 0x20(%r14), %rax
jne 0xc54f
movq 0x18(%r14), %rax
jmp 0xc588
movq 0x1230(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x14242a(%rip), %rdx    # 0x14e960
movq 0x140(%rbx), %r8
movq 0x14641c(%rip), %r9     # 0x152960
movq %rbx, %rdi
movq %r14, %rcx
jmp 0xc4b7
cmpb $0x1c, (%r15)
jne 0xc576
movq %r15, %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
je 0xc56d
cmpq %r14, 0x8(%rcx)
je 0xc58e
movq 0x18(%rcx), %rcx
jmp 0xc55c
movq 0x10(%rax), %rax
cmpb $0x1c, (%rax)
je 0xc558
movq (%r15), %rax
btl $0x1e, %eax
jb 0xc594
movq 0x10(%r14), %rax
cmpb $0x20, (%rax)
jne 0xc5a1
movq 0x10(%rax), %rax
jmp 0xc5a8
movq 0x10(%rcx), %rax
jmp 0xc5a8
notl %eax
testl $0x44000000, %eax       # imm = 0x44000000
je 0xc4d3
movq 0x128(%rbx), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq