// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: mask_ovlps(ul_idx_t const*, ug_opt_t const*, ma_ug_t*, overlap_region_alloc*, mask_ul_ov_t*, kv_ul_ov_t*, asg64_v*, asg64_v*, idx_emask_t*, double, unsigned long, long)
uint64_t mask_ovlps(const ul_idx_t *uref, const ug_opt_t *uopt, ma_ug_t *ug, overlap_region_alloc* ol, mask_ul_ov_t *mk, kv_ul_ov_t *ov_db, asg64_v *coor_srt, asg64_v* buf1, idx_emask_t *mm, double len_diff, uint64_t rlen, int64_t bd)
{
    mk->srt.n = mk->idx.n = 0;
    int64_t k, m, i, osrt_n, osrt_n1, on = ol->length; uint64_t wt, w[2], is_exact, sid, tot, tol, qi, ti; 
    overlap_region *z; ul_ov_t ou; kv_ul_ov_t *osrt = &(mk->srt); ul_ov_t p, q;
    for (k = osrt->n = 0; k < on; k++) {
        z = &(ol->list[k]); if(!(z->x_pos_strand)) continue;///x_pos_strand: how many masks
        if(gen_aln_ul_ov_t(k, ug->g->seq[z->y_id].len, z, &ou)) {
            kv_push(ul_ov_t, *osrt, ou);
        }
    }
    if(!(osrt->n)) return 0;

    osrt_n = osrt->n; memset(&ou, 0, sizeof(ou));
    radix_sort_uov_srt_qs(osrt->a, osrt->a+osrt->n); ///sort by qs; for quick filtering between overlaps
    for (k = tot = tol = 0; k < osrt_n; k++) {
        tol += osrt->a[k].qe-osrt->a[k].qs; 
        convert_ul_ov_t(&p, &(ol->list[osrt->a[k].qn]), ug); p.qn = osrt->a[k].qn;
        for (i = k+1; i < osrt_n && osrt->a[i].qs < osrt->a[k].qe; i++) {
            ///for a pair of overlap, only need to calculate it in one side
            if(ol->list[osrt->a[i].qn].y_id >= ol->list[osrt->a[k].qn].y_id) continue;
            is_exact = 0; sid = (uint32_t)-1;
            convert_ul_ov_t(&q, &(ol->list[osrt->a[i].qn]), ug); q.qn = osrt->a[i].qn;
            if(if_direct_mask(uref, uopt, &p, &q, 16, len_diff)) is_exact = 1;
            if((!is_exact) && (!check_mask_exist(ug, &(ol->list[osrt->a[i].qn]), &(ol->list[osrt->a[k].qn]), ov_db, mm, len_diff, &is_exact, &sid))) {
                continue;
            }
            
            if(is_exact) {///if two overlaps are exactly the same; no need to do anything
                ou.qs = 0; ou.qe = sid; ou.ts = ou.te = 0; ou.el = 1;
            } else {
                w[0] = ol->list[osrt->a[k].qn].non_homopolymer_errors;
                w[1] = ol->list[osrt->a[i].qn].non_homopolymer_errors;
                wt = w[0] + w[1] + ((w[0]>=w[1])?(w[0]-w[1]):(w[1]-w[0]));
                if(wt > (uint32_t)-1) wt = (uint32_t)-1;
                //qs: weight; qe: idx with in ov_db; el: exact match?
                ou.qs = wt; ou.qe = sid; ou.el = 0;
                ou.ts = osrt->a[i].qe-osrt->a[i].qs;
                ou.te = osrt->a[k].qe-osrt->a[k].qs;
            }
            ou.qn = osrt->a[i].qn; ou.tn = osrt->a[k].qn;///id of the ol->list, instead of real yid
            tot += ou.ts + ou.te;
            kv_push(ul_ov_t, *osrt, ou);
        }
        for (i = k-1; i >= 0; i--) {
            ///for a pair of overlap, only need to calculate it in one side
            if(ol->list[osrt->a[i].qn].y_id >= ol->list[osrt->a[k].qn].y_id) continue;
            is_exact = 0; sid = (uint32_t)-1;
            convert_ul_ov_t(&q, &(ol->list[osrt->a[i].qn]), ug); q.qn = osrt->a[i].qn;
            if(if_direct_mask(uref, uopt, &p, &q, 16, len_diff)) is_exact = 1;
            if((!is_exact) && (!check_mask_exist(ug, &(ol->list[osrt->a[i].qn]), &(ol->list[osrt->a[k].qn]), ov_db, mm, len_diff, &is_exact, &sid))) {
                continue;
            }
            
            if(is_exact) {
                ou.qs = 0; ou.qe = sid; ou.ts = ou.te = 0; ou.el = 1;
            } else {
                w[0] = ol->list[osrt->a[k].qn].non_homopolymer_errors;
                w[1] = ol->list[osrt->a[i].qn].non_homopolymer_errors;
                wt = w[0] + w[1] + ((w[0]>=w[1])?(w[0]-w[1]):(w[1]-w[0]));
                if(wt > (uint32_t)-1) wt = (uint32_t)-1;
                ou.qs = wt; ou.qe = sid; ou.el = 0;
                ou.ts = osrt->a[i].qe-osrt->a[i].qs;
                ou.te = osrt->a[k].qe-osrt->a[k].qs;
            }
            ou.qn = osrt->a[i].qn; ou.tn = osrt->a[k].qn;///id of the ol->list, instead of real yid
            tot += ou.ts + ou.te;
            kv_push(ul_ov_t, *osrt, ou);
        }
    }

    // fprintf(stderr, "0[M::%s]\tosrt_n::%u\tosrt->n::%u\n", __func__, (uint32_t)osrt_n, (uint32_t)osrt->n);

    if((tot > (rlen*256)) && (tot > (tol*32))) {
        tot = MAX((rlen*256), (tol*32)); osrt_n1 = osrt->n;
        radix_sort_uov_srt_qs(osrt->a+osrt_n, osrt->a+osrt->n); ///sort by weight (qs)
        for (k = osrt_n, wt = 0; k < osrt_n1 && wt <= tot; k++) {
            if(osrt->a[k].el) continue;///exact match, no additional work
            wt += (uint64_t)osrt->a[k].ts + (uint64_t)osrt->a[k].te;
        }
        osrt->n = k;
    }

    memset(&ou, 0, sizeof(ou)); osrt_n1 = osrt->n;
    ///note: osrt will be updated here, so do not use the address within osrt
    for (k = osrt_n, m = 0; k < osrt_n1; k++) {
        qi = osrt->a[k].qn; ti = osrt->a[k].tn; ///represent a pair of read ol->list[qi] <-> ol->list[ti]
        sid = osrt->a[k].qe; wt = 1;
        ///p->qn/p->tn:: id within the ol->list
        ///p->el:: if equally best
        ///p->qs:: err(query)-err(target)
        ///p->ts:: err(target)-err(query)
        if(osrt->a[k].el) {///exact match; no need base-check
            ou.qn = qi; ou.tn = ti; ou.el = 1; ou.qs = ou.ts = 0;
        } else {///do base-check
            wt = gen_mask_ovlp0(ug, ol->list, qi, ti, ov_db, osrt, mm, len_diff, rlen, sid, coor_srt, buf1, bd, &(ou));
        }
        if(wt) {
            osrt->a[m++] = ou;
            // fprintf(stderr, "[M::%s]\tutg%.6u%c\tqerr::%u\t\tutg%.6u%c\tterr::%u\tel::%u\n", 
            // __func__, ol->list[ou.qn].y_id+1, "lc"[ug->u.a[ol->list[ou.qn].y_id].circ], ou.qs, 
            // ol->list[ou.tn].y_id+1, "lc"[ug->u.a[ol->list[ou.tn].y_id].circ], ou.ts, ou.el);
        }
    }
    osrt->n = m;
    if(!(osrt->n)) return 0;

    ///double
    ///p->qn/p->tn:: id within the ol->list
    ///p->el:: if equally best
    ///p->qs:: err(query)-err(target)
    ///p->ts:: err(target)-err(query)
    kv_resize(ul_ov_t, *osrt, (osrt->n<<1)); 
    memcpy(osrt->a+osrt->n, osrt->a, (sizeof((*(osrt->a)))*osrt->n));
    osrt_n = osrt->n; osrt->n <<= 1; osrt_n1 = osrt->n;
    for (k = osrt_n; k < osrt_n1; k++) {
        m = osrt->a[k].qn; osrt->a[k].qn = osrt->a[k].tn; osrt->a[k].tn = m;
        m = osrt->a[k].qs; osrt->a[k].qs = osrt->a[k].ts; osrt->a[k].ts = m;
    }

    ///osrt = &(mk->srt);
    radix_sort_ul_ov_srt_qn1(osrt->a, osrt->a+osrt->n);
    kv_resize(uint64_t, mk->idx, ol->length); mk->idx.n = ol->length;
    memset(mk->idx.a, 0, sizeof((*(mk->idx.a)))*ol->length);
    for (k = 1, i = 0; k <= osrt_n1; k++) {
        if(k == osrt_n1 || osrt->a[i].qn != osrt->a[k].qn) {
            if(k - i > 1) radix_sort_ul_ov_srt_tn1(osrt->a+i, osrt->a+k);
            mk->idx.a[osrt->a[i].qn] = (((uint64_t)i)<<32)|((uint64_t)k);
            i = k;
        }
    }

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movsd %xmm0, 0xa0(%rsp)
movq %r9, 0xb8(%rsp)
movq %rdx, 0x98(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdi, 0xe0(%rsp)
xorl %eax, %eax
movq %rax, (%r8)
movq %rax, 0x20(%r8)
movq %rcx, 0x78(%rsp)
movq 0x10(%rcx), %r14
movq %r8, 0x40(%rsp)
movq %rax, 0x20(%r8)
testq %r14, %r14
jle 0x77188
xorl %r12d, %r12d
leaq 0x50(%rsp), %r15
movl $0x2, %r13d
xorl %ebp, %ebp
movq 0x78(%rsp), %rax
movq (%rax), %rdx
cmpl $0x0, 0xc(%rdx,%r12)
je 0x77175
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x10(%rdx,%r12), %ecx
addq %r12, %rdx
movl (%rax,%rcx,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %rbp, %rdi
movq %r15, %rcx
callq 0x73afd
testq %rax, %rax
je 0x77175
movq 0x40(%rsp), %rdx
movq 0x28(%rdx), %rax
cmpq %rax, 0x20(%rdx)
jne 0x77144
leaq (%rax,%rax), %rcx
testq %rax, %rax
cmoveq %r13, %rcx
movq %rcx, 0x28(%rdx)
movq 0x18(%rdx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq 0x40(%rsp), %rdx
movq %rax, 0x18(%rdx)
movq 0x18(%rdx), %rax
movq 0x20(%rdx), %rcx
movq %rdx, %rsi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rsi)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x50(%rsp), %xmm0
movups 0x5c(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
incq %rbp
addq $0xa8, %r12
cmpq %rbp, %r14
jne 0x770c4
movq 0x40(%rsp), %rax
movq 0x20(%rax), %r14
testq %r14, %r14
je 0x77c80
movq 0x198(%rsp), %r15
leaq 0x18(%rax), %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x5c(%rsp)
movaps %xmm0, 0x50(%rsp)
movq (%rbx), %rdi
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rdi,%r14), %rsi
movq %rax, 0xa8(%rsp)
addq %rax, %rsi
callq 0x46de0
testq %r14, %r14
movq %rbx, 0x90(%rsp)
jle 0x77879
movl $0x1, %eax
movq %rax, 0xd0(%rsp)
movl 0x68(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq $0x0, 0xb0(%rsp)
xorl %eax, %eax
xorl %r12d, %r12d
movq $0x0, 0xc0(%rsp)
movq %r14, 0xd8(%rsp)
movq %r12, 0x108(%rsp)
movq %rax, %r15
movq (%rbx), %rbx
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rbp
addq %r15, %rbp
movl 0x8(%rbx,%rbp), %eax
subl 0x4(%rbx,%rbp), %eax
movq %rax, 0xf8(%rsp)
movl (%rbx,%rbp), %eax
imulq $0xa8, %rax, %rsi
movq 0x78(%rsp), %rax
addq (%rax), %rsi
leaq 0x12c(%rsp), %rdi
movq 0x98(%rsp), %rdx
callq 0x6f306
movl (%rbx,%rbp), %eax
movl %eax, 0x12c(%rsp)
movq %r15, 0xf0(%rsp)
incq %r15
cmpq %r14, %r15
movq %rbp, 0xc8(%rsp)
movq %r15, 0x100(%rsp)
jge 0x77567
movq 0xb0(%rsp), %r14
movq 0x90(%rsp), %rbx
movq (%rbx), %r13
movl 0x20(%r13,%r14), %eax
cmpl 0x8(%r13,%rbp), %eax
jae 0x7756f
movq %r13, %rbx
addq %rbp, %rbx
movq 0x78(%rsp), %rax
movq (%rax), %r12
movl 0x1c(%r13,%r14), %eax
imulq $0xa8, %rax, %rsi
movl 0x10(%r12,%rsi), %eax
movl (%rbx), %ecx
imulq $0xa8, %rcx, %rcx
cmpl 0x10(%r12,%rcx), %eax
jae 0x7753e
movq $0x0, 0x88(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x80(%rsp)
addq %r12, %rsi
leaq 0x110(%rsp), %rbp
movq %rbp, %rdi
movq 0x98(%rsp), %rdx
callq 0x6f306
movl 0x1c(%r13,%r14), %eax
movl %eax, 0x110(%rsp)
movl $0x10, %r8d
movq 0xe0(%rsp), %rdi
movq 0xe8(%rsp), %rsi
leaq 0x12c(%rsp), %rdx
movq %rbp, %rcx
movsd 0xa0(%rsp), %xmm0
callq 0x76fbd
testq %rax, %rax
je 0x77371
movq $0x1, 0x88(%rsp)
cmpq $0x0, 0x88(%rsp)
jne 0x773da
movl 0x1c(%r13,%r14), %eax
imulq $0xa8, %rax, %rsi
addq %r12, %rsi
movl (%rbx), %eax
imulq $0xa8, %rax, %rdx
addq %r12, %rdx
leaq 0x80(%rsp), %rax
movq %rax, (%rsp)
movq 0x98(%rsp), %rdi
movq 0xb8(%rsp), %rcx
movq 0x190(%rsp), %r8
movsd 0xa0(%rsp), %xmm0
leaq 0x88(%rsp), %r9
callq 0x74a12
testq %rax, %rax
je 0x7755d
cmpq $0x0, 0x88(%rsp)
movq 0xc8(%rsp), %rbp
je 0x77421
movl $0x0, 0x54(%rsp)
movl 0x80(%rsp), %eax
movl %eax, 0x58(%rsp)
movq $0x0, 0x60(%rsp)
movl 0x4c(%rsp), %eax
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, 0x4c(%rsp)
movl %eax, 0x68(%rsp)
xorl %ebx, %ebx
jmp 0x774b5
movq 0x78(%rsp), %rax
movq (%rax), %rcx
movq 0x90(%rsp), %rax
movq (%rax), %rax
movl (%rax,%rbp), %edx
imulq $0xa8, %rdx, %rdx
movl 0x30(%rcx,%rdx), %edx
movl 0x1c(%rax,%r14), %esi
imulq $0xa8, %rsi, %rsi
movl 0x30(%rcx,%rsi), %ecx
leaq (%rcx,%rdx), %rsi
movq %rdx, %rdi
subq %rcx, %rdi
movq %rcx, %r8
subq %rdx, %r8
cmpl %ecx, %edx
cmovaeq %rdi, %r8
addq %rsi, %r8
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %r8
cmovaeq %rcx, %r8
movl %r8d, 0x54(%rsp)
movl 0x80(%rsp), %ecx
movl %ecx, 0x58(%rsp)
movl 0x4c(%rsp), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
movl %ecx, 0x4c(%rsp)
movl %ecx, 0x68(%rsp)
movl 0x24(%rax,%r14), %ecx
subl 0x20(%rax,%r14), %ecx
movl %ecx, 0x60(%rsp)
movl 0x8(%rax,%rbp), %ebx
subl 0x4(%rax,%rbp), %ebx
movl %ebx, 0x64(%rsp)
addl %ecx, %ebx
movq 0x40(%rsp), %rdx
movq 0x18(%rdx), %rdi
movl 0x1c(%rdi,%r14), %eax
movl %eax, 0x50(%rsp)
movl (%rdi,%rbp), %eax
movl %eax, 0x5c(%rsp)
movq 0x28(%rdx), %rax
cmpq %rax, 0x20(%rdx)
jne 0x77505
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x28(%rdx)
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq 0x40(%rsp), %rdx
movq %rax, 0x18(%rdx)
addq %rbx, 0xc0(%rsp)
movq 0x18(%rdx), %rax
movq 0x20(%rdx), %rcx
movq %rdx, %rsi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rsi)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x5c(%rsp), %xmm0
movups %xmm0, 0xc(%rax,%rdx)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rax,%rdx)
incq %r15
addq $0x1c, %r14
cmpq 0xd8(%rsp), %r15
movq 0x90(%rsp), %rbx
jl 0x772ab
jmp 0x7756f
movq 0xc8(%rsp), %rbp
jmp 0x7753e
movq 0x90(%rsp), %rbx
cmpq $0x0, 0xf0(%rsp)
je 0x77824
movq 0xb0(%rsp), %r14
movq 0xd0(%rsp), %r15
movq 0x78(%rsp), %rax
movq (%rax), %r12
movq (%rbx), %r13
movl -0x1c(%r13,%r14), %eax
imulq $0xa8, %rax, %rsi
movl 0x10(%r12,%rsi), %eax
movl (%r13,%rbp), %ecx
imulq $0xa8, %rcx, %rcx
cmpl 0x10(%r12,%rcx), %eax
jae 0x77813
movq $0x0, 0x88(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x80(%rsp)
addq %r12, %rsi
leaq 0x110(%rsp), %rbp
movq %rbp, %rdi
movq 0x98(%rsp), %rdx
callq 0x6f306
movl -0x1c(%r13,%r14), %eax
movl %eax, 0x110(%rsp)
movl $0x10, %r8d
movq 0xe0(%rsp), %rdi
movq 0xe8(%rsp), %rsi
leaq 0x12c(%rsp), %rdx
movq %rbp, %rcx
movsd 0xa0(%rsp), %xmm0
callq 0x76fbd
testq %rax, %rax
je 0x77641
movq $0x1, 0x88(%rsp)
cmpq $0x0, 0x88(%rsp)
movq 0xc8(%rsp), %rbp
jne 0x776b7
movl -0x1c(%r13,%r14), %eax
addq %rbp, %r13
imulq $0xa8, %rax, %rsi
addq %r12, %rsi
movl (%r13), %eax
imulq $0xa8, %rax, %rdx
addq %r12, %rdx
leaq 0x80(%rsp), %rax
movq %rax, (%rsp)
movq 0x98(%rsp), %rdi
movq 0xb8(%rsp), %rcx
movq 0x190(%rsp), %r8
movsd 0xa0(%rsp), %xmm0
leaq 0x88(%rsp), %r9
callq 0x74a12
testq %rax, %rax
je 0x77813
cmpq $0x0, 0x88(%rsp)
je 0x776f6
movl $0x0, 0x54(%rsp)
movl 0x80(%rsp), %eax
movl %eax, 0x58(%rsp)
movq $0x0, 0x60(%rsp)
movl 0x4c(%rsp), %eax
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, 0x4c(%rsp)
movl %eax, 0x68(%rsp)
xorl %ebx, %ebx
jmp 0x77782
movq 0x78(%rsp), %rax
movq (%rax), %rcx
movq (%rbx), %rax
movl (%rax,%rbp), %edx
imulq $0xa8, %rdx, %rdx
movl 0x30(%rcx,%rdx), %edx
movl -0x1c(%rax,%r14), %esi
imulq $0xa8, %rsi, %rsi
movl 0x30(%rcx,%rsi), %ecx
leaq (%rcx,%rdx), %rsi
movq %rdx, %rdi
subq %rcx, %rdi
movq %rcx, %r8
subq %rdx, %r8
cmpl %ecx, %edx
cmovaeq %rdi, %r8
addq %rsi, %r8
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %r8
cmovaeq %rcx, %r8
movl %r8d, 0x54(%rsp)
movl 0x80(%rsp), %ecx
movl %ecx, 0x58(%rsp)
movl 0x4c(%rsp), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
movl %ecx, 0x4c(%rsp)
movl %ecx, 0x68(%rsp)
movl -0x14(%rax,%r14), %ecx
subl -0x18(%rax,%r14), %ecx
movl %ecx, 0x60(%rsp)
movl 0x8(%rax,%rbp), %ebx
subl 0x4(%rax,%rbp), %ebx
movl %ebx, 0x64(%rsp)
addl %ecx, %ebx
movq 0x40(%rsp), %rdx
movq 0x18(%rdx), %rdi
movl -0x1c(%rdi,%r14), %eax
movl %eax, 0x50(%rsp)
movl (%rdi,%rbp), %eax
movl %eax, 0x5c(%rsp)
movq 0x28(%rdx), %rax
cmpq %rax, 0x20(%rdx)
jne 0x777d2
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x28(%rdx)
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq 0x40(%rsp), %rdx
movq %rax, 0x18(%rdx)
addq %rbx, 0xc0(%rsp)
movq 0x18(%rdx), %rax
movq 0x20(%rdx), %rcx
movq %rdx, %rsi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rsi)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x5c(%rsp), %xmm0
movups %xmm0, 0xc(%rax,%rdx)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rax,%rdx)
movq 0x90(%rsp), %rbx
decq %r15
addq $-0x1c, %r14
cmpq $0x1, %r15
jg 0x7758e
movq 0x108(%rsp), %r12
addq 0xf8(%rsp), %r12
addq $0x1c, 0xb0(%rsp)
incq 0xd0(%rsp)
movq 0xd8(%rsp), %r14
movq 0x100(%rsp), %rax
cmpq %r14, %rax
jne 0x7721d
shlq $0x5, %r12
movq 0x40(%rsp), %rdx
movq 0x198(%rsp), %r15
movq 0xc0(%rsp), %rax
jmp 0x77883
xorl %eax, %eax
xorl %r12d, %r12d
movq 0x40(%rsp), %rdx
shlq $0x8, %r15
cmpq %r15, %rax
jbe 0x7791e
cmpq %r12, %rax
jbe 0x7791e
cmpq %r12, %r15
cmovaq %r15, %r12
movq 0x18(%rdx), %rsi
movq %r14, %r15
movq 0x20(%rdx), %r14
leaq (%rsi,%r15), %rdi
addq 0xa8(%rsp), %rdi
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rsi
addq %rax, %rsi
callq 0x46de0
movq %r15, %rax
movq %r15, %r8
cmpq %r14, %r15
jge 0x77912
movq (%rbx), %rax
movq 0xa8(%rsp), %rcx
addq %r8, %rcx
addq %rax, %rcx
addq $0x18, %rcx
xorl %edx, %edx
movq %r8, %rax
testb $0x40, 0x3(%rcx)
jne 0x77901
movl -0x8(%rcx), %esi
movl -0x4(%rcx), %edi
addq %rsi, %rdx
addq %rdi, %rdx
incq %rax
cmpq %r14, %rax
jge 0x77912
addq $0x1c, %rcx
cmpq %r12, %rdx
jbe 0x778ef
movq 0x40(%rsp), %rdx
movq %rax, 0x20(%rdx)
movq %r8, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x5c(%rsp)
movaps %xmm0, 0x50(%rsp)
movq 0x20(%rdx), %r15
xorl %r12d, %r12d
subq %r14, %r15
jle 0x77a1f
movq 0xa8(%rsp), %rbp
addq %r14, %rbp
xorl %r14d, %r14d
movq (%rbx), %rax
movl (%rax,%rbp), %edx
movl 0x8(%rax,%rbp), %r13d
movl 0xc(%rax,%rbp), %ecx
testb $0x40, 0x1b(%rax,%rbp)
jne 0x779d0
movq 0x78(%rsp), %rax
movq (%rax), %rsi
leaq 0x50(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x1a0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x188(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %r13, 0x10(%rsp)
movq 0x190(%rsp), %rax
movq %rax, (%rsp)
movq 0x98(%rsp), %rdi
movq 0xb8(%rsp), %r8
movq %rbx, %r9
movsd 0xa0(%rsp), %xmm0
callq 0x76c0b
testl %eax, %eax
jne 0x779e7
jmp 0x77a0b
movl %edx, 0x50(%rsp)
movl %ecx, 0x5c(%rsp)
orb $0x40, 0x6b(%rsp)
movl %r12d, 0x60(%rsp)
movl %r12d, 0x54(%rsp)
movq (%rbx), %rax
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r14, %rcx
incq %r14
movups 0x5c(%rsp), %xmm0
movups %xmm0, 0xc(%rax,%rcx)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rax,%rcx)
movq 0x40(%rsp), %rdx
addq $0x1c, %rbp
decq %r15
jne 0x77949
jmp 0x77a2a
movq 0x80(%rsp), %r13
xorl %r14d, %r14d
movq %r13, 0x80(%rsp)
movq %r14, 0x20(%rdx)
testq %r14, %r14
je 0x77c80
addq %r14, %r14
cmpq %r14, 0x28(%rdx)
jae 0x77aa5
decq %r14
movq %r14, %rax
shrq %rax
orq %r14, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x28(%rdx)
movq 0x18(%rdx), %rdi
leaq (%rcx,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx), %rsi
incq %rsi
callq 0x2370
movq 0x40(%rsp), %rdx
movq %rax, 0x18(%rdx)
movq 0x18(%rdx), %rsi
movq 0x20(%rdx), %rax
leaq (%rax,%rax,8), %rcx
movq %rdx, %rbx
leaq (%rcx,%rcx,2), %rdx
addq %rax, %rdx
leaq (%rsi,%rdx), %rdi
callq 0x2160
movq 0x20(%rbx), %rax
leaq (%rax,%rax), %r14
movq %r14, 0x20(%rbx)
cmpq %r14, %rax
jge 0x77b0b
movq 0x90(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %rdx
addq %rdx, %rcx
addq $0x10, %rcx
movq -0x10(%rcx), %rdx
movq -0x4(%rcx), %rsi
movq %rsi, -0x10(%rcx)
movq %rdx, -0x4(%rcx)
addq $0x1c, %rcx
decq %rax
jne 0x77af2
movq 0x40(%rsp), %rbx
movq 0x18(%rbx), %rdi
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rsi
addq %r14, %rsi
addq %rdi, %rsi
callq 0x47a9b
movq %rbx, %rdx
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
cmpq %rax, 0x8(%rbx)
jae 0x77b8f
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rdx)
movq 0x10(%rdx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x40(%rsp), %rdx
movq %rax, 0x10(%rdx)
movq %rdx, %rax
movq 0x78(%rsp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, (%rax)
movq 0x10(%rax), %rdi
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x20e0
testq %r14, %r14
jle 0x77c79
negq %r14
movl $0x1, %r15d
movl $0x1c, %r12d
xorl %r13d, %r13d
movq 0x40(%rsp), %rdx
movq 0x90(%rsp), %rbx
movq %r14, %rax
addq %r15, %rax
je 0x77bfb
movq (%rbx), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r13, %rcx
movl (%rax,%rcx), %ecx
cmpl (%rax,%r12), %ecx
je 0x77c61
movq %r15, %rax
subq %r13, %rax
cmpq $0x2, %rax
jl 0x77c2c
movq (%rbx), %rsi
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rdi
addq %r13, %rdi
addq %rsi, %rdi
addq %r12, %rsi
callq 0x4781a
movq 0x40(%rsp), %rdx
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rax
addq %r13, %rax
shlq $0x20, %r13
orq %r15, %r13
movq 0x10(%rdx), %rcx
movq 0x40(%rsp), %rdx
movq 0x18(%rdx), %rdx
movl (%rdx,%rax), %eax
movq 0x40(%rsp), %rdx
movq %r13, (%rcx,%rax,8)
movq %r15, %r13
leaq (%r14,%r15), %rax
incq %rax
incq %r15
addq $0x1c, %r12
cmpq $0x1, %rax
jne 0x77bd5
movl $0x1, %eax
jmp 0x77c82
xorl %eax, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq