// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_poly_ug(asg_t*, ma_sub_t*, ma_hit_t_alloc*, ma_hit_t_alloc*, int, int, R_to_U*, bub_label_t*)
ma_ug_t *get_poly_ug(asg_t *sg, ma_sub_t* coverage_cut, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, 
int max_hang, int min_ovlp, R_to_U* ruIndex, bub_label_t* b_mask_t)
{
    kvec_asg_arc_t_warp new_rtg_edges, d_edges;
    kv_init(new_rtg_edges.a); kv_init(d_edges.a);

    ma_ug_t *ug = ma_ug_gen_primary(sg, PRIMARY_LABLE);

    uint8_t* is_r_het = NULL;
    CALLOC(is_r_het, sg->n_seq);
    set_r_het_flag(ug, sg, coverage_cut, sources, ruIndex, is_r_het);

    adjust_utg_advance(sg, ug, reverse_sources, ruIndex, b_mask_t, is_r_het);
    asg_t* nsg = (*ug).g;
    uint32_t v, n_vtx = nsg->n_seq;
    for (v = 0; v < n_vtx; ++v)
    {
        if(nsg->seq[v].del) continue;
        nsg->seq[v].c = PRIMARY_LABLE;
    }
    delete_useless_nodes(&ug);
    renew_utg(&ug, sg, NULL); 

    ma_ug_seq(ug, sg, coverage_cut, sources, &new_rtg_edges, max_hang, min_ovlp, &d_edges, 1);

    kv_destroy(new_rtg_edges.a);  kv_destroy(d_edges.a);
    horder_clean_sg_by_utg(sg, ug);
    free(is_r_het);
    return ug;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0xe7ae0
movq %rax, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq 0x10(%rbp), %r8
movq -0x78(%rbp), %r9
callq 0xfc080
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq 0x18(%rbp), %r8
movq -0x78(%rbp), %r9
callq 0x10e9e0
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x88(%rbp)
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x88(%rbp), %eax
jae 0x10e94f
movq -0x80(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x84(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x10e92b
jmp 0x10e93e
movq -0x80(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x84(%rbp), %ecx
movb $0x0, 0x4(%rax,%rcx,8)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x10e902
leaq -0x70(%rbp), %rdi
callq 0x10ea80
movq -0x8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0xf6030
movq -0x70(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x24(%rbp), %r9d
movl -0x28(%rbp), %r10d
leaq -0x48(%rbp), %r8
leaq -0x68(%rbp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
callq 0xed140
movq -0x38(%rbp), %rdi
callq 0x2210
movq -0x58(%rbp), %rdi
callq 0x2210
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x2354a0
movq -0x78(%rbp), %rdi
callq 0x2210
movq -0x70(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)