// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x88(%rbp)
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1263d3
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x12637c
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x12637c
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x12637e
jmp 0x1263c2
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x1263c0
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movb $0x1, (%rax,%rcx)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x126386
jmp 0x1263c2
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x126328
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x12648e
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x126437
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x126437
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x126439
jmp 0x12647d
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x12647b
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movb $0x1, (%rax,%rcx)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x126441
jmp 0x12647d
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1263e3
movq $0x0, -0x38(%rbp)
movq $0x0, -0x58(%rbp)
leaq 0x29e353(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x148(%rax)
je 0x1264c7
leaq 0x29e343(%rip), %rax    # 0x3c47f8
cvtsi2sdl 0x144(%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
jmp 0x1264ea
leaq 0x29e32a(%rip), %rax    # 0x3c47f8
cvtsi2sdl 0x144(%rax), %xmm0
movsd 0x260362(%rip), %xmm1   # 0x386840
divsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd 0x25bafe(%rip), %xmm2   # 0x381ff8
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rcx
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0x58(%rbp)
cmpq $0x40, -0x58(%rbp)
jae 0x126536
movq $0x40, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl %eax, %esi
movsd 0x258ae8(%rip), %xmm0   # 0x37f030
callq 0xe62d0
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x126678
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x1265ad
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x1265ad
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1265b2
jmp 0x126667
movq $0x0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x12660c
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
cmpb $0x0, (%rax,%rcx)
je 0x1265fc
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x1265fe
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1265c2
cmpq $0x0, -0x60(%rbp)
jbe 0x126665
movaps 0x25b9f6(%rip), %xmm1   # 0x382010
movq -0x60(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x25b9f5(%rip), %xmm1   # 0x382020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
cvtsi2sd %rax, %xmm1
movsd 0x2589c2(%rip), %xmm2   # 0x37f010
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x126665
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x125e20
jmp 0x126667
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x126559
movq -0x8(%rbp), %rsi
leaq -0x38(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0xf6030
movq $0x0, -0x80(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1268f7
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x1266f8
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x1266f8
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1266fd
jmp 0x1268e6
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
cmpq -0x28(%rbp), %rax
jb 0x12671d
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
cmpq -0x30(%rbp), %rax
jae 0x126722
jmp 0x1268e6
movq $0x0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x12677c
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
cmpb $0x0, (%rax,%rcx)
je 0x12676c
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x12676e
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x126732
cmpq $0x0, -0x60(%rbp)
jbe 0x1267cd
movaps 0x25b886(%rip), %xmm1   # 0x382010
movq -0x60(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x25b885(%rip), %xmm1   # 0x382020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
cvtsi2sd %rax, %xmm1
movsd 0x258852(%rip), %xmm2   # 0x37f010
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1267cd
jmp 0x1268e6
movq $0x0, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x126870
leaq 0x29ead4(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x126829
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
leaq 0x29eaa0(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x2, %eax
jne 0x12685d
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x12685f
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1267e5
movq -0x68(%rbp), %rax
cmpq -0x70(%rbp), %rax
jbe 0x1268b0
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x126060
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x1268e4
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x126060
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x1268e6
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1266a4
movq -0x38(%rbp), %rdi
callq 0xcd6f0
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x1269e3
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rdi
callq 0x2210
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq $0x0, 0x28(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x4(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x4(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xcdd10
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xce020
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x30(%rax)
je 0x1269e1
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x30(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x30(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rdx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x2100
jmp 0x1269e3
cmpq $0x0, -0x80(%rbp)
je 0x126abe
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rdi
callq 0x2210
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq $0x0, 0x28(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x4(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x4(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xcdd10
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xce020
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x30(%rax)
je 0x126abc
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x30(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x30(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rdx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x2100
jmp 0x126abe
movq -0x88(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nop