// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x7811b
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x77e62
movq -0x68(%rbp), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
je 0x77e67
jmp 0x7810a
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x78108
movq -0x68(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x14(%rax), %eax
cmpl $0x7fff, %eax           # imm = 0x7FFF
jne 0x77ed5
movq -0x68(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jne 0x77ed5
movq -0x68(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x12(%rax), %eax
cmpl $0x0, %eax
jge 0x77ed5
jmp 0x780f7
movq -0x68(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x68(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jl 0x780f5
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x28(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x77fc3
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x77f88
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x77f93
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x77f93
movq -0x78(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x77fe6
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x7804a
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x78014
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x7801f
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x7801f
movq -0x80(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movq -0x68(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x68(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x70(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x70(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
movl %eax, %edx
movq -0x70(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x18(%rax)
jmp 0x780f7
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x77e6f
jmp 0x7810a
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x77e1a
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq $0x1, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
ja 0x782c5
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
je 0x7819d
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x782b2
movq -0x30(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq $0x1, %rax
jbe 0x782aa
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x7827f
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq -0x40(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
movl %edx, %edx
addq %rdx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movl 0xc(%rcx), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
movl (%rcx), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq -0x70(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
subl %ecx, %eax
cltq
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x781b7
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x782b4
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x7814e
addq $0x80, %rsp
popq %rbp
retq
nop