// File: /workspace/github_cpp_makefile_star2_O2/yangwanyuan[P]HLKVDS/src/GcManager.cc
// Function: hlkvds::GcManager::doMerge(std::multimap<unsigned int, unsigned int, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int>>>&)
void GcManager::FullGC() {
    std::unique_lock < std::mutex > lck_gc(gcMtx_, std::defer_lock);

    __DEBUG("Begin do Full GC!");
    uint32_t free_before = vol_->GetTotalFreeSegs();
    uint32_t free_after = 0;
    uint32_t used_total = 0;

    uint32_t seg_num = vol_->GetNumberOfSeg();
    uint32_t total_free = 0;
    uint64_t theory_size = 0;
    uint32_t free_seg_num = 0;
    uint32_t used_seg_num = 0;
    uint64_t used_size = 0;

    while (true) {
        lck_gc.lock();
        std::multimap < uint32_t, uint32_t > cands_map;
        vol_->SortSegsByUtils(cands_map, options_.seg_full_rate);
        if (cands_map.size() < SEG_RESERVED_FOR_GC) {
            free_after = vol_->GetTotalFreeSegs();
            used_total = vol_->GetNumberOfSeg() - free_after;
            __DEBUG("End do Full GC! befor have %u segment free, after do full GC now have %u segments free, now used %u segments!", free_before, free_after, used_total);
            break;
        }

        total_free = doMerge(cands_map);
        theory_size = idxMgr_->GetDataTheorySize();
        free_seg_num = vol_->GetTotalFreeSegs();
        used_seg_num = seg_num - free_seg_num;
        used_size = (uint64_t) vol_->GetSegmentSize()
                * (uint64_t) used_seg_num;

        __DEBUG("complete once merge, and this merge free %u segments, theory_size is %lu Byte, used Segments total is %u, occur space is %lu, total seg is %u, free seg is %u", total_free, theory_size, used_seg_num, used_size, seg_num, free_seg_num);
        cands_map.clear();
        lck_gc.unlock();
    } __DEBUG("End do Full GC! total free %u segments", free_after - free_before);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
andq $0x0, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x50(%rsp), %r14
movq %r14, 0x8(%r14)
movq %r14, (%r14)
andq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
pushq $0x50
popq %rdi
callq 0x6410
movq %rax, %r12
movq (%rbx), %rsi
movq %rbx, 0x8(%rsp)
movq 0x8(%rbx), %rdx
movq %rax, %rdi
callq 0x19436
movq 0x18(%r15), %rbp
addq $0x8, %r15
movq %r15, 0x30(%rsp)
leaq 0x38(%rsp), %r15
cmpq 0x30(%rsp), %rbp
movq %rbp, %rbx
je 0xd916
movl 0x24(%rbp), %esi
movl %esi, (%rsp)
movq 0x8(%rsp), %rdi
movq %r14, %rdx
callq 0xdd3c
testb %al, %al
je 0xd792
movq 0x50(%rsp), %r13
cmpq %r14, %r13
je 0xd785
movq 0x10(%r13), %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0x18962
testb %al, %al
je 0xd7a2
movq %r12, %rdi
movq %rbp, %rsi
callq 0x1897c
leaq 0x10(%r13), %rsi
movq %r15, %rdi
callq 0xe040
movq (%r13), %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0xe04c
movq %rbp, %r13
movq %rbx, %rbp
jmp 0xd73f
leaq 0x10(%rsp), %rdi
movq %rsp, %rsi
callq 0xe05a
movq %rbp, %rdi
callq 0x62c0
movq %rax, %rbp
jmp 0xd715
movl (%rsp), %ebp
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %rsp, %rsi
callq 0x1df64
movl (%rsp), %eax
movl %eax, (%r12)
movq %r12, %rdi
callq 0x18a22
testb %al, %al
je 0xd91d
movl 0x18(%r12), %edx
subl 0x14(%r12), %edx
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movl (%rsp), %esi
callq 0x1df82
movq %r12, %rdi
callq 0x19452
movq 0x10(%rsp), %r15
cmpq 0x18(%rsp), %r15
je 0xd810
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movl (%r15), %esi
callq 0x1df78
addq $0x4, %r15
jmp 0xd7f3
movq %r12, %rdi
callq 0x18894
movq %r12, %rdi
callq 0x63f0
leaq 0x38(%rsp), %rsi
callq 0xddd2
movq 0x18(%rsp), %r15
subq 0x10(%rsp), %r15
shrq $0x2, %r15
decl %r15d
cmpq 0x30(%rsp), %rbx
je 0xd8e6
pushq $0x50
popq %rdi
callq 0x6410
movq %rax, %r12
movq 0x8(%rsp), %rbx
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %rax, %rdi
callq 0x19436
movq (%rbx), %rdi
leaq 0x4(%rsp), %rsi
callq 0x1df64
movq %r14, %r13
movq (%r13), %r13
cmpq %r14, %r13
je 0xd88c
movq 0x10(%r13), %rsi
movq %r12, %rdi
callq 0x1897c
jmp 0xd875
movl 0x4(%rsp), %eax
movl %eax, (%r12)
movq %r12, %rdi
callq 0x18a22
testb %al, %al
je 0xd9a9
movl 0x18(%r12), %edx
subl 0x14(%r12), %edx
movq (%rbx), %rdi
movl 0x4(%rsp), %esi
callq 0x1df82
movq %r12, %rdi
callq 0x19452
movq (%rbx), %rdi
movl %ebp, %esi
callq 0x1df78
movq %r12, %rdi
callq 0x18894
movq %r12, %rdi
callq 0x63f0
leaq 0x50(%rsp), %rsi
callq 0xddd2
leaq 0x38(%rsp), %rdi
callq 0xe0c8
leaq 0x50(%rsp), %rdi
callq 0xe0c8
leaq 0x10(%rsp), %rdi
callq 0xe11a
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0xd7a5
movq 0x246b4(%rip), %r13     # 0x31fd8
movq (%r13), %r14
callq 0x63c0
leaq 0x11971(%rip), %rsi     # 0x1f2a5
leaq 0x1206d(%rip), %rcx     # 0x1f9a8
leaq 0x1206e(%rip), %r8      # 0x1f9b0
xorl %r15d, %r15d
movq %r14, %rdi
movq %rax, %rdx
movl $0xb7, %r9d
xorl %eax, %eax
callq 0x6580
movq (%r13), %rcx
leaq 0x1205e(%rip), %rdi     # 0x1f9c1
pushq $0x38
popq %rsi
pushq $0x1
popq %rdx
callq 0x6750
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0x64b0
movq %r12, %rdi
callq 0x18894
movq %r12, %rdi
callq 0x63f0
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movl (%rsp), %esi
callq 0x1df6e
leaq 0x38(%rsp), %rsi
callq 0xddd2
jmp 0xd8dc
movq 0x24628(%rip), %r13     # 0x31fd8
movq (%r13), %r14
callq 0x63c0
leaq 0x118e5(%rip), %rsi     # 0x1f2a5
leaq 0x11fe1(%rip), %rcx     # 0x1f9a8
leaq 0x11fe2(%rip), %r8      # 0x1f9b0
movq %r14, %rdi
movq %rax, %rdx
movl $0xe0, %r9d
xorl %eax, %eax
callq 0x6580
movq (%r13), %rdi
leaq 0x1200e(%rip), %rsi     # 0x1f9fa
movl %r15d, %edx
xorl %eax, %eax
callq 0x6580
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0x64b0
movq %r12, %rdi
callq 0x18894
movq %r12, %rdi
callq 0x63f0
movq (%rbx), %rdi
movl 0x4(%rsp), %esi
callq 0x1df6e
jmp 0xd8dc
jmp 0xda27
jmp 0xda42
movq %rax, %rbx
movq %r12, %rdi
callq 0x63f0
jmp 0xda45
jmp 0xda42
jmp 0xda42
jmp 0xda42
jmp 0xda42
jmp 0xda42
jmp 0xda42
jmp 0xda42
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xe0c8
leaq 0x50(%rsp), %rdi
callq 0xe0c8
leaq 0x10(%rsp), %rdi
callq 0xe11a
movq %rbx, %rdi
callq 0x6680
nop