// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_ov_lidel_variant(kv_ul_ov_t*, overlap_region_alloc*, asg64_v*, long)
void gen_ov_lidel_variant(kv_ul_ov_t *cz, overlap_region_alloc *ol, asg64_v *idx, int64_t bd)
{
    uint64_t cbn = cz->n, k, i, t, zwn, m; int64_t q[2]; overlap_region *z; ul_ov_t *cp;
    for (k = idx->n = 0; k < ol->length; k++) {
        z = &(ol->list[k]); zwn = z->w_list.n; 
        if((!zwn) || (z->is_match != 1)) continue;
        for (i = 0; i < zwn; i++) {
            if(is_ualn_win(z->w_list.a[i])) continue;
            q[0] = z->w_list.a[i].x_start; q[1] = z->w_list.a[i].x_end;
            q[0] += bd; q[1] -= bd;
            if(q[1] >= q[0]) {
                m = ((uint64_t)q[0]); m <<= 32; 
                m += (cz->n - cbn); kv_push(uint64_t, *idx, m);

                kv_pushp(ul_ov_t, *cz, &cp);
                ovlp_id(*cp) = k; ///ovlp id
                ovlp_cur_wid(*cp) = i; ///cur id of windows
                ovlp_cur_xoff(*cp) = z->w_list.a[i].x_start; ///cur xpos
                ovlp_cur_yoff(*cp) = z->w_list.a[i].y_start; ///cur xpos
                ovlp_cur_ylen(*cp) = 0;
                ovlp_cur_coff(*cp) = 0; ///cur cigar off in cur window
                ovlp_bd(*cp) = bd;
            }
        }
    }

    radix_sort_bc64(idx->a, idx->a + idx->n);
    for (k = 1, i = 0; k <= idx->n; k++) {
        if (k == idx->n || (idx->a[k]>>32) != (idx->a[i]>>32)) {
            if(k - i > 1) {
                for (t = i; t < k; t++) {
                    cp = &(cz->a[cbn + ((uint32_t)idx->a[t])]);
                    m = ol->list[ovlp_id(*cp)].w_list.a[ovlp_cur_wid(*cp)].x_end+1-ovlp_bd(*cp);
                    m <<= 32; m += ((uint32_t)idx->a[t]); idx->a[t] = m;
                }
                radix_sort_bc64(idx->a + i, idx->a + k);
            }
            i = k;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r12
movq %rsi, %rbx
movq %rdi, %r15
movq 0x8(%rdi), %rax
movq %rax, 0x18(%rsp)
movq $0x0, (%rdx)
movq 0x10(%rsi), %rax
xorl %ecx, %ecx
testq %rax, %rax
movq %rdx, 0x8(%rsp)
je 0x71d6a
movl %r12d, %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x14(%rsp)
xorl %r8d, %r8d
movq %rbx, 0x28(%rsp)
movq (%rbx), %r14
imulq $0xa8, %r8, %rcx
movq 0x48(%r14,%rcx), %rsi
testq %rsi, %rsi
je 0x71d5b
addq %rcx, %r14
cmpb $0x1, 0x2c(%r14)
jne 0x71d5b
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r8, 0x20(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x58(%r14), %rax
cmpw $0x7fff, 0x14(%rax,%r13) # imm = 0x7FFF
jne 0x71c42
cmpl $0x0, 0x1c(%rax,%r13)
jne 0x71c42
cmpw $0x0, 0x12(%rax,%r13)
js 0x71d42
movslq (%rax,%r13), %rbx
movslq 0x4(%rax,%r13), %rax
addq %r12, %rbx
subq %r12, %rax
cmpq %rbx, %rax
jl 0x71d42
shlq $0x20, %rbx
subq 0x18(%rsp), %rbx
addq 0x8(%r15), %rbx
movq (%rdx), %rcx
movq 0x10(%rdx), %rax
cmpq 0x8(%rdx), %rcx
jne 0x71ca0
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %rdx
movq %rax, 0x10(%rdx)
movq (%rdx), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rdx)
movq %rbx, (%rax,%rcx,8)
movq (%r15), %rax
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x71ceb
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r15)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %rdx
movq %rax, (%r15)
movq 0x8(%r15), %rcx
movq 0x20(%rsp), %r8
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r15)
leaq (%rcx,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rdi
addq %rcx, %rdi
movl %r8d, 0xc(%rax,%rdi)
movl %ebp, (%rax,%rdi)
movq 0x58(%r14), %rcx
movl (%rcx,%r13), %esi
movl %esi, 0x4(%rax,%rdi)
movl 0x8(%rcx,%r13), %ecx
movl %ecx, 0x10(%rax,%rdi)
xorl %ecx, %ecx
movl %ecx, 0x14(%rax,%rdi)
movl %ecx, 0x8(%rax,%rdi)
movl 0x18(%rax,%rdi), %ecx
movl $0xc0000000, %esi       # imm = 0xC0000000
andl %esi, %ecx
addl 0x14(%rsp), %ecx
movl %ecx, 0x18(%rax,%rdi)
movq 0x30(%rsp), %rsi
incq %rbp
addq $0x20, %r13
cmpq %rbp, %rsi
jne 0x71c1f
movq 0x28(%rsp), %rbx
movq 0x10(%rbx), %rax
incq %r8
cmpq %rax, %r8
jb 0x71bea
movq (%rdx), %rcx
movq 0x10(%rdx), %rdi
leaq (%rdi,%rcx,8), %rsi
callq 0x45373
movq 0x8(%rsp), %rdi
movq (%rdi), %rcx
testq %rcx, %rcx
je 0x71e5a
movl $0x1, %r14d
xorl %eax, %eax
movq 0x18(%rsp), %rsi
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %r12
addq %rsi, %r12
movl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
cmpq %rcx, %r14
je 0x71dc4
movq 0x10(%rdi), %rdx
movq (%rdx,%rax,8), %rsi
xorq (%rdx,%r14,8), %rsi
shrq $0x20, %rsi
jne 0x71dc4
movq %rax, %rdx
jmp 0x71e4b
movq %r14, %rsi
subq %rax, %rsi
movq %r14, %rdx
cmpq $0x2, %rsi
jb 0x71e4b
movq 0x10(%rdi), %rcx
cmpq %rax, %r14
jbe 0x71e33
movq (%r15), %rdx
addq %r12, %rdx
movq (%rbx), %rsi
movq %rax, %rdi
movl (%rcx,%rdi,8), %r8d
leaq (%r8,%r8,8), %r9
leaq (%r9,%r9,2), %r9
addq %r8, %r9
movl (%rdx,%r9), %r8d
movl 0xc(%rdx,%r9), %r10d
imulq $0xa8, %r10, %r10
movq 0x58(%rsi,%r10), %r10
shlq $0x5, %r8
movl 0x4(%r10,%r8), %r8d
movl 0x18(%rdx,%r9), %r9d
andl %ebp, %r9d
negl %r9d
addl %r9d, %r8d
incl %r8d
movl %r8d, 0x4(%rcx,%rdi,8)
incq %rdi
cmpq %rdi, %r14
jne 0x71de8
leaq (%rcx,%rax,8), %rdi
leaq (%rcx,%r14,8), %rsi
callq 0x45373
movq 0x8(%rsp), %rdi
movq (%rdi), %rcx
movq %r14, %rdx
incq %r14
movq %rdx, %rax
cmpq %rcx, %r14
jbe 0x71da5
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq