// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/gc.c
// Function: janet_sweep
void janet_sweep() {
    JanetGCObject *previous = NULL;
    JanetGCObject *current = janet_vm.weak_blocks;
    JanetGCObject *next;

    /* Sweep weak heap to drop weak refs */
    while (NULL != current) {
        next = current->data.next;
        if (current->flags & (JANET_MEM_REACHABLE | JANET_MEM_DISABLED)) {
            /* Check for dead references */
            enum JanetMemoryType type = janet_gc_type(current);
            if (type == JANET_MEMORY_ARRAY_WEAK) {
                JanetArray *array = (JanetArray *) current;
                for (uint32_t i = 0; i < (uint32_t) array->count; i++) {
                    if (!janet_check_liveref(array->data[i])) {
                        array->data[i] = janet_wrap_nil();
                    }
                }
            } else {
                JanetTable *table = (JanetTable *) current;
                int check_values = (type == JANET_MEMORY_TABLE_WEAKV) || (type == JANET_MEMORY_TABLE_WEAKKV);
                int check_keys = (type == JANET_MEMORY_TABLE_WEAKK) || (type == JANET_MEMORY_TABLE_WEAKKV);
                JanetKV *end = table->data + table->capacity;
                JanetKV *kvs = table->data;
                while (kvs < end) {
                    int drop = 0;
                    if (check_keys && !janet_check_liveref(kvs->key)) drop = 1;
                    if (check_values && !janet_check_liveref(kvs->value)) drop = 1;
                    if (drop) {
                        /* Inlined from janet_table_remove without search */
                        table->count--;
                        table->deleted++;
                        kvs->key = janet_wrap_nil();
                        kvs->value = janet_wrap_false();
                    }
                    kvs++;
                }
            }
        }
        current = next;
    }

    /* Sweep weak heap to free blocks */
    previous = NULL;
    current = janet_vm.weak_blocks;
    while (NULL != current) {
        next = current->data.next;
        if (current->flags & (JANET_MEM_REACHABLE | JANET_MEM_DISABLED)) {
            previous = current;
            current->flags &= ~JANET_MEM_REACHABLE;
        } else {
            janet_vm.block_count--;
            janet_deinit_block(current);
            if (NULL != previous) {
                previous->data.next = next;
            } else {
                janet_vm.weak_blocks = next;
            }
            janet_free(current);
        }
        current = next;
    }

    /* Sweep main heap to free blocks */
    previous = NULL;
    current = janet_vm.blocks;
    while (NULL != current) {
        next = current->data.next;
        if (current->flags & (JANET_MEM_REACHABLE | JANET_MEM_DISABLED)) {
            previous = current;
            current->flags &= ~JANET_MEM_REACHABLE;
        } else {
            janet_vm.block_count--;
            janet_deinit_block(current);
            if (NULL != previous) {
                previous->data.next = next;
            } else {
                janet_vm.blocks = next;
            }
            janet_free(current);
        }
        current = next;
    }

#ifdef JANET_EV
    /* Sweep threaded abstract types for references to decrement */
    JanetKV *items = janet_vm.threaded_abstracts.data;
    for (int32_t i = 0; i < janet_vm.threaded_abstracts.capacity; i++) {
        if (janet_checktype(items[i].key, JANET_ABSTRACT)) {

            /* If item was not visited during the mark phase, then this
             * abstract type isn't present in the heap and needs its refcount
             * decremented, and shouuld be removed from table. If the refcount is
             * then 0, the item will be collected. This ensures that only one interpreter
             * will clean up the threaded abstract. */

            /* If not visited... */
            if (!janet_truthy(items[i].value)) {
                void *abst = janet_unwrap_abstract(items[i].key);
                if (0 == janet_abstract_decref(abst)) {
                    /* Run finalizer */
                    JanetAbstractHead *head = janet_abstract_head(abst);
                    if (head->type->gc) {
                        janet_assert(!head->type->gc(head->data, head->size), "finalizer failed");
                    }
                    /* Free memory */
                    janet_free(janet_abstract_head(abst));
                }

                /* Mark as tombstone in place */
                items[i].key = janet_wrap_nil();
                items[i].value = janet_wrap_false();
                janet_vm.threaded_abstracts.deleted++;
                janet_vm.threaded_abstracts.count--;
            }

            /* Reset for next sweep */
            items[i].value = janet_wrap_false();
        }
    }
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq $0x0, -0x8(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x98(%rax), %rax
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq -0x10(%rbp), %rax
je 0x395f1
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x300, %eax            # imm = 0x300
cmpl $0x0, %eax
je 0x395e4
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xff, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x11, -0x1c(%rbp)
jne 0x3947d
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x39478
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x39b90
cmpl $0x0, %eax
jne 0x3946b
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xb0(%rbp)
movl -0x2c(%rbp), %eax
movq %rax, -0xb8(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0xb8(%rbp), %rcx
movq %rax, %rdx
movq -0xb0(%rbp), %rax
movq %rdx, -0x38(%rbp)
movq -0x38(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x3946d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x39401
jmp 0x395e2
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movb $0x1, %al
cmpl $0xf, -0x1c(%rbp)
movb %al, -0xb9(%rbp)
je 0x394a0
cmpl $0x10, -0x1c(%rbp)
sete %al
movb %al, -0xb9(%rbp)
movb -0xb9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x44(%rbp)
movb $0x1, %al
cmpl $0xe, -0x1c(%rbp)
movb %al, -0xba(%rbp)
je 0x394c9
cmpl $0x10, -0x1c(%rbp)
sete %al
movb %al, -0xba(%rbp)
movb -0xba(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movslq 0x14(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x395e0
movl $0x0, -0x5c(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x39531
movq -0x58(%rbp), %rax
movq (%rax), %rdi
callq 0x39b90
cmpl $0x0, %eax
jne 0x39531
movl $0x1, -0x5c(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x39550
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x39b90
cmpl $0x0, %eax
jne 0x39550
movl $0x1, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x395cf
movq -0x40(%rbp), %rax
movl 0x10(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movq -0x58(%rbp), %rax
movq %rax, -0xd0(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq %rcx, -0x68(%rbp)
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
movq -0x58(%rbp), %rax
movq %rax, -0xc8(%rbp)
movabsq $-0x7000000000000, %rdi # imm = 0xFFF9000000000000
callq 0x7b460
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x58(%rbp)
jmp 0x394fe
jmp 0x395e2
jmp 0x395e4
movq -0x18(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x393ae
movq $0x0, -0x8(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x98(%rax), %rax
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq -0x10(%rbp), %rax
je 0x396d4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x300, %eax            # imm = 0x300
cmpl $0x0, %eax
je 0x39654
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
movl %ecx, (%rax)
jmp 0x396c7
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0xb0(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0xb0(%rax)
movq -0x10(%rbp), %rdi
callq 0x39c70
xorl %eax, %eax
cmpq -0x8(%rbp), %rax
je 0x39695
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x396be
movq -0x18(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq -0xd8(%rbp), %rcx
movq %rcx, 0x98(%rax)
movq -0x10(%rbp), %rdi
callq 0x120b0
movq -0x18(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x39614
movq $0x0, -0x8(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x90(%rax), %rax
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq -0x10(%rbp), %rax
je 0x397b7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x300, %eax            # imm = 0x300
cmpl $0x0, %eax
je 0x39737
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
movl %ecx, (%rax)
jmp 0x397aa
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0xb0(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0xb0(%rax)
movq -0x10(%rbp), %rdi
callq 0x39c70
xorl %eax, %eax
cmpq -0x8(%rbp), %rax
je 0x39778
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x397a1
movq -0x18(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq -0xe0(%rbp), %rcx
movq %rcx, 0x90(%rax)
movq -0x10(%rbp), %rdi
callq 0x120b0
movq -0x18(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x396f7
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x288(%rax), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0xe4(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, %rcx
movl -0xe4(%rbp), %eax
cmpl 0x27c(%rcx), %eax
jge 0x39b84
xorl %eax, %eax
testb $0x1, %al
jne 0x3980f
jmp 0x39854
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x3982f
jmp 0x39883
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x39883
jmp 0x39b74
movq -0x78(%rbp), %rcx
movslq -0x7c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq (%rcx), %rax
movabsq $-0x1000000000000, %rcx # imm = 0xFFFF000000000000
cmpq %rcx, %rax
jne 0x39b74
xorl %eax, %eax
testb $0x1, %al
jne 0x3988b
jmp 0x398d6
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x398af
jmp 0x399a6
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x399a6
jmp 0x39906
movq -0x78(%rbp), %rcx
movslq -0x7c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq 0x8(%rcx), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
je 0x399a6
xorl %eax, %eax
testb $0x1, %al
jne 0x3990e
jmp 0x39955
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x3992f
jmp 0x39985
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x39985
jmp 0x39b33
movq -0x78(%rbp), %rcx
movslq -0x7c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq 0x8(%rcx), %rax
movabsq $-0x7000000000000, %rcx # imm = 0xFFF9000000000000
cmpq %rcx, %rax
jne 0x39b33
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0x39b33
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x7b260
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0x13150
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x39a74
movq -0x88(%rbp), %rax
addq $-0x20, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x39a64
jmp 0x39a02
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq -0x90(%rbp), %rdi
addq $0x20, %rdi
movq -0x90(%rbp), %rcx
movq 0x18(%rcx), %rsi
callq *%rax
cmpl $0x0, %eax
je 0x39a60
jmp 0x39a30
movq 0x765b9(%rip), %rax     # 0xafff0
movq (%rax), %rdi
leaq 0x475d3(%rip), %rsi     # 0x81014
movl $0x1f8, %edx            # imm = 0x1F8
leaq 0x51303(%rip), %rcx     # 0x8ad50
leaq 0x5130a(%rip), %r8      # 0x8ad5e
movb $0x0, %al
callq 0x125f0
callq 0x12100
jmp 0x39a62
jmp 0x39a64
movq -0x88(%rbp), %rdi
addq $-0x20, %rdi
callq 0x120b0
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0xf8(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq %rax, %rcx
movq -0xf8(%rbp), %rax
movq %rcx, -0x98(%rbp)
movq -0x98(%rbp), %rcx
movq %rcx, (%rax)
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0xf0(%rbp)
movabsq $-0x7000000000000, %rdi # imm = 0xFFF9000000000000
callq 0x7b460
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movq %rcx, -0xa0(%rbp)
movq -0xa0(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movl 0x280(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x280(%rax)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movl 0x278(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x278(%rax)
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x100(%rbp)
movabsq $-0x7000000000000, %rdi # imm = 0xFFF9000000000000
callq 0x7b460
movq %rax, %rcx
movq -0x100(%rbp), %rax
movq %rcx, -0xa8(%rbp)
movq -0xa8(%rbp), %rcx
movq %rcx, 0x8(%rax)
jmp 0x39b76
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x397d9
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)