// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: build_unitig_index(ma_ug_t*, int, unsigned long, unsigned long, unsigned long)
ha_ug_index* build_unitig_index(ma_ug_t *ug, int k, uint64_t up_occ, uint64_t low_occ, uint64_t thread_num)
{
    ha_ug_index* idx = NULL; CALLOC(idx, 1);
    pldat_t pl; pl.h = idx; pl.is_cnt = 1;
    double index_time = yak_realtime(), beg_time;
    init_ha_ug_index_opt(idx, ug, k, &pl, up_occ, low_occ, thread_num);

    beg_time = yak_realtime();
    pl.is_cnt = 1;
    parallel_count_hc_pt1(&pl);
    fprintf(stderr, "[M::%s::%.3f] ==> Counting\n", __func__, yak_realtime()-beg_time);

    beg_time = yak_realtime();
    hc_pt_t_gen(pl.h, NULL);
    fprintf(stderr, "[M::%s::%.3f] ==> Memory allocating\n", __func__, yak_realtime()-beg_time);

    beg_time = yak_realtime();
    pl.is_cnt = 0;
    parallel_count_hc_pt1(&pl);
    fprintf(stderr, "[M::%s::%.3f] ==> Filling pos\n", __func__, yak_realtime()-beg_time);

    beg_time = yak_realtime();
    hc_pt_t_gen(pl.h, &pl);
    fprintf(stderr, "[M::%s::%.3f] ==> Sorting pos\n", __func__, yak_realtime()-beg_time);

    fprintf(stderr, "[M::%s::%.3f] ==> HiC index has been built\n", __func__, yak_realtime()-index_time);
    
    uint64_t i;
    for (i = 0; i < idx->tot; i++)
    {
        kv_destroy(pl.cnt[i].a);
        kv_destroy(pl.buf[i].a);
    }
    free(pl.cnt); free(pl.buf);

    return idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %r15
movq %rcx, 0x8(%rsp)
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r12
pushq $0x1
popq %rdi
movl $0xc0, %esi
callq 0x2120
movq %rax, %rbx
leaq 0x18(%rsp), %r14
movq %rax, 0x10(%r14)
callq 0x1365ef
movsd %xmm0, 0x10(%rsp)
movq %r15, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %r14, %rcx
movq %r13, %r8
movq 0x8(%rsp), %r9
callq 0x13a3b1
callq 0x1365ef
movsd %xmm0, 0x8(%rsp)
movl $0x1, (%r14)
movq %r14, %rdi
callq 0x13b0ce
movq 0x28017e(%rip), %r13    # 0x294fe0
movq (%r13), %r12
callq 0x1365ef
subsd 0x8(%rsp), %xmm0
leaq 0x2264de(%rip), %rsi    # 0x23b356
leaq 0x2264f3(%rip), %r15    # 0x23b372
movq %r12, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
callq 0x1365ef
movsd %xmm0, 0x8(%rsp)
movq 0x10(%r14), %rdi
xorl %esi, %esi
callq 0x13af86
movq (%r13), %r12
callq 0x1365ef
subsd 0x8(%rsp), %xmm0
leaq 0x2264cd(%rip), %rsi    # 0x23b385
movq %r12, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
callq 0x1365ef
movsd %xmm0, 0x8(%rsp)
andl $0x0, (%r14)
movq %r14, %rdi
callq 0x13b0ce
movq (%r13), %r12
callq 0x1365ef
subsd 0x8(%rsp), %xmm0
leaq 0x2264b8(%rip), %rsi    # 0x23b3aa
movq %r12, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
callq 0x1365ef
movsd %xmm0, 0x8(%rsp)
movl 0x28(%r14), %edi
movq 0x10(%r14), %rax
movq 0x58(%rax), %rcx
leaq 0x1260d2(%rip), %rsi    # 0x13afef
movq %r14, %rdx
callq 0x108f2c
movq (%r13), %r14
callq 0x1365ef
subsd 0x8(%rsp), %xmm0
leaq 0x22648e(%rip), %rsi    # 0x23b3c9
movq %r14, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
movq (%r13), %r14
callq 0x1365ef
subsd 0x10(%rsp), %xmm0
leaq 0x22648a(%rip), %rsi    # 0x23b3e8
movq %r14, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
cmpq $0x0, 0x58(%rbx)
je 0x14fa2
pushq $0x10
popq %r14
xorl %r15d, %r15d
movq 0x30(%rsp), %rax
movq (%rax,%r14), %rdi
callq 0x2220
movq 0x38(%rsp), %rax
movq (%rax,%r14), %rdi
callq 0x2220
incq %r15
addq $0x18, %r14
cmpq 0x58(%rbx), %r15
jb 0x14f79
movq 0x30(%rsp), %rdi
callq 0x2220
movq 0x38(%rsp), %rdi
callq 0x2220
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq