// File: /workspace/github_cpp_makefile_star2_O3/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 0x7d32e
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 0x7d36f
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), %rcx
jmp 0x7d373
movq 0x10(%rbx), %rax
movq %r15, (%rax,%rcx,8)
movq $0x0, (%rbx)
cmpq $0x0, 0x48(%r14)
je 0x7d49b
movq 0x58(%r14), %rcx
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq $0x0, (%rbx)
je 0x7d3d8
cmpw $0x7fff, 0x14(%rcx,%r12) # imm = 0x7FFF
jne 0x7d3b7
cmpl $0x0, 0x1c(%rcx,%r12)
jne 0x7d3b7
cmpw $0x0, 0x12(%rcx,%r12)
js 0x7d3c6
movslq 0x4(%rcx,%r12), %rdx
movslq (%rcx,%r12), %rsi
subq %rsi, %rdx
addq %rdx, %r15
incq %r13
addq $0x20, %r12
cmpq 0x48(%r14), %r13
jb 0x7d396
jmp 0x7d484
movl (%rcx,%r12), %edx
shlq $0x20, %rdx
movslq 0x8(%rcx,%r12), %rbp
addq %rdx, %rbp
cmpq -0x8(%rax), %rbp
je 0x7d42e
cmpq $0x0, 0x8(%rbx)
je 0x7d3f9
xorl %edx, %edx
jmp 0x7d419
movq $0x2, 0x8(%rbx)
movl $0x10, %esi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rdx
movq 0x58(%r14), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movq %rbp, (%rax,%rdx,8)
cmpq $0x0, (%rbx)
jne 0x7d39c
movl 0x4(%rcx,%r12), %edx
shlq $0x20, %rdx
movslq 0xc(%rcx,%r12), %rbp
addq %rdx, %rbp
cmpq -0x8(%rax), %rbp
je 0x7d39c
cmpq $0x0, 0x8(%rbx)
je 0x7d454
xorl %edx, %edx
jmp 0x7d474
movq $0x2, 0x8(%rbx)
movl $0x10, %esi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rdx
movq 0x58(%r14), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movq %rbp, (%rax,%rdx,8)
jmp 0x7d39c
cmpq $0x0, (%rbx)
jne 0x7d4e5
movl 0x8(%r14), %ecx
movl 0x18(%r14), %r14d
shlq $0x20, %rcx
orq %rcx, %r14
jmp 0x7d4ad
movl 0x8(%r14), %ecx
movl 0x18(%r14), %r14d
shlq $0x20, %rcx
orq %rcx, %r14
xorl %r15d, %r15d
cmpq -0x8(%rax), %r14
je 0x7d4e5
cmpq $0x0, 0x8(%rbx)
je 0x7d4be
xorl %ecx, %ecx
jmp 0x7d4da
movq $0x2, 0x8(%rbx)
movl $0x10, %esi
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