// File: /workspace/github_cpp_makefile_star2_O2/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, 0x50(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x48(%rdi), %rbx
testq %rbx, %rbx
je 0x43425
movq %rsi, %r11
movq (%rcx), %rax
movq %rax, 0x58(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movups %xmm0, 0xc(%rax)
movaps %xmm0, (%rax)
xorl %eax, %eax
testq %rbx, %rbx
cmovleq %rax, %rbx
movq $-0x80000000, %rdi      # imm = 0x80000000
xorl %edx, %edx
movq $-0x80000000, %r10      # imm = 0x80000000
movq $-0x80000000, (%rsp)    # imm = 0x80000000
movq $-0x80000000, %rbp      # imm = 0x80000000
movq $-0x80000000, %rsi      # imm = 0x80000000
movq $-0x80000000, %rax      # imm = 0x80000000
xorl %r12d, %r12d
movq %rcx, 0x18(%rsp)
movq %r11, 0x10(%rsp)
movq %rbx, 0x60(%rsp)
cmpq %rbx, %rdx
je 0x433c0
movq %rdx, %r13
movq 0x8(%rsp), %rdx
movq 0x58(%rdx), %rdx
movq %r13, %r14
shlq $0x5, %r14
movslq (%rdx,%r14), %r8
incq %rdi
cmpq %r8, %rdi
jne 0x43264
leaq (%rdx,%r14), %rdi
movslq 0x8(%rdi), %rdi
movq (%rsp), %r9
incq %r9
cmpq %rdi, %r9
je 0x433a6
cmpq $-0x80000000, %r10      # imm = 0x80000000
je 0x4339b
movq %rax, %r8
shlq $0x5, %r8
movl (%rdx,%r8), %edi
movl %edi, 0x2c(%rsp)
movl %eax, 0x30(%rsp)
movl %esi, 0x34(%rsp)
movl %eax, 0x20(%rsp)
movl 0x8(%rdx,%r8), %eax
movl %eax, 0x24(%rsp)
andl $0x0, 0x28(%rsp)
movq (%rsp), %rax
leaq 0x1(%rax), %rbx
cmpq $-0x1, %r12
pushq $-0x1
popq %rax
cmovlq %r12, %rax
testq %r12, %r12
js 0x432c3
movl (%r11,%r12,8), %edx
cmpq %rbp, %rdx
jle 0x432c0
decq %r12
jmp 0x432ad
movq %r12, %rax
testq %rax, %rax
movl $0x0, %edx
cmovleq %rdx, %rax
movq %rax, %r12
cmpq 0x50(%rsp), %r12
jge 0x43389
movq (%r11,%r12,8), %r15
movl %r15d, %edx
shrq $0x20, %r15
cmpq %r15, %rbp
movq %r15, %rsi
cmovgq %rbp, %rsi
cmpq %rdx, %rbx
cmovlq %rbx, %rdx
cmpq %rsi, %rdx
jle 0x4337b
movq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x42e66
movq 0x10(%rsp), %r11
movq 0x18(%rsp), %rcx
testq %rax, %rax
je 0x4337b
movq (%rcx), %rdi
movq 0x10(%rcx), %rax
cmpq 0x8(%rcx), %rdi
jne 0x43362
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rdx
cmoveq %rdx, %rsi
movq %rsi, 0x8(%rcx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %r11
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 (%rsp), %r15
jg 0x43389
incq %r12
jmp 0x432d2
movq 0x8(%rsp), %rax
movq 0x58(%rax), %rdx
movslq (%rdx,%r14), %r8
movq 0x60(%rsp), %rbx
movslq 0x8(%rdx,%r14), %rbp
movq %r8, %r10
movq %r13, %rax
movslq 0xc(%rdx,%r14), %rsi
movq %rsi, (%rsp)
movslq 0x4(%rdx,%r14), %rdi
leaq 0x1(%r13), %rdx
movq %r13, %rsi
jmp 0x43224
cmpq $-0x80000000, %r10      # imm = 0x80000000
je 0x434f4
movq 0x8(%rsp), %rdx
movq 0x58(%rdx), %r8
movq %rax, %rdx
shlq $0x5, %rdx
movl (%r8,%rdx), %edi
movl %edi, 0x2c(%rsp)
movl %eax, 0x30(%rsp)
movl %esi, 0x34(%rsp)
movl %eax, 0x20(%rsp)
movl 0x8(%r8,%rdx), %eax
movl %eax, 0x24(%rsp)
andl $0x0, 0x28(%rsp)
movq (%rsp), %rax
leaq 0x1(%rax), %r14
cmpq $-0x1, %r12
pushq $-0x1
popq %rdx
cmovlq %r12, %rdx
testq %r12, %r12
js 0x4342f
movl (%r11,%r12,8), %eax
cmpq %rbp, %rax
jle 0x4342c
decq %r12
jmp 0x43412
xorl %eax, %eax
jmp 0x434fc
movq %r12, %rdx
xorl %ebx, %ebx
testq %rdx, %rdx
cmovgq %rdx, %rbx
leaq 0x48(%rsp), %r15
leaq 0x40(%rsp), %r13
cmpq 0x50(%rsp), %rbx
jge 0x434f4
movq (%r11,%rbx,8), %r12
movl %r12d, %edx
shrq $0x20, %r12
cmpq %r12, %rbp
movq %r12, %rsi
cmovgq %rbp, %rsi
cmpq %rdx, %r14
cmovlq %r14, %rdx
cmpq %rsi, %rdx
jle 0x434e7
movq 0x8(%rsp), %rdi
movq %r15, %rcx
movq %r13, %r8
leaq 0x20(%rsp), %r9
callq 0x42e66
movq 0x10(%rsp), %r11
movq 0x18(%rsp), %rcx
testq %rax, %rax
je 0x434e7
movq (%rcx), %rdi
movq 0x10(%rcx), %rax
cmpq 0x8(%rcx), %rdi
jne 0x434ce
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rdx
cmoveq %rdx, %rsi
movq %rsi, 0x8(%rcx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %r11
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)
incq %rbx
cmpq (%rsp), %r12
jle 0x43442
movq (%rcx), %rax
subq 0x58(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq