// File: /workspace/github_cpp_makefile_star2_O1/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)
pushq $0x1
popq %rax
movl %eax, (%r14)
callq 0x1303c7
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 0x1341ec
callq 0x1303c7
movsd %xmm0, 0x8(%rsp)
pushq $0x1
popq %rax
movl %eax, (%r14)
movq %r14, %rdi
callq 0x134fad
movq 0x2748b4(%rip), %r13    # 0x289fe0
movq (%r13), %r12
callq 0x1303c7
subsd 0x8(%rsp), %xmm0
leaq 0x2199c4(%rip), %rsi    # 0x22f106
leaq 0x2199d9(%rip), %r15    # 0x22f122
movq %r12, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
callq 0x1303c7
movsd %xmm0, 0x8(%rsp)
movq 0x10(%r14), %rdi
xorl %esi, %esi
callq 0x134e65
movq (%r13), %r12
callq 0x1303c7
subsd 0x8(%rsp), %xmm0
leaq 0x2199b3(%rip), %rsi    # 0x22f135
movq %r12, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
callq 0x1303c7
movsd %xmm0, 0x8(%rsp)
andl $0x0, (%r14)
movq %r14, %rdi
callq 0x134fad
movq (%r13), %r12
callq 0x1303c7
subsd 0x8(%rsp), %xmm0
leaq 0x21999e(%rip), %rsi    # 0x22f15a
movq %r12, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
callq 0x1303c7
movsd %xmm0, 0x8(%rsp)
movl 0x28(%r14), %edi
movq 0x10(%r14), %rax
movq 0x58(%rax), %rcx
leaq 0x11f6e7(%rip), %rsi    # 0x134ece
movq %r14, %rdx
callq 0x1047b4
movq (%r13), %r14
callq 0x1303c7
subsd 0x8(%rsp), %xmm0
leaq 0x219974(%rip), %rsi    # 0x22f179
movq %r14, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
movq (%r13), %r14
callq 0x1303c7
subsd 0x10(%rsp), %xmm0
leaq 0x219970(%rip), %rsi    # 0x22f198
movq %r14, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
cmpq $0x0, 0x58(%rbx)
je 0x1586c
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 0x15843
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