// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ug_ext_strict(asg64_v*, asg64_v*, ul_resolve_t*, usg_t*, unsigned int, unsigned char**, unsigned int**, unsigned long**, asg64_v*, asg64_v*)
uint32_t ug_ext_strict(asg64_v *ob, asg64_v *ub, ul_resolve_t *uidx, usg_t *ng, uint32_t max_ext, 
uint8_t **ff, uint32_t **ng_occ, uint64_t **i_idx, asg64_v *b64, asg64_v *ub64)
{
    // fprintf(stderr, "[M::%s::]\n", __func__);
    uint32_t k, i, n_vtx = ng->n<<1, a_n;
    REALLOC((*ff), n_vtx); REALLOC((*ng_occ), n_vtx); REALLOC((*i_idx), n_vtx);
    u2g_hybrid_aln(uidx, ng, ob, ub); b64->n = ub64->n = 0; 
    uint64_t *int_idx = ub->a, int_idx_n = ub->n, *int_a = ob->a; 
    uint64_t *r_a, r_n, zs, ze, s, e, pi, v, *pz;

    memset((*ng_occ), 0, sizeof((*(*ng_occ)))*n_vtx);  
    for (k = 0; k < int_idx_n; k++) {///scan all integer contigs
        r_a = int_a + (int_idx[k]>>32); r_n = (uint32_t)int_idx[k];
        assert(r_n >= 2);
        for (i = 1; i + 1 < r_n; i++) {
            (*ng_occ)[r_a[i]]++; (*ng_occ)[r_a[i]^1]++;
        }
        (*ng_occ)[r_a[0]]++; (*ng_occ)[r_a[r_n-1]^1]++;
    }

    ma_ug_t *un_g = ma_ug_hybrid_gen(ng); 
    int32_t ui, un; ma_utg_t *u = NULL;
    for (k = 0; k < un_g->u.n; k++) {///all unitigs of raw utg 
        u = &(un_g->u.a[k]); 
        zs = ze = (uint32_t)-1; un = u->n;
        for (ui = 0; ui < un; ui++) {
            if(occ_m((*ng_occ)[(u->a[ui]>>32)^1]) == 1) {
                zs = ui; break;
            }
        }

        for (ui = ((int32_t)un)-1; ui >= 0; ui--) {
            if(occ_m((*ng_occ)[u->a[ui]>>32]) == 1) {
                ze = ui; break;
            }
        }
        if(zs != (uint32_t)-1 && ze != (uint32_t)-1 && zs > ze) continue;
        if(zs != (uint32_t)-1) (*ng_occ)[(u->a[zs]>>32)^1] |= ((uint32_t)0x80000000);
        if(ze != (uint32_t)-1) (*ng_occ)[(u->a[ze]>>32)] |= ((uint32_t)0x80000000);
    }
    ma_ug_destroy(un_g);

        // fprintf(stderr, ">>>>>>[M::%s::] int_idx[0]::%lu, int_idx[1]::%lu\n", __func__, int_idx[0], int_idx[1]);
    // prt_intg_info(int_idx, int_idx_n, int_a, "intg");
    for (i = b64->n = a_n = 0; i < int_idx_n; i++) {///scan all integer contigs
        s = int_idx[i]>>32; e = s + ((uint32_t)int_idx[i]); 
        assert(e > s + 1);//the length is at least 2
        for (k = s, pi = (uint64_t)-1; k < e; k++) {
            v = int_a[k]; 
            if((!((*ng_occ)[v]&((uint32_t)0x80000000)))&&(!((*ng_occ)[v^1]&((uint32_t)0x80000000)))) {
                continue;///it must be a unique node
            }
            if((pi != (uint64_t)-1) && ((*ng_occ)[v^1]&((uint32_t)0x80000000))) {
                pz = (b64->n>0)? &(b64->a[b64->n-1]):(NULL);
                if((!pz) || (((*pz)>>32) != pi)) {//keep the shortest pi<->k 
                    kv_pushp(uint64_t, *b64, &pz); 
                    *pz = pi; (*pz) <<= 32; (*pz) |= k;
                    a_n++;
                }
            }
            if((*ng_occ)[v]&((uint32_t)0x80000000)) pi = k;//keep the shortest pi<->k
        }
    }
    // prt_thread_info(b64.a, a_n+ua_n, NULL, 0, "tt_minus");
    // fprintf(stderr, "**0**[M::%s::] a_n::%lu, ua_n::%lu\n", __func__, a_n, ua_n);
    radix_sort_srt64(b64->a, b64->a + b64->n);///keeps the coordinates within int_a[]

    a_n = ug_ext_0(uidx, ng, ub->a, ub->n, ob->a, max_ext, *ff, *ng_occ, *i_idx, b64, ub64, a_n);
    // if(a_n) usg_cleanup(ng);
    return a_n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r14
movl %r8d, 0xc(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %r13
movq %rdi, %r12
movq 0x80(%rsp), %rbx
movq %rcx, 0x10(%rsp)
movl 0x8(%rcx), %r15d
addl %r15d, %r15d
movq (%r9), %rdi
movq %r15, %rsi
callq 0x2370
movq %r14, 0x38(%rsp)
movq %rax, (%r14)
movq (%rbx), %rdi
leaq (,%r15,4), %rbp
movq %rbp, %rsi
callq 0x2370
movq %rax, (%rbx)
movq 0x88(%rsp), %r14
movq (%r14), %rdi
shlq $0x3, %r15
movq %r15, %rsi
callq 0x2370
movq %rax, (%r14)
movq 0x18(%rsp), %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1cefc1
movq 0x98(%rsp), %rax
andq $0x0, (%rax)
movq 0x90(%rsp), %rax
andq $0x0, (%rax)
movq (%r13), %rax
movq %rax, 0x28(%rsp)
movq 0x10(%r13), %rax
movq %rax, 0x20(%rsp)
movq %r12, 0x30(%rsp)
movq 0x10(%r12), %r12
movq (%rbx), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
leaq 0x8(%r12), %rax
movl %r14d, %r14d
cmpq %r14, 0x28(%rsp)
jbe 0x1d1c45
movq 0x20(%rsp), %rcx
movq (%rcx,%r14,8), %rdi
movl %edi, %ecx
cmpq $0x2, %rcx
jb 0x1d1eca
shrq $0x20, %rdi
leaq (%r12,%rdi,8), %rdx
leaq -0x2(%rcx), %rsi
leaq (%rax,%rdi,8), %rdi
xorl %r8d, %r8d
cmpq %r8, %rsi
je 0x1d1c2b
movq (%rbx), %r9
movq (%rdi,%r8,8), %r10
incl (%r9,%r10,4)
xorq $0x1, %r10
incl (%r9,%r10,4)
incq %r8
jmp 0x1d1c0e
movq (%rbx), %rsi
movq (%rdx), %rdi
incl (%rsi,%rdi,4)
movq -0x8(%rdx,%rcx,8), %rcx
xorq $0x1, %rcx
incl (%rsi,%rcx,4)
incl %r14d
jmp 0x1d1bdc
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rdi
callq 0x1cbbbd
movq (%rax), %rcx
xorl %edx, %edx
pushq $-0x1
popq %rsi
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0x1d1d39
movq 0x10(%rax), %r9
imulq $0x28, %rdx, %r10
leaq (%r9,%r10), %r8
movl 0x10(%r9,%r10), %r9d
testl %r9d, %r9d
movl $0x0, %r11d
cmovgl %r9d, %r11d
negq %r11
movq %rsi, %r10
leaq (%r11,%r10), %r15
cmpq $-0x1, %r15
je 0x1d1cbf
movq (%rbx), %r15
movq 0x18(%r8), %r13
movl 0xc(%r13,%r10,8), %r13d
shlq $0x2, %r13
xorq $0x4, %r13
movl (%r15,%r13), %ebp
andl %edi, %ebp
incq %r10
cmpl $0x1, %ebp
jne 0x1d1c91
jmp 0x1d1cc5
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
testl %r9d, %r9d
jle 0x1d1ce8
movq (%rbx), %r11
movq 0x18(%r8), %r15
movl -0x4(%r15,%r9,8), %r15d
decq %r9
movl (%r11,%r15,4), %r11d
andl %edi, %r11d
cmpl $0x1, %r11d
jne 0x1d1cc5
jmp 0x1d1cee
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpq %r14, %r10
je 0x1d1cf8
cmpq %r9, %r10
ja 0x1d1d32
cmpq %r14, %r10
je 0x1d1d19
movq (%rbx), %r11
movq 0x18(%r8), %r15
movl 0x4(%r15,%r10,8), %r10d
shlq $0x2, %r10
xorq $0x4, %r10
orl $0x80000000, (%r11,%r10) # imm = 0x80000000
cmpq %r14, %r9
je 0x1d1d32
movq (%rbx), %r10
movq 0x18(%r8), %r8
movl 0x4(%r8,%r9,8), %r8d
orl $0x80000000, (%r10,%r8,4) # imm = 0x80000000
incl %edx
jmp 0x1d1c62
movq %rax, %rdi
callq 0x6921d
movq 0x90(%rsp), %rdi
andq $0x0, (%rdi)
xorl %r8d, %r8d
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, 0x28(%rsp)
jbe 0x1d1e69
movq 0x20(%rsp), %rax
movq %rcx, 0x40(%rsp)
movq (%rax,%rcx,8), %r15
movl %r15d, %r14d
cmpq $0x1, %r14
jbe 0x1d1ee9
shrq $0x20, %r15
addq %r15, %r14
pushq $-0x1
popq %rbp
movl %r15d, %r15d
cmpq %r15, %r14
jbe 0x1d1e5d
movq (%r12,%r15,8), %r13
movq (%rbx), %rax
movl (%rax,%r13,4), %ecx
testl %ecx, %ecx
js 0x1d1db0
movq %r13, %rdx
xorq $0x1, %rdx
cmpl $0x0, (%rax,%rdx,4)
jns 0x1d1e55
cmpq $-0x1, %rbp
je 0x1d1e4f
movq %r13, %rdx
xorq $0x1, %rdx
cmpl $0x0, (%rax,%rdx,4)
jns 0x1d1e4f
movq (%rdi), %rdx
movq 0x10(%rdi), %rax
testq %rdx, %rdx
je 0x1d1de9
leaq (%rax,%rdx,8), %rsi
addq $-0x8, %rsi
je 0x1d1de9
movl 0x4(%rsi), %esi
cmpq %rbp, %rsi
je 0x1d1e4f
cmpq 0x8(%rdi), %rdx
jne 0x1d1e37
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdi)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r12, %rbx
movl %r8d, %r12d
callq 0x2370
movl %r12d, %r8d
movq %rbx, %r12
movq 0x80(%rsp), %rbx
movq 0x90(%rsp), %rdi
movq %rax, 0x10(%rdi)
movq (%rdi), %rdx
movq (%rbx), %rcx
movl (%rcx,%r13,4), %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rdi)
movq %rbp, %rsi
shlq $0x20, %rsi
orq %r15, %rsi
movq %rsi, (%rax,%rdx,8)
incl %r8d
testl %ecx, %ecx
cmovsq %r15, %rbp
incl %r15d
jmp 0x1d1d84
movq 0x40(%rsp), %rcx
incl %ecx
jmp 0x1d1d52
movq (%rdi), %rax
movq %rdi, %r14
movq 0x10(%rdi), %rdi
leaq (%rdi,%rax,8), %rsi
movl %r8d, %ebp
callq 0x1a3def
movq 0x30(%rsp), %rax
movq 0x10(%rax), %r8
movl %ebp, %eax
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0xc(%rsp), %r9d
pushq %rax
pushq 0xa0(%rsp)
pushq %r14
movq 0xa0(%rsp), %rax
pushq (%rax)
pushq (%rbx)
movq 0x60(%rsp), %rax
pushq (%rax)
callq 0x1d11bc
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x29084(%rip), %rdi     # 0x1faf55
leaq 0x25601(%rip), %rsi     # 0x1f74d9
leaq 0x29874(%rip), %rcx     # 0x1fb753
movl $0x3857, %edx           # imm = 0x3857
callq 0x2110
leaq 0x28cdb(%rip), %rdi     # 0x1fabcb
leaq 0x255e2(%rip), %rsi     # 0x1f74d9
leaq 0x29855(%rip), %rcx     # 0x1fb753
movl $0x3878, %edx           # imm = 0x3878
callq 0x2110