// File: /workspace/github_c_makefile_star2_O1/mahrr[P]raven/src/mem.c
// Function: allocator_gc
void allocator_gc(Allocator *allocator) {
#ifdef DEBUG_TRACE_MEMORY
    puts("[Memory] --- GC Round Start ---");
    size_t size_before = allocator->bytes_allocated;
#endif

    // Mark all root objects, on stacks, globals ..etc.
    mark_roots(allocator);

    // Mark all reachable objects through the root objects.
    trace_references(allocator);

    // Remove the weak references of the interned strings table.
    table_remove_weak(&allocator->strings);

    // Free the memory of the unreachable objects.
    sweep(allocator);

    // Adjust the threshold of the next GC round.
    allocator->next_gc = allocator->bytes_allocated * GC_GROWTH_FACTOR;

#ifdef DEBUG_TRACE_MEMORY
    size_t size_current = allocator->bytes_allocated;
    size_t size_diff = size_before - size_current;
    size_t next_gc = allocator->next_gc;

    puts("[Memory] --- GC Round End ---");

    printf("[Memory] size collected: %ld (%ldkb)\n",
           size_diff, size_diff / 1000);
    printf("[Memory] size before: %ld (%ldkb)\n",
           size_before, size_before / 1000);
    printf("[Memory] size current: %ld (%ldkb)\n",
           size_current, size_current / 1000);

    printf("[Memory] next GC: %ld (%ldkb)\n",
           next_gc, next_gc / 1000);
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0xab98
movl 0x2c(%rbx), %eax
testl %eax, %eax
jle 0xab1e
movabsq $-0x4000000000001, %r14 # imm = 0xFFFBFFFFFFFFFFFF
movq 0x20(%rbx), %rcx
decl %eax
movl %eax, 0x2c(%rbx)
movq (%rcx,%rax,8), %r13
movl (%r13), %eax
decl %eax
cmpl $0x5, %eax
ja 0xab79
leaq 0x1821(%rip), %rcx      # 0xc1dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%r13), %rsi
cmpq %r14, %rsi
jbe 0xa9e2
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
movq %rbx, %rdi
callq 0xac9d
movq 0x18(%r13), %rsi
cmpq %r14, %rsi
jbe 0xab13
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
jmp 0xaa37
movslq 0x848(%r13), %r12
testq %r12, %r12
je 0xaa33
xorl %ebp, %ebp
movq 0x40(%r13,%rbp,8), %rsi
cmpq %r14, %rsi
jbe 0xaa2b
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
movq %rbx, %rdi
callq 0xac9d
incq %rbp
cmpq %rbp, %r12
jne 0xaa0c
movq 0x10(%r13), %rsi
movq %rbx, %rdi
callq 0xac9d
jmp 0xab13
movq 0x18(%r13), %r12
testq %r12, %r12
je 0xab13
movq 0x10(%r13), %r13
xorl %ebp, %ebp
movq (%r13,%rbp,8), %rsi
cmpq %r14, %rsi
jbe 0xaa76
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
movq %rbx, %rdi
callq 0xac9d
incq %rbp
cmpq %rbp, %r12
jne 0xaa57
jmp 0xab13
cmpl $0x0, 0x1c(%r13)
js 0xab13
movq $-0x1, %rbp
movl $0x8, %r12d
movq 0x10(%r13), %r15
movq -0x8(%r15,%r12), %rsi
testq %rsi, %rsi
je 0xaacf
movq %rbx, %rdi
callq 0xac9d
movq (%r15,%r12), %rsi
cmpq %r14, %rsi
jbe 0xaacf
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
movq %rbx, %rdi
callq 0xac9d
movslq 0x1c(%r13), %rax
incq %rbp
addq $0x10, %r12
cmpq %rax, %rbp
jl 0xaa9b
jmp 0xab13
movq 0x10(%r13), %rsi
movq %rbx, %rdi
callq 0xac9d
cmpl $0x0, 0x20(%r13)
jle 0xab13
xorl %r12d, %r12d
movq 0x18(%r13), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
callq 0xac9d
incq %r12
movslq 0x20(%r13), %rax
cmpq %rax, %r12
jl 0xaaf7
movl 0x2c(%rbx), %eax
testl %eax, %eax
jg 0xa998
movq %rbx, %rdi
callq 0x5258
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0xab5f
leaq 0x10(%rbx), %r14
cmpb $0x1, 0x4(%rsi)
jne 0xab47
movb $0x0, 0x4(%rsi)
addq $0x8, %rsi
movq %rsi, %r14
jmp 0xab56
movq 0x8(%rsi), %rax
movq %rax, (%r14)
movq %rbx, %rdi
callq 0xa863
movq (%r14), %rsi
cmpq 0x18(%rbx), %rsi
jne 0xab34
movq 0x30(%rbx), %rax
addq %rax, %rax
movq %rax, 0x38(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xab5(%rip), %rdi       # 0xb635
leaq 0x166d(%rip), %rsi      # 0xc1f4
leaq 0x1698(%rip), %rcx      # 0xc226
movl $0xfe, %edx
callq 0x20e0