// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %r9, %r15
movq %rdx, %r11
movl (%r9), %edx
movl 0x4(%r9), %r10d
movq %r10, 0x30(%rsp)
movl 0xc(%r9), %eax
movq %rax, 0x18(%rsp)
movl 0x8(%r9), %eax
movq %rax, 0x10(%rsp)
movl 0x10(%r9), %r9d
movl 0x14(%r15), %ebx
movq $0x7fffffff, (%rcx)     # imm = 0x7FFFFFFF
orq $-0x1, (%r8)
movq %r11, 0x40(%rsp)
subq %rsi, %r11
jle 0x42ef8
movq %rsi, %r13
movq %rdi, %rbp
cmpl %ebx, %edx
movq %rdx, %r12
cmovaq %r9, %r12
cmpl %r9d, %edx
cmovbq %r9, %r12
movq %r12, %r14
shlq $0x5, %r14
xorl %eax, %eax
cmpq %r9, %r12
jl 0x42efa
movq 0x58(%rbp), %rdi
movslq 0x8(%rdi,%r14), %rsi
cmpq %r13, %rsi
jle 0x42ef3
decq %r12
addq $-0x20, %r14
jmp 0x42ed7
cmpq %rbx, %r12
jle 0x42f0c
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
cmpq %rbx, %r12
jg 0x42efa
movslq 0xc(%rdi,%r14), %rsi
cmpq %r13, %rsi
jge 0x42f26
incq %r12
addq $0x20, %r14
jmp 0x42f0e
cmpq %r9, %r12
jl 0x42ef8
cmpq %r12, %rdx
je 0x42f49
movslq 0x8(%rdi,%r14), %r10
movq %r10, 0x30(%rsp)
movslq (%rdi,%r14), %rax
movq %rax, 0x18(%rsp)
andq $0x0, 0x10(%rsp)
movq 0x40(%rsp), %rdx
movq %rcx, 0x20(%rsp)
movq %r8, 0x8(%rsp)
cmpq %rbx, %r12
jg 0x43152
movl 0x8(%rdi,%r14), %r9d
movslq %r9d, %rsi
cmpq %rdx, %rsi
jge 0x43152
movslq 0xc(%rdi,%r14), %r8
movq %r8, 0x48(%rsp)
leaq 0x1(%r8), %rax
cmpq %r13, %rsi
cmovleq %r13, %rsi
cmpq %rdx, %rax
cmovlq %rax, %rdx
movq %rdx, 0x38(%rsp)
subq %rsi, %rdx
movl $0x0, %r8d
cmovleq %r8, %rdx
movq %rdx, %r8
testq %rdx, %rdx
je 0x43109
movq %r11, 0x28(%rsp)
movl %eax, %ecx
subl %r9d, %ecx
movslq %ecx, %r10
movswl 0x14(%rdi,%r14), %ecx
movl 0x1c(%rdi,%r14), %r11d
cmpl $0x7fff, %ecx           # imm = 0x7FFF
jne 0x42ffd
testl %r11d, %r11d
jne 0x43002
xorl %r11d, %r11d
cmpw $0x0, 0x12(%rdi,%r14)
jns 0x43002
cmpq %r10, %r8
jge 0x430d0
movslq 0x4(%rdi,%r14), %rdx
incq %rdx
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r11
jmp 0x430fb
testl %r11d, %r11d
je 0x42fdd
movl %r11d, %r11d
cmpq %r10, %r8
jne 0x43048
movslq 0x4(%rdi,%r14), %rsi
incq %rsi
movq %rsi, 0x18(%rsp)
movq %r11, 0x10(%rsp)
movslq (%rdi,%r14), %rdx
movq 0x20(%rsp), %rcx
cmpq %rdx, (%rcx)
jle 0x4302d
movq %rdx, (%rcx)
movq 0x8(%rsp), %rdx
cmpq %rsi, (%rdx)
movq 0x28(%rsp), %r11
jge 0x43106
movq %rsi, (%rdx)
jmp 0x43106
movl 0x18(%rdi,%r14), %eax
addq %rax, %rax
addq 0x70(%rbp), %rax
movq %rax, 0x108(%rsp)
movq %r11, 0x100(%rsp)
movq %r11, 0xf8(%rsp)
movq (%rdi,%r14), %rax
movq %rax, 0x6c(%rsp)
movl %r9d, 0x60(%rsp)
movq 0x48(%rsp), %rax
movl %eax, 0x64(%rsp)
movl %ecx, 0x7c(%rsp)
movl %ecx, 0x78(%rsp)
leaq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %r8, 0x38(%rsp)
leaq 0x18(%rsp), %r8
leaq 0x10(%rsp), %r9
pushq 0x8(%rsp)
pushq 0x28(%rsp)
callq 0x42ce3
movq 0x48(%rsp), %r8
movq 0x30(%rsp), %rcx
addq $0x10, %rsp
movq 0x30(%rsp), %r10
movq 0x28(%rsp), %r11
jmp 0x43109
movslq (%rdi,%r14), %rdx
movq 0x20(%rsp), %rcx
cmpq %rdx, (%rcx)
movq 0x28(%rsp), %r11
jle 0x430e6
movq %rdx, (%rcx)
movslq 0x4(%rdi,%r14), %rdx
incq %rdx
movq 0x8(%rsp), %rsi
cmpq %rdx, (%rsi)
jge 0x430fb
movq %rdx, (%rsi)
movq %rdx, 0x18(%rsp)
andq $0x0, 0x10(%rsp)
movq %rax, %r10
subq %r8, %r11
movq 0x40(%rsp), %rdx
cmpq %rdx, %r10
jge 0x4314d
cmpq %rbx, %r12
jge 0x4314a
movq 0x58(%rbp), %rdi
movslq 0x28(%rdi,%r14), %r10
movq %r10, 0x30(%rsp)
movslq 0x20(%rdi,%r14), %rax
andq $0x0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
addq $0x20, %r14
incq %r12
movq 0x8(%rsp), %r8
jmp 0x42f58
incq %r12
movq 0x8(%rsp), %r8
testq %r11, %r11
jne 0x4317e
movl %r12d, (%r15)
movl %r10d, 0x4(%r15)
movl 0x18(%rsp), %eax
movl %eax, 0xc(%r15)
movl 0x10(%rsp), %eax
movl %eax, 0x8(%r15)
movq (%r8), %rdx
xorl %eax, %eax
cmpq (%rcx), %rdx
setg %al
jmp 0x42efa
leaq 0x1a2932(%rip), %rdi    # 0x1e5ab7
leaq 0x1a0517(%rip), %rsi    # 0x1e36a3
leaq 0x1a340c(%rip), %rcx    # 0x1e659f
movl $0x5161, %edx           # imm = 0x5161
callq 0x2110