// File: chhylp123[P]hifiasm/Correct.cpp
// Function: cal_paired_distance(ma_ug_t*, overlap_region*, overlap_region*, ul_ov_t*, unsigned int, asg64_v*, asg64_v*, idx_emask_t*, long)
int64_t cal_paired_distance(ma_ug_t *ug, overlap_region *q, overlap_region *t, ul_ov_t *a, uint32_t a_n, 
asg64_v *srt, asg64_v* buf1, idx_emask_t *mm, int64_t bd)
{
    uint64_t k, cn, *qa, *ta, *ca, m, qn, tn, rev, rev_n, tl, mt, qocc, tocc, s, e; 
    ul_ov_t ou; memset((&ou), 0, sizeof(ou)); int64_t eq, et;
    srt->n = 0; kv_resize(uint64_t, *srt, (a_n<<1)); qa = srt->a; ta = qa + a_n;

    // if(q->y_id == 4 && t->y_id == 6) {
    //     fprintf(stderr, "\n\n\n[M::%s]\tutg%.6u%c\tutg%.6u%c\n", __func__, q->y_id+1, "lc"[ug->u.a[q->y_id].circ], 
    //     t->y_id+1, "lc"[ug->u.a[t->y_id].circ]);
    // }

    for (k = cn = 0; k < a_n; k++) {
        // if(q->y_id == 4 && t->y_id == 6) {
        //     fprintf(stderr, "[M::%s]\tk::%lu\n", __func__, k); 
        //     fprintf(stderr, "au\tutg%.6u%c\txl::%u\tx::[%u,\t%u)\t%c\tutg%.6u%c\tyl::%u\ty::[%u,\t%u)\tfull::%u\tis_cal::%u\n", 
        //     a[k].qn + 1, "lc"[ug->u.a[a[k].qn].circ], ug->u.a[a[k].qn].len, a[k].qs, a[k].qe, "+-"[a[k].rev],
        //     a[k].tn + 1, "lc"[ug->u.a[a[k].tn].circ], ug->u.a[a[k].tn].len, a[k].ts, a[k].te,
        //     a[k].el, (a[k].sec!=((uint32_t)(0x3fffffff)))?1:0);
        // }
        if(!cal_no_bd_coor(&(a[k]), &ou, mm, bd)) continue;
        qa[cn] = (((uint64_t)ou.qs)<<32)|((uint64_t)ou.qe);
        ta[cn] = (((uint64_t)ou.ts)<<32)|((uint64_t)ou.te);
        cn++;
        // if(q->y_id == 4 && t->y_id == 6) {
        //     fprintf(stderr, "ou\tutg%.6u%c\txl::%u\tx::[%u,\t%u)\t%c\tutg%.6u%c\tyl::%u\ty::[%u,\t%u)\n", 
        //     ou.qn + 1, "lc"[ug->u.a[ou.qn].circ], ug->u.a[ou.qn].len, ou.qs, ou.qe, "+-"[ou.rev],
        //     ou.tn + 1, "lc"[ug->u.a[ou.tn].circ], ug->u.a[ou.tn].len, ou.ts, ou.te);
        // }
    }
    radix_sort_bc64(qa, qa+cn); ca = qa; rev = q->y_pos_strand; tl = ug->g->seq[q->y_id].len;
    for (k = m = 0; k < cn; k++) {
        if(m <= 0 || (((uint32_t)ca[m-1])) < (ca[k]>>32)) {
            ca[m++] = ca[k];
        } else if(((uint32_t)ca[m-1]) < ((uint32_t)ca[k])) {
            ca[m-1] += ((uint32_t)ca[k])-((uint32_t)ca[m-1]);
        }
    }
    if(rev) {
        rev_n = m>>1; ///tl = (tl<<32) + tl;
        for (k = 0; k < rev_n; k++) {
            mt = ca[k]; ca[k] = ca[m-k-1]; ca[m-k-1] = mt;

            s = tl-((uint32_t)ca[k]); e = tl-(ca[k]>>32);
            ca[k] = (s<<32)|e;
            s = tl-((uint32_t)ca[m-k-1]); e = tl-(ca[m-k-1]>>32);
            ca[m-k-1] = (s<<32)|e;
        }
        if(m&1) {
            s = tl-((uint32_t)ca[k]); e = tl-(ca[k]>>32);
            ca[k] = (s<<32)|e;
        }
    }
    qn = m;
    // if(q->y_id == 4 && t->y_id == 6) {
    // fprintf(stderr, "[M::%s]\tqn::%lu\trev::%lu\n", __func__, qn, rev); 
    // for (k = 0; k < qn; k++) {
    //     s = qa[k]>>32; e = ((uint32_t)qa[k]);
    //     fprintf(stderr, "[M::%s]\tqstr::[%lu,\t%lu)\n", __func__, s, e); 
    // }
    // }

    radix_sort_bc64(ta, ta+cn); ca = ta; rev = t->y_pos_strand; tl = ug->g->seq[t->y_id].len;
    for (k = m = 0; k < cn; k++) {
        if(m <= 0 || (((uint32_t)ca[m-1])) < (ca[k]>>32)) {
            ca[m++] = ca[k];
        } else if(((uint32_t)ca[m-1]) < ((uint32_t)ca[k])) {
            ca[m-1] += ((uint32_t)ca[k])-((uint32_t)ca[m-1]);
        }
    }
    if(rev) {
        rev_n = m>>1; ///tl = (tl<<32) + tl;
        for (k = 0; k < rev_n; k++) {
            mt = ca[k]; ca[k] = ca[m-k-1]; ca[m-k-1] = mt;

            s = tl-((uint32_t)ca[k]); e = tl-(ca[k]>>32);
            ca[k] = (s<<32)|e;
            s = tl-((uint32_t)ca[m-k-1]); e = tl-(ca[m-k-1]>>32);
            ca[m-k-1] = (s<<32)|e;
        }
        if(m&1) {
            s = tl-((uint32_t)ca[k]); e = tl-(ca[k]>>32);
            ca[k] = (s<<32)|e;
        }
    }
    tn = m;
    // if(q->y_id == 4 && t->y_id == 6) {
    // fprintf(stderr, "[M::%s]\ttn::%lu\trev::%lu\n", __func__, tn, rev); 
    // for (k = 0; k < tn; k++) {
    //     s = ta[k]>>32; e = ((uint32_t)ta[k]);
    //     fprintf(stderr, "[M::%s]\ttstr::[%lu,\t%lu)\n", __func__, s, e); 
    // }
    // }

    buf1->n = 0; qocc = tocc = 0; srt->n = 0;
    if(qn > 0 && tn > 0) {
        qocc = extract_xcoordates(q, qa, qn, buf1);
        tocc = extract_xcoordates(t, ta, tn, buf1);
        // if(q->y_id == 4 && t->y_id == 6) {
        //     fprintf(stderr, "[M::%s]\tqocc::%lu\ttocc::%lu\n", __func__, qocc, tocc);
        // }
        if((!qocc) || (!tocc)) qocc = tocc = buf1->n = 0;
    }
    if(!(buf1->n)) return INT32_MIN;
    update_masks(buf1, q, t, bd);   

    eq = et = 0;
    if(buf1->n) {
        eq = cal_xerr(q, buf1->a, buf1->n);
        et = cal_xerr(t, buf1->a, buf1->n);
    }   
    // if(q->y_id == 4 && t->y_id == 6) {
    //     s = MAX(q->x_pos_s, t->x_pos_s);
    //     e = MIN(q->x_pos_e, t->x_pos_e) + 1;
    //     buf1->n = 0;
    //     kv_push(uint64_t, *buf1, ((s<<32)|e));
    //     fprintf(stderr, "[M::%s]\teq::%ld\tet::%ld\tbuf1->n::%u\n", __func__, eq, et, (uint32_t)buf1->n);
    //     eq = cal_xerr(q, buf1->a, buf1->n); et = cal_xerr(t, buf1->a, buf1->n);
    //     fprintf(stderr, "[M::%s]\teq1::%ld\tet1::%ld\tbuf1->n::%u\ts::%lu\te::%lu\n", 
    //     __func__, eq, et, (uint32_t)buf1->n, s, e);
    // }

    return eq - et;    
    // return get_pe_diff(q, qa, qn, t, ta, tn, bd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
leaq -0xd4(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x2c(%rbp), %ecx
shll %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x811a1
movl -0x2c(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq -0x38(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq -0x38(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq -0x38(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq -0x38(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq -0x38(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x811a3
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl -0x2c(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x81268
movq -0x28(%rbp), %rdi
imulq $0x1c, -0x40(%rbp), %rax
addq %rax, %rdi
movq 0x18(%rbp), %rdx
movq 0x20(%rbp), %rcx
leaq -0xd4(%rbp), %rsi
callq 0x7da00
cmpq $0x0, %rax
jne 0x81209
jmp 0x81257
movl -0xd0(%rbp), %eax
movl %eax, %edx
shlq $0x20, %rdx
movl -0xcc(%rbp), %eax
orq %rax, %rdx
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0xc4(%rbp), %eax
movl %eax, %edx
shlq $0x20, %rdx
movl -0xc0(%rbp), %eax
orq %rax, %rdx
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x811d1
movq -0x50(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x90(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x81393
cmpq $0x0, -0x68(%rbp)
jbe 0x81303
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jae 0x81328
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x68(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x81380
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jae 0x8137e
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
subl %ecx, %eax
movl %eax, %eax
movl %eax, %edx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq $0x1, %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x81380
jmp 0x81382
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x812c7
cmpq $0x0, -0x80(%rbp)
je 0x81566
movq -0x68(%rbp), %rax
shrq %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0x814f8
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x98(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdx
shlq $0x20, %rdx
orq -0xb8(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq -0x40(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq -0x40(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdx
shlq $0x20, %rdx
orq -0xb8(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x813b4
movq -0x68(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x81564
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdx
shlq $0x20, %rdx
orq -0xb8(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x81566
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x48(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x90(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x81699
cmpq $0x0, -0x68(%rbp)
jbe 0x81609
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jae 0x8162e
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x68(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x81686
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jae 0x81684
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
subl %ecx, %eax
movl %eax, %eax
movl %eax, %edx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq $0x1, %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x81686
jmp 0x81688
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x815cd
cmpq $0x0, -0x80(%rbp)
je 0x8186c
movq -0x68(%rbp), %rax
shrq %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0x817fe
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x98(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdx
shlq $0x20, %rdx
orq -0xb8(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq -0x40(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq -0x40(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdx
shlq $0x20, %rdx
orq -0xb8(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x816ba
movq -0x68(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x8186a
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdx
shlq $0x20, %rdx
orq -0xb8(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x8186c
movq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq 0x10(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, -0x70(%rbp)
jbe 0x8191d
cmpq $0x0, -0x78(%rbp)
jbe 0x8191d
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x7ef00
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x7ef00
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0x818fa
cmpq $0x0, -0xa8(%rbp)
jne 0x8191b
movq 0x10(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
jmp 0x8191d
movq 0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x81934
movq $-0x80000000, -0x8(%rbp) # imm = 0x80000000
jmp 0x819b9
movq 0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq 0x20(%rbp), %rcx
callq 0x7fd90
movq $0x0, -0xe8(%rbp)
movq $0x0, -0xe0(%rbp)
movq 0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x819a7
movq -0x18(%rbp), %rdi
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x10(%rbp), %rax
movq (%rax), %rdx
callq 0x7f730
movq %rax, -0xe0(%rbp)
movq -0x20(%rbp), %rdi
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x10(%rbp), %rax
movq (%rax), %rdx
callq 0x7f730
movq %rax, -0xe8(%rbp)
movq -0xe0(%rbp), %rax
subq -0xe8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)