// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_is_defined
static s7_pointer g_is_defined(s7_scheme *sc, s7_pointer args)
    {
#define H_is_defined "(defined? symbol (env (curlet)) ignore-globals) returns #t if symbol has a binding (a value) in the environment env.  Only env is searched if ignore-globals is not #f."
#define Q_is_defined s7_make_signature(sc, 4, sc->is_boolean_symbol, sc->is_symbol_symbol, sc->is_let_symbol, sc->is_boolean_symbol)

        s7_pointer sym;
        /* is this correct?
         *    (defined? '_x) #f (symbol->value '_x) #<undefined>
         *    (define x #<undefined>) (defined? 'x) #t
         * can't return the value here because it might be #f
         */

        sym = car(args);
        if (!is_symbol(sym))
            return(method_or_bust(sc, sym, sc->is_defined_symbol, args, T_SYMBOL, 1));

        if (is_pair(cdr(args)))
        {
            s7_pointer e, b, x;

            e = cadr(args);
            if (!is_let(e))
                return(wrong_type_argument_with_type(sc, sc->is_defined_symbol, 2, e, a_let_string));
            if (e == sc->s7_let)
                return(make_boolean(sc, symbol_s7_let(sym) != 0));

            if (is_pair(cddr(args)))
            {
                b = caddr(args);
                if (!s7_is_boolean(b))
                    return(method_or_bust_with_type(sc, b, sc->is_defined_symbol, args, a_boolean_string, 3));
            }
            else b = sc->F;

            if (e == sc->rootlet) /* we checked (let? e) above */
            {
                if (b == sc->F)
                    return(make_boolean(sc, is_slot(global_slot(sym)))); /* new_symbol and gensym initialize global_slot to #<undefined> */
                return(sc->F);
            }

            x = symbol_to_local_slot(sc, sym, e);
            if (is_slot(x))
                return(sc->T);

            if (b == sc->T)
                return(sc->F);
            return(make_boolean(sc, is_slot(global_slot(sym))));
        }
        if (is_global(sym))
            return(sc->T);
        return(make_boolean(sc, is_slot(symbol_to_slot(sc, sym))));
    }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rax
movq %rdi, %rbx
movq 0x8(%rsi), %r14
cmpb $0xa, (%r14)
jne 0x4e1e5
movq 0x10(%rax), %rdx
cmpb $0x1, (%rdx)
jne 0x4e207
movq 0x8(%rdx), %rcx
cmpb $0x1c, (%rcx)
jne 0x4e227
cmpq 0x2150(%rbx), %rcx
je 0x4e254
movq 0x10(%rdx), %rdx
cmpb $0x1, (%rdx)
jne 0x4e26f
movq 0x8(%rdx), %r15
cmpb $0x7, (%r15)
je 0x4e276
movq 0x1050(%rbx), %rdx
movq 0xd6442(%rip), %r8      # 0x124610
pushq $0x3
popq %r9
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rcx
popq %rbx
popq %r14
popq %r15
jmp 0xcf9a
movq 0x1050(%rbx), %rdx
pushq $0xa
popq %r8
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
popq %rbx
popq %r14
popq %r15
jmp 0xcd70
testb $0x1, 0x2(%r14)
jne 0x4e2c5
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb00b
xorl %ecx, %ecx
cmpb $0x20, (%rax)
setne %cl
jmp 0x4e265
movq 0x1050(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xc7727(%rip), %rdx     # 0x115960
movq 0x140(%rbx), %r8
movq 0xcb711(%rip), %r9      # 0x119958
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x9bbb
movq 0x8(%r14), %rax
movq 0x20(%rax), %rax
xorl %ecx, %ecx
cmpb $0x0, 0x11(%rax)
sete %cl
movq 0x118(%rbx,%rcx,8), %rax
jmp 0x4e2cc
movq 0x120(%rbx), %r15
cmpq 0x150(%rbx), %rcx
je 0x4e2b0
movq %rbx, %rdi
movq %r14, %rsi
movq %rcx, %rdx
callq 0xb1df
cmpb $0x20, (%rax)
movq 0x118(%rbx), %rax
je 0x4e2cc
cmpq %rax, %r15
je 0x4e2a7
movq 0x10(%r14), %rcx
cmpb $0x20, (%rcx)
je 0x4e2cc
movq 0x120(%rbx), %rax
jmp 0x4e2cc
movq 0x120(%rbx), %rax
cmpq %rax, %r15
jne 0x4e2cc
movq 0x10(%r14), %rcx
cmpb $0x20, (%rcx)
jne 0x4e2cc
movq 0x118(%rbx), %rax
popq %rbx
popq %r14
popq %r15
retq