// File: /workspace/github_c_makefile_star2_O1/BernardTatin[P]s7sh/s7.c
// Function: s7_remove_from_heap
static inline void s7_remove_from_heap(s7_scheme *sc, s7_pointer x)
    {
        /* global functions are very rarely redefined, so we can remove the function body from
         *   the heap when it is defined.  If redefined, we currently lose the memory held by the
         *   old definition.  (It is not trivial to recover this memory because it is allocated
         *   in blocks, not by the pointer, I think, but s7_define is the point to try).
         */
        if (not_in_heap(x)) return;
        if (is_pair(x))
        {
            s7_pointer p;
            p = x;
            do {
                petrify(sc, p);
                s7_remove_from_heap(sc, car(p));
                p = cdr(p);
            } while (is_pair(p) && (in_heap(p)));
            if (in_heap(p)) petrify(sc, p);
            return;
        }

        switch (type(x))
        {
            case T_LET:
                if (is_funclet(x)) set_immutable(x);
            case T_HASH_TABLE:
            case T_VECTOR:
                /* not int|float_vector or string because none of their elements are GC-able (so unheap below is ok)
                 *   but hash-table and let seem like they need protection? And let does happen via define-class.
                 */
                add_permanent_object(sc, x);
                return;

            case T_SYMBOL:
                if (is_gensym(x))
                {
                    s7_int i;
                    gc_list *gp;
                    int64_t loc;
                    loc = heap_location(sc, x);
#if S7_DEBUGGING
                    check_heap_location(sc, x, loc, __func__, __LINE__);
                    petrified_pointers++;
#endif
                    sc->heap[loc] = (s7_pointer)alloc_big_pointer(sc, loc);
                    free_cell(sc, sc->heap[loc]);
                    unheap(sc, x);

                    gp = sc->gensyms;
                    for (i = 0; i < gp->loc; i++) /* sc->gensyms reaches size 512 during s7test, but this search is called 3 times and costs nothing */
                        if (gp->list[i] == x)
                        {
                            s7_int j;
                            for (j = i + 1; i < gp->loc - 1; i++, j++)
                                gp->list[i] = gp->list[j];
                            gp->list[i] = NULL;
                            gp->loc--;
                            if (gp->loc == 0) mark_function[T_SYMBOL] = mark_noop;
                            break;
                        }
                }
                return;

            case T_CLOSURE: case T_CLOSURE_STAR:
            case T_MACRO:   case T_MACRO_STAR:
            case T_BACRO:   case T_BACRO_STAR:
                /* these need to be GC-protected! */
                add_permanent_object(sc, x);
                return;

            default:
                break;
        }

        petrify(sc, x);
    }

