// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: append_miss_nid(asg_t*, ma_ug_t*, ma_ug_t*, unsigned char*, unsigned long, unsigned long)
uint64_t append_miss_nid(asg_t *sg, ma_ug_t *hap0, ma_ug_t *hap1, uint8_t *ff, uint64_t len_cut, uint64_t occ_cut)
{
    ma_ug_t *ug = NULL; ma_utg_t *u; uint64_t k, z, pscut, n_set, fn, nfn, hap0n, hap1n, n_base = 0; 
    kvec_asg_arc_t_warp fe; memset(&fe, 0, sizeof(fe));
    memset(ff, 0, sizeof((*ff))*sg->n_seq);
    ug = hap0;
    for (k = 0; k < ug->u.n; k++) {
        u = &(ug->u.a[k]); 
        if((u->n == 0) || (u->m == 0) || (ug->g->seq[k].del)) continue;
        for (z = 0; z < u->n; z++) ff[u->a[z]>>33] = 1;
    }
    ug = hap1;
    for (k = 0; k < ug->u.n; k++) {
        u = &(ug->u.a[k]); 
        if((u->n == 0) || (u->m == 0) || (ug->g->seq[k].del)) continue;
        for (z = 0; z < u->n; z++) ff[u->a[z]>>33] = 1;
    }
    ug = NULL; pscut = 0;
    pscut = (asm_opt.hom_global_coverage_set?(asm_opt.hom_global_coverage):(((double)asm_opt.hom_global_coverage)/((double)HOM_PEAK_RATE)));
    pscut *= PHASE_SEF; if(pscut < PHASE_SEP) pscut = PHASE_SEP;
    ug = ma_ug_gen_phase(sg, pscut, PHASE_SEP_RATE);
    for (k = 0; k < ug->u.n; k++) {
        u = &(ug->u.a[k]); 
        if((u->n == 0) || (u->m == 0) || (ug->g->seq[k].del)) continue;
        for (z = n_set = 0; z < u->n; z++) {
            if(ff[u->a[z]>>33]) n_set++;
        }
        if((n_set > 0) && (n_set >= (u->n*0.2))) delete_ug_node(ug, k);
    }
    renew_utg((&ug), sg, &fe);

    for (k = hap0n = hap1n = 0; k < ug->u.n; k++) {
        u = &(ug->u.a[k]); 
        if((u->n == 0) || (u->m == 0) || (ug->g->seq[k].del)) continue;
        if((u->len < len_cut) || (u->n < occ_cut)) continue;
        for (z = n_set = 0; z < u->n; z++) {
            if(ff[u->a[z]>>33]) n_set++;
        }
        if((n_set > 0) && (n_set >= (u->n*0.2))) continue;
        for (z = fn = nfn = 0; z < u->n; z++) {
            if(R_INF.trio_flag[u->a[z]>>33] == FATHER) fn++;
            if(R_INF.trio_flag[u->a[z]>>33] == MOTHER) nfn++;
        }
        if(fn > nfn) {
            push_ma_utg_t(hap0, u); hap0n++; n_base += u->len;
        } else {
            push_ma_utg_t(hap1, u); hap1n++; n_base += u->len;
        }
    }
    ma_ug_destroy(ug); ug = NULL;
    if(hap0n) {
        ug = hap0; 
        free(ug->g->idx); ug->g->idx = 0; ug->g->is_srt = 0;
        asg_cleanup(ug->g); asg_symm(ug->g);
        if(ug->g->seq_vis) {
            REALLOC(ug->g->seq_vis, (ug->g->n_seq*2));
            memset(ug->g->seq_vis, 0, sizeof((*(ug->g->seq_vis)))*(ug->g->n_seq*2));
        }
    }
    if(hap1n) {
        ug = hap1; 
        free(ug->g->idx); ug->g->idx = 0; ug->g->is_srt = 0;
        asg_cleanup(ug->g); asg_symm(ug->g);
        if(ug->g->seq_vis) {
            REALLOC(ug->g->seq_vis, (ug->g->n_seq*2));
            memset(ug->g->seq_vis, 0, sizeof((*(ug->g->seq_vis)))*(ug->g->n_seq*2));
        }
    }
    return n_base;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x18(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %rbp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
movl 0x14(%rdi), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
movq %rcx, %rdi
xorl %esi, %esi
callq 0x20e0
cmpq (%r14), %r15
jae 0x9d599
movq 0x10(%r14), %rax
imulq $0x28, %r15, %rdx
movl 0x10(%rax,%rdx), %ecx
testl %ecx, %ecx
je 0x9d594
addq %rdx, %rax
cmpl $0x0, 0xc(%rax)
je 0x9d594
movq 0x18(%r14), %rdx
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%r15,8)
js 0x9d594
xorl %edx, %edx
movl %ecx, %ecx
cmpq %rcx, %rdx
jae 0x9d594
movq 0x18(%rax), %rcx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movb $0x1, (%r13,%rcx)
incq %rdx
movl 0x10(%rax), %ecx
jmp 0x9d573
incq %r15
jmp 0x9d544
xorl %eax, %eax
cmpq (%rbx), %rax
jae 0x9d5ef
movq 0x10(%rbx), %rcx
imulq $0x28, %rax, %rsi
movl 0x10(%rcx,%rsi), %edx
testl %edx, %edx
je 0x9d5ea
addq %rsi, %rcx
cmpl $0x0, 0xc(%rcx)
je 0x9d5ea
movq 0x18(%rbx), %rsi
movq 0x20(%rsi), %rsi
cmpl $0x0, (%rsi,%rax,8)
js 0x9d5ea
xorl %esi, %esi
movl %edx, %edx
cmpq %rdx, %rsi
jae 0x9d5ea
movq 0x18(%rcx), %rdx
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
movb $0x1, (%r13,%rdx)
incq %rsi
movl 0x10(%rcx), %edx
jmp 0x9d5c9
incq %rax
jmp 0x9d59b
leaq 0x1b6162(%rip), %rax    # 0x253758
cmpl $0x0, 0x148(%rax)
cvtsi2sdl 0x144(%rax), %xmm0
jne 0x9d60f
divsd 0x14a651(%rip), %xmm0   # 0x1e7c60
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x145c79(%rip), %xmm0   # 0x1e3298
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
addq %rdx, %rdx
cmpq $0x41, %rdx
pushq $0x40
popq %rsi
cmovaeq %rdx, %rsi
movsd 0x145ef4(%rip), %xmm0   # 0x1e3538
movq %rbp, %rdi
callq 0x773c3
movq %rax, %r15
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
cmpq (%r15), %r12
jae 0x9d6fd
movq 0x10(%r15), %rcx
imulq $0x28, %r12, %rdx
movl 0x10(%rcx,%rdx), %eax
testq %rax, %rax
je 0x9d6f5
addq %rdx, %rcx
cmpl $0x0, 0xc(%rcx)
je 0x9d6f5
movq 0x18(%r15), %rdx
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%r12,8)
js 0x9d6f5
movq 0x18(%rcx), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
cmpq %rsi, %rax
je 0x9d6b1
movq (%rdx,%rsi,8), %rdi
shrq $0x21, %rdi
cmpb $0x1, (%r13,%rdi)
sbbq $-0x1, %rcx
incq %rsi
jmp 0x9d695
testq %rcx, %rcx
je 0x9d6f5
movq %rcx, %xmm0
punpckldq 0x145bad(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x145bb5(%rip), %xmm0   # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
cvtsi2sd %rax, %xmm2
addsd %xmm0, %xmm1
mulsd 0x145dec(%rip), %xmm2   # 0x1e34d0
ucomisd %xmm2, %xmm1
jb 0x9d6f5
movq %r15, %rdi
movq %r12, %rsi
callq 0x9d229
incq %r12
jmp 0x9d657
leaq 0x28(%rsp), %r15
leaq 0x30(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x80328
xorl %ebp, %ebp
movq (%r15), %r12
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %r8
cmpq (%r12), %rbp
jae 0x9d876
movq 0x10(%r12), %r15
imulq $0x28, %rbp, %rcx
movl 0x10(%r15,%rcx), %eax
testq %rax, %rax
je 0x9d86e
addq %rcx, %r15
cmpl $0x0, 0xc(%r15)
je 0x9d86e
movq 0x18(%r12), %rcx
movq 0x20(%rcx), %rcx
cmpl $0x0, (%rcx,%rbp,8)
js 0x9d86e
cmpq %r8, %rax
jb 0x9d86e
movl (%r15), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq 0x20(%rsp), %rcx
jb 0x9d86e
movq 0x18(%r15), %rcx
xorl %esi, %esi
xorl %edx, %edx
cmpq %rsi, %rax
je 0x9d7b9
movq (%rcx,%rsi,8), %rdi
shrq $0x21, %rdi
cmpb $0x1, (%r13,%rdi)
sbbq $-0x1, %rdx
incq %rsi
jmp 0x9d79d
testq %rdx, %rdx
je 0x9d7f2
movq %rdx, %xmm0
punpckldq 0x145aa5(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x145aad(%rip), %xmm0   # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
cvtsi2sd %rax, %xmm2
addsd %xmm0, %xmm1
mulsd 0x145ce4(%rip), %xmm2   # 0x1e34d0
ucomisd %xmm2, %xmm1
jae 0x9d86e
leaq 0x1b6a37(%rip), %rdx    # 0x254230
movq 0x28(%rdx), %rdx
xorl %edi, %edi
xorl %esi, %esi
xorl %r8d, %r8d
cmpq %rdi, %rax
je 0x9d836
movq (%rcx,%rdi,8), %r9
shrq $0x21, %r9
movb (%rdx,%r9), %r9b
xorl %r10d, %r10d
cmpb $0x1, %r9b
sete %r10b
addq %r10, %rsi
xorl %r10d, %r10d
cmpb $0x2, %r9b
sete %r10b
addq %r10, %r8
incq %rdi
jmp 0x9d804
cmpq %r8, %rsi
jbe 0x9d84c
movq %r14, %rdi
movq %r15, %rsi
callq 0x9d3a0
incq (%rsp)
jmp 0x9d85c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9d3a0
incq 0x8(%rsp)
movl (%r15), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, 0x10(%rsp)
movq 0x18(%rsp), %r8
incq %rbp
jmp 0x9d736
movq %r12, %rdi
callq 0x6921d
cmpq $0x0, (%rsp)
je 0x9d8df
movq 0x18(%r14), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x18(%r14), %rax
andq $0x0, 0x28(%rax)
andb $0x7f, 0x7(%rax)
movq 0x18(%r14), %rdi
callq 0x694eb
movq 0x18(%r14), %rdi
callq 0x69638
movq 0x18(%r14), %rax
movq 0x30(%rax), %rdi
testq %rdi, %rdi
je 0x9d8df
movl 0x14(%rax), %esi
addl %esi, %esi
callq 0x2370
movq 0x18(%r14), %rcx
movq %rax, 0x30(%rcx)
movl 0x14(%rcx), %edx
addl %edx, %edx
movq %rax, %rdi
xorl %esi, %esi
callq 0x20e0
cmpq $0x0, 0x8(%rsp)
je 0x9d941
movq 0x18(%rbx), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x18(%rbx), %rax
andq $0x0, 0x28(%rax)
andb $0x7f, 0x7(%rax)
movq 0x18(%rbx), %rdi
callq 0x694eb
movq 0x18(%rbx), %rdi
callq 0x69638
movq 0x18(%rbx), %rax
movq 0x30(%rax), %rdi
testq %rdi, %rdi
je 0x9d941
movl 0x14(%rax), %esi
addl %esi, %esi
callq 0x2370
movq 0x18(%rbx), %rcx
movq %rax, 0x30(%rcx)
movl 0x14(%rcx), %edx
addl %edx, %edx
movq %rax, %rdi
xorl %esi, %esi
callq 0x20e0
movq 0x10(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq