// File: /workspace/github_cpp_makefile_star2_O1/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 $0xb8, %rsp
movq %r9, %r15
movq %r8, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq 0xf0(%rsp), %r8
movq %rsi, 0x38(%rsp)
movq (%rsi,%rcx,8), %rax
movq 0x28(%rdi), %rdx
movq %rdx, 0x58(%rsp)
movq 0x1a0(%rdi), %rsi
movl %eax, %r9d
shrl %r9d
movq (%rsi,%r9,8), %rdx
movq %r9, 0xb0(%rsp)
movq 0x8(%rsi,%r9,8), %r9
leaq (,%rdx,8), %r10
movq %rdi, 0x30(%rsp)
addq 0x1b8(%rdi), %r10
movq $0x0, (%r8)
subq %rdx, %r9
jne 0x203550
xorl %ecx, %ecx
xorl %eax, %eax
xorl %edx, %edx
jmp 0x203c02
movl %eax, %eax
movq %rax, 0xa8(%rsp)
leaq 0x1(%rcx), %rdx
testq %rcx, %rcx
setns 0xf(%rsp)
leaq 0x2(%rcx), %rax
movq %rax, 0x78(%rsp)
leaq -0x1(%rcx), %rax
movq %rax, 0x70(%rsp)
xorl %edi, %edi
movq $0x0, 0x88(%rsp)
movq $0x0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
movq %r15, 0x50(%rsp)
movq %rcx, %rsi
movq %rcx, 0x48(%rsp)
movq %r9, 0x18(%rsp)
movq %r10, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
movq 0x30(%rsp), %rax
movq 0x1d0(%rax), %rax
movq (%r10,%rdi,8), %r12
movq %r12, %r8
shrq $0x20, %r8
movq %r8, %rcx
shlq $0x5, %rcx
movl 0x18(%rax,%rcx), %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
cmpl $0x2, %ebx
jb 0x203bde
addq %rcx, %rax
movq 0x10(%rax), %rax
movl %r12d, %ebp
movq %rax, 0x40(%rsp)
movq (%rax,%rbp,8), %rax
movl %eax, %ecx
shrl %ecx
cmpl 0xb0(%rsp), %ecx
jne 0x203c85
movl %eax, %eax
cmpl %eax, 0xa8(%rsp)
movq %rdi, 0x28(%rsp)
movq %r8, 0xa0(%rsp)
jne 0x203745
cmpq 0x60(%rsp), %rdx
setl %al
incl %r12d
cmpq %rbx, %r12
setb %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x20385e
movq 0x40(%rsp), %rax
movq (%rax,%r12,8), %rax
movl %eax, %edx
movq 0x38(%rsp), %rdi
cmpq 0x8(%rdi,%rsi,8), %rdx
jne 0x203871
movq 0x30(%rsp), %rcx
movq 0x30(%rcx), %rcx
movq 0x48(%rcx), %rcx
imulq $0x58, %r8, %rdx
movq 0x30(%rcx,%rdx), %r15
incq %r12
movq 0x78(%rsp), %r14
xorl %r13d, %r13d
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,8), %rdx
movl (%r15,%rdx,4), %ecx
movl 0x20(%r15,%rdx,4), %esi
shrl $0x5, %esi
andl $0x1, %esi
leal (%rsi,%rcx,2), %esi
cmpl %eax, %esi
jne 0x203c47
cmpq $0x0, 0x68(%rsp)
je 0x2036ca
movq 0x58(%rsp), %rsi
movq (%rsi), %rax
movq 0x80(%rsi), %rsi
movl (%rax,%rcx,4), %eax
incq %rsi
cmpq %rax, %rsi
jb 0x2036f1
leaq (%r15,%rdx,4), %rax
movl 0xc(%rax), %edi
movl 0x10(%rax), %esi
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
callq 0x1f2d50
addq %rax, %r13
cmpq %rbx, %r12
setb %al
cmpq 0x60(%rsp), %r14
setl %cl
andb %al, %cl
je 0x20389d
movq 0x40(%rsp), %rax
movq (%rax,%r12,8), %rax
movl %eax, %esi
incq %r12
leaq 0x1(%r14), %rdx
movq 0x38(%rsp), %rdi
cmpq (%rdi,%r14,8), %rsi
movq %rdx, %r14
je 0x203683
decq %rdx
movq %rdx, %r14
movq 0x50(%rsp), %r15
movq 0x48(%rsp), %rsi
movq 0x20(%rsp), %rdx
jmp 0x20387c
cmpq 0x60(%rsp), %rdx
setl %al
decl %r12d
movslq %r12d, %r12
testq %r12, %r12
setns %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x203866
movq 0x40(%rsp), %rax
movq (%rax,%r12,8), %rax
movl %eax, %edx
movq 0x38(%rsp), %rdi
xorq 0x8(%rdi,%rsi,8), %rdx
cmpq $0x1, %rdx
jne 0x203885
movq 0x30(%rsp), %rcx
movq 0x30(%rcx), %rcx
movq 0x48(%rcx), %rcx
imulq $0x58, %r8, %rdx
movq 0x30(%rcx,%rdx), %r15
movq 0x78(%rsp), %r14
xorl %r13d, %r13d
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,8), %rdx
movl (%r15,%rdx,4), %ecx
movl 0x20(%r15,%rdx,4), %esi
shrl $0x5, %esi
andl $0x1, %esi
leal (%rsi,%rcx,2), %esi
cmpl %eax, %esi
jne 0x203c28
cmpq $0x0, 0x68(%rsp)
je 0x2037e8
movq 0x58(%rsp), %rsi
movq (%rsi), %rax
movq 0x80(%rsi), %rsi
movl (%rax,%rcx,4), %eax
incq %rsi
cmpq %rax, %rsi
jb 0x20380f
leaq (%r15,%rdx,4), %rax
movl 0xc(%rax), %edi
movl 0x10(%rax), %esi
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
callq 0x1f2d50
addq %rax, %r13
testq %r12, %r12
setg %al
cmpq 0x60(%rsp), %r14
setl %cl
andb %al, %cl
je 0x2039e5
movq 0x40(%rsp), %rax
movq -0x8(%rax,%r12,8), %rax
decq %r12
movl %eax, %edx
movq 0x38(%rsp), %rsi
xorq (%rsi,%r14,8), %rdx
incq %r14
cmpq $0x1, %rdx
je 0x2037a1
decq %r14
movq 0x50(%rsp), %r15
movq 0x48(%rsp), %rsi
movq 0x20(%rsp), %rdx
jmp 0x203890
xorl %r13d, %r13d
movq %rdx, %r14
jmp 0x2038ac
xorl %r13d, %r13d
movq %rdx, %r14
jmp 0x2039f4
movq 0x20(%rsp), %rdx
movq %rdx, %r14
xorl %r13d, %r13d
testb %cl, %cl
je 0x2038ac
jmp 0x203bcf
movq 0x20(%rsp), %rdx
movq %rdx, %r14
xorl %r13d, %r13d
testb %cl, %cl
je 0x2039f4
jmp 0x203bcf
movq 0x50(%rsp), %r15
movq 0x48(%rsp), %rsi
movq 0x20(%rsp), %rdx
cmpq %rdx, %r14
jle 0x203bcf
testq %r13, %r13
je 0x203bcf
testq %rsi, %rsi
movq %r13, 0x98(%rsp)
js 0x2039b5
movq 0x40(%rsp), %rax
movq (%rax,%rbp,8), %rax
movl %eax, %ecx
movq 0x38(%rsp), %rdx
cmpq (%rdx,%rsi,8), %rcx
jne 0x2039b5
movq 0x30(%rsp), %rcx
movq 0x30(%rcx), %rcx
movq 0x48(%rcx), %rcx
imulq $0x58, 0xa0(%rsp), %rdx
movq 0x30(%rcx,%rdx), %rbx
movq 0x70(%rsp), %rdx
xorl %r13d, %r13d
movq %rdx, %r12
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,8), %rdx
movl (%rbx,%rdx,4), %ecx
movl 0x20(%rbx,%rdx,4), %esi
shrl $0x5, %esi
andl $0x1, %esi
leal (%rsi,%rcx,2), %esi
cmpl %eax, %esi
jne 0x203c66
cmpq $0x0, 0x68(%rsp)
je 0x203954
movq 0x58(%rsp), %rsi
movq (%rsi), %rax
movq 0x80(%rsi), %rsi
movl (%rax,%rcx,4), %eax
incq %rsi
cmpq %rax, %rsi
jb 0x20397b
leaq (%rbx,%rdx,4), %rax
movl 0xc(%rax), %edi
movl 0x10(%rax), %esi
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
callq 0x1f2d50
addq %rax, %r13
leaq 0x1(%r12), %rax
testq %rbp, %rbp
setg %dl
testq %rax, %rax
setg %cl
andb %dl, %cl
je 0x2039bf
movq 0x40(%rsp), %rax
movq -0x8(%rax,%rbp,8), %rax
decq %rbp
movl %eax, %esi
leaq -0x1(%r12), %rdx
movq 0x38(%rsp), %rdi
cmpq (%rdi,%r12,8), %rsi
je 0x20390c
jmp 0x2039bf
xorl %r13d, %r13d
movq %rsi, %r12
movb 0xf(%rsp), %cl
movq 0x48(%rsp), %rsi
cmpq %rsi, %r12
jge 0x203ce2
testq %r13, %r13
sete %al
orb %al, %cl
movq 0x20(%rsp), %rdx
je 0x203b4c
jmp 0x203bcf
movq 0x50(%rsp), %r15
movq 0x48(%rsp), %rsi
movq 0x20(%rsp), %rdx
cmpq %rdx, %r14
jle 0x203bcf
testq %r13, %r13
je 0x203bcf
testq %rsi, %rsi
setns %cl
cmpl %ebx, %ebp
setb %al
andb %cl, %al
cmpb $0x1, %al
movq %r13, 0x98(%rsp)
jne 0x203b1d
movq 0x40(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movl %ecx, %edx
movq 0x38(%rsp), %rdi
xorq (%rdi,%rsi,8), %rdx
cmpq $0x1, %rdx
jne 0x203b1d
movq 0x30(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x48(%rax), %rax
imulq $0x58, 0xa0(%rsp), %rdx
movq 0x30(%rax,%rdx), %r13
incq %rbp
movq 0x70(%rsp), %rdx
xorl %r15d, %r15d
movq %rdx, %r12
movq %rcx, %rax
shrq $0x20, %rax
leaq (%rax,%rax,8), %rdx
movl (%r13,%rdx,4), %eax
movl 0x20(%r13,%rdx,4), %esi
shrl $0x5, %esi
andl $0x1, %esi
leal (%rsi,%rax,2), %esi
cmpl %ecx, %esi
jne 0x203ca4
cmpq $0x0, 0x68(%rsp)
je 0x203ab2
movq 0x58(%rsp), %rsi
movq (%rsi), %rcx
movq 0x80(%rsi), %rsi
movl (%rcx,%rax,4), %ecx
incq %rsi
cmpq %rcx, %rsi
jb 0x203ae0
leaq (,%rdx,4), %rcx
addq %r13, %rcx
movl 0xc(%rcx), %edi
movl 0x10(%rcx), %esi
movq 0x30(%rsp), %rcx
movq 0x18(%rcx), %rcx
leaq (%rax,%rax,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rcx), %rdx
callq 0x1f2d50
addq %rax, %r15
leaq 0x1(%r12), %rax
cmpq %rbx, %rbp
setb %cl
testq %rax, %rax
setg %al
andb %cl, %al
je 0x203b23
movq 0x40(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movl %ecx, %esi
movq 0x38(%rsp), %rdx
xorq (%rdx,%r12,8), %rsi
incq %rbp
leaq -0x1(%r12), %rdx
cmpq $0x1, %rsi
je 0x203a67
jmp 0x203b23
xorl %r15d, %r15d
movq %rsi, %r12
movq 0x48(%rsp), %rsi
cmpq %rsi, %r12
jge 0x203cc3
movq %r15, %r13
testq %r15, %r15
sete %cl
orb %cl, %al
movq 0x20(%rsp), %rdx
movq 0x50(%rsp), %r15
jne 0x203bcf
testq %r15, %r15
je 0x203baf
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x203b84
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x48(%rsp), %rsi
movq %rax, 0x10(%r15)
shlq $0x20, %r12
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r12
orq %r14, %r12
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movq %r12, (%rcx,%rax,8)
movq 0x20(%rsp), %rdx
incq 0x88(%rsp)
addq %r13, 0x80(%rsp)
movq 0x98(%rsp), %rax
addq %rax, 0x90(%rsp)
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %r10
movq 0x28(%rsp), %rdi
incq %rdi
cmpq %r9, %rdi
jne 0x2035ba
movq 0x90(%rsp), %rcx
movq 0x88(%rsp), %rdx
movq 0x80(%rsp), %rax
cmpq %rcx, %rax
cmovbq %rax, %rcx
movq 0xf0(%rsp), %rax
movq %rcx, (%rax)
movl %edx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x381bc(%rip), %rdi     # 0x23bdeb
leaq 0x356ef(%rip), %rsi     # 0x239325
leaq 0x38140(%rip), %rcx     # 0x23bd7d
movl $0x247f, %edx           # imm = 0x247F
callq 0x2110
leaq 0x3819d(%rip), %rdi     # 0x23bdeb
leaq 0x356d0(%rip), %rsi     # 0x239325
leaq 0x38121(%rip), %rcx     # 0x23bd7d
movl $0x2467, %edx           # imm = 0x2467
callq 0x2110
leaq 0x3817e(%rip), %rdi     # 0x23bdeb
leaq 0x356b1(%rip), %rsi     # 0x239325
leaq 0x38102(%rip), %rcx     # 0x23bd7d
movl $0x2473, %edx           # imm = 0x2473
callq 0x2110
leaq 0x380df(%rip), %rdi     # 0x23bd6b
leaq 0x35692(%rip), %rsi     # 0x239325
leaq 0x380e3(%rip), %rcx     # 0x23bd7d
movl $0x2461, %edx           # imm = 0x2461
callq 0x2110
leaq 0x38140(%rip), %rdi     # 0x23bdeb
leaq 0x35673(%rip), %rsi     # 0x239325
leaq 0x380c4(%rip), %rcx     # 0x23bd7d
movl $0x248b, %edx           # imm = 0x248B
callq 0x2110
leaq 0x3814f(%rip), %rdi     # 0x23be19
leaq 0x35654(%rip), %rsi     # 0x239325
leaq 0x380a5(%rip), %rcx     # 0x23bd7d
movl $0x248f, %edx           # imm = 0x248F
callq 0x2110
leaq 0x38130(%rip), %rdi     # 0x23be19
leaq 0x35635(%rip), %rsi     # 0x239325
leaq 0x38086(%rip), %rcx     # 0x23bd7d
movl $0x2477, %edx           # imm = 0x2477
callq 0x2110