// File: /workspace/github_cpp_makefile_star2_O2/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 %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r15
movq 0x8(%rdi), %rax
movq %rax, 0x18(%rsp)
andq $0x0, (%rdx)
movl %ecx, %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, 0xc(%rsp)
xorl %r8d, %r8d
movq %rcx, 0x10(%rsp)
movq %rsi, 0x30(%rsp)
cmpq 0x10(%r13), %r8
jae 0x4022e
movq (%r13), %rbp
imulq $0xa8, %r8, %rax
movq 0x48(%rbp,%rax), %r9
testq %r9, %r9
je 0x40221
addq %rax, %rbp
cmpb $0x1, 0x2c(%rbp)
jne 0x40221
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %r8, 0x28(%rsp)
movq %r9, 0x20(%rsp)
cmpq %r13, %r9
je 0x40221
movq 0x58(%rbp), %rax
cmpw $0x7fff, 0x14(%rax,%r14) # imm = 0x7FFF
jne 0x4012b
cmpl $0x0, 0x1c(%rax,%r14)
jne 0x4012b
cmpw $0x0, 0x12(%rax,%r14)
js 0x40215
movslq (%rax,%r14), %r12
movslq 0x4(%rax,%r14), %rax
addq %rcx, %r12
subq %rcx, %rax
cmpq %r12, %rax
jl 0x40215
shlq $0x20, %r12
subq 0x18(%rsp), %r12
addq 0x8(%r15), %r12
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x40182
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq %r12, (%rax,%rcx,8)
movq (%r15), %rax
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
jne 0x401bf
leaq (%rsi,%rsi), %rdx
testq %rsi, %rsi
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r15)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r15)
movq 0x8(%r15), %rsi
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
leaq 0x1(%rsi), %rdx
movq %rdx, 0x8(%r15)
imulq $0x1c, %rsi, %rdi
movl %r8d, 0xc(%rax,%rdi)
movl %r13d, (%rax,%rdi)
movq 0x58(%rbp), %rdx
movl (%rdx,%r14), %esi
movl %esi, 0x4(%rax,%rdi)
movl 0x8(%rdx,%r14), %edx
movl %edx, 0x10(%rax,%rdi)
andl $0x0, 0x14(%rax,%rdi)
andl $0x0, 0x8(%rax,%rdi)
movl 0x18(%rax,%rdi), %edx
movl $0xc0000000, %esi       # imm = 0xC0000000
andl %esi, %edx
addl 0xc(%rsp), %edx
movl %edx, 0x18(%rax,%rdi)
incq %r13
addq $0x20, %r14
jmp 0x400ff
incq %r8
movq 0x30(%rsp), %r13
jmp 0x400bf
movq (%rbx), %rax
movq 0x10(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1905d
pushq $0x1
popq %r14
xorl %eax, %eax
imulq $0x1c, 0x18(%rsp), %r12
movl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
cmpq (%rbx), %r14
ja 0x402f0
je 0x40271
movq 0x10(%rbx), %rcx
movq (%rcx,%rax,8), %rdx
xorq (%rcx,%r14,8), %rdx
shrq $0x20, %rdx
jne 0x40271
movq %rax, %rcx
jmp 0x402e5
movq %r14, %rdx
subq %rax, %rdx
movq %r14, %rcx
cmpq $0x2, %rdx
jb 0x402e5
movq %rax, %rcx
cmpq %r14, %rcx
jae 0x402d1
movq 0x10(%rbx), %rdx
movl (%rdx,%rcx,8), %esi
movq (%r15), %rdi
addq %r12, %rdi
imulq $0x1c, %rsi, %rsi
movq (%r13), %r8
movl (%rsi,%rdi), %r9d
movl 0xc(%rsi,%rdi), %r10d
imulq $0xa8, %r10, %r10
movq 0x58(%r8,%r10), %r8
shlq $0x5, %r9
movl 0x4(%r8,%r9), %r8d
movl 0x18(%rsi,%rdi), %esi
andl %ebp, %esi
negl %esi
addl %r8d, %esi
incl %esi
movl %esi, 0x4(%rdx,%rcx,8)
incq %rcx
jmp 0x40283
movq 0x10(%rbx), %rcx
leaq (%rcx,%rax,8), %rdi
leaq (%rcx,%r14,8), %rsi
callq 0x1905d
movq %r14, %rcx
incq %r14
movq %rcx, %rax
jmp 0x4024f
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq