// File: 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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x7ef46
movq $0x0, -0x8(%rbp)
jmp 0x7f71e
movq $-0x80000000, -0x68(%rbp) # imm = 0x80000000
movq $-0x80000000, -0x70(%rbp) # imm = 0x80000000
movq $-0x80000000, -0x58(%rbp) # imm = 0x80000000
movq $-0x80000000, -0x60(%rbp) # imm = 0x80000000
movq $-0x80000000, -0x48(%rbp) # imm = 0x80000000
movq $-0x80000000, -0x50(%rbp) # imm = 0x80000000
leaq -0xdc(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movq $0x0, -0x80(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x7f3e7
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq -0x48(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x7f031
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x7f031
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0xc(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x7f3d4
cmpq $-0x80000000, -0x50(%rbp) # imm = 0x80000000
je 0x7f359
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0xd0(%rbp)
movq -0x70(%rbp), %rax
movl %eax, -0xcc(%rbp)
movq -0x68(%rbp), %rax
movl %eax, -0xc8(%rbp)
movq -0x70(%rbp), %rax
movl %eax, -0xdc(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0xd8(%rbp)
movl $0x0, -0xd4(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
jl 0x7f127
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jg 0x7f111
jmp 0x7f127
jmp 0x7f113
movq -0x88(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x7f0c3
cmpq $0x0, -0x88(%rbp)
jge 0x7f13c
movq $0x0, -0x88(%rbp)
jmp 0x7f13e
movq -0x88(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x7f34e
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x90(%rbp), %rax
jl 0x7f1a1
movq -0xa0(%rbp), %rax
movq %rax, -0xf8(%rbp)
jmp 0x7f1af
movq -0x90(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0x98(%rbp), %rax
jg 0x7f1dd
movq -0xa8(%rbp), %rax
movq %rax, -0x100(%rbp)
jmp 0x7f1eb
movq -0x98(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jle 0x7f220
movq -0xb8(%rbp), %rax
subq -0xb0(%rbp), %rax
movq %rax, -0x108(%rbp)
jmp 0x7f22b
xorl %eax, %eax
movq %rax, -0x108(%rbp)
jmp 0x7f22b
movq -0x108(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
je 0x7f323
movq -0x10(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
leaq -0xf0(%rbp), %r8
leaq -0xdc(%rbp), %r9
callq 0x7e7c0
cmpq $0x0, %rax
je 0x7f321
jmp 0x7f27f
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x7f2f0
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x7f2af
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x110(%rbp)
jmp 0x7f2bd
movl $0x2, %eax
movq %rax, -0x110(%rbp)
jmp 0x7f2bd
movq -0x110(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0xe8(%rbp), %rdx
shlq $0x20, %rdx
orq -0xf0(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x7f321
jmp 0x7f323
movq -0x90(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jl 0x7f335
jmp 0x7f34e
jmp 0x7f337
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x7f13e
movq -0x88(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0xc(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x7f3d6
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x7ef99
cmpq $-0x80000000, -0x50(%rbp) # imm = 0x80000000
je 0x7f70f
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0xd0(%rbp)
movq -0x70(%rbp), %rax
movl %eax, -0xcc(%rbp)
movq -0x68(%rbp), %rax
movl %eax, -0xc8(%rbp)
movq -0x70(%rbp), %rax
movl %eax, -0xdc(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0xd8(%rbp)
movl $0x0, -0xd4(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
jl 0x7f4dd
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jg 0x7f4c7
jmp 0x7f4dd
jmp 0x7f4c9
movq -0x88(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x7f479
cmpq $0x0, -0x88(%rbp)
jge 0x7f4f2
movq $0x0, -0x88(%rbp)
jmp 0x7f4f4
movq -0x88(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x7f704
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x90(%rbp), %rax
jl 0x7f557
movq -0xa0(%rbp), %rax
movq %rax, -0x118(%rbp)
jmp 0x7f565
movq -0x90(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0x98(%rbp), %rax
jg 0x7f593
movq -0xa8(%rbp), %rax
movq %rax, -0x120(%rbp)
jmp 0x7f5a1
movq -0x98(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jle 0x7f5d6
movq -0xb8(%rbp), %rax
subq -0xb0(%rbp), %rax
movq %rax, -0x128(%rbp)
jmp 0x7f5e1
xorl %eax, %eax
movq %rax, -0x128(%rbp)
jmp 0x7f5e1
movq -0x128(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
je 0x7f6d9
movq -0x10(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
leaq -0xf0(%rbp), %r8
leaq -0xdc(%rbp), %r9
callq 0x7e7c0
cmpq $0x0, %rax
je 0x7f6d7
jmp 0x7f635
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x7f6a6
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x7f665
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x130(%rbp)
jmp 0x7f673
movl $0x2, %eax
movq %rax, -0x130(%rbp)
jmp 0x7f673
movq -0x130(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0xe8(%rbp), %rdx
shlq $0x20, %rdx
orq -0xf0(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x7f6d7
jmp 0x7f6d9
movq -0x90(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jl 0x7f6eb
jmp 0x7f704
jmp 0x7f6ed
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x7f4f4
movq -0x88(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
subq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax,%rax)