// File: chhylp123[P]hifiasm/Correct.cpp
// Function: extract_xcoordates0(overlap_region*, long, long, long*, long*, ul_ov_t*)
uint64_t extract_xcoordates0(overlap_region *z, int64_t ys, int64_t ye, int64_t *rxs, int64_t *rxe, ul_ov_t *p)
{
    int64_t wk = ovlp_cur_wid(*p), yk = ovlp_cur_xoff(*p), xk = ovlp_id(*p), ck = ovlp_cur_coff(*p);
    int64_t min_w = ovlp_min_wid(*p), max_w = ovlp_max_wid(*p);//[min_w, max_w]
    bit_extz_t ez; window_list *m; (*rxs) = INT32_MAX; (*rxe) = -1;
    if(ys >= ye) return 0;
    ///[ys, ye) but [z->w_list.a[wk].y_start, z->w_list.a[wk].y_end]
    int64_t ws, we, os, oe, ovlp, yl, tot = ye - ys;
    if(wk < min_w || wk > max_w) wk = min_w;
    for (; wk >= min_w && z->w_list.a[wk].y_start > ys; wk--); 
    if(wk < min_w || wk > max_w) return 0;
    for (; wk <= max_w && z->w_list.a[wk].y_end < ys; wk++); 
    if(wk < min_w || wk > max_w) return 0;
    //s >= w_list.a[wk].x_start && s <= w_list.a[wk].x_end
    if(wk != ovlp_cur_wid(*p)) {//xk is global, while ck is local
        yk = z->w_list.a[wk].y_start; 
        xk = z->w_list.a[wk].x_start; 
        ck = 0;
    }

    ///[ys, ye) but [z->w_list.a[wk].y_start, z->w_list.a[wk].y_end]
    while(wk <= max_w && z->w_list.a[wk].y_start < ye) {
        m = &(z->w_list.a[wk]); 
        ws = m->y_start; we = m->y_end+1;
        os = MAX(ys, ws); oe = MIN(ye, we);
        ovlp = ((oe>os)? (oe-os):0);
        
        if(ovlp) {
            yl = m->y_end+1-m->y_start;
            if((is_ualn_win((*m))) || (is_est_aln((*m)))) {
                if(ovlp >= yl) {
                    if((*rxs) > m->x_start) (*rxs) = m->x_start;
                    if((*rxe) < (m->x_end+1)) (*rxe) = m->x_end+1;
                }
                //skip the whole window
                yk = m->y_end+1; xk = m->x_end+1; ck = m->clen;
            } else {
                if(ovlp == yl) {
                    //skip the whole window
                    yk = m->y_end+1; xk = m->x_end+1; ck = m->clen;
                    if((*rxs) > m->x_start) (*rxs) = m->x_start;
                    if((*rxe) < (m->x_end+1)) (*rxe) = m->x_end+1;
                } else {
                    set_bit_extz_t(ez, (*z), wk); 
                    retrieve_cigar_xcoord(&ez, os, oe, &yk, &xk, &ck, rxs, rxe);
                }                
            }
        }
        tot -= ovlp; 
        if(yk >= ye) break;//[min_w, max_w] && [ys, ye)
        wk++; if(wk > max_w) break;
        yk = z->w_list.a[wk].y_start; xk = z->w_list.a[wk].x_start; ck = 0;//reset
    }
    assert(!tot);
    ovlp_cur_wid(*p) = wk; ovlp_cur_xoff(*p) = yk; ovlp_id(*p) = xk; ovlp_cur_coff(*p) = ck;
    if((*rxe) > (*rxs)) return 1;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq $0x7fffffff, (%rax)     # imm = 0x7FFFFFFF
movq -0x30(%rbp), %rax
movq $-0x1, (%rax)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0x7e851
movq $0x0, -0x8(%rbp)
jmp 0x7eef3
movq -0x20(%rbp), %rax
subq -0x18(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x60(%rbp), %rax
jl 0x7e874
movq -0x40(%rbp), %rax
cmpq -0x68(%rbp), %rax
jle 0x7e87c
movq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x7e87e
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq -0x60(%rbp), %rcx
movb %al, -0x181(%rbp)
jl 0x7e8b4
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rax
cmpq -0x18(%rbp), %rax
setg %al
movb %al, -0x181(%rbp)
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0x7e8c0
jmp 0x7e8d0
jmp 0x7e8c2
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x7e87e
movq -0x40(%rbp), %rax
cmpq -0x60(%rbp), %rax
jl 0x7e8e4
movq -0x40(%rbp), %rax
cmpq -0x68(%rbp), %rax
jle 0x7e8f1
movq $0x0, -0x8(%rbp)
jmp 0x7eef3
jmp 0x7e8f3
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq -0x68(%rbp), %rcx
movb %al, -0x182(%rbp)
jg 0x7e929
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0xc(%rax), %rax
cmpq -0x18(%rbp), %rax
setl %al
movb %al, -0x182(%rbp)
movb -0x182(%rbp), %al
testb $0x1, %al
jne 0x7e935
jmp 0x7e945
jmp 0x7e937
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x7e8f3
movq -0x40(%rbp), %rax
cmpq -0x60(%rbp), %rax
jl 0x7e959
movq -0x40(%rbp), %rax
cmpq -0x68(%rbp), %rax
jle 0x7e966
movq $0x0, -0x8(%rbp)
jmp 0x7eef3
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
je 0x7e9b2
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
jmp 0x7e9b4
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq -0x68(%rbp), %rcx
movb %al, -0x183(%rbp)
jg 0x7e9ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rax
cmpq -0x20(%rbp), %rax
setl %al
movb %al, -0x183(%rbp)
movb -0x183(%rbp), %al
testb $0x1, %al
jne 0x7e9f9
jmp 0x7ee6a
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0x150(%rbp)
movq -0x148(%rbp), %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x158(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x150(%rbp), %rax
jl 0x7ea55
movq -0x18(%rbp), %rax
movq %rax, -0x190(%rbp)
jmp 0x7ea63
movq -0x150(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x190(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x158(%rbp), %rax
jg 0x7ea8b
movq -0x20(%rbp), %rax
movq %rax, -0x198(%rbp)
jmp 0x7ea99
movq -0x158(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rax
cmpq -0x160(%rbp), %rax
jle 0x7eace
movq -0x168(%rbp), %rax
subq -0x160(%rbp), %rax
movq %rax, -0x1a0(%rbp)
jmp 0x7ead9
xorl %eax, %eax
movq %rax, -0x1a0(%rbp)
jmp 0x7ead9
movq -0x1a0(%rbp), %rax
movq %rax, -0x170(%rbp)
cmpq $0x0, -0x170(%rbp)
je 0x7edec
movq -0x148(%rbp), %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
movq -0x148(%rbp), %rcx
subl 0x8(%rcx), %eax
cltq
movq %rax, -0x178(%rbp)
movq -0x148(%rbp), %rax
movswl 0x14(%rax), %eax
cmpl $0x7fff, %eax           # imm = 0x7FFF
jne 0x7eb44
movq -0x148(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x7eb44
movq -0x148(%rbp), %rax
movswl 0x12(%rax), %eax
cmpl $0x0, %eax
jl 0x7eb6b
movq -0x148(%rbp), %rax
movswl 0x14(%rax), %eax
cmpl $0x7fff, %eax           # imm = 0x7FFF
jge 0x7ec10
movq -0x148(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x7ec10
movq -0x170(%rbp), %rax
cmpq -0x178(%rbp), %rax
jl 0x7ebd7
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x148(%rbp), %rcx
movslq (%rcx), %rcx
cmpq %rcx, %rax
jle 0x7eba2
movq -0x148(%rbp), %rax
movslq (%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x148(%rbp), %rcx
movl 0x4(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x7ebd5
movq -0x148(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x7ebd7
movq -0x148(%rbp), %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x48(%rbp)
movq -0x148(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x50(%rbp)
movq -0x148(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x58(%rbp)
jmp 0x7edea
movq -0x170(%rbp), %rax
cmpq -0x178(%rbp), %rax
jne 0x7ecb7
movq -0x148(%rbp), %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x48(%rbp)
movq -0x148(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x50(%rbp)
movq -0x148(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x148(%rbp), %rcx
movslq (%rcx), %rcx
cmpq %rcx, %rax
jle 0x7ec7f
movq -0x148(%rbp), %rax
movslq (%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x148(%rbp), %rcx
movl 0x4(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x7ecb2
movq -0x148(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x7ede8
jmp 0x7ecb9
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x40(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x18(%rcx), %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq %rax, -0x90(%rbp)
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x124(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x120(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x130(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x12c(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x14(%rax), %eax
movl %eax, -0x114(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x14(%rax), %eax
movl %eax, -0x118(%rbp)
movq -0x160(%rbp), %rsi
movq -0x168(%rbp), %rdx
movq -0x28(%rbp), %r10
movq -0x30(%rbp), %rax
leaq -0x140(%rbp), %rdi
leaq -0x48(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0x58(%rbp), %r9
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x7e470
jmp 0x7edea
jmp 0x7edec
movq -0x170(%rbp), %rcx
movq -0x180(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x180(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0x7ee10
jmp 0x7ee6a
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x68(%rbp), %rax
jle 0x7ee28
jmp 0x7ee6a
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
jmp 0x7e9b4
cmpq $0x0, -0x180(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7ee7d
jmp 0x7ee7f
jmp 0x7ee9e
leaq 0x3058a9(%rip), %rdi    # 0x38472f
leaq 0x30348e(%rip), %rsi    # 0x38231b
movl $0x5161, %edx           # imm = 0x5161
leaq 0x30637e(%rip), %rcx    # 0x385217
callq 0x2130
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x50(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jle 0x7eeeb
movq $0x1, -0x8(%rbp)
jmp 0x7eef3
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq