// File: /workspace/github_cpp_makefile_star2_O3/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 %rsi, %r13
movl (%r9), %esi
movl 0x4(%r9), %r11d
movq %r11, 0x28(%rsp)
movl 0xc(%r9), %eax
movq %rax, 0x10(%rsp)
movl 0x8(%r9), %eax
movq %rax, 0x8(%rsp)
movl 0x10(%r9), %r10d
movl 0x14(%r9), %ebx
movq $0x7fffffff, (%rcx)     # imm = 0x7FFFFFFF
movq $-0x1, (%r8)
movq %rdx, %r12
subq %r13, %r12
jle 0x75127
movq %rdx, %rbp
cmpl %ebx, %esi
movq %rsi, %rdx
cmovaq %r10, %rdx
cmpl %r10d, %esi
cmovbq %r10, %rdx
cmpq %r10, %rdx
jb 0x75127
movq %r9, %r15
movq %rdi, 0x40(%rsp)
movq 0x58(%rdi), %rdi
movq %rdx, %r14
shlq $0x5, %r14
xorl %eax, %eax
movslq 0x8(%rdi,%r14), %r9
cmpq %r13, %r9
jle 0x750ff
leaq -0x1(%rdx), %r9
addq $-0x20, %r14
cmpq %r10, %rdx
movq %r9, %rdx
jg 0x750e3
jmp 0x75129
cmpq %rbx, %rdx
jg 0x75127
xorl %eax, %eax
movslq 0xc(%rdi,%r14), %r9
cmpq %r13, %r9
jge 0x75122
leaq 0x1(%rdx), %r9
addq $0x20, %r14
cmpq %rbx, %rdx
movq %r9, %rdx
jl 0x75106
jmp 0x75129
cmpq %r10, %rdx
jge 0x7513b
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %rdx, %rsi
je 0x7515c
movslq 0x8(%rdi,%r14), %r11
movq %r11, 0x28(%rsp)
movslq (%rdi,%r14), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
cmpq %rbx, %rdx
jg 0x7536a
movl 0x8(%rdi,%r14), %r10d
movslq %r10d, %rsi
cmpq %rbp, %rsi
jge 0x7536a
movq %r8, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
leaq (%rdi,%r14), %rax
movq %rdx, 0x38(%rsp)
movslq 0xc(%rax), %rdx
movq %rdx, 0x48(%rsp)
leaq 0x1(%rdx), %r9
cmpq %r13, %rsi
cmovleq %r13, %rsi
cmpq %rbp, %r9
movq %rbp, %r8
cmovlq %r9, %r8
movq %r8, %rdx
subq %rsi, %rdx
movl $0x0, %ecx
cmovleq %rcx, %rdx
movq %rdx, 0x30(%rsp)
testq %rdx, %rdx
je 0x752f6
movl %r9d, %ecx
subl %r10d, %ecx
movslq %ecx, %r11
movswl 0x14(%rax), %edx
movl 0x1c(%rax), %ecx
cmpl $0x7fff, %edx           # imm = 0x7FFF
jne 0x75200
testl %ecx, %ecx
jne 0x75204
xorl %ecx, %ecx
cmpw $0x0, 0x12(%rax)
jns 0x75204
cmpq %r11, 0x30(%rsp)
jge 0x752c1
movslq 0x4(%rax), %rax
incq %rax
jmp 0x752e5
testl %ecx, %ecx
je 0x751e9
movl %ecx, %ecx
cmpq %r11, 0x30(%rsp)
jne 0x75244
movslq 0x4(%rax), %rdx
incq %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movslq (%rax), %rax
movq 0x20(%rsp), %rcx
cmpq %rax, (%rcx)
jle 0x7522e
movq %rax, (%rcx)
movq 0x18(%rsp), %rax
cmpq %rdx, (%rax)
jge 0x752f3
movq %rdx, (%rax)
jmp 0x752f3
movl 0x18(%rdi,%r14), %r9d
addq %r9, %r9
movq 0x40(%rsp), %r11
addq 0x70(%r11), %r9
movq %r9, 0x108(%rsp)
movq %rcx, 0x100(%rsp)
movq %rcx, 0xf8(%rsp)
movl (%rax), %eax
movl %eax, 0x6c(%rsp)
movl 0x4(%rdi,%r14), %eax
movl %eax, 0x70(%rsp)
movl %r10d, 0x60(%rsp)
movq 0x48(%rsp), %rax
movl %eax, 0x64(%rsp)
movl %edx, 0x7c(%rsp)
movl %edx, 0x78(%rsp)
leaq 0x50(%rsp), %rdi
movq %r8, %rdx
leaq 0x28(%rsp), %rcx
leaq 0x10(%rsp), %r8
leaq 0x8(%rsp), %r9
pushq 0x18(%rsp)
pushq 0x28(%rsp)
callq 0x74eda
addq $0x10, %rsp
movq 0x28(%rsp), %r11
jmp 0x752f6
movslq (%rax), %rcx
movq 0x20(%rsp), %rdx
cmpq %rcx, (%rdx)
jle 0x752d1
movq %rcx, (%rdx)
movslq 0x4(%rax), %rax
incq %rax
movq 0x18(%rsp), %rcx
cmpq %rax, (%rcx)
jge 0x752e5
movq %rax, (%rcx)
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq %r9, %r11
subq 0x30(%rsp), %r12
cmpq %rbp, %r11
jge 0x7535b
movq 0x38(%rsp), %rcx
cmpq %rbx, %rcx
jge 0x75353
leaq 0x1(%rcx), %rdx
movq 0x40(%rsp), %rax
movq 0x58(%rax), %rdi
movslq 0x28(%rdi,%r14), %r11
movq %r11, 0x28(%rsp)
movslq 0x20(%rdi,%r14), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq %rdx, %rax
shlq $0x5, %rax
addq %rdi, %rax
movl 0x28(%rdi,%r14), %r10d
movslq %r10d, %rsi
addq $0x20, %r14
cmpq %rbp, %rsi
jl 0x75184
incq %rcx
movq %rcx, %rdx
jmp 0x75360
movq 0x38(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %r8
testq %r12, %r12
jne 0x75396
movl %edx, (%r15)
movl %r11d, 0x4(%r15)
movl 0x10(%rsp), %eax
movl %eax, 0xc(%r15)
movl 0x8(%rsp), %eax
movl %eax, 0x8(%r15)
movq (%r8), %rdx
xorl %eax, %eax
cmpq (%rcx), %rdx
setg %al
jmp 0x75129
leaq 0x1be7ca(%rip), %rdi    # 0x233b67
leaq 0x1bc3af(%rip), %rsi    # 0x231753
leaq 0x1bf2a4(%rip), %rcx    # 0x23464f
movl $0x5161, %edx           # imm = 0x5161
callq 0x2110