// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movq %rsi, %r13
movl (%r9), %ebx
movl 0x4(%r9), %eax
movq %rax, (%rsp)
movl 0xc(%r9), %eax
movq %rax, 0x10(%rsp)
movl 0x8(%r9), %eax
movq %rax, 0x8(%rsp)
movl 0x10(%r9), %esi
movl 0x14(%r9), %r14d
movq $0x7fffffff, (%rcx)     # imm = 0x7FFFFFFF
movq $-0x1, (%r8)
movq %rdx, %r12
subq %r13, %r12
jle 0x756fd
movq %r9, %r15
movq %r8, %r11
movq %rcx, %r10
cmpl %r14d, %ebx
movq %rbx, %rcx
cmovaq %rsi, %rcx
cmpl %esi, %ebx
cmovbq %rsi, %rcx
cmpq %rsi, %rcx
setb %bpl
jb 0x756a5
movq 0x58(%rdi), %r8
movq %rcx, %r9
shlq $0x5, %r9
movslq 0x8(%r8,%r9), %rax
cmpq %r13, %rax
jle 0x756a5
leaq -0x1(%rsi), %rax
addq %r9, %r8
addq $-0x18, %r8
cmpq %rsi, %rcx
setle %bpl
jle 0x756a2
decq %rcx
movslq (%r8), %r9
addq $-0x20, %r8
cmpq %r13, %r9
jg 0x75688
jmp 0x756a5
movq %rax, %rcx
xorl %eax, %eax
testb %bpl, %bpl
jne 0x756ff
cmpq %r14, %rcx
jg 0x756ff
movq 0x58(%rdi), %rax
movq %rcx, %r8
shlq $0x5, %r8
movslq 0xc(%rax,%r8), %r9
cmpq %r13, %r9
jge 0x756ea
leaq 0x1(%r14), %rbp
addq %rax, %r8
addq $0x2c, %r8
cmpq %r14, %rcx
setge %al
jge 0x756ee
incq %rcx
movslq (%r8), %r9
addq $0x20, %r8
cmpq %r13, %r9
jl 0x756d1
jmp 0x756f1
xorl %eax, %eax
jmp 0x756f1
movq %rbp, %rcx
cmpq %rsi, %rcx
setl %sil
orb %al, %sil
je 0x75711
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %rbx, %rcx
je 0x7573c
movq 0x58(%rdi), %rax
movq %rcx, %r8
shlq $0x5, %r8
movslq 0x8(%rax,%r8), %rsi
movq %rsi, (%rsp)
movslq (%rax,%r8), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
cmpq %r14, %rcx
jg 0x75949
movq %rdi, 0x18(%rsp)
movq 0x58(%rdi), %rdi
movq %rcx, %rbp
shlq $0x5, %rbp
movl 0x8(%rdi,%rbp), %r8d
movslq %r8d, %rsi
cmpq %rdx, %rsi
jge 0x75949
leaq (%rdi,%rbp), %rax
movq %r10, 0x30(%rsp)
movq %r11, 0x28(%rsp)
movq %rdx, 0x38(%rsp)
movq %rcx, 0x20(%rsp)
movslq 0xc(%rax), %rcx
incq %rcx
cmpq %r13, %rsi
cmovleq %r13, %rsi
cmpq %rdx, %rcx
cmovlq %rcx, %rdx
movq %rdx, %rbx
subq %rsi, %rbx
movl $0x0, %r9d
cmovleq %r9, %rbx
testq %rbx, %rbx
je 0x758d8
movl %ecx, %r9d
subl %r8d, %r9d
movslq %r9d, %r8
movzwl 0x14(%rax), %r9d
cmpl $0x7fff, %r9d           # imm = 0x7FFF
jne 0x757dd
cmpl $0x0, 0x1c(%rax)
jne 0x757d0
cmpw $0x0, 0x12(%rax)
js 0x7581c
movzwl %r9w, %r9d
cmpl $0x7fff, %r9d           # imm = 0x7FFF
je 0x757e3
cmpl $0x0, 0x1c(%rax)
je 0x7581c
cmpq %r8, %rbx
jne 0x75858
movq %rcx, (%rsp)
movslq 0x4(%rax), %rcx
incq %rcx
movq %rcx, 0x10(%rsp)
movl 0x1c(%rax), %edx
movq %rdx, 0x8(%rsp)
movslq (%rax), %rax
cmpq %rax, (%r10)
jle 0x7580b
movq %rax, (%r10)
cmpq %rcx, (%r11)
jge 0x758d8
movq %rcx, (%r11)
jmp 0x758d8
cmpq %r8, %rbx
jl 0x7583b
movslq (%rax), %rdx
cmpq %rdx, (%r10)
jle 0x7582c
movq %rdx, (%r10)
movslq 0x4(%rax), %rdx
incq %rdx
cmpq %rdx, (%r11)
jge 0x7583b
movq %rdx, (%r11)
movq %rcx, (%rsp)
movslq 0x4(%rax), %rcx
incq %rcx
movq %rcx, 0x10(%rsp)
movl 0x1c(%rax), %eax
movq %rax, 0x8(%rsp)
jmp 0x758d8
movl 0x18(%rdi,%rbp), %ecx
addq %rcx, %rcx
movq 0x18(%rsp), %r8
addq 0x70(%r8), %rcx
movq %rcx, 0xf8(%rsp)
movl 0x1c(%rdi,%rbp), %ecx
movq %rcx, 0xf0(%rsp)
movq %rcx, 0xe8(%rsp)
movl (%rax), %eax
movl %eax, 0x5c(%rsp)
movl 0x4(%rdi,%rbp), %eax
movl %eax, 0x60(%rsp)
movl 0x8(%rdi,%rbp), %eax
movl %eax, 0x50(%rsp)
movl 0xc(%rdi,%rbp), %eax
movl %eax, 0x54(%rsp)
movswl 0x14(%rdi,%rbp), %eax
movl %eax, 0x6c(%rsp)
movl %eax, 0x68(%rsp)
leaq 0x40(%rsp), %rdi
movq %rsp, %rcx
leaq 0x10(%rsp), %r8
leaq 0x8(%rsp), %r9
pushq %r11
pushq %r10
callq 0x75472
movq 0x38(%rsp), %r11
movq 0x40(%rsp), %r10
addq $0x10, %rsp
subq %rbx, %r12
movq 0x38(%rsp), %rdx
cmpq %rdx, (%rsp)
jge 0x75944
movq 0x20(%rsp), %r9
cmpq %r14, %r9
jge 0x7593c
leaq 0x1(%r9), %rcx
movq 0x18(%rsp), %rdi
movq 0x58(%rdi), %rax
movslq 0x28(%rax,%rbp), %rsi
movq %rsi, (%rsp)
movslq 0x20(%rax,%rbp), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x58(%rdi), %rdi
movq %rcx, %rax
shlq $0x5, %rax
addq %rdi, %rax
movl 0x28(%rdi,%rbp), %r8d
movslq %r8d, %rsi
addq $0x20, %rbp
cmpq %rdx, %rsi
jl 0x75779
incq %r9
movq %r9, %rcx
jmp 0x75949
movq 0x20(%rsp), %rcx
testq %r12, %r12
jne 0x75978
movl %ecx, (%r15)
movl (%rsp), %eax
movl %eax, 0x4(%r15)
movl 0x10(%rsp), %eax
movl %eax, 0xc(%r15)
movl 0x8(%rsp), %eax
movl %eax, 0x8(%r15)
movq (%r11), %rcx
xorl %eax, %eax
cmpq (%r10), %rcx
setg %al
jmp 0x756ff
leaq 0x1b20d8(%rip), %rdi    # 0x227a57
leaq 0x1afcbd(%rip), %rsi    # 0x225643
leaq 0x1b2bb2(%rip), %rcx    # 0x22853f
movl $0x5161, %edx           # imm = 0x5161
callq 0x2110