// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: extract_xcoordates(overlap_region*, unsigned long*, long, asg64_v*)
uint64_t extract_xcoordates(overlap_region *z, uint64_t *a, int64_t a_n, asg64_v *b)
{
    int64_t i, zwn, q[2], t[2], w[2], bn = b->n, a_i, a_z, as, ae, is, ie, os, oe, ovlp; 
    ul_ov_t m; int64_t qs, qe;
    zwn = z->w_list.n; if(!zwn) return 0;
    q[0] = q[1] = t[0] = t[1] = w[0] = w[1] = INT32_MIN; memset(&m, 0, sizeof(m));
    for (i = a_i = 0; i < zwn; i++) {
        if((z->w_list.a[i].x_start==(q[1]+1)) && ((z->w_list.a[i].y_start==(t[1]+1)))) {
            q[1] = z->w_list.a[i].x_end;
            t[1] = z->w_list.a[i].y_end;
            w[1] = i;
        } else {
            if(q[0] != INT32_MIN) {
                ovlp_id(m) = z->w_list.a[w[0]].x_start; ///cur xpos
                ovlp_min_wid(m) = w[0]; ///beg id of windows
                ovlp_max_wid(m) = w[1]; ///end id of windows
                ovlp_cur_wid(m) = w[0]; ///cur id of windows
                ovlp_cur_xoff(m) = z->w_list.a[w[0]].y_start; ///cur ypos
                ovlp_cur_coff(m) = 0; ///cur cigar off in cur window

                is = t[0]; ie = t[1]+1; ///[is, ie)
                for (a_z = a_i; a_z >= 0; a_z--) {
                    as = a[a_z]>>32; ae = (uint32_t)a[a_z];
                    if(ae <= is) break;
                }
                if(a_z < 0) a_z = 0;
                for (; a_z < a_n; a_z++) {
                    as = a[a_z]>>32; ae = (uint32_t)a[a_z];
                    os = MAX(is, as); oe = MIN(ie, ae);
                    ovlp = ((oe>os)? (oe-os):0);
                    if(ovlp) {
                        if(extract_xcoordates0(z, os, oe, &qs, &qe, &m)) {
                            kv_push(uint64_t, *b, (((uint64_t)qs)<<32)|((uint64_t)qe));
                        }
                    }
                    if(as >= ie) break;
                }
                a_i = a_z;
            }
            q[0] = z->w_list.a[i].x_start; q[1] = z->w_list.a[i].x_end;
            t[0] = z->w_list.a[i].y_start; t[1] = z->w_list.a[i].y_end;
            w[0] = i; w[1] = i;
        }
    }

    if(q[0] != INT32_MIN) {
        ovlp_id(m) = z->w_list.a[w[0]].x_start; ///cur xpos
        ovlp_min_wid(m) = w[0]; ///beg id of windows
        ovlp_max_wid(m) = w[1]; ///end id of windows
        ovlp_cur_wid(m) = w[0]; ///cur id of windows
        ovlp_cur_xoff(m) = z->w_list.a[w[0]].y_start; ///cur ypos
        ovlp_cur_coff(m) = 0; ///cur cigar off in cur window

        is = t[0]; ie = t[1]+1; 
        for (a_z = a_i; a_z >= 0; a_z--) {
            as = a[a_z]>>32; ae = (uint32_t)a[a_z];
            if(ae <= is) break;
        }
        if(a_z < 0) a_z = 0;
        for (; a_z < a_n; a_z++) {
            as = a[a_z]>>32; ae = (uint32_t)a[a_z];
            os = MAX(is, as); oe = MIN(ie, ae);
            ovlp = ((oe>os)? (oe-os):0);
            if(ovlp) {
                if(extract_xcoordates0(z, os, oe, &qs, &qe, &m)) {
                    kv_push(uint64_t, *b, (((uint64_t)qs)<<32)|((uint64_t)qe));
                }
            }
            if(as >= ie) break;
        }
        a_i = a_z;
    }
    return b->n - bn;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, (%rsp)
movq %rdi, 0x8(%rsp)
movq 0x48(%rdi), %r11
testq %r11, %r11
je 0x75710
movq (%rcx), %rax
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x2c(%rsp)
movaps %xmm0, 0x20(%rsp)
jle 0x75706
movq %rsi, %r10
movq 0x8(%rsp), %rax
movq 0x58(%rax), %rax
movq $-0x80000000, %r9       # imm = 0x80000000
xorl %ebx, %ebx
xorl %r14d, %r14d
movq $-0x80000000, %rsi      # imm = 0x80000000
movq $-0x80000000, %rbp      # imm = 0x80000000
movq $-0x80000000, %r13      # imm = 0x80000000
movq $-0x80000000, %rdx      # imm = 0x80000000
movq $-0x80000000, %rdi      # imm = 0x80000000
xorl %r8d, %r8d
movq %rcx, 0x18(%rsp)
movq %r10, 0x10(%rsp)
movq %r11, 0x58(%rsp)
movq %r8, %r15
movq %r8, %r12
shlq $0x5, %r12
movslq (%rax,%r12), %r8
incq %rdi
cmpq %r8, %rdi
jne 0x7546c
leaq (%rax,%r12), %rdi
movslq 0x8(%rdi), %rdi
leaq 0x1(%r13), %r8
cmpq %rdi, %r8
je 0x755b6
cmpq $-0x80000000, %rdx      # imm = 0x80000000
je 0x755aa
movq %r9, %rdx
shlq $0x5, %rdx
movl (%rax,%rdx), %edi
movl %edi, 0x2c(%rsp)
movl %r9d, 0x30(%rsp)
movl %esi, 0x34(%rsp)
movl %r9d, 0x20(%rsp)
movl 0x8(%rax,%rdx), %edx
movl %edx, 0x24(%rsp)
movl $0x0, 0x28(%rsp)
testq %r14, %r14
js 0x754c6
movl (%r10,%r14,8), %edx
cmpq %rbp, %rdx
jle 0x754c6
leaq -0x1(%r14), %rdx
testq %r14, %r14
movq %rdx, %r14
jg 0x754aa
movq $-0x1, %r14
testq %r14, %r14
cmovleq %rbx, %r14
cmpq (%rsp), %r14
jge 0x755aa
movq %r15, 0x60(%rsp)
leaq 0x1(%r13), %r15
movq (%r10,%r14,8), %rbx
movl %ebx, %edx
shrq $0x20, %rbx
cmpq %rbx, %rbp
movq %rbx, %rsi
cmovgq %rbp, %rsi
cmpq %rdx, %r15
cmovlq %r15, %rdx
cmpq %rsi, %rdx
jle 0x7557f
movq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x75066
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %rcx
testq %rax, %rax
je 0x7557f
movq (%rcx), %rdi
movq 0x10(%rcx), %rax
cmpq 0x8(%rcx), %rdi
jne 0x75566
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %edx
cmoveq %rdx, %rsi
movq %rsi, 0x8(%rcx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq (%rcx), %rdi
movq 0x48(%rsp), %rdx
shlq $0x20, %rdx
orq 0x40(%rsp), %rdx
leaq 0x1(%rdi), %rsi
movq %rsi, (%rcx)
movq %rdx, (%rax,%rdi,8)
cmpq %r13, %rbx
jg 0x75595
incq %r14
cmpq %r14, (%rsp)
jne 0x754e0
movq (%rsp), %r14
movq 0x8(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x58(%rsp), %r11
xorl %ebx, %ebx
movq 0x60(%rsp), %r15
movslq (%rax,%r12), %rdx
movslq 0x8(%rax,%r12), %rbp
movq %r15, %r9
movslq 0xc(%rax,%r12), %r13
movslq 0x4(%rax,%r12), %rdi
leaq 0x1(%r15), %r8
movq %r15, %rsi
cmpq %r11, %r8
jne 0x75441
cmpq $-0x80000000, %rdx      # imm = 0x80000000
je 0x75706
movq 0x8(%rsp), %rax
movq 0x58(%rax), %rax
movq %r9, %rdx
shlq $0x5, %rdx
movl (%rax,%rdx), %esi
movl %esi, 0x2c(%rsp)
movl %r9d, 0x30(%rsp)
movl %r15d, 0x34(%rsp)
movl %r9d, 0x20(%rsp)
movl 0x8(%rax,%rdx), %eax
movl %eax, 0x24(%rsp)
movl $0x0, 0x28(%rsp)
testq %r14, %r14
js 0x75634
movl (%r10,%r14,8), %eax
cmpq %rbp, %rax
jle 0x75634
leaq -0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
jg 0x75618
movq $-0x1, %r14
xorl %ebx, %ebx
testq %r14, %r14
cmovgq %r14, %rbx
cmpq (%rsp), %rbx
jge 0x75706
leaq 0x1(%r13), %r14
decq (%rsp)
movl $0x2, %r12d
movq (%r10,%rbx,8), %r15
movl %r15d, %edx
shrq $0x20, %r15
cmpq %r15, %rbp
movq %r15, %rsi
cmovgq %rbp, %rsi
cmpq %rdx, %r14
cmovlq %r14, %rdx
cmpq %rsi, %rdx
jle 0x756f0
movq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x75066
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %rcx
testq %rax, %rax
je 0x756f0
movq (%rcx), %rdi
movq 0x10(%rcx), %rax
cmpq 0x8(%rcx), %rdi
jne 0x756d7
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
cmoveq %r12, %rsi
movq %rsi, 0x8(%rcx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq (%rcx), %rdi
movq 0x48(%rsp), %rdx
shlq $0x20, %rdx
orq 0x40(%rsp), %rdx
leaq 0x1(%rdi), %rsi
movq %rsi, (%rcx)
movq %rdx, (%rax,%rdi,8)
cmpq %r13, %r15
jg 0x75706
leaq 0x1(%rbx), %rax
cmpq %rbx, (%rsp)
movq %rax, %rbx
jne 0x75655
movq (%rcx), %rax
subq 0x50(%rsp), %rax
jmp 0x75712
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq