// File: /workspace/github_cpp_makefile_star2_O3/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
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movl 0x14(%rdi), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %rcx, %rdi
xorl %esi, %esi
callq 0x20e0
movq (%r14), %rcx
testq %rcx, %rcx
je 0xdaa57
xorl %eax, %eax
movq 0x10(%r14), %rdx
leaq (%rax,%rax,4), %rsi
cmpl $0x0, 0x10(%rdx,%rsi,8)
je 0xdaa4f
leaq (%rdx,%rsi,8), %rdx
cmpl $0x0, 0xc(%rdx)
je 0xdaa4f
movq 0x18(%r14), %rsi
movq 0x20(%rsi), %rsi
cmpl $0x0, (%rsi,%rax,8)
js 0xdaa4f
xorl %ecx, %ecx
movq 0x18(%rdx), %rsi
movq (%rsi,%rcx,8), %rsi
shrq $0x21, %rsi
movb $0x1, (%r13,%rsi)
incq %rcx
movl 0x10(%rdx), %esi
cmpq %rsi, %rcx
jb 0xdaa2f
movq (%r14), %rcx
incq %rax
cmpq %rcx, %rax
jb 0xdaa06
movq (%rbx), %rcx
testq %rcx, %rcx
je 0xdaab2
xorl %eax, %eax
movq 0x10(%rbx), %rdx
leaq (%rax,%rax,4), %rsi
cmpl $0x0, 0x10(%rdx,%rsi,8)
je 0xdaaaa
leaq (%rdx,%rsi,8), %rdx
cmpl $0x0, 0xc(%rdx)
je 0xdaaaa
movq 0x18(%rbx), %rsi
movq 0x20(%rsi), %rsi
cmpl $0x0, (%rsi,%rax,8)
js 0xdaaaa
xorl %ecx, %ecx
movq 0x18(%rdx), %rsi
movq (%rsi,%rcx,8), %rsi
shrq $0x21, %rsi
movb $0x1, (%r13,%rsi)
incq %rcx
movl 0x10(%rdx), %esi
cmpq %rsi, %rcx
jb 0xdaa8a
movq (%rbx), %rcx
incq %rax
cmpq %rcx, %rax
jb 0xdaa61
leaq 0x1bac9f(%rip), %rax    # 0x295758
cmpl $0x0, 0x148(%rax)
xorps %xmm0, %xmm0
cvtsi2sdl 0x144(%rax), %xmm0
jne 0xdaad5
divsd 0x15b28b(%rip), %xmm0   # 0x235d60
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x156823(%rip), %xmm0   # 0x231308
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
addq %rdx, %rdx
cmpq $0x41, %rdx
movl $0x40, %esi
cmovaeq %rdx, %rsi
movsd 0x156adc(%rip), %xmm0   # 0x2315e8
movq %rbp, %rdi
callq 0xb18e6
movq %rax, %r15
movq %rax, 0x28(%rsp)
movq (%rax), %rax
testq %rax, %rax
je 0xdabf9
xorl %r12d, %r12d
movq 0x15674d(%rip), %xmm3   # 0x231280
movapd 0x156755(%rip), %xmm4   # 0x231290
movsd 0x156a3d(%rip), %xmm5   # 0x231580
movq 0x10(%r15), %rdx
leaq (%r12,%r12,4), %rsi
movl 0x10(%rdx,%rsi,8), %ecx
testq %rcx, %rcx
je 0xdabed
leaq (%rdx,%rsi,8), %rdx
cmpl $0x0, 0xc(%rdx)
je 0xdabed
movq 0x18(%r15), %rsi
movq 0x20(%rsi), %rsi
cmpl $0x0, (%rsi,%r12,8)
js 0xdabed
movq 0x18(%rdx), %rsi
xorl %edx, %edx
xorl %edi, %edi
movq (%rsi,%rdi,8), %r8
shrq $0x21, %r8
cmpb $0x1, (%r13,%r8)
sbbq $-0x1, %rdx
incq %rdi
cmpq %rdi, %rcx
jne 0xdab7d
testq %rdx, %rdx
je 0xdabed
movq %rdx, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm4, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
xorps %xmm2, %xmm2
cvtsi2sd %rcx, %xmm2
addsd %xmm0, %xmm1
mulsd %xmm5, %xmm2
ucomisd %xmm2, %xmm1
jb 0xdabed
movq %r15, %rdi
movq %r12, %rsi
callq 0xda616
movsd 0x1569a6(%rip), %xmm5   # 0x231580
movapd 0x1566ae(%rip), %xmm4   # 0x231290
movq 0x156696(%rip), %xmm3   # 0x231280
movq (%r15), %rax
incq %r12
cmpq %rax, %r12
jb 0xdab43
leaq 0x28(%rsp), %r15
leaq 0x30(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0xbb7a4
movq (%r15), %r12
cmpq $0x0, (%r12)
je 0xdae76
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movq 0x18(%rsp), %r8
movq 0x10(%r12), %rcx
leaq (,%rbp,4), %rdx
addq %rbp, %rdx
movl 0x10(%rcx,%rdx,8), %eax
testq %rax, %rax
je 0xdad71
leaq (%rcx,%rdx,8), %r15
cmpl $0x0, 0xc(%r15)
je 0xdad71
movq 0x18(%r12), %rcx
movq 0x20(%rcx), %rcx
cmpl $0x0, (%rcx,%rbp,8)
js 0xdad71
cmpq %r8, %rax
jb 0xdad71
movl (%r15), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq 0x20(%rsp), %rcx
jb 0xdad71
movq 0x18(%r15), %rcx
xorl %edx, %edx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
shrq $0x21, %rdi
cmpb $0x1, (%r13,%rdi)
sbbq $-0x1, %rdx
incq %rsi
cmpq %rsi, %rax
jne 0xdaca1
testq %rdx, %rdx
je 0xdacf7
movq %rdx, %xmm0
punpckldq 0x1565b3(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1565bb(%rip), %xmm0   # 0x231290
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
addsd %xmm0, %xmm1
mulsd 0x15688f(%rip), %xmm2   # 0x231580
ucomisd %xmm2, %xmm1
jae 0xdad71
leaq 0x1bb532(%rip), %rdx    # 0x296230
movq 0x28(%rdx), %rdx
xorl %esi, %esi
xorl %edi, %edi
xorl %r8d, %r8d
movq (%rcx,%r8,8), %r9
shrq $0x21, %r9
movb (%rdx,%r9), %r9b
xorl %r10d, %r10d
cmpb $0x1, %r9b
sete %r10b
addq %r10, %rdi
xorl %r10d, %r10d
cmpb $0x2, %r9b
sete %r10b
addq %r10, %rsi
incq %r8
cmpq %r8, %rax
jne 0xdad09
cmpq %rsi, %rdi
jbe 0xdad50
movq %r14, %rdi
movq %r15, %rsi
callq 0xda85f
incq 0x10(%rsp)
jmp 0xdad60
movq %rbx, %rdi
movq %r15, %rsi
callq 0xda85f
incq 0x8(%rsp)
movl (%r15), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%rsp)
movq 0x18(%rsp), %r8
incq %rbp
cmpq (%r12), %rbp
jb 0xdac3d
movq %r12, %rdi
callq 0xa0761
cmpq $0x0, 0x10(%rsp)
je 0xdadfb
movq 0x18(%r14), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x18(%r14), %rax
movq $0x0, 0x28(%rax)
andb $0x7f, 0x7(%rax)
movq 0x18(%r14), %rdi
callq 0xa0a7d
movq 0x18(%r14), %r15
movq %r15, %rdi
callq 0xa0ab6
movq %r15, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%r15)
movq 0x18(%r14), %rax
movq 0x30(%rax), %rdi
testq %rdi, %rdi
je 0xdadfb
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 0xdae70
movq 0x18(%rbx), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x18(%rbx), %rax
movq $0x0, 0x28(%rax)
andb $0x7f, 0x7(%rax)
movq 0x18(%rbx), %rdi
callq 0xa0a7d
movq 0x18(%rbx), %r14
movq %r14, %rdi
callq 0xa0ab6
movq %r14, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%r14)
movq 0x18(%rbx), %rax
movq 0x30(%rax), %rdi
testq %rdi, %rdi
je 0xdae70
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 (%rsp), %rax
jmp 0xdae80
movq %r12, %rdi
callq 0xa0761
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq