// File: /workspace/github_c_makefile_star2_O3/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 0xa263
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movzbl (%rsi), %eax
cmpl $0x1a, %eax
jle 0xa096
leal -0x28(%rax), %ecx
cmpl $0x6, %ecx
jb 0xa0ad
cmpl $0x1b, %eax
je 0xa0ad
cmpl $0x1c, %eax
jne 0xa1ca
movq (%rbx), %rax
btl $0x1d, %eax
jae 0xa0ad
orq $0x1000000, %rax        # imm = 0x1000000
movq %rax, (%rbx)
jmp 0xa0ad
cmpl $0x1, %eax
je 0xa0d1
cmpl $0xa, %eax
je 0xa19c
cmpl $0x15, %eax
jne 0xa1ca
movl $0x10, %edi
callq 0x8480
movq %rbx, (%rax)
movq 0xc0(%r14), %rcx
movq %rcx, 0x8(%rax)
movq %rax, 0xc0(%r14)
jmp 0xa258
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movq 0x2a68(%r14), %rcx
testq %rcx, %rcx
je 0xa0fb
movq (%rcx), %rdx
cmpq %rbx, %rdx
jg 0xa0f5
cmpq %rbx, 0x8(%rcx)
jg 0xa101
movq 0x18(%rcx), %rcx
jmp 0xa0e2
movq 0x30(%rbx), %r15
jmp 0xa115
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 0x8c46b
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 0xa04c
movq 0x10(%rbx), %rbx
movzwl 0x6(%rbx), %eax
cmpb $0x1, (%rbx)
jne 0xa172
movl %eax, %ecx
andl $0x4000, %ecx           # imm = 0x4000
je 0xa0db
btl $0xe, %eax
jb 0xa258
movq 0x2a68(%r14), %rcx
testq %rcx, %rcx
je 0xa1ea
movq (%rcx), %rdx
cmpq %rbx, %rdx
jg 0xa196
cmpq %rbx, 0x8(%rcx)
jg 0xa20e
movq 0x18(%rcx), %rcx
jmp 0xa183
testb $0x20, 0x3(%rbx)
je 0xa258
movq 0x2a68(%r14), %rcx
testq %rcx, %rcx
je 0xa1f0
movq (%rcx), %rdx
cmpq %rbx, %rdx
jg 0xa1c4
cmpq %rbx, 0x8(%rcx)
jg 0xa264
movq 0x18(%rcx), %rcx
jmp 0xa1ad
movq 0x2a68(%r14), %rcx
testq %rcx, %rcx
je 0xa1ea
movq (%rcx), %rdx
cmpq %rbx, %rdx
jg 0xa1e4
cmpq %rbx, 0x8(%rcx)
jg 0xa1f9
movq 0x18(%rcx), %rcx
jmp 0xa1d1
movq 0x30(%rbx), %r15
jmp 0xa222
movq 0x30(%rbx), %r15
jmp 0xa282
movq %rbx, %rax
subq %rdx, %rax
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rdx
jmp 0xa217
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 0x8c46b
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 %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 0x8c46b
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 0xa258
movq (%rax), %rsi
xorl %edx, %edx
cmpq %rbx, (%rsi,%rdx,8)
je 0xa2eb
incq %rdx
cmpq %rdx, %rcx
jne 0xa2d8
jmp 0xa258
decq %rcx
cmpq %rcx, %rdx
jge 0xa30a
movq (%rax), %rsi
movq 0x8(%rsi,%rdx,8), %rdi
movq %rdi, (%rsi,%rdx,8)
incq %rdx
cmpq %rcx, %rdx
jl 0xa2f3
movq (%rax), %rsi
movq $0x0, (%rsi,%rdx,8)
movq %rcx, 0x10(%rax)
testq %rcx, %rcx
jne 0xa258
leaq 0x821ad(%rip), %rax     # 0x8c4d3
movq %rax, 0x13c493(%rip)    # 0x1467c0
jmp 0xa258