// File: /workspace/github_c_makefile_star2_O3/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 0xa7db
movl 0x2c(%rbx), %eax
testl %eax, %eax
jle 0xa75b
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 0xa7bc
leaq 0x1c24(%rip), %rcx      # 0xc21c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%r13), %rsi
cmpq %r14, %rsi
jbe 0xa61f
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
movq %rbx, %rdi
callq 0xa8e3
movq 0x18(%r13), %rsi
cmpq %r14, %rsi
jbe 0xa750
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
jmp 0xa674
movslq 0x848(%r13), %r12
testq %r12, %r12
je 0xa670
xorl %ebp, %ebp
movq 0x40(%r13,%rbp,8), %rsi
cmpq %r14, %rsi
jbe 0xa668
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
movq %rbx, %rdi
callq 0xa8e3
incq %rbp
cmpq %rbp, %r12
jne 0xa649
movq 0x10(%r13), %rsi
movq %rbx, %rdi
callq 0xa8e3
jmp 0xa750
movq 0x18(%r13), %r12
testq %r12, %r12
je 0xa750
movq 0x10(%r13), %r13
xorl %ebp, %ebp
movq (%r13,%rbp,8), %rsi
cmpq %r14, %rsi
jbe 0xa6b3
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
movq %rbx, %rdi
callq 0xa8e3
incq %rbp
cmpq %rbp, %r12
jne 0xa694
jmp 0xa750
cmpl $0x0, 0x1c(%r13)
js 0xa750
movq $-0x1, %rbp
movl $0x8, %r12d
movq 0x10(%r13), %r15
movq -0x8(%r15,%r12), %rsi
testq %rsi, %rsi
je 0xa70c
movq %rbx, %rdi
callq 0xa8e3
movq (%r15,%r12), %rsi
cmpq %r14, %rsi
jbe 0xa70c
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq %rax, %rsi
movq %rbx, %rdi
callq 0xa8e3
movslq 0x1c(%r13), %rax
incq %rbp
addq $0x10, %r12
cmpq %rax, %rbp
jl 0xa6d8
jmp 0xa750
movq 0x10(%r13), %rsi
movq %rbx, %rdi
callq 0xa8e3
cmpl $0x0, 0x20(%r13)
jle 0xa750
xorl %r12d, %r12d
movq 0x18(%r13), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
callq 0xa8e3
incq %r12
movslq 0x20(%r13), %rax
cmpq %rax, %r12
jl 0xa734
movl 0x2c(%rbx), %eax
testl %eax, %eax
jg 0xa5d5
movq %rbx, %rdi
callq 0x4f83
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rax
cmpq %rax, %rsi
je 0xa7a2
leaq 0x10(%rbx), %r14
cmpb $0x1, 0x4(%rsi)
jne 0xa787
movb $0x0, 0x4(%rsi)
addq $0x8, %rsi
movq %rsi, %r14
jmp 0xa79a
movq 0x8(%rsi), %rax
movq %rax, (%r14)
movq %rbx, %rdi
callq 0xa49b
movq 0x18(%rbx), %rax
movq (%r14), %rsi
cmpq %rax, %rsi
jne 0xa774
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 0xeb2(%rip), %rdi       # 0xb675
leaq 0x1a6a(%rip), %rsi      # 0xc234
leaq 0x1a95(%rip), %rcx      # 0xc266
movl $0xfe, %edx
callq 0x20e0