// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_woff_idx(overlap_region*, asg64_v*)
kv_resize(uint64_t, *oidx, (z->w_list.n<<1)+2); 
    mm = z->x_pos_s; mm <<= 32; mm += z->y_pos_s; kv_push(uint64_t, *oidx, mm);
    for (k = oidx->n = 0; k < z->w_list.n; k++) {
        mm = z->w_list.a[k].x_start; mm <<= 32; mm += z->w_list.a[k].y_start;
        if((oidx->n == 0) && (mm != oidx->a[oidx->n-1])) {
            kv_push(uint64_t, *oidx, mm);
        }

        mm = z->w_list.a[k].x_end; mm <<= 32; mm += z->w_list.a[k].y_end;
        if((oidx->n == 0) && (mm != oidx->a[oidx->n-1])) {
            kv_push(uint64_t, *oidx, mm);
        }
        if(!(is_ualn_win(z->w_list.a[k]))) aln += z->w_list.a[k].x_end - z->w_list.a[k].x_start;
    }
    mm = z->x_pos_e; mm <<= 32; mm += z->y_pos_e; 
    if((oidx->n == 0) && (mm != oidx->a[oidx->n-1])) {
        kv_push(uint64_t, *oidx, mm);
    }
    return aln;
}

//return [rq, rt]
void win_boundary_offset(window_list *a, int64_t w_n, int64_t wi, int64_t toff, int64_t ql, int64_t *rq, int64_t *rt)
{
    int64_t q[2], t[2], qdis, tdis, dis; q[0] = q[1] = t[0] = t[1] = -1;
    ///[q[0], q[1]] && [t[0], t[1]]
    if(toff >= a[wi].y_start && toff <= a[wi].y_end) {///within the window
        q[0] = a[wi].x_start; q[1] = a[wi].x_end;
        t[0] = a[wi].y_start; t[1] = a[wi].y_end;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rsi), %rax
movq 0x48(%rdi), %rcx
leaq 0x2(,%rcx,2), %rdx
cmpq %rdx, %rax
jae 0x4a140
leaq (%rcx,%rcx), %rax
movabsq $0x7ffffffffffffffe, %rdx # imm = 0x7FFFFFFFFFFFFFFE
andq %rcx, %rdx
orq %rax, %rdx
movq %rdx, %rax
shrq $0x2, %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
orq $0x1, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%r14), %ecx
movl 0x14(%r14), %r15d
shlq $0x20, %rcx
orq %rcx, %r15
movq (%rbx), %rcx
cmpq %rax, %rcx
jne 0x4a17f
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rsi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
jmp 0x4a183
movq 0x10(%rbx), %rax
movq %r15, (%rax,%rcx,8)
andq $0x0, (%rbx)
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpq 0x48(%r14), %rbp
jae 0x4a283
movq 0x58(%r14), %rcx
cmpq $0x0, (%rbx)
je 0x4a1ab
xorl %edx, %edx
jmp 0x4a1fe
movl (%rcx,%r13), %edx
shlq $0x20, %rdx
movslq 0x8(%rcx,%r13), %r12
addq %rdx, %r12
movb $0x1, %dl
cmpq -0x8(%rax), %r12
je 0x4a1fe
cmpq $0x0, 0x8(%rbx)
je 0x4a1ce
xorl %edx, %edx
jmp 0x4a1ec
movq $0x2, 0x8(%rbx)
movq %rax, %rdi
pushq $0x10
popq %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rdx
movq 0x58(%r14), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movq %r12, (%rax,%rdx,8)
cmpq $0x0, (%rbx)
sete %dl
testb %dl, %dl
je 0x4a24d
movl 0x4(%rcx,%r13), %edx
shlq $0x20, %rdx
movslq 0xc(%rcx,%r13), %r12
addq %rdx, %r12
cmpq -0x8(%rax), %r12
je 0x4a24d
cmpq $0x0, 0x8(%rbx)
je 0x4a224
xorl %edx, %edx
jmp 0x4a242
movq $0x2, 0x8(%rbx)
movq %rax, %rdi
pushq $0x10
popq %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rdx
movq 0x58(%r14), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movq %r12, (%rax,%rdx,8)
cmpw $0x7fff, 0x14(%rcx,%r13) # imm = 0x7FFF
jne 0x4a268
cmpl $0x0, 0x1c(%rcx,%r13)
jne 0x4a268
cmpw $0x0, 0x12(%rcx,%r13)
js 0x4a277
movslq 0x4(%rcx,%r13), %rdx
movslq (%rcx,%r13), %rcx
subq %rcx, %rdx
addq %rdx, %r15
incq %rbp
addq $0x20, %r13
jmp 0x4a193
cmpq $0x0, (%rbx)
jne 0x4a2ce
movl 0x8(%r14), %ecx
movl 0x18(%r14), %r14d
shlq $0x20, %rcx
orq %rcx, %r14
cmpq -0x8(%rax), %r14
je 0x4a2ce
cmpq $0x0, 0x8(%rbx)
je 0x4a2a9
xorl %ecx, %ecx
jmp 0x4a2c3
movq $0x2, 0x8(%rbx)
pushq $0x10
popq %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq %r14, (%rax,%rcx,8)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq