// File: /workspace/github_c_makefile_star2_O1/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 0x5a2c
movq 0x58(%rbx), %rax
testq %rax, %rax
je 0x50d5
movq 0x28(%rax), %rsi
movq %rbx, %rdi
callq 0x5a2c
cmpq $0x0, 0x78(%rbx)
je 0x50fb
xorl %r15d, %r15d
movq 0x80(%rbx,%r15,8), %rsi
orq %r14, %rsi
movq %rbx, %rdi
callq 0x5a2c
incq %r15
cmpq 0x78(%rbx), %r15
jb 0x50df
movq 0x68(%rbx), %rsi
movq %rbx, %rdi
callq 0x5a2c
movq (%rbx), %rsi
testq %rsi, %rsi
je 0x51b7
movabsq $0x3ffffffffffff, %r15  # imm = 0x3FFFFFFFFFFFF
leaq 0x2bdb(%rip), %r14      # 0x7cff
leaq 0x2965(%rip), %r12      # 0x7a90
movq %rbx, %r13
cmpb $0x0, 0x4(%rsi)
je 0x5153
movb $0x0, 0x4(%rsi)
andq %r15, %rsi
movl (%rsi), %eax
cmpq $0x7, %rax
ja 0x518f
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x20, %eax
jmp 0x519e
movq 0x8(%rsi), %rax
movq %rax, (%r13)
movq %rbx, %rdi
callq 0x46d0
jmp 0x51aa
movl $0x30, %eax
jmp 0x519e
movl 0x10(%rsi), %eax
incl %eax
addq $0x20, %rax
jmp 0x519e
movl 0x10(%rsi), %eax
leaq 0x20(,%rax,8), %rax
jmp 0x519e
movl 0x10(%rsi), %eax
incl %eax
addq $0x18, %rax
jmp 0x519e
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x4e18
xorl %eax, %eax
addq %rax, 0x8(%rbx)
movq (%r13), %r13
addq $0x8, %r13
movq (%r13), %rsi
testq %rsi, %rsi
jne 0x512e
movsd 0x8(%rbx), %xmm0
unpcklps 0x289d(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x28a5(%rip), %xmm0     # 0x7a70
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x48(%rbx), %xmm0
addsd 0x289c(%rip), %xmm0     # 0x7a80
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x288c(%rip), %xmm0     # 0x7a88
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