// File: /workspace/github_cpp_makefile_star2_O3/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 $0xa8, %rsp
movq %r8, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movq %rdi, %r10
movq 0xe0(%rsp), %r8
movq (%rsi,%rcx,8), %rax
movq 0x28(%rdi), %rdx
movq %rdx, 0x58(%rsp)
movq 0x1a0(%rdi), %rdi
movl %eax, %r15d
shrl %r15d
movq (%rdi,%r15,8), %rdx
movq 0x8(%rdi,%r15,8), %rbp
leaq (,%rdx,8), %r11
addq 0x1b8(%r10), %r11
movq $0x0, (%r8)
subq %rdx, %rbp
jne 0x20eb95
movq $0x0, 0x80(%rsp)
movq $0x0, 0x78(%rsp)
movl $0x0, 0x44(%rsp)
movq 0x80(%rsp), %rcx
movq 0x78(%rsp), %rax
cmpq %rcx, %rax
cmovbq %rax, %rcx
movq 0xe0(%rsp), %rax
movq %rcx, (%rax)
movl 0x44(%rsp), %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %eax
movq %rax, 0x98(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x90(%rsp)
leaq (%rsi,%rcx,8), %rax
addq $0x8, %rax
movq %rax, 0xa0(%rsp)
xorl %r8d, %r8d
movl $0x0, 0x44(%rsp)
movq $0x0, 0x78(%rsp)
movq $0x0, 0x80(%rsp)
movq %r9, 0x88(%rsp)
movq %rcx, 0x8(%rsp)
movq %rsi, %rdi
movq %rsi, 0x28(%rsp)
movq %r10, 0x38(%rsp)
movq %r15, 0x30(%rsp)
movq %rbp, 0x20(%rsp)
movq %r11, 0x10(%rsp)
movq 0x1d0(%r10), %rax
movq (%r11,%r8,8), %r12
movq %r12, %r13
shrq $0x20, %r13
movq %r13, %rdx
shlq $0x5, %rdx
movl 0x18(%rax,%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %rsi, 0x50(%rsp)
cmpl $0x2, %esi
jb 0x20f06f
movq %r8, 0x18(%rsp)
addq %rdx, %rax
movq 0x10(%rax), %rax
movl %r12d, %r14d
movq %rax, 0x60(%rsp)
movq (%rax,%r14,8), %rax
movl %eax, %edx
shrl %edx
cmpl %r15d, %edx
jne 0x20f1a2
movl %eax, %eax
cmpl %eax, 0x98(%rsp)
jne 0x20ee63
movq 0x90(%rsp), %rax
cmpq 0x68(%rsp), %rax
setl %al
incl %r12d
cmpq 0x50(%rsp), %r12
setb %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x20f065
movq 0x60(%rsp), %rax
leaq (%rax,%r12,8), %rbx
incq %r12
xorl %ebp, %ebp
movq $0x0, 0x48(%rsp)
movq (%rbx,%rbp,8), %rsi
movl %esi, %eax
movq 0xa0(%rsp), %rcx
cmpq (%rcx,%rbp,8), %rax
jne 0x20f051
movq 0x30(%r10), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r13, %r15
movq 0x30(%rax,%r15), %rcx
movq %rsi, %rax
shrq $0x20, %rax
leaq (%rax,%rax,8), %rdx
movl (%rcx,%rdx,4), %eax
movl 0x20(%rcx,%rdx,4), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rax,2), %edi
cmpl %esi, %edi
jne 0x20f164
cmpq $0x0, 0x70(%rsp)
je 0x20ed14
movq 0x58(%rsp), %rdi
movq (%rdi), %rsi
movq 0x80(%rdi), %rdi
movl (%rsi,%rax,4), %esi
incq %rdi
cmpq %rsi, %rdi
jb 0x20ed3d
leaq (%rcx,%rdx,4), %rcx
movl 0xc(%rcx), %edi
movl 0x10(%rcx), %esi
movq 0x18(%r10), %rcx
leaq (%rax,%rax,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rcx), %rdx
callq 0x1fe266
movq 0x38(%rsp), %r10
addq %rax, 0x48(%rsp)
leaq (%r12,%rbp), %rcx
leaq 0x1(%rbp), %rax
cmpq 0x50(%rsp), %rcx
jae 0x20ed66
movq 0x8(%rsp), %rcx
addq %rbp, %rcx
addq $0x2, %rcx
movq %rax, %rbp
cmpq 0x68(%rsp), %rcx
jl 0x20eca6
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %rdx
cmpq %rcx, %rdx
movq 0x28(%rsp), %rdi
jle 0x20f05b
cmpq $0x0, 0x48(%rsp)
je 0x20f05b
testq %rcx, %rcx
js 0x20f21e
leaq (%rcx,%rax), %rbx
incq %rbx
movq %rcx, %r12
xorl %r8d, %r8d
movq 0x60(%rsp), %rax
movq (%rax,%r14,8), %rsi
movl %esi, %r9d
movq (%rdi,%r12,8), %rbp
cmpq %rbp, %r9
movq %r9, 0x50(%rsp)
jne 0x20f080
movq 0x30(%r10), %rax
movq 0x48(%rax), %rax
movq 0x30(%rax,%r15), %rcx
movq %rsi, %rax
shrq $0x20, %rax
leaq (%rax,%rax,8), %rdx
movl (%rcx,%rdx,4), %eax
movl 0x20(%rcx,%rdx,4), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rax,2), %edi
cmpl %esi, %edi
jne 0x20f1c1
cmpq $0x0, 0x70(%rsp)
je 0x20ee0f
movq 0x58(%rsp), %rdi
movq (%rdi), %rsi
movq 0x80(%rdi), %rdi
movl (%rsi,%rax,4), %esi
incq %rdi
cmpq %rsi, %rdi
jb 0x20ee37
leaq (%rcx,%rdx,4), %rcx
movl 0xc(%rcx), %edi
movl 0x10(%rcx), %esi
movq 0x18(%r10), %rcx
leaq (%rax,%rax,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rcx), %rdx
movq %r8, %r13
callq 0x1fe266
movq %r13, %r8
addq %rax, %r8
movq 0x28(%rsp), %rdi
leaq -0x1(%r12), %r13
testq %r14, %r14
jle 0x20f08a
decq %r14
testq %r12, %r12
movq %r13, %r12
movq 0x38(%rsp), %r10
jg 0x20ed9f
jmp 0x20f08f
movq 0x90(%rsp), %rax
cmpq 0x68(%rsp), %rax
setl %al
decl %r12d
movslq %r12d, %rbp
testq %rbp, %rbp
setns %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x20f060
movq %rcx, %r12
movq $0x0, 0x48(%rsp)
movq 0x60(%rsp), %rax
movq (%rax,%rbp,8), %rsi
movl %esi, %eax
xorq 0x8(%rdi,%r12,8), %rax
cmpq $0x1, %rax
jne 0x20f04a
movq 0x30(%r10), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r13, %r15
movq 0x30(%rax,%r15), %rcx
movq %rsi, %rax
shrq $0x20, %rax
leaq (%rax,%rax,8), %rdx
movl (%rcx,%rdx,4), %eax
movl 0x20(%rcx,%rdx,4), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rax,2), %edi
cmpl %esi, %edi
jne 0x20f183
cmpq $0x0, 0x70(%rsp)
je 0x20ef06
movq 0x58(%rsp), %rdi
movq (%rdi), %rsi
movq 0x80(%rdi), %rdi
movl (%rsi,%rax,4), %esi
incq %rdi
cmpq %rsi, %rdi
jb 0x20ef2f
leaq (%rcx,%rdx,4), %rcx
movl 0xc(%rcx), %edi
movl 0x10(%rcx), %esi
movq 0x18(%r10), %rcx
leaq (%rax,%rax,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rcx), %rdx
callq 0x1fe266
movq 0x38(%rsp), %r10
addq %rax, 0x48(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x1(%r12), %rbx
testq %rbp, %rbp
jle 0x20ef53
decq %rbp
addq $0x2, %r12
cmpq 0x68(%rsp), %r12
movq %rbx, %r12
jl 0x20ee96
cmpq 0x8(%rsp), %rbx
jle 0x20f04a
cmpq $0x0, 0x48(%rsp)
je 0x20f04a
cmpl 0x50(%rsp), %r14d
jae 0x20f1ff
cmpq $0x0, 0x8(%rsp)
js 0x20f1ff
incq %rbx
incq %r14
movq 0x8(%rsp), %r12
xorl %r8d, %r8d
movq 0x60(%rsp), %rax
movq -0x8(%rax,%r14,8), %rsi
movl %esi, %ebp
xorq (%rdi,%r12,8), %rbp
cmpq $0x1, %rbp
jne 0x20f085
movq 0x30(%r10), %rax
movq 0x48(%rax), %rax
movq 0x30(%rax,%r15), %rcx
movq %rsi, %rax
shrq $0x20, %rax
leaq (%rax,%rax,8), %rdx
movl (%rcx,%rdx,4), %eax
movl 0x20(%rcx,%rdx,4), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rax,2), %edi
cmpl %esi, %edi
jne 0x20f1e0
cmpq $0x0, 0x70(%rsp)
je 0x20effb
movq 0x58(%rsp), %rdi
movq (%rdi), %rsi
movq 0x80(%rdi), %rdi
movl (%rsi,%rax,4), %esi
incq %rdi
cmpq %rsi, %rdi
jb 0x20f023
leaq (%rcx,%rdx,4), %rcx
movl 0xc(%rcx), %edi
movl 0x10(%rcx), %esi
movq 0x18(%r10), %rcx
leaq (%rax,%rax,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rcx), %rdx
movq %r8, %r13
callq 0x1fe266
movq %r13, %r8
addq %rax, %r8
movq 0x28(%rsp), %rdi
leaq -0x1(%r12), %r13
cmpq 0x50(%rsp), %r14
jae 0x20f0a1
incq %r14
testq %r12, %r12
movq %r13, %r12
movq 0x38(%rsp), %r10
jg 0x20ef8f
jmp 0x20f0a6
movq 0x8(%rsp), %rcx
jmp 0x20f05b
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %r15
movq 0x20(%rsp), %rbp
movq 0x10(%rsp), %r11
movq 0x18(%rsp), %r8
incq %r8
cmpq %rbp, %r8
jne 0x20ec04
jmp 0x20eb60
movq %r12, %r13
jmp 0x20f08f
movq %r12, %r13
jmp 0x20f0a6
movq 0x38(%rsp), %r10
cmpq 0x8(%rsp), %r13
jge 0x20f21e
cmpq %rbp, 0x50(%rsp)
jmp 0x20f0b5
movq 0x38(%rsp), %r10
cmpq 0x8(%rsp), %r13
jge 0x20f1ff
cmpq $0x1, %rbp
movq 0x30(%rsp), %r15
jne 0x20f15a
testq %r8, %r8
movq 0x88(%rsp), %r14
movq 0x20(%rsp), %rbp
je 0x20f150
testq %r14, %r14
je 0x20f13a
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x20f11b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r8, %r12
callq 0x2370
movq %r12, %r8
movq 0x38(%rsp), %r10
movq 0x28(%rsp), %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rcx
shlq $0x20, %r13
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rdx, %r13
orq %rbx, %r13
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movq %r13, (%rax,%rcx,8)
incl 0x44(%rsp)
addq %r8, 0x78(%rsp)
movq 0x48(%rsp), %rax
addq %rax, 0x80(%rsp)
movq 0x8(%rsp), %rcx
jmp 0x20f065
movq 0x8(%rsp), %rcx
jmp 0x20f060
leaq 0x38f64(%rip), %rdi     # 0x2480cf
leaq 0x36497(%rip), %rsi     # 0x245609
leaq 0x38ee8(%rip), %rcx     # 0x248061
movl $0x2467, %edx           # imm = 0x2467
callq 0x2110
leaq 0x38f45(%rip), %rdi     # 0x2480cf
leaq 0x36478(%rip), %rsi     # 0x245609
leaq 0x38ec9(%rip), %rcx     # 0x248061
movl $0x247f, %edx           # imm = 0x247F
callq 0x2110
leaq 0x38ea6(%rip), %rdi     # 0x24804f
leaq 0x36459(%rip), %rsi     # 0x245609
leaq 0x38eaa(%rip), %rcx     # 0x248061
movl $0x2461, %edx           # imm = 0x2461
callq 0x2110
leaq 0x38f07(%rip), %rdi     # 0x2480cf
leaq 0x3643a(%rip), %rsi     # 0x245609
leaq 0x38e8b(%rip), %rcx     # 0x248061
movl $0x2473, %edx           # imm = 0x2473
callq 0x2110
leaq 0x38ee8(%rip), %rdi     # 0x2480cf
leaq 0x3641b(%rip), %rsi     # 0x245609
leaq 0x38e6c(%rip), %rcx     # 0x248061
movl $0x248b, %edx           # imm = 0x248B
callq 0x2110
leaq 0x38ef7(%rip), %rdi     # 0x2480fd
leaq 0x363fc(%rip), %rsi     # 0x245609
leaq 0x38e4d(%rip), %rcx     # 0x248061
movl $0x248f, %edx           # imm = 0x248F
callq 0x2110
leaq 0x38ed8(%rip), %rdi     # 0x2480fd
leaq 0x363dd(%rip), %rsi     # 0x245609
leaq 0x38e2e(%rip), %rcx     # 0x248061
movl $0x2477, %edx           # imm = 0x2477
callq 0x2110