// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq 0x48(%rdi), %r11
testq %r11, %r11
je 0x75bc4
movq %rsi, %r9
movq %rcx, 0x8(%rsp)
movq (%rcx), %rax
movq %rax, 0x60(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x2c(%rsp)
movaps %xmm0, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
jle 0x75bcb
movq $-0x80000000, %rax      # 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, %rcx      # imm = 0x80000000
movq $-0x80000000, %rdi      # imm = 0x80000000
xorl %edx, %edx
movq %r11, 0x50(%rsp)
movq %rdx, %r10
movq 0x10(%rsp), %rdx
movq 0x58(%rdx), %rdx
movq %r10, %r12
shlq $0x5, %r12
movslq (%rdx,%r12), %r8
incq %rdi
cmpq %r8, %rdi
jne 0x75a4d
leaq (%rdx,%r12), %rdi
movslq 0x8(%rdi), %rdi
leaq 0x1(%r13), %r8
cmpq %rdi, %r8
je 0x75b9e
cmpq $-0x80000000, %rcx      # imm = 0x80000000
je 0x75b89
movq %rax, %rcx
shlq $0x5, %rcx
movl (%rdx,%rcx), %edi
movl %edi, 0x2c(%rsp)
movl %eax, 0x30(%rsp)
movl %esi, 0x34(%rsp)
movl %eax, 0x20(%rsp)
movl 0x8(%rdx,%rcx), %eax
movl %eax, 0x24(%rsp)
movl $0x0, 0x28(%rsp)
testq %r14, %r14
js 0x75aa5
movl (%r9,%r14,8), %eax
cmpq %rbp, %rax
jle 0x75aa5
leaq -0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
jg 0x75a89
movq $-0x1, %r14
testq %r14, %r14
cmovleq %rbx, %r14
cmpq (%rsp), %r14
jge 0x75b89
movq %r10, 0x58(%rsp)
leaq 0x1(%r13), %rbx
movq (%r9,%r14,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 0x75b67
movq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x755f3
movq 0x18(%rsp), %r9
testq %rax, %rax
je 0x75b67
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
cmpq %rax, (%rcx)
jne 0x75b44
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rcx)
movq 0x10(%rcx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq 0x48(%rsp), %rax
shlq $0x20, %rax
orq 0x40(%rsp), %rax
movq %rcx, %rdi
movq (%rcx), %rcx
movq 0x10(%rdi), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rdi)
movq %rax, (%rdx,%rcx,8)
cmpq %r13, %r15
jg 0x75b7d
incq %r14
cmpq %r14, (%rsp)
jne 0x75abf
movq (%rsp), %r14
movq 0x58(%rsp), %r10
movq 0x50(%rsp), %r11
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movq 0x58(%rax), %rdx
movslq (%rdx,%r12), %rcx
movslq 0x8(%rdx,%r12), %rbp
movq %r10, %rax
movslq 0xc(%rdx,%r12), %r13
movslq 0x4(%rdx,%r12), %rdi
leaq 0x1(%r10), %rdx
movq %r10, %rsi
cmpq %r11, %rdx
jne 0x75a19
cmpq $-0x80000000, %rcx      # imm = 0x80000000
sete %cl
jmp 0x75beb
xorl %eax, %eax
jmp 0x75d2b
movl $0x80000000, %r10d      # imm = 0x80000000
movq $-0x80000000, %r13      # imm = 0x80000000
movb $0x1, %cl
xorl %r14d, %r14d
movq $-0x80000000, %rbp      # imm = 0x80000000
movq $-0x80000000, %rax      # imm = 0x80000000
testb %cl, %cl
jne 0x75d1e
movq 0x10(%rsp), %rcx
movq 0x58(%rcx), %rcx
movq %rax, %rdx
shlq $0x5, %rdx
movl (%rcx,%rdx), %esi
movl %esi, 0x2c(%rsp)
movl %eax, 0x30(%rsp)
movl %r10d, 0x34(%rsp)
movl %eax, 0x20(%rsp)
movl 0x8(%rcx,%rdx), %eax
movl %eax, 0x24(%rsp)
movl $0x0, 0x28(%rsp)
testq %r14, %r14
js 0x75c48
movl (%r9,%r14,8), %eax
cmpq %rbp, %rax
jle 0x75c48
leaq -0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
jg 0x75c2c
movq $-0x1, %r14
xorl %ebx, %ebx
testq %r14, %r14
cmovgq %r14, %rbx
cmpq (%rsp), %rbx
jge 0x75d1e
leaq 0x1(%r13), %r14
decq (%rsp)
movl $0x2, %r12d
movq (%r9,%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 0x75d08
movq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x755f3
movq 0x18(%rsp), %r9
testq %rax, %rax
je 0x75d08
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
cmpq %rax, (%rcx)
jne 0x75ce5
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r12, %rsi
movq %rsi, 0x8(%rcx)
movq 0x10(%rcx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq 0x48(%rsp), %rax
shlq $0x20, %rax
orq 0x40(%rsp), %rax
movq %rcx, %rdi
movq (%rcx), %rcx
movq 0x10(%rdi), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rdi)
movq %rax, (%rdx,%rcx,8)
cmpq %r13, %r15
jg 0x75d1e
leaq 0x1(%rbx), %rax
cmpq %rbx, (%rsp)
movq %rax, %rbx
jne 0x75c69
movq 0x8(%rsp), %rax
movq (%rax), %rax
subq 0x60(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq