// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: shrink_ul0(all_ul_t*, ul_str_t*, unsigned long, integer_t*, ma_ug_t*)
void shrink_ul0(all_ul_t *uls, ul_str_t *str, uint64_t id, integer_t *buf, ma_ug_t *ug)
{
    uint32_t k, c_k, p_k, cv, pv, bl, i; uc_block_t *xi, *yi; buf->u.n = 0; nid_t *np = NULL;
    asg_arc_t *av; uint32_t nv, s, e, m, d, mm, is_conn; uint64_t *z; ul_vec_t *x;
    if(str->cn < 2) return;
    for (k = 0, bl = 0, c_k = p_k = pv = (uint32_t)-1; k < str->cn; k++) {
        xi = &(uls->a[id].bb.a[str->a[k]>>32]); is_conn = 0;
        c_k = k; cv = ((uint32_t)str->a[k])^1;
        assert(((xi->hid<<1)+xi->rev)==((uint32_t)str->a[k]));
        if(p_k != (uint32_t)-1) {
            if(xi->pidx == (str->a[p_k]>>32)) {
                av = asg_arc_a(ug->g, cv); nv = asg_arc_n(ug->g, cv);
                for (i = 0; i < nv; i++) {
                    if(av[i].del) continue;
                    if(av[i].v == pv) break;
                }
                if(i < nv) {
                    s = (uint32_t)av[i].ul;
                    if(s == xi->pdis) {
                        is_conn = 1;
                    } else {
                        d = (s>=xi->pdis?s-xi->pdis:xi->pdis-s);
                        mm = MAX(s, xi->pdis);
                        if((d <= (mm*0.08)) || (d <= 512)) is_conn = 1;
                    }
                }
            } else if(xi->pidx == (uint32_t)-1) {
                is_conn = 1;
            }
        }
        if(is_conn) {
            is_conn = 0; assert(k);
            yi = &(uls->a[id].bb.a[str->a[k-1]>>32]);
            if((xi->qs >= yi->qs) && (xi->qe >= yi->qe)) is_conn = 1;
        }
        if(is_conn) {
            bl++;
        } else {
            if(bl > 0) {
                kv_pushp(uint64_t, buf->u, &z);
                (*z) = k - 1 - bl; (*z) <<= 32; (*z) += bl + 1;
            }
            bl = 0;
        }
        p_k = c_k; pv = cv;
    }

    if(bl > 0) {
        kv_pushp(uint64_t, buf->u, &z);
        (*z) = k - 1 - bl; (*z) <<= 32; (*z) += bl + 1;
    }
    // fprintf(stderr, "[M::%s::] buf->u.n::%u, str->cn::%u\n", __func__, buf->u.n, str->cn);
    if(buf->u.n <= 0) {
        str->cn = str->n = 0;
    } else if(buf->u.n > 0) {
        uint32_t pidx, aidx, pdis;
        for (i = 0; i + 1 < buf->u.n; i++) {
            s = (buf->u.a[i]>>32); e = s + ((uint32_t)buf->u.a[i]); 
            ///new id
            kv_pushp(nid_t, uls->nid, &np);
            np->n = uls->nid.a[id].n; MALLOC(np->a, np->n+1);
            memcpy(np->a, uls->nid.a[id].a, np->n); np->a[np->n] = '\0';
            ///new ovlps
            kv_pushp(ul_vec_t, *uls, &x); memset(x, 0, sizeof(*x));
            MALLOC(x->bb.a, e - s); x->bb.n = x->bb.m = e - s;

            for (k = s, m = 0; k < e; k++, m++) {
                pidx = uls->a[id].bb.a[str->a[k]>>32].pidx; 
                aidx = uls->a[id].bb.a[str->a[k]>>32].aidx; 
                pdis = uls->a[id].bb.a[str->a[k]>>32].pdis;
                x->bb.a[m] = uls->a[id].bb.a[str->a[k]>>32];
                if(k == s) {
                    x->bb.a[m].pidx = x->bb.a[m].pdis = (uint32_t)-1;
                } else if(pidx != (uint32_t)-1) {
                    x->bb.a[m].pidx = m - 1; x->bb.a[m].pdis = pdis;
                }
                if(k + 1 == e) {
                    x->bb.a[m].aidx = (uint32_t)-1;
                } else if(aidx != (uint32_t)-1) {
                    x->bb.a[m].aidx = m + 1;
                }
            }
            x->bb.n = m;
            assert(x->bb.n > 1);

            shrink_1b(ug, &(x->bb.a[0]), ((x->bb.n>=2)?&(x->bb.a[1]):(NULL)), 1);
            shrink_1b(ug, &(x->bb.a[x->bb.n-1]), ((x->bb.n>=2)?&(x->bb.a[x->bb.n-2]):(NULL)), 0);
            
            d = x->bb.a[0].qs;
            for (k = 0; k < x->bb.n; k++) {
                x->bb.a[k].qs -= d; x->bb.a[k].qe -= d;
            }
            x->rlen = x->bb.a[x->bb.n-1].qe;
            renew_ul_vec_t(x, ug);
        }

        ///the last one; update in-place
        s = (buf->u.a[i]>>32); e = s + ((uint32_t)buf->u.a[i]); x = &(uls->a[id]);
        for (k = s, m = 0; k < e; k++, m++) {
            pidx = x->bb.a[str->a[k]>>32].pidx; 
            aidx = x->bb.a[str->a[k]>>32].aidx; 
            pdis = x->bb.a[str->a[k]>>32].pdis;
            x->bb.a[m] = x->bb.a[str->a[k]>>32];
            if(k == s) {
                x->bb.a[m].pidx = x->bb.a[m].pdis = (uint32_t)-1;
            } else if(pidx != (uint32_t)-1) {
                x->bb.a[m].pidx = m - 1; x->bb.a[m].pdis = pdis;
            }
            if(k + 1 == e) {
                x->bb.a[m].aidx = (uint32_t)-1;
            } else if(aidx != (uint32_t)-1) {
                x->bb.a[m].aidx = m + 1;
            }
        }
        x->bb.n = m;
        assert(x->bb.n > 1);
        shrink_1b(ug, &(x->bb.a[0]), ((x->bb.n>=2)?&(x->bb.a[1]):(NULL)), 1);
        shrink_1b(ug, &(x->bb.a[x->bb.n-1]), ((x->bb.n>=2)?&(x->bb.a[x->bb.n-2]):(NULL)), 0);
        d = x->bb.a[0].qs;
        for (k = 0; k < x->bb.n; k++) {
            x->bb.a[k].qs -= d; x->bb.a[k].qe -= d;
        }
        x->rlen = x->bb.a[x->bb.n-1].qe;
        renew_ul_vec_t(x, ug);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x18(%rsp)
movq $0x0, 0x90(%rcx)
movq %rsi, 0x8(%rsp)
movl 0x18(%rsi), %eax
testl $0x7ffffffe, %eax       # imm = 0x7FFFFFFE
je 0x209b52
movq %rdi, 0x10(%rsp)
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x209b3f
movq %r8, %r15
movq %rcx, 0x20(%rsp)
xorl %r14d, %r14d
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
imulq $0x58, 0x18(%rsp), %r12
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %ebx, %ebx
movl %r13d, %edi
movq 0x10(%rsp), %rcx
movq 0x48(%rcx), %rcx
movq 0x30(%rcx,%r12), %rcx
movq 0x8(%rsp), %rdx
movq 0x10(%rdx), %rdx
movq (%rdx,%r14,8), %r13
movq %r13, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,8), %rsi
movl (%rcx,%rsi,4), %r9d
movl 0x20(%rcx,%rsi,4), %r10d
shrl $0x5, %r10d
andl $0x1, %r10d
leal (%r10,%r9,2), %r9d
cmpl %r13d, %r9d
jne 0x209fea
movq %r14, %rbp
xorl $0x1, %r13d
cmpl $-0x1, %r8d
je 0x209a1c
leaq (%rcx,%rsi,4), %rsi
movl 0x14(%rsi), %r9d
movl %r8d, %r8d
cmpl %r9d, 0x4(%rdx,%r8,8)
jne 0x2099a5
movq 0x18(%r15), %r8
movq 0x28(%r8), %r9
movl %r13d, %r10d
movq (%r9,%r10,8), %r9
testl %r9d, %r9d
je 0x209a1c
movq 0x8(%r8), %r8
movq %r9, %r10
shrq $0x20, %r10
movl %r9d, %r11d
leaq (%r10,%r10,2), %r9
leaq (%r8,%r9,8), %r10
addq $0xc, %r10
shlq $0x3, %r11
leaq (%r11,%r11,2), %r14
xorl %r11d, %r11d
cmpl $0x0, (%r10,%r11)
js 0x20999a
cmpl %edi, -0x4(%r10,%r11)
je 0x2099ad
addq $0x18, %r11
cmpq %r11, %r14
jne 0x20998c
jmp 0x209a1c
cmpl $-0x1, %r9d
jne 0x209a1c
jmp 0x2099c1
leaq (%r8,%r9,8), %rdi
movl (%r11,%rdi), %edi
movl 0x18(%rsi), %r9d
movl %r9d, %r8d
subl %edi, %r8d
jne 0x2099ee
testq %rbp, %rbp
je 0x20a030
movl -0x4(%rdx,%rbp,8), %edx
leaq (%rdx,%rdx,8), %rdx
movl 0x4(%rsi), %edi
cmpl 0x4(%rcx,%rdx,4), %edi
jb 0x209a1c
leaq (%rcx,%rdx,4), %rcx
movl 0x8(%rsi), %edx
cmpl 0x8(%rcx), %edx
jb 0x209a1c
incl %ebx
jmp 0x209a95
movl %edi, %r10d
cmoval %r9d, %r10d
subl %r9d, %edi
cmovbl %r8d, %edi
cvtsi2sd %r10, %xmm0
mulsd 0x27bff(%rip), %xmm0    # 0x231608
cmpl $0x201, %edi            # imm = 0x201
jb 0x2099c1
cvtsi2sd %rdi, %xmm1
ucomisd %xmm1, %xmm0
jae 0x2099c1
testl %ebx, %ebx
je 0x209a93
movq 0x20(%rsp), %r14
movq 0x90(%r14), %rcx
movq 0xa0(%r14), %rax
cmpq 0x98(%r14), %rcx
jne 0x209a6d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x98(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xa0(%r14)
movq 0x90(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x90(%r14)
movl %ebx, %edx
notl %edx
addl %ebp, %edx
shlq $0x20, %rdx
incl %ebx
orq %rdx, %rbx
movq %rbx, (%rax,%rcx,8)
movq 0x8(%rsp), %rax
movl 0x18(%rax), %eax
xorl %ebx, %ebx
leaq 0x1(%rbp), %r14
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ebp, %r8d
cmpq %rcx, %r14
jb 0x2098e5
movq 0x20(%rsp), %r13
movq 0x90(%r13), %rcx
testl %ebx, %ebx
je 0x209b2a
cmpq 0x98(%r13), %rcx
jne 0x209afd
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x98(%r13)
movq 0xa0(%r13), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0xa0(%r13)
movq 0x90(%r13), %rcx
jmp 0x209b04
movq 0xa0(%r13), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x90(%r13)
movl %ebx, %edx
notl %edx
addl %edx, %r14d
shlq $0x20, %r14
incl %ebx
orq %r14, %rbx
movq %rbx, (%rax,%rcx,8)
movq 0x90(%r13), %rcx
movq %r13, %rbx
testq %rcx, %rcx
je 0x209b3f
cmpq $0x1, %rcx
jne 0x209b61
xorl %eax, %eax
jmp 0x209e51
movq 0x8(%rsp), %rax
movq $0x0, (%rax)
andl $0x80000000, 0x18(%rax) # imm = 0x80000000
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
shlq $0x4, 0x18(%rsp)
xorl %ecx, %ecx
movq %r15, 0x38(%rsp)
movq %r12, 0x30(%rsp)
movl %ecx, %ecx
movq %rax, 0x40(%rsp)
movq 0xa0(%rbx), %rax
movq (%rax,%rcx,8), %r14
movq 0x10(%rsp), %r15
movq (%r15), %r13
movq 0x10(%r15), %rbx
cmpq 0x8(%r15), %r13
jne 0x209bca
leaq (,%r13,2), %rsi
testq %r13, %r13
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
shlq $0x4, %rsi
movq %rbx, %rdi
callq 0x2370
movq %rax, %rbx
movq %rax, 0x10(%r15)
movq (%r15), %r13
leaq 0x1(%r13), %rax
movq %rax, (%r15)
shlq $0x4, %r13
movq 0x18(%rsp), %r12
movl 0x8(%rbx,%r12), %ebp
movl %ebp, 0x8(%rbx,%r13)
leal 0x1(%rbp), %edi
callq 0x2280
movq %rax, (%rbx,%r13)
movq (%rbx,%r12), %rsi
movq %rax, %rdi
movq %rbp, %rdx
callq 0x2160
movq (%rbx,%r13), %rax
movl 0x8(%rbx,%r13), %ecx
movb $0x0, (%rax,%rcx)
movq 0x48(%r15), %rbx
movq 0x50(%r15), %rax
cmpq 0x58(%r15), %rax
jne 0x209c45
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x58(%r15)
imulq $0x58, %rcx, %rsi
movq %rbx, %rdi
callq 0x2370
movq %rax, %rbx
movq %rax, 0x48(%r15)
movq 0x50(%r15), %rax
movq %r14, %r13
shrq $0x20, %r13
leal (%r14,%r13), %ecx
movl %ecx, 0x2c(%rsp)
leaq 0x1(%rax), %rcx
movq %rcx, 0x50(%r15)
imulq $0x58, %rax, %r12
leaq (%rbx,%r12), %rbp
xorpd %xmm0, %xmm0
movupd %xmm0, 0x40(%rbx,%r12)
movupd %xmm0, 0x30(%rbx,%r12)
movupd %xmm0, 0x20(%rbx,%r12)
movupd %xmm0, 0x10(%rbx,%r12)
movupd %xmm0, (%rbx,%r12)
movq $0x0, 0x50(%rbx,%r12)
movl %r14d, %r15d
leaq (,%r15,4), %rax
leaq (%rax,%rax,8), %rdi
callq 0x2280
movq %rax, 0x30(%rbx,%r12)
movl 0x2c(%rsp), %eax
movq %r15, 0x28(%rbx,%r12)
movq %r15, 0x20(%rbx,%r12)
cmpl %r13d, %eax
jbe 0x20a009
movl %eax, %ecx
leaq (,%r13,8), %rax
notq %r13
addq %rcx, %r13
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x38(%rsp), %r15
movq 0x30(%rsp), %r12
movq 0x10(%rsp), %rsi
movq 0x48(%rsi), %rsi
movq 0x30(%rsi,%r12), %r9
movq 0x8(%rsp), %rsi
movq 0x10(%rsi), %rsi
addq %rax, %rsi
movl 0x4(%rsi,%rdx,8), %esi
leaq (%rsi,%rsi,8), %r10
movl 0x14(%r9,%r10,4), %r8d
movl 0x1c(%r9,%r10,4), %esi
movl 0x18(%r9,%r10,4), %edi
movq 0x30(%rbp), %r11
movl 0x20(%r9,%r10,4), %ebx
movl %ebx, 0x20(%r11,%rcx)
movupd (%r9,%r10,4), %xmm0
movupd 0x10(%r9,%r10,4), %xmm1
movupd %xmm1, 0x10(%r11,%rcx)
movupd %xmm0, (%r11,%rcx)
testq %rdx, %rdx
je 0x209d59
cmpl $-0x1, %r8d
je 0x209d66
leal -0x1(%rdx), %r8d
movq 0x30(%rbp), %r9
movl %r8d, 0x14(%r9,%rcx)
movl %edi, 0x18(%r9,%rcx)
jmp 0x209d66
movq 0x30(%rbp), %rdi
movq $-0x1, 0x14(%rdi,%rcx)
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpq %rdx, %r13
je 0x209d78
cmpl $-0x1, %esi
je 0x209d80
leal 0x1(%rdx), %edi
movq 0x30(%rbp), %rsi
movl %edi, 0x1c(%rsi,%rcx)
incq %rdx
addq $0x24, %rcx
cmpl %edx, %r14d
jne 0x209ce1
movl %r14d, %eax
movq %rax, 0x20(%rbp)
cmpl $0x1, %r14d
jbe 0x20a011
movq 0x30(%rbp), %rsi
leaq 0x24(%rsi), %rdx
movq %r15, %rdi
movl $0x1, %ecx
callq 0x2094f0
movq 0x20(%rbp), %rax
movq 0x30(%rbp), %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rcx,%rdx,4), %rsi
addq $-0x24, %rsi
cmpq $0x2, %rax
leaq -0x48(%rcx,%rdx,4), %rdx
movl $0x0, %eax
cmovbq %rax, %rdx
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x2094f0
movq 0x20(%rbp), %rcx
movq 0x30(%rbp), %rax
testq %rcx, %rcx
movq 0x20(%rsp), %rbx
je 0x209e24
movd 0x4(%rax), %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
leaq 0x4(%rax), %rdx
movl $0x1, %esi
movq (%rdx), %xmm1
psubd %xmm0, %xmm1
movq %xmm1, (%rdx)
movl %esi, %edi
addq $0x24, %rdx
incl %esi
cmpq %rdi, %rcx
ja 0x209e0b
leaq (%rcx,%rcx,8), %rcx
movl -0x1c(%rax,%rcx,4), %eax
movl %eax, 0x18(%rbp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x209653
movq 0x40(%rsp), %rcx
leal 0x1(%rcx), %eax
cmpq %rax, 0x90(%rbx)
ja 0x209b78
movl %ecx, %eax
movq 0xa0(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
leal (%rcx,%rax), %edx
movq 0x10(%rsp), %rsi
addq 0x48(%rsi), %r12
cmpl %ecx, %edx
jbe 0x20a04f
movl %edx, %esi
leaq (,%rcx,8), %rdx
notq %rcx
addq %rsi, %rcx
xorl %esi, %esi
xorl %edi, %edi
movq 0x30(%r12), %r11
movq 0x8(%rsp), %r8
movq 0x10(%r8), %r8
addq %rdx, %r8
movl 0x4(%r8,%rdi,8), %r8d
leaq (%r8,%r8,8), %rbx
movl 0x14(%r11,%rbx,4), %r10d
movl 0x1c(%r11,%rbx,4), %r8d
movl 0x18(%r11,%rbx,4), %r9d
movl 0x20(%r11,%rbx,4), %ebp
movl %ebp, 0x20(%r11,%rsi)
movupd (%r11,%rbx,4), %xmm0
movupd 0x10(%r11,%rbx,4), %xmm1
movupd %xmm1, 0x10(%r11,%rsi)
movupd %xmm0, (%r11,%rsi)
testq %rdi, %rdi
je 0x209ef8
cmpl $-0x1, %r10d
je 0x209f06
leal -0x1(%rdi), %r10d
movq 0x30(%r12), %r11
movl %r10d, 0x14(%r11,%rsi)
movl %r9d, 0x18(%r11,%rsi)
jmp 0x209f06
movq 0x30(%r12), %r9
movq $-0x1, 0x14(%r9,%rsi)
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpq %rdi, %rcx
je 0x209f1b
cmpl $-0x1, %r8d
je 0x209f25
leal 0x1(%rdi), %r9d
movq 0x30(%r12), %r8
movl %r9d, 0x1c(%r8,%rsi)
incq %rdi
addq $0x24, %rsi
cmpl %edi, %eax
jne 0x209e8b
movl %eax, %ecx
movq %rcx, 0x20(%r12)
cmpl $0x1, %eax
jbe 0x20a058
movq 0x30(%r12), %rsi
leaq 0x24(%rsi), %rdx
movl $0x1, %ebx
movq %r15, %rdi
movl $0x1, %ecx
callq 0x2094f0
movq 0x20(%r12), %rax
movq 0x30(%r12), %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rcx,%rdx,4), %rsi
addq $-0x24, %rsi
xorl %edi, %edi
cmpq $0x2, %rax
leaq -0x48(%rcx,%rdx,4), %rdx
cmovbq %rdi, %rdx
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x2094f0
movq 0x20(%r12), %rcx
movq 0x30(%r12), %rax
testq %rcx, %rcx
je 0x209fc4
movd 0x4(%rax), %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
leaq 0x4(%rax), %rdx
movq (%rdx), %xmm1
psubd %xmm0, %xmm1
movq %xmm1, (%rdx)
movl %ebx, %esi
addq $0x24, %rdx
incl %ebx
cmpq %rsi, %rcx
ja 0x209fab
leaq (%rcx,%rcx,8), %rcx
movl -0x1c(%rax,%rcx,4), %eax
movl %eax, 0x18(%r12)
movq %r12, %rdi
movq %r15, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x209653
leaq 0x3d4e7(%rip), %rdi     # 0x2474d8
leaq 0x3b611(%rip), %rsi     # 0x245609
leaq 0x3dad6(%rip), %rcx     # 0x247ad5
movl $0x1e46, %edx           # imm = 0x1E46
callq 0x2110
movq $0x0, 0x20(%rbp)
leaq 0x3db07(%rip), %rdi     # 0x247b1f
leaq 0x3b5ea(%rip), %rsi     # 0x245609
leaq 0x3daaf(%rip), %rcx     # 0x247ad5
movl $0x1e91, %edx           # imm = 0x1E91
callq 0x2110
leaq 0x3cf42(%rip), %rdi     # 0x246f79
leaq 0x3b5cb(%rip), %rsi     # 0x245609
leaq 0x3da90(%rip), %rcx     # 0x247ad5
movl $0x1e5d, %edx           # imm = 0x1E5D
callq 0x2110
movq $0x0, 0x20(%r12)
leaq 0x3dac0(%rip), %rdi     # 0x247b1f
leaq 0x3b5a3(%rip), %rsi     # 0x245609
leaq 0x3da68(%rip), %rcx     # 0x247ad5
movl $0x1eb1, %edx           # imm = 0x1EB1
callq 0x2110