// File: /workspace/github_c_makefile_star2_O3/jiribenes[P]scheme/src/vm.c
// Function: vm_gc
void vm_gc(vm_t *vm) {
#if NOGC
    return;
#endif  // NOGC
#if DEBUG
    fprintf(stdout, "GC started\n");
    size_t allocated_prev = vm->allocated;
    double time_start = (double) clock() / CLOCKS_PER_SEC;
#endif  // DEBUG
    vm->allocated = 0;
    markall(vm);
    ptrvalue_t **head = &vm->head;
    while (*head != NULL) {
        if (!((*head)->gcmark)) {
            ptrvalue_t *not_found = *head;
            *head = not_found->next;
            ptr_free(vm, not_found);
        } else {
            (*head)->gcmark = false;
            vm->allocated += vm_size(vm, PTR_VAL(*head));
            head = &(*head)->next;
        }
    }
    vm->gc_threshold = vm->allocated * (1 + vm->config.heap_growth);
    if (vm->gc_threshold < vm->config.heap_size_min) {
        vm->gc_threshold = vm->config.heap_size_min;
    }
#if DEBUG
    double time_delta = ((double) clock() / CLOCKS_PER_SEC) - time_start;
    fprintf(stdout, "GC finished: %zuB previously, %zuB now (%zuB gc'd), "
                    "new threshold at %zuB! Time delta: %.3lfs.\n",
            allocated_prev, vm->allocated, (allocated_prev - vm->allocated),
            vm->gc_threshold, time_delta);
#endif  // DEBUG
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
movabsq $-0x4000000000000, %r14 # imm = 0xFFFC000000000000
movq $0x0, 0x8(%rdi)
movq 0x50(%rdi), %rsi
orq %r14, %rsi
callq 0x5899
movq 0x58(%rbx), %rax
testq %rax, %rax
je 0x4fb3
movq 0x28(%rax), %rsi
movq %rbx, %rdi
callq 0x5899
cmpq $0x0, 0x78(%rbx)
je 0x4fd9
xorl %r15d, %r15d
movq 0x80(%rbx,%r15,8), %rsi
orq %r14, %rsi
movq %rbx, %rdi
callq 0x5899
incq %r15
cmpq 0x78(%rbx), %r15
jb 0x4fbd
movq 0x68(%rbx), %rsi
movq %rbx, %rdi
callq 0x5899
movq (%rbx), %rsi
testq %rsi, %rsi
je 0x509b
movabsq $0x3ffffffffffff, %r15  # imm = 0x3FFFFFFFFFFFF
leaq 0x1cfd(%rip), %r14      # 0x6cff
leaq 0x1a87(%rip), %r12      # 0x6a90
movq %rbx, %r13
cmpb $0x0, 0x4(%rsi)
je 0x5034
movb $0x0, 0x4(%rsi)
movq %rsi, %rax
andq %r15, %rax
movl (%rax), %ecx
cmpq $0x7, %rcx
ja 0x5070
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movl $0x20, %eax
jmp 0x5083
movq 0x8(%rsi), %rax
movq %rax, (%r13)
movq %rbx, %rdi
callq 0x45b4
jmp 0x508e
movl $0x30, %eax
jmp 0x5083
movl 0x10(%rax), %eax
incl %eax
addq $0x20, %rax
jmp 0x5083
movl 0x10(%rax), %eax
leaq 0x20(,%rax,8), %rax
jmp 0x5083
movl 0x10(%rax), %eax
incl %eax
addq $0x18, %rax
jmp 0x5083
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x4cc4
movq (%r13), %rsi
xorl %eax, %eax
addq %rax, 0x8(%rbx)
addq $0x8, %rsi
movq %rsi, %r13
movq (%r13), %rsi
testq %rsi, %rsi
jne 0x500c
movsd 0x8(%rbx), %xmm0
unpcklps 0x19b9(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x19c1(%rip), %xmm0     # 0x6a70
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x48(%rbx), %xmm0
addsd 0x19b8(%rip), %xmm0     # 0x6a80
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x19a8(%rip), %xmm0     # 0x6a88
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
movq 0x40(%rbx), %rax
cmpq %rdx, %rax
cmovaq %rax, %rdx
movq %rdx, 0x10(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq