// File: /workspace/github_c_makefile_star2_O2/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:
pushq %r15
pushq %r14
pushq %rbx
testb $0x40, 0x7(%rsi)
jne 0x9a03
movq %rsi, %rbx
movq %rdi, %r14
movzbl (%rsi), %eax
leal -0x28(%rax), %ecx
cmpl $0x6, %ecx
jae 0x98c7
movq %r14, %rdi
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x70d0d
cmpl $0x1c, %eax
je 0x9928
cmpl $0xa, %eax
je 0x993f
cmpl $0x15, %eax
je 0x98b7
cmpl $0x1b, %eax
je 0x98b7
cmpl $0x1, %eax
jne 0x9918
movq %r14, %rdi
movq %rbx, %rsi
callq 0x70cbe
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x9897
movq 0x10(%rbx), %rbx
movzwl 0x6(%rbx), %eax
cmpb $0x1, (%rbx)
jne 0x990e
movl %eax, %ecx
andl $0x4000, %ecx           # imm = 0x4000
je 0x98e0
btl $0xe, %eax
jb 0x9a03
movq %r14, %rdi
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x70cbe
movq (%rbx), %rax
btl $0x1d, %eax
jae 0x98b7
orq $0x1000000, %rax        # imm = 0x1000000
movq %rax, (%rbx)
jmp 0x98b7
testb $0x20, 0x3(%rbx)
je 0x9a03
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2b6dd
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x70d3c
movq 0x80(%r14), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x80(%r14), %rax
movq (%rax,%r15,8), %rax
andq $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
xorl %edx, %edx
testq %rcx, %rcx
movl $0x0, %esi
cmovgq %rcx, %rsi
cmpq %rdx, %rsi
je 0x9a03
movq (%rax), %rdi
cmpq %rbx, (%rdi,%rdx,8)
je 0x99c1
incq %rdx
jmp 0x99ae
decq %rcx
cmpq %rcx, %rdx
movq %rcx, %rsi
cmovgq %rdx, %rsi
cmpq %rdx, %rsi
je 0x99e4
movq (%rax), %rdi
movq 0x8(%rdi,%rdx,8), %r8
movq %r8, (%rdi,%rdx,8)
incq %rdx
jmp 0x99ce
movq (%rax), %rdx
andq $0x0, (%rdx,%rsi,8)
movq %rcx, 0x10(%rax)
testq %rcx, %rcx
jne 0x9a03
leaq 0x673a6(%rip), %rax     # 0x70da2
movq %rax, 0x10bdbd(%rip)    # 0x1157c0
popq %rbx
popq %r14
popq %r15
retq