// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq $0x0, (%rdx)
cmpq $0x0, 0x10(%rsi)
je 0x723b7
movl %ecx, %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, 0xc(%rsp)
xorl %edi, %edi
movq %r13, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movq (%r13), %r14
imulq $0xa8, %rdi, %rax
movq 0x48(%r14,%rax), %rdx
testq %rdx, %rdx
je 0x723a5
addq %rax, %r14
cmpb $0x1, 0x2c(%r14)
jne 0x723a5
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %rdi, 0x18(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x58(%r14), %rax
cmpw $0x7fff, 0x14(%rax,%r13) # imm = 0x7FFF
jne 0x72295
cmpl $0x0, 0x1c(%rax,%r13)
jne 0x72295
cmpw $0x0, 0x12(%rax,%r13)
js 0x72395
movslq (%rax,%r13), %r12
movslq 0x4(%rax,%r13), %rax
addq %rcx, %r12
subq %rcx, %rax
cmpq %r12, %rax
jl 0x72395
shlq $0x20, %r12
subq 0x10(%rsp), %r12
addq 0x8(%r15), %r12
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x722ed
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x18(%rsp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %r12, (%rcx,%rax,8)
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x72338
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r15)
movq (%r15), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq 0x18(%rsp), %rdi
movq %rax, (%r15)
movq (%r15), %rax
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl %edi, 0xc(%rax,%rdx)
movl %ebp, (%rax,%rdx)
movq 0x58(%r14), %rcx
movl (%rcx,%r13), %esi
movl %esi, 0x4(%rax,%rdx)
movl 0x8(%rcx,%r13), %ecx
movl %ecx, 0x10(%rax,%rdx)
xorl %ecx, %ecx
movl %ecx, 0x14(%rax,%rdx)
movl %ecx, 0x8(%rax,%rdx)
movl 0x18(%rax,%rdx), %ecx
movl $0xc0000000, %esi       # imm = 0xC0000000
andl %esi, %ecx
addl 0xc(%rsp), %ecx
movl %ecx, 0x18(%rax,%rdx)
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rdx
incq %rbp
addq $0x20, %r13
cmpq %rbp, %rdx
jne 0x72272
incq %rdi
movq 0x20(%rsp), %r13
cmpq 0x10(%r13), %rdi
jb 0x7223c
movq (%rbx), %rax
movq 0x10(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x45d47
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x724a5
movl $0x1, %r14d
xorl %eax, %eax
movq 0x10(%rsp), %rsi
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %r12
addq %rsi, %r12
movl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
cmpq %rcx, %r14
je 0x7240f
movq 0x10(%rbx), %rcx
movq (%rcx,%rax,8), %rdx
xorq (%rcx,%r14,8), %rdx
shrq $0x20, %rdx
jne 0x7240f
movq %rax, %rdx
jmp 0x72493
movq %r14, %rcx
subq %rax, %rcx
movq %r14, %rdx
cmpq $0x2, %rcx
jb 0x72493
cmpq %rax, %r14
jbe 0x7247f
movq 0x10(%rbx), %rcx
movq (%r15), %rdx
addq %r12, %rdx
movq (%r13), %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 0x72434
movq 0x10(%rbx), %rcx
leaq (%rcx,%rax,8), %rdi
leaq (%rcx,%r14,8), %rsi
callq 0x45d47
movq %r14, %rdx
incq %r14
movq (%rbx), %rcx
movq %rdx, %rax
cmpq %rcx, %r14
jbe 0x723f0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq