// File: /workspace/github_cpp_makefile_star2_O1/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 0x48(%rdi), %rax
leaq 0x2(,%rax,2), %rcx
cmpq %rcx, 0x8(%rsi)
jae 0x7d8b2
leaq (%rax,%rax), %rcx
movabsq $0x7ffffffffffffffe, %rdx # imm = 0x7FFFFFFFFFFFFFFE
andq %rax, %rdx
orq %rcx, %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)
movl 0x4(%r14), %eax
movl 0x14(%r14), %r15d
shlq $0x20, %rax
orq %rax, %r15
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x7d8ef
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %r15, (%rcx,%rax,8)
movq $0x0, (%rbx)
cmpq $0x0, 0x48(%r14)
je 0x7da04
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq $0x0, (%rbx)
jne 0x7d96f
movq 0x58(%r14), %rax
movl (%rax,%r12), %ecx
shlq $0x20, %rcx
movslq 0x8(%rax,%r12), %rbp
addq %rcx, %rbp
movq 0x10(%rbx), %rdi
cmpq -0x8(%rdi), %rbp
je 0x7d96f
cmpq $0x0, 0x8(%rbx)
jne 0x7d95d
movq $0x2, 0x8(%rbx)
movl $0x10, %esi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %rbp, (%rcx,%rax,8)
cmpq $0x0, (%rbx)
jne 0x7d9c3
movq 0x58(%r14), %rax
movl 0x4(%rax,%r12), %ecx
shlq $0x20, %rcx
movslq 0xc(%rax,%r12), %rbp
addq %rcx, %rbp
movq 0x10(%rbx), %rdi
cmpq -0x8(%rdi), %rbp
je 0x7d9c3
cmpq $0x0, 0x8(%rbx)
jne 0x7d9b1
movq $0x2, 0x8(%rbx)
movl $0x10, %esi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %rbp, (%rcx,%rax,8)
movq 0x58(%r14), %rax
cmpw $0x7fff, 0x14(%rax,%r12) # imm = 0x7FFF
jne 0x7d9e2
cmpl $0x0, 0x1c(%rax,%r12)
jne 0x7d9e2
cmpw $0x0, 0x12(%rax,%r12)
js 0x7d9f1
movslq 0x4(%rax,%r12), %rcx
movslq (%rax,%r12), %rax
subq %rax, %rcx
addq %rcx, %r15
incq %r13
addq $0x20, %r12
cmpq 0x48(%r14), %r13
jb 0x7d91c
jmp 0x7da07
xorl %r15d, %r15d
cmpq $0x0, (%rbx)
jne 0x7da55
movl 0x8(%r14), %eax
movl 0x18(%r14), %r14d
shlq $0x20, %rax
orq %rax, %r14
movq 0x10(%rbx), %rdi
cmpq -0x8(%rdi), %r14
je 0x7da55
cmpq $0x0, 0x8(%rbx)
jne 0x7da43
movq $0x2, 0x8(%rbx)
movl $0x10, %esi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %r14, (%rcx,%rax,8)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq