// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: get_integer_seq_ovlps(ul_resolve_t*, unsigned long*, long, long, unsigned long, asg64_v*, unsigned long*)
uint32_t get_integer_seq_ovlps(ul_resolve_t *uidx, uint64_t *p_a, int64_t p_n, int64_t match_bound, uint64_t skip_hom, asg64_v *res, uint64_t *r_w)
{
    ul_str_idx_t *str_idx = &(uidx->pstr); uint32_t v = p_a[match_bound]; uc_block_t *xi;
    uint64_t *hid_a, hid_n, z, vz, ps, pe, ww[2], sw[2], occ; ul_str_t *str; int64_t s_n, s, p;
    bubble_type *bub = uidx->bub;

    hid_a = str_idx->occ.a + str_idx->idx.a[v>>1];
    hid_n = str_idx->idx.a[(v>>1)+1] - str_idx->idx.a[v>>1];
    for (z = ww[0] = ww[1] = (*r_w) = occ = 0; z < hid_n; z++) {
        str = &(str_idx->str.a[hid_a[z]>>32]); s_n = str->cn;
        if(s_n < 2) continue;
        vz = (uint32_t)(str->a[(uint32_t)hid_a[z]]);
        assert((v>>1) == (vz>>1)); ps = pe = (uint64_t)-1;
        sw[0] = sw[1] = 0;
        if(v == vz) {
            s = ((uint32_t)hid_a[z]) + 1; p = match_bound + 1; 
            for (; (s < s_n) && (p < p_n) && ((uint32_t)(str->a[s]) == p_a[p]); s++, p++) {
                xi = &(uidx->idx->a[hid_a[z]>>32].bb.a[str->a[s]>>32]);
                assert(((xi->hid<<1)+xi->rev)==((uint32_t)str->a[s]));
                if(skip_hom && IF_HOM(xi->hid, *bub)) continue;
                sw[1] += ug_occ_w(xi->ts, xi->te, &(uidx->l1_ug->u.a[xi->hid]));
            }
            if(s < s_n && p < p_n) continue;
            if(p <= match_bound + 1) continue;///bridging the two sides of the breakpoint
            if(sw[1] == 0) continue;
            pe = p;

            s = (uint32_t)hid_a[z]; p = match_bound; 
            for (; (s >= 0) && (p >= 0) && ((uint32_t)(str->a[s]) == p_a[p]); s--, p--) {
                xi = &(uidx->idx->a[hid_a[z]>>32].bb.a[str->a[s]>>32]);
                assert(((xi->hid<<1)+xi->rev)==((uint32_t)str->a[s]));
                if(skip_hom && IF_HOM(xi->hid, *bub)) continue;
                sw[0] += ug_occ_w(xi->ts, xi->te, &(uidx->l1_ug->u.a[xi->hid]));
            }
            assert(p < match_bound);
            if(s >= 0 && p >= 0) continue;
            if(sw[0] == 0) continue;
            ps = p + 1;
        } else {
            s = ((int32_t)((uint32_t)hid_a[z]))-1; p = match_bound + 1; 
            for (; (s >= 0) && (p < p_n) && ((uint32_t)(str->a[s]) == (p_a[p]^1)); s--, p++) {
                xi = &(uidx->idx->a[hid_a[z]>>32].bb.a[str->a[s]>>32]);
                assert(((xi->hid<<1)+xi->rev)==((uint32_t)str->a[s]));
                if(skip_hom && IF_HOM(xi->hid, *bub)) continue;
                sw[1] += ug_occ_w(xi->ts, xi->te, &(uidx->l1_ug->u.a[xi->hid]));
            }
            if(s >= 0 && p < p_n) continue;
            if(p <= match_bound + 1) continue;///bridging the two sides of the breakpoint
            if(sw[1] == 0) continue;
            pe = p;

            s = (uint32_t)hid_a[z]; p = match_bound; 
            for (; (s < s_n) && (p >= 0) && ((uint32_t)(str->a[s]) == (p_a[p]^1)); s++, p--) {
                xi = &(uidx->idx->a[hid_a[z]>>32].bb.a[str->a[s]>>32]);
                assert(((xi->hid<<1)+xi->rev)==((uint32_t)str->a[s]));
                if(skip_hom && IF_HOM(xi->hid, *bub)) continue;
                sw[0] += ug_occ_w(xi->ts, xi->te, &(uidx->l1_ug->u.a[xi->hid]));
            }
            assert(p < match_bound);
            if(s < s_n && p >= 0) continue;
            if(sw[0] == 0) continue;
            ps = p + 1;
        }
        if(res) kv_push(uint64_t, *res, ((ps<<32)|(pe)));
        occ++;
        ww[0] += sw[0]; ww[1] += sw[1]; 
        // if(match_bound == 15 && p_n == 36) {
        //     fprintf(stderr, "[M::%s::] z::%lu, ulid::%lu, ps::%lu, pe::%lu\n", __func__, z, hid_a[z]>>32, ps, pe);
        // }
    }

    (*r_w) = MIN(ww[0], ww[1]);
    return occ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, 0x40(%rsp)
movq %rdx, 0x78(%rsp)
movq %rdi, %rbp
movq 0xd0(%rsp), %rdx
movq %rsi, 0x48(%rsp)
movq (%rsi,%rcx,8), %rdi
movl %edi, %eax
movq %rax, 0x80(%rsp)
movq 0x28(%rbp), %rax
movq %rax, 0x38(%rsp)
movq 0x1a0(%rbp), %rax
shrl %edi
movq (%rax,%rdi,8), %rsi
leaq (,%rsi,8), %r8
addq 0x1b8(%rbp), %r8
movq %rdi, 0x88(%rsp)
movq 0x8(%rax,%rdi,8), %rdi
andq $0x0, (%rdx)
subq %rsi, %rdi
movq %rcx, 0x28(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movl $0x0, 0x24(%rsp)
xorl %edx, %edx
movq %r9, 0x60(%rsp)
movq %r8, 0x8(%rsp)
movq %rdi, (%rsp)
cmpq %rdi, %rdx
je 0x1c2196
movq 0x1d0(%rbp), %rax
movq (%r8,%rdx,8), %r15
movq %r15, %r14
shrq $0x20, %r14
movq %r14, %rcx
shlq $0x5, %rcx
movl 0x18(%rax,%rcx), %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
cmpl $0x2, %ebx
jb 0x1c218e
addq %rcx, %rax
movq 0x10(%rax), %r13
movl %r15d, %eax
movq %rax, 0x68(%rsp)
movq (%r13,%rax,8), %rax
movl %eax, %ecx
shrl %ecx
cmpl 0x88(%rsp), %ecx
jne 0x1c2244
movq %rdx, 0x10(%rsp)
movl %eax, %eax
cmpl %eax, 0x80(%rsp)
movq %r13, 0x70(%rsp)
jne 0x1c1e6a
incl %r15d
movq $0x0, 0x18(%rsp)
movq 0x30(%rsp), %r12
cmpq %rbx, %r15
jae 0x1c1f2c
cmpq 0x78(%rsp), %r12
jge 0x1c1f2c
movq (%r13,%r15,8), %rsi
movl %esi, %eax
movq 0x48(%rsp), %rcx
cmpq (%rcx,%r12,8), %rax
jne 0x1c2180
movq 0x30(%rbp), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r14, %rcx
movq 0x30(%rax,%rcx), %rax
movq %rsi, %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rdx
movl (%rax,%rdx), %ecx
movl 0x20(%rax,%rdx), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rcx,2), %edi
cmpl %esi, %edi
jne 0x1c21c8
cmpq $0x0, 0x40(%rsp)
je 0x1c1e40
movq 0x38(%rsp), %rdi
movq (%rdi), %rsi
movq 0x80(%rdi), %rdi
movl (%rsi,%rcx,4), %esi
incq %rdi
cmpq %rsi, %rdi
jb 0x1c1e5f
addq %rdx, %rax
movl 0xc(%rax), %edi
movl 0x10(%rax), %esi
movq 0x18(%rbp), %rax
imulq $0x28, %rcx, %rdx
addq 0x10(%rax), %rdx
callq 0x1b2312
addq %rax, 0x18(%rsp)
incq %r15
incq %r12
jmp 0x1c1dc0
decl %r15d
movslq %r15d, %r15
movq $0x0, 0x18(%rsp)
movq 0x30(%rsp), %r12
testq %r15, %r15
js 0x1c1ffe
cmpq 0x78(%rsp), %r12
jge 0x1c1ffe
movq (%r13,%r15,8), %rsi
movl %esi, %eax
movq 0x48(%rsp), %rcx
xorq (%rcx,%r12,8), %rax
cmpq $0x1, %rax
jne 0x1c2180
movq 0x30(%rbp), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r14, %rcx
movq 0x30(%rax,%rcx), %rax
movq %rsi, %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rdx
movl (%rax,%rdx), %ecx
movl 0x20(%rax,%rdx), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rcx,2), %edi
cmpl %esi, %edi
jne 0x1c21e7
cmpq $0x0, 0x40(%rsp)
je 0x1c1f02
movq 0x38(%rsp), %rdi
movq (%rdi), %rsi
movq 0x80(%rdi), %rdi
movl (%rsi,%rcx,4), %esi
incq %rdi
cmpq %rsi, %rdi
jb 0x1c1f21
addq %rdx, %rax
movl 0xc(%rax), %edi
movl 0x10(%rax), %esi
movq 0x18(%rbp), %rax
imulq $0x28, %rcx, %rdx
addq 0x10(%rax), %rdx
callq 0x1b2312
addq %rax, 0x18(%rsp)
decq %r15
incq %r12
jmp 0x1c1e7e
cmpq 0x30(%rsp), %r12
jle 0x1c2180
cmpq $0x0, 0x18(%rsp)
je 0x1c2180
xorl %r8d, %r8d
movq 0x28(%rsp), %r15
movq 0x68(%rsp), %rbx
movq %rbx, %rax
orq %r15, %rax
setns %al
js 0x1c20e8
movq (%r13,%rbx,8), %rsi
movl %esi, %ecx
movq 0x48(%rsp), %rdx
cmpq (%rdx,%r15,8), %rcx
jne 0x1c20e8
movq 0x30(%rbp), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r14, %rcx
movq 0x30(%rax,%rcx), %rax
movq %rsi, %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rdx
movl (%rax,%rdx), %ecx
movl 0x20(%rax,%rdx), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rcx,2), %edi
cmpl %esi, %edi
jne 0x1c2225
cmpq $0x0, 0x40(%rsp)
je 0x1c1fcb
movq 0x38(%rsp), %rdi
movq (%rdi), %rsi
movq 0x80(%rdi), %rdi
movl (%rsi,%rcx,4), %esi
incq %rdi
cmpq %rsi, %rdi
jb 0x1c1ff3
addq %rdx, %rax
movl 0xc(%rax), %edi
movl 0x10(%rax), %esi
movq 0x18(%rbp), %rax
imulq $0x28, %rcx, %rdx
addq 0x10(%rax), %rdx
movq %r8, %r13
callq 0x1b2312
movq %r13, %r8
movq 0x70(%rsp), %r13
addq %rax, %r8
decq %rbx
decq %r15
jmp 0x1c1f50
cmpq 0x30(%rsp), %r12
jle 0x1c2180
cmpq $0x0, 0x18(%rsp)
je 0x1c2180
movq %rbx, 0x90(%rsp)
xorl %r8d, %r8d
movq 0x28(%rsp), %r15
movq 0x68(%rsp), %rbx
cmpq 0x90(%rsp), %rbx
setb %cl
testq %r15, %r15
setns %al
andb %cl, %al
cmpb $0x1, %al
jne 0x1c20f4
movq (%r13,%rbx,8), %rsi
movl %esi, %ecx
movq 0x48(%rsp), %rdx
xorq (%rdx,%r15,8), %rcx
cmpq $0x1, %rcx
jne 0x1c20f4
movq 0x30(%rbp), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r14, %rcx
movq 0x30(%rax,%rcx), %rax
movq %rsi, %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rdx
movl (%rax,%rdx), %ecx
movl 0x20(%rax,%rdx), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rcx,2), %edi
cmpl %esi, %edi
jne 0x1c2206
cmpq $0x0, 0x40(%rsp)
je 0x1c20b5
movq 0x38(%rsp), %rdi
movq (%rdi), %rsi
movq 0x80(%rdi), %rdi
movl (%rsi,%rcx,4), %esi
incq %rdi
cmpq %rsi, %rdi
jb 0x1c20dd
addq %rdx, %rax
movl 0xc(%rax), %edi
movl 0x10(%rax), %esi
movq 0x18(%rbp), %rax
imulq $0x28, %rcx, %rdx
addq 0x10(%rax), %rdx
movq %r8, %r13
callq 0x1b2312
movq %r13, %r8
movq 0x70(%rsp), %r13
addq %rax, %r8
incq %rbx
decq %r15
jmp 0x1c202a
cmpq 0x28(%rsp), %r15
jl 0x1c20ff
jmp 0x1c2282
cmpq 0x28(%rsp), %r15
jge 0x1c2263
testq %r8, %r8
sete %cl
orb %cl, %al
movq 0x60(%rsp), %r13
jne 0x1c2180
testq %r13, %r13
je 0x1c216d
movq (%r13), %rcx
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rcx
jne 0x1c214d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r13)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r8, %rbx
callq 0x2370
movq %rbx, %r8
movq %rax, 0x10(%r13)
movq (%r13), %rcx
shlq $0x20, %r15
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rdx, %r15
orq %r12, %r15
leaq 0x1(%rcx), %rdx
movq %rdx, (%r13)
movq %r15, (%rax,%rcx,8)
incl 0x24(%rsp)
addq %r8, 0x50(%rsp)
movq 0x18(%rsp), %rax
addq %rax, 0x58(%rsp)
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
movq 0x10(%rsp), %rdx
incq %rdx
jmp 0x1c1d3c
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %rax
cmpq %rcx, %rax
cmovbq %rax, %rcx
movq 0xd0(%rsp), %rax
movq %rcx, (%rax)
movl 0x24(%rsp), %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x37ebf(%rip), %rdi     # 0x1fa08e
leaq 0x35303(%rip), %rsi     # 0x1f74d9
leaq 0x37e43(%rip), %rcx     # 0x1fa020
movl $0x2467, %edx           # imm = 0x2467
callq 0x2110
leaq 0x37ea0(%rip), %rdi     # 0x1fa08e
leaq 0x352e4(%rip), %rsi     # 0x1f74d9
leaq 0x37e24(%rip), %rcx     # 0x1fa020
movl $0x247f, %edx           # imm = 0x247F
callq 0x2110
leaq 0x37e81(%rip), %rdi     # 0x1fa08e
leaq 0x352c5(%rip), %rsi     # 0x1f74d9
leaq 0x37e05(%rip), %rcx     # 0x1fa020
movl $0x248b, %edx           # imm = 0x248B
callq 0x2110
leaq 0x37e62(%rip), %rdi     # 0x1fa08e
leaq 0x352a6(%rip), %rsi     # 0x1f74d9
leaq 0x37de6(%rip), %rcx     # 0x1fa020
movl $0x2473, %edx           # imm = 0x2473
callq 0x2110
leaq 0x37dc3(%rip), %rdi     # 0x1fa00e
leaq 0x35287(%rip), %rsi     # 0x1f74d9
leaq 0x37dc7(%rip), %rcx     # 0x1fa020
movl $0x2461, %edx           # imm = 0x2461
callq 0x2110
leaq 0x37e52(%rip), %rdi     # 0x1fa0bc
leaq 0x35268(%rip), %rsi     # 0x1f74d9
leaq 0x37da8(%rip), %rcx     # 0x1fa020
movl $0x248f, %edx           # imm = 0x248F
callq 0x2110
leaq 0x37e33(%rip), %rdi     # 0x1fa0bc
leaq 0x35249(%rip), %rsi     # 0x1f74d9
leaq 0x37d89(%rip), %rcx     # 0x1fa020
movl $0x2477, %edx           # imm = 0x2477
callq 0x2110