// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
pushq $0x1
popq %rdi
movl $0xc0, %esi
callq 0x2120
movq %rax, %rbx
leaq 0x18(%rsp), %r12
movq %rax, 0x10(%r12)
callq 0xefea7
movsd %xmm0, 0x10(%rsp)
movq %r15, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
movq %r12, %rcx
movq %r13, %r8
movq 0x8(%rsp), %r9
callq 0xf39a0
callq 0xefea7
movsd %xmm0, 0x8(%rsp)
movl $0x1, (%r12)
movq %r12, %rdi
movq %r12, %rbp
callq 0xf46c3
movq 0x15e126(%rip), %r13    # 0x252fe0
movq (%r13), %r14
callq 0xefea7
subsd 0x8(%rsp), %xmm0
leaq 0xf8376(%rip), %rsi     # 0x1ed246
leaq 0xf838b(%rip), %r15     # 0x1ed262
movq %r14, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
callq 0xefea7
movsd %xmm0, 0x8(%rsp)
movq 0x10(%r12), %rdi
xorl %r12d, %r12d
xorl %esi, %esi
callq 0xf4579
movq (%r13), %r14
callq 0xefea7
subsd 0x8(%rsp), %xmm0
leaq 0xf8361(%rip), %rsi     # 0x1ed275
movq %r14, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
callq 0xefea7
movsd %xmm0, 0x8(%rsp)
andl $0x0, (%rbp)
movq %rbp, %rdi
callq 0xf46c3
movq (%r13), %r14
callq 0xefea7
subsd 0x8(%rsp), %xmm0
leaq 0xf834c(%rip), %rsi     # 0x1ed29a
movq %r14, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
callq 0xefea7
movsd %xmm0, 0x8(%rsp)
movq 0x10(%rbp), %rdi
movq %rbp, %rsi
callq 0xf4579
movq (%r13), %r14
callq 0xefea7
subsd 0x8(%rsp), %xmm0
leaq 0xf8331(%rip), %rsi     # 0x1ed2b9
movq %r14, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
movq (%r13), %r14
callq 0xefea7
subsd 0x10(%rsp), %xmm0
leaq 0xf832d(%rip), %rsi     # 0x1ed2d8
movq %r14, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x22b0
pushq $0x10
popq %r14
movq 0x30(%rsp), %rdi
cmpq 0x58(%rbx), %r12
jae 0xf4fe7
movq (%rdi,%r14), %rdi
callq 0x2220
movq 0x38(%rsp), %rax
movq (%rax,%r14), %rdi
callq 0x2220
incq %r12
addq $0x18, %r14
jmp 0xf4fbc
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