// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbp
andq $0x0, 0x8(%rdi)
movabsq $-0x4000000000000, %r14 # imm = 0xFFFC000000000000
movq 0x50(%rdi), %rsi
orq %r14, %rsi
callq 0x50f1
movq 0x58(%rbp), %rax
testq %rax, %rax
je 0x48a5
movq 0x28(%rax), %rsi
movq %rbp, %rdi
callq 0x50f1
xorl %ebx, %ebx
cmpq 0x78(%rbp), %rbx
jae 0x48c5
movq 0x80(%rbp,%rbx,8), %rsi
orq %r14, %rsi
movq %rbp, %rdi
callq 0x50f1
incq %rbx
jmp 0x48a7
movq 0x68(%rbp), %rsi
movq %rbp, %rdi
callq 0x50f1
movabsq $0x3ffffffffffff, %r15  # imm = 0x3FFFFFFFFFFFF
pushq $0x20
popq %r12
leaq 0x218a(%rip), %r13      # 0x6a70
pushq $0x30
popq %r14
movq %rbp, %rbx
movq (%rbx), %rsi
testq %rsi, %rsi
je 0x497f
cmpb $0x0, 0x4(%rsi)
jne 0x4910
movq 0x8(%rsi), %rax
movq %rax, (%rbx)
movq %rbp, %rdi
callq 0x3f0c
jmp 0x48ed
movb $0x0, 0x4(%rsi)
movq %rsi, %rax
andq %r15, %rax
movl (%rax), %ecx
cmpq $0x7, %rcx
ja 0x4959
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
movq %r12, %rax
jmp 0x496f
movq %r14, %rax
jmp 0x496f
movl 0x10(%rax), %eax
incl %eax
addq $0x20, %rax
jmp 0x496f
movl 0x10(%rax), %eax
leaq 0x20(,%rax,8), %rax
jmp 0x496f
movl 0x10(%rax), %eax
incl %eax
addq $0x18, %rax
jmp 0x496f
movq %rbp, %rdi
leaq 0x237c(%rip), %rsi      # 0x6cdf
xorl %eax, %eax
callq 0x45ec
movq (%rbx), %rsi
xorl %eax, %eax
addq %rax, 0x8(%rbp)
addq $0x8, %rsi
movq %rsi, %rbx
jmp 0x48ed
movsd 0x8(%rbp), %xmm0
unpcklps 0x20b5(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x20bd(%rip), %xmm0     # 0x6a50
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x48(%rbp), %xmm0
addsd 0x20b4(%rip), %xmm0     # 0x6a60
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x20a4(%rip), %xmm0     # 0x6a68
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
movq 0x40(%rbp), %rax
cmpq %rdx, %rax
cmovaq %rax, %rdx
movq %rdx, 0x10(%rbp)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq