// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xf8, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movl %r8d, -0x3c(%rbp)
movq %r9, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movl %eax, -0x54(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x35f8d0
movq 0x28(%rbp), %rax
movq $0x0, (%rax)
movq 0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq 0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x54(%rbp), %eax
movl %eax, %edx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2100
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpq -0x68(%rbp), %rax
jae 0x364906
movq -0x70(%rbp), %rax
movq -0x60(%rbp), %rcx
movl -0x4c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x60(%rbp), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x80(%rbp)
cmpq $0x2, -0x80(%rbp)
jb 0x364844
jmp 0x364863
leaq 0x3543b(%rip), %rdi     # 0x399c86
leaq 0x31967(%rip), %rsi     # 0x3961b9
movl $0x3857, %edx           # imm = 0x3857
leaq 0x35c26(%rip), %rcx     # 0x39a484
callq 0x2130
movl $0x1, -0x50(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
cmpq -0x80(%rbp), %rax
jae 0x3648bd
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0x78(%rbp), %rcx
movl -0x50(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0x78(%rbp), %rcx
movl -0x50(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x36486a
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0x78(%rbp), %rcx
movq (%rcx), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3647ff
movq -0x38(%rbp), %rdi
callq 0x359c70
movq %rax, -0xc0(%rbp)
movq $0x0, -0xd0(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0xc0(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x364b0d
movq -0xc0(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x90(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x88(%rbp)
movq -0xd0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0xc8(%rbp)
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpl -0xc8(%rbp), %eax
jge 0x3649ec
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0xd0(%rbp), %rcx
movq 0x18(%rcx), %rcx
movslq -0xc4(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,4), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x1, %eax
jne 0x3649d9
movslq -0xc4(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x3649ec
jmp 0x3649db
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x364989
movl -0xc8(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xc4(%rbp)
cmpl $0x0, -0xc4(%rbp)
jl 0x364a55
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0xd0(%rbp), %rcx
movq 0x18(%rcx), %rcx
movslq -0xc4(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
movl (%rax,%rcx,4), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x1, %eax
jne 0x364a42
movslq -0xc4(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x364a55
jmp 0x364a44
movl -0xc4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x3649fb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x88(%rbp)
je 0x364a83
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x90(%rbp)
je 0x364a83
movq -0x88(%rbp), %rax
cmpq -0x90(%rbp), %rax
jbe 0x364a83
jmp 0x364aff
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x88(%rbp)
je 0x364ac2
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0xd0(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x88(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,4), %edx
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax,%rcx,4)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x90(%rbp)
je 0x364afd
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0xd0(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x90(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
movl (%rax,%rcx,4), %edx
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax,%rcx,4)
jmp 0x364aff
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x364928
movq -0xc0(%rbp), %rdi
callq 0xcd6f0
movl $0x0, -0x58(%rbp)
movq 0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpq -0x68(%rbp), %rax
jae 0x364ddb
movq -0x60(%rbp), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq -0x60(%rbp), %rcx
movl -0x50(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x364b8c
jmp 0x364bab
leaq 0x34d69(%rip), %rdi     # 0x3998fc
leaq 0x3161f(%rip), %rsi     # 0x3961b9
movl $0x3878, %edx           # imm = 0x3878
leaq 0x358de(%rip), %rcx     # 0x39a484
callq 0x2130
movq -0x98(%rbp), %rax
movl %eax, -0x4c(%rbp)
movq $-0x1, -0xa8(%rbp)
movl -0x4c(%rbp), %eax
cmpq -0xa0(%rbp), %rax
jae 0x364dcb
movq -0x70(%rbp), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0xb0(%rbp)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0xb0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x364c21
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0xb0(%rbp), %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,4), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x364c21
jmp 0x364dbd
cmpq $-0x1, -0xa8(%rbp)
je 0x364d96
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0xb0(%rbp), %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,4), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x364d96
movq 0x20(%rbp), %rax
cmpq $0x0, (%rax)
jbe 0x364c7f
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
jmp 0x364c8a
xorl %eax, %eax
movq %rax, -0xd8(%rbp)
jmp 0x364c8a
movq -0xd8(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
je 0x364cbd
movq -0xb8(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
cmpq -0xa8(%rbp), %rax
je 0x364d94
jmp 0x364cbf
movq 0x20(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x364d30
movq 0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x364cef
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xe0(%rbp)
jmp 0x364cfd
movl $0x2, %eax
movq %rax, -0xe0(%rbp)
jmp 0x364cfd
movq -0xe0(%rbp), %rcx
movq 0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xa8(%rbp), %rcx
movq -0xb8(%rbp), %rax
movq %rcx, (%rax)
movq -0xb8(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq %rcx, (%rax)
movl -0x4c(%rbp), %eax
movl %eax, %ecx
movq -0xb8(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x364d96
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0xb0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x364dbb
movl -0x4c(%rbp), %eax
movq %rax, -0xa8(%rbp)
jmp 0x364dbd
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x364bc0
jmp 0x364dcd
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x364b32
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x30ed90
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %r8
movl -0x3c(%rbp), %r9d
movq -0x48(%rbp), %rax
movq (%rax), %r15
movq 0x10(%rbp), %rax
movq (%rax), %r14
movq 0x18(%rbp), %rax
movq (%rax), %rbx
movq 0x20(%rbp), %r11
movq 0x28(%rbp), %r10
movl -0x58(%rbp), %eax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x363650
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
addq $0xf8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)