// File: /workspace/github_cpp_makefile_star2_O3/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, %rbp
movl %r8d, 0x4(%rsp)
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r14
movq 0x80(%rsp), %rbx
movq %rcx, 0x8(%rsp)
movl 0x8(%rcx), %r15d
addl %r15d, %r15d
movq (%r9), %rdi
movq %r15, %rsi
callq 0x2370
movq %rbp, 0x30(%rsp)
movq %rax, (%rbp)
movq (%rbx), %rdi
leaq (,%r15,4), %rbp
movq %rbp, %rsi
callq 0x2370
movq %rax, (%rbx)
movq 0x88(%rsp), %rbx
movq (%rbx), %rdi
shlq $0x3, %r15
movq %r15, %rsi
callq 0x2370
movq %rax, (%rbx)
movq %r12, 0x28(%rsp)
movq %r12, %rdi
movq %r14, %rdx
movq %r13, %rcx
callq 0x21dd4b
xorl %ebx, %ebx
movq 0x98(%rsp), %rax
movq %rbx, (%rax)
movq 0x90(%rsp), %rax
movq %rbx, (%rax)
movq (%r13), %r15
movq 0x10(%r13), %rax
movq %rax, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq 0x10(%r14), %r12
movq 0x80(%rsp), %rax
movq (%rax), %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
testq %r15, %r15
je 0x220bc1
leaq 0x8(%r12), %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rbx,8), %rdx
movl %edx, %ecx
cmpq $0x2, %rcx
jb 0x220e97
shrq $0x20, %rdx
movq 0x80(%rsp), %rsi
movq (%rsi), %rsi
cmpl $0x2, %ecx
je 0x220ba4
leaq -0x2(%rcx), %rdi
leaq (%rax,%rdx,8), %r8
xorl %r9d, %r9d
movq (%r8,%r9,8), %r10
incl (%rsi,%r10,4)
xorq $0x1, %r10
incl (%rsi,%r10,4)
incq %r9
cmpq %r9, %rdi
jne 0x220b8c
leaq (%r12,%rdx,8), %rdx
movq (%rdx), %rdi
incl (%rsi,%rdi,4)
movq -0x8(%rdx,%rcx,8), %rcx
xorq $0x1, %rcx
incl (%rsi,%rcx,4)
incl %ebx
cmpq %rbx, %r15
ja 0x220b58
movq %r15, 0x10(%rsp)
movq 0x8(%rsp), %rdi
callq 0x21a43d
movq (%rax), %rcx
testq %rcx, %rcx
je 0x220ce8
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x10(%rax), %rsi
xorl %edi, %edi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
leaq (%rdi,%rdi,4), %r9
leaq (%rsi,%r9,8), %r11
movl 0x10(%r11), %r9d
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
testl %r9d, %r9d
jle 0x220c3d
movq 0x80(%rsp), %r10
movq (%r10), %rbx
movq 0x18(%r11), %r14
xorl %r10d, %r10d
movl 0x4(%r14,%r10,8), %r15d
shlq $0x2, %r15
xorq $0x4, %r15
movl (%rbx,%r15), %ebp
andl %r8d, %ebp
cmpl $0x1, %ebp
je 0x220c3d
incq %r10
cmpq %r10, %r9
jne 0x220c16
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
testl %r9d, %r9d
jle 0x220ca7
movq 0x80(%rsp), %rbx
movq (%rbx), %rbx
movq 0x18(%r11), %r14
movq -0x8(%r14,%r9,8), %r15
decq %r9
shrq $0x20, %r15
movl (%rbx,%r15,4), %ebp
movl %ebp, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
cmpl $0x1, %r13d
jne 0x220c3d
cmpq %rdx, %r10
je 0x220c7b
cmpq %r9, %r10
ja 0x220cd9
cmpq %rdx, %r10
je 0x220ca1
movl 0x4(%r14,%r10,8), %r10d
shlq $0x2, %r10
xorq $0x4, %r10
orl $0x80000000, (%rbx,%r10) # imm = 0x80000000
movq (%r14,%r9,8), %r15
shrq $0x20, %r15
movl (%rbx,%r15,4), %ebp
leaq (%rbx,%r15,4), %r9
jmp 0x220cd0
cmpq %rdx, %r10
je 0x220cd9
movq 0x80(%rsp), %r9
movq (%r9), %rbx
movq 0x18(%r11), %r9
movl 0x4(%r9,%r10,8), %r10d
shlq $0x2, %r10
xorq $0x4, %r10
leaq (%rbx,%r10), %r9
movl (%rbx,%r10), %ebp
orl $0x80000000, %ebp       # imm = 0x80000000
movl %ebp, (%r9)
incq %rdi
movl %edi, %r9d
cmpq %r9, %rcx
ja 0x220bed
movq %rax, %rdi
callq 0xa0761
xorl %ecx, %ecx
movq 0x90(%rsp), %rdi
movq $0x0, (%rdi)
cmpq $0x0, 0x10(%rsp)
je 0x220e34
xorl %r8d, %r8d
movq %r12, 0x38(%rsp)
movq 0x18(%rsp), %rax
movq %rcx, 0x40(%rsp)
movq (%rax,%rcx,8), %rbp
movl %ebp, %r15d
cmpq $0x1, %r15
jbe 0x220eb6
shrq $0x20, %rbp
addq %rbp, %r15
movq 0x80(%rsp), %rax
movq (%rax), %rcx
leal 0x1(%rbp), %ebx
movq $-0x1, %r14
movq (%r12,%rbp,8), %r13
cmpl $0x0, (%rcx,%r13,4)
js 0x220d68
movq %r13, %rax
xorq $0x1, %rax
cmpl $0x0, (%rcx,%rax,4)
jns 0x220e0d
cmpq $-0x1, %r14
je 0x220e04
movq %r13, %rax
xorq $0x1, %rax
cmpl $0x0, (%rcx,%rax,4)
jns 0x220e04
movq (%rdi), %rdx
movq 0x10(%rdi), %rax
testq %rdx, %rdx
je 0x220da1
leaq (%rax,%rdx,8), %rsi
addq $-0x8, %rsi
je 0x220da1
movl 0x4(%rsi), %esi
cmpq %r14, %rsi
je 0x220e04
cmpq 0x8(%rdi), %rdx
jne 0x220dec
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdi)
shlq $0x3, %rsi
movq %rax, %rdi
movl %r8d, %r12d
callq 0x2370
movl %r12d, %r8d
movq 0x38(%rsp), %r12
movq 0x90(%rsp), %rdi
movq %rax, 0x10(%rdi)
movq (%rdi), %rdx
movq 0x80(%rsp), %rcx
movq (%rcx), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rdi)
movq %r14, %rsi
shlq $0x20, %rsi
orq %rbp, %rsi
movq %rsi, (%rax,%rdx,8)
incl %r8d
cmpl $0x0, (%rcx,%r13,4)
cmovsq %rbp, %r14
movl %ebx, %ebp
incl %ebx
cmpq %rbp, %r15
ja 0x220d4c
movq 0x40(%rsp), %rcx
incl %ecx
cmpq %rcx, 0x10(%rsp)
ja 0x220d15
movq (%rdi), %rcx
movl %r8d, %ebx
jmp 0x220e36
xorl %ebx, %ebx
movq %rdi, %r14
movq 0x10(%rdi), %rdi
leaq (%rdi,%rcx,8), %rsi
callq 0x1ee586
movq 0x20(%rsp), %rax
movq 0x10(%rax), %r8
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x4(%rsp), %r9d
pushq %rbx
pushq 0xa0(%rsp)
pushq %r14
movq 0xa0(%rsp), %rax
pushq (%rax)
movq 0xa0(%rsp), %rax
pushq (%rax)
movq 0x58(%rsp), %rax
pushq (%rax)
callq 0x2200d2
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x280f8(%rip), %rdi     # 0x248f96
leaq 0x24764(%rip), %rsi     # 0x245609
leaq 0x288e8(%rip), %rcx     # 0x249794
movl $0x3857, %edx           # imm = 0x3857
callq 0x2110
leaq 0x27d4f(%rip), %rdi     # 0x248c0c
leaq 0x24745(%rip), %rsi     # 0x245609
leaq 0x288c9(%rip), %rcx     # 0x249794
movl $0x3878, %edx           # imm = 0x3878
callq 0x2110