// Assembly:
testb $0x40, 0x7(%rsi)
jne 0xb141
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movzbl (%rsi), %eax
cmpl $0x1a, %eax
jle 0xaecf
leal -0x28(%rax), %ecx
cmpl $0x6, %ecx
jb 0xaee6
cmpl $0x1b, %eax
je 0xaee6
cmpl $0x1c, %eax
jne 0xaffb
movq (%rbx), %rax
btl $0x1d, %eax
jae 0xaee6
orq $0x1000000, %rax        # imm = 0x1000000
movq %rax, (%rbx)
jmp 0xaee6
cmpl $0x1, %eax
je 0xaf0a
cmpl $0xa, %eax
je 0xafd1
cmpl $0x15, %eax
jne 0xaffb
movl $0x10, %edi
callq 0x9480
movq %rbx, (%rax)
movq 0xc0(%r14), %rcx
movq %rcx, 0x8(%rax)
movq %rax, 0xc0(%r14)
jmp 0xb136
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movq 0x2a68(%r14), %rcx
testq %rcx, %rcx
je 0xaf34
movq (%rcx), %rdx
cmpq %rbx, %rdx
jg 0xaf2e
cmpq %rbx, 0x8(%rcx)
jg 0xaf3a
movq 0x18(%rcx), %rcx
jmp 0xaf1b
movq 0x30(%rbx), %r15
jmp 0xaf4e
movq %rbx, %rax
subq %rdx, %rax
mulq %r12
movq %rdx, %r15
shrq $0x5, %r15
addq 0x10(%rcx), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x92863
movq 0x80(%r14), %rcx
movq %rax, (%rcx,%r15,8)
movq $0x0, (%rax)
movq 0x90(%r14), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x90(%r14)
movq %rax, (%rcx)
orb $0x40, 0x7(%rbx)
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0xae85
movq 0x10(%rbx), %rbx
cmpb $0x1, (%rbx)
jne 0xafa3
testb $0x40, 0x7(%rbx)
je 0xaf14
testb $0x40, 0x7(%rbx)
jne 0xb136
movq 0x2a68(%r14), %rcx
testq %rcx, %rcx
je 0xb01b
movq (%rcx), %rdx
cmpq %rbx, %rdx
jg 0xafcb
cmpq %rbx, 0x8(%rcx)
jg 0xb0ec
movq 0x18(%rcx), %rcx
jmp 0xafb4
testb $0x20, 0x3(%rbx)
je 0xb136
movq 0x2a68(%r14), %rcx
testq %rcx, %rcx
je 0xb024
movq (%rcx), %rdx
cmpq %rbx, %rdx
jg 0xaff5
cmpq %rbx, 0x8(%rcx)
jg 0xb042
movq 0x18(%rcx), %rcx
jmp 0xafe2
movq 0x2a68(%r14), %rcx
testq %rcx, %rcx
je 0xb01b
movq (%rcx), %rdx
cmpq %rbx, %rdx
jg 0xb015
cmpq %rbx, 0x8(%rcx)
jg 0xb02a
movq 0x18(%rcx), %rcx
jmp 0xb002
movq 0x30(%rbx), %r15
jmp 0xb100
movq 0x30(%rbx), %r15
jmp 0xb060
movq %rbx, %rax
subq %rdx, %rax
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rdx
jmp 0xb0f5
movq %rbx, %rax
subq %rdx, %rax
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rdx
movq %rdx, %r15
shrq $0x5, %r15
addq 0x10(%rcx), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x92863
movq 0x80(%r14), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x80(%r14), %rax
movq (%rax,%r15,8), %rax
movq $0x0, (%rax)
movq 0x90(%r14), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x90(%r14)
movq %rax, (%rcx)
orb $0x40, 0x7(%rbx)
movq 0x778(%r14), %rax
movq 0x10(%rax), %rcx
testq %rcx, %rcx
jle 0xb136
movq (%rax), %rsi
xorl %edx, %edx
cmpq %rbx, (%rsi,%rdx,8)
je 0xb0ca
incq %rdx
cmpq %rdx, %rcx
jne 0xb0ba
jmp 0xb136
decq %rcx
cmpq %rcx, %rdx
jge 0xb142
leaq 0x1(%rdx), %rsi
movq (%rax), %rdi
movq 0x8(%rdi,%rdx,8), %r8
movq %r8, (%rdi,%rdx,8)
movq %rsi, %rdx
cmpq %rcx, %rsi
jl 0xb0d2
jmp 0xb145
movq %rbx, %rax
subq %rdx, %rax
mulq %r12
movq %rdx, %r15
shrq $0x5, %r15
addq 0x10(%rcx), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x92863
movq 0x80(%r14), %rcx
movq %rax, (%rcx,%r15,8)
movq $0x0, (%rax)
movq 0x90(%r14), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x90(%r14)
movq %rax, (%rcx)
orb $0x40, 0x7(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rdx, %rsi
movq (%rax), %rdx
movq $0x0, (%rdx,%rsi,8)
movq %rcx, 0x10(%rax)
testq %rcx, %rcx
jne 0xb136
leaq 0x87772(%rip), %rax     # 0x928d2
movq %rax, 0x143659(%rip)    # 0x14e7c0
jmp 0xb136