// File: chhylp123[P]hifiasm/Correct.cpp
// Function: rphase_hl(overlap_region_alloc*, ul_idx_t const*, ug_opt_t const*, kv_ul_ov_t*, asg64_v*, asg64_v*, asg64_v*, long, long, long, mask_ul_ov_t*, idx_emask_t*, double)
void rphase_hl(overlap_region_alloc* ol, const ul_idx_t *uref, const ug_opt_t *uopt, kv_ul_ov_t *c_idx, asg64_v* idx, asg64_v* buf, asg64_v* buf1, int64_t ulid, int64_t bd, 
int64_t rlen, mask_ul_ov_t *mk, idx_emask_t *mm, double len_diff)
{
    uint64_t on0 = ol->length, k, i, l, m0, m1, sec, zwn, m, mmov; 
    overlap_region *z, h; ma_ug_t *ug = uref->ug;

    for (k = i = 0; k < ol->length; k++) {
        z = &(ol->list[k]); 
        z->align_length = 0; 
        z->non_homopolymer_errors = 0;
        z->overlapLen = (uint32_t)-1;
        z->x_pos_strand = 0;
        // fprintf(stderr, "i[M::%s]\tutg%.6u%c\txl::%ld\tx::[%u,\t%u)\t%c\tyl::%u\ty::[%u,\t%u)\tsec::%u\n", 
        // __func__, z->y_id + 1, "lc"[ug->u.a[z->y_id].circ], 
        // rlen, z->x_pos_s, z->x_pos_e+1, "+-"[z->y_pos_strand], 
        // ug->u.a[z->y_id].len, z->y_pos_s, z->y_pos_e+1, z->non_homopolymer_errors);
        if(!(z->w_list.n)) continue;///no base-level; cis
        if(k != i) {
            h = ol->list[k];
            ol->list[k] = ol->list[i];
            ol->list[i] = h;
        }
        i++;
    }
    ol->length = i; ///[ol->length, on0) keeps cis overlaps without the base-level alignment
    
    rphase_rr(ol, uref, uopt, c_idx, idx, buf, ulid, bd, NULL); 
    ///could use idx && buf here
    for (k = idx->n = buf->n = 0; k < ol->length; k++) {
        z = &(ol->list[k]); 
        ///sort overlaps by sec error
        for (i = sec = 0; i < z->align_length; i++) {
            sec += z->w_list.a[z->w_list.n+i].clen;
        }
        z->non_homopolymer_errors = sec; sec = sec - (sec&3);///normalize by 4
        kv_push(uint64_t, *buf, (((uint64_t)sec)<<32)|((uint64_t)k));

        ///sort overlaps by yid for filtering
        kv_push(uint64_t, *idx, (((uint64_t)z->y_id)<<32)|((uint64_t)k));

        // fprintf(stderr, "+[M::%s]\tutg%.6u%c\txl::%ld\tx::[%u,\t%u)\t%c\tyl::%u\ty::[%u,\t%u)\tsec::%u\tn_sec::%lu\n", 
        // __func__, z->y_id + 1, "lc"[ug->u.a[z->y_id].circ], 
        // rlen, z->x_pos_s, z->x_pos_e+1, "+-"[z->y_pos_strand], 
        // ug->u.a[z->y_id].len, z->y_pos_s, z->y_pos_e+1, z->non_homopolymer_errors, sec);
    }
    radix_sort_bc64(idx->a, idx->a+idx->n); ///for filtering

    radix_sort_bc64(buf->a, buf->a+buf->n);///sort by error; smaller error first
    for (l = 0, k = 1; k <= buf->n; k++) {
        if(k == buf->n || (buf->a[l]>>32) == (buf->a[k]>>32)) {///with equal number of normalized errors
            if(((k - l) > 1) && (k < buf->n)) {
                for (i = l; i < k; i++) {
                    // fprintf(stderr, "[M::%s]\tl::%lu\tk::%lu\tbuf->a[i]>>32::%lu\n", __func__, l, k, buf->a[i]>>32);
                    z = &(ol->list[(uint32_t)buf->a[i]]);
                    m0 = z->x_pos_e+1-z->x_pos_s;
                    m1 = z->y_pos_e+1-z->y_pos_s;
                    sec = MIN(m0, m1); sec = ((uint32_t)-1)-((uint32_t)sec);
                    buf->a[i] = (((uint64_t)sec)<<32)|((uint32_t)buf->a[i]);
                }
                radix_sort_bc64(buf->a+l, buf->a+k);///sort by lenght; longer first
            }
            l = k;
        }
    }
    
    mk->idx.n = mk->srt.n = 0; c_idx->n = 0;
    mmov = 1000000; if(mmov > (ol->length*32)) mmov = (ol->length*32);
    for (k = 0; k < buf->n && c_idx->n <= mmov; k++) {///need to add overlap that directly connected in the graph
        z = &(ol->list[(uint32_t)buf->a[k]]); z->overlapLen = c_idx->n; 

        // fprintf(stderr, "\n-[M::%s]\tutg%.6u%c\txl::%ld\tx::[%u,\t%u)\t%c\tyl::%u\ty::[%u,\t%u)\tsec::%u\n", 
        // __func__, z->y_id + 1, "lc"[ug->u.a[z->y_id].circ], 
        // rlen, z->x_pos_s, z->x_pos_e+1, "+-"[z->y_pos_strand], 
        // ug->u.a[z->y_id].len, z->y_pos_s, z->y_pos_e+1, z->non_homopolymer_errors);

        m0 = push_emask_flt(&(mm->a[z->y_id]), idx->a, idx->n, z->y_id, c_idx);


        // fprintf(stderr, "-[M::%s]\tm0::%lu\n", __func__, m0);
        // prt_masks(ug, c_idx->a+c_idx->n-m0, m0);


        m1 = gen_src_shared_interval_simple(z->y_id, ug, idx->a, idx->n, c_idx);


        // fprintf(stderr, "-[M::%s]\tm1::%lu\n", __func__, m1);
        // prt_masks(ug, c_idx->a+c_idx->n-m1, m1);


        dedup_src_shared1(ug, c_idx, m0, m1, mm);
        z->x_pos_strand = c_idx->n - z->overlapLen;
        if(!(z->x_pos_strand)) z->overlapLen = (uint32_t)-1;

        // fprintf(stderr, "-[M::%s]\tutg%.6u%c\txl::%ld\tx::[%u,\t%u)\t%c\tyl::%u\ty::[%u,\t%u)\tsec::%u\tm0::%lu\tm1::%lu\tcan_n::%u\n", 
        // __func__, z->y_id + 1, "lc"[ug->u.a[z->y_id].circ], 
        // rlen, z->x_pos_s, z->x_pos_e+1, "+-"[z->y_pos_strand], 
        // ug->u.a[z->y_id].len, z->y_pos_s, z->y_pos_e+1, z->non_homopolymer_errors, m0, m1, z->x_pos_strand);
        // fprintf(stderr, "-[M::%s]\tcan_n::%u\n", __func__, z->x_pos_strand);
        // if(z->x_pos_strand) prt_masks(ug, c_idx->a+z->overlapLen, z->x_pos_strand);
    }

    ///if no mask overlaps, some overlaps may be still masked using the overlap within the graph
    if(((c_idx->n) || (ol->length > 1)) && mask_ovlps(uref, uopt, ug, ol, mk, c_idx, idx, buf1, mm, len_diff, rlen, bd)) {
        // for (k = 0; k < mk->srt.n; k++) {
        //     fprintf(stderr, "*[M::%s]\tutg%.6u%c\txl::%u\tqerr::%u\t%c\tutg%.6u%c\tyl::%u\tterr::%u\tel::%u\n", 
        //     __func__, 
        //     ol->list[mk->srt.a[k].qn].y_id + 1, "lc"[ug->u.a[ol->list[mk->srt.a[k].qn].y_id].circ], 
        //     ug->u.a[ol->list[mk->srt.a[k].qn].y_id].len, mk->srt.a[k].qs, 
        //     "+-"[mk->srt.a[k].rev],
        //     ol->list[mk->srt.a[k].tn].y_id + 1, "lc"[ug->u.a[ol->list[mk->srt.a[k].tn].y_id].circ], 
        //     ug->u.a[ol->list[mk->srt.a[k].tn].y_id].len, mk->srt.a[k].ts, 
        //     mk->srt.a[k].el);
        // }
        


        rphase_rr(ol, uref, uopt, c_idx, idx, buf, ulid, bd, mk); 
        for (k = 0; k < ol->length; k++) {
            if(((uint32_t)mk->idx.a[k]) > (mk->idx.a[k]>>32)) {///it has masks
                refine_rphase(ug, rlen, ol->list, ol->length, k, mk->srt.a+(mk->idx.a[k]>>32), ((uint32_t)mk->idx.a[k])-(mk->idx.a[k]>>32), idx);
            }
        }
    }
    // assert(on0 <= ol->length);
    ol->length = on0;

    for (k = 0; k < ol->length; k++) {
        z = &(ol->list[k]); 
        if(z->x_pos_strand == (uint32_t)-1) {
        // fprintf(stderr, ">[M::%s]\tutg%.6u%c\txl::%ld\tx::[%u,\t%u)\t%c\tyl::%u\ty::[%u,\t%u)\tsec::%u\n", 
        //     __func__, z->y_id + 1, "lc"[ug->u.a[z->y_id].circ], 
        //     rlen, z->x_pos_s, z->x_pos_e+1, "+-"[z->y_pos_strand], 
        //     ug->u.a[z->y_id].len, z->y_pos_s, z->y_pos_e+1, z->non_homopolymer_errors);

            z->x_pos_strand = 0; continue;
        }
        z->overlapLen = z->x_pos_e+1-z->x_pos_s; 
        z->non_homopolymer_errors = 0; zwn = 0;
        for (i = m = 0; i < z->align_length; i++) {
            z->w_list.a[m] = z->w_list.a[z->w_list.n+i];
            if(z->w_list.a[m].clen > 0) {
                z->non_homopolymer_errors += z->w_list.a[m].clen;
                zwn += z->w_list.a[m].x_end-z->w_list.a[m].x_start;
            } 
            m++;
        }
        z->w_list.n = m; z->x_pos_strand = 0;
        assert(zwn <= z->overlapLen);///zwn is the length with secondary-best alignment
        z->align_length = z->overlapLen - zwn;
        
        // fprintf(stderr, ">[M::%s]\tutg%.6u%c\txl::%ld\tx::[%u,\t%u)\t%c\tyl::%u\ty::[%u,\t%u)\tsec::%u\tsec_len::%lu\n", 
        // __func__, z->y_id + 1, "lc"[ug->u.a[z->y_id].circ], 
        // rlen, z->x_pos_s, z->x_pos_e+1, "+-"[z->y_pos_strand], 
        // ug->u.a[z->y_id].len, z->y_pos_s, z->y_pos_e+1, z->non_homopolymer_errors, zwn);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x190, %rsp            # imm = 0x190
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movsd %xmm0, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x150(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x857de
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x58(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0xa0(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0xa0(%rbp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq -0xa0(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0xa0(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x85743
jmp 0x857cd
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
je 0x857c1
movq -0x18(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x58(%rbp), %rax
addq %rax, %rsi
leaq -0x148(%rbp), %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x18(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x60(%rbp), %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x58(%rbp), %rax
addq %rax, %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x18(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x60(%rbp), %rax
addq %rax, %rdi
leaq -0x148(%rbp), %rsi
movl $0xa8, %edx
callq 0x2180
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x856cd
movq -0x60(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movq 0x18(%rbp), %r10
movq 0x20(%rbp), %rax
xorl %r11d, %r11d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x74490
movq -0x40(%rbp), %rax
movq $0x0, (%rax)
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x85a3e
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x58(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0xa0(%rbp), %rcx
movl 0x28(%rcx), %ecx
cmpq %rcx, %rax
jae 0x858ca
movq -0xa0(%rbp), %rax
movq 0x58(%rax), %rax
movq -0xa0(%rbp), %rcx
movq 0x48(%rcx), %rcx
addq -0x60(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
addq -0x80(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x8587d
movq -0x80(%rbp), %rax
movl %eax, %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x80(%rbp), %rax
movq -0x80(%rbp), %rcx
andq $0x3, %rcx
subq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x8595e
movq -0x40(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x8591d
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x158(%rbp)
jmp 0x8592b
movl $0x2, %eax
movq %rax, -0x158(%rbp)
jmp 0x8592b
movq -0x158(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x80(%rbp), %rdx
shlq $0x20, %rdx
orq -0x58(%rbp), %rdx
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x85989
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x859fa
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x859b9
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x160(%rbp)
jmp 0x859c7
movl $0x2, %eax
movq %rax, -0x160(%rbp)
jmp 0x859c7
movq -0x160(%rbp), %rcx
movq -0x38(%rbp), %rax
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)
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
shlq $0x20, %rdx
orq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x85a2d
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x85842
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x40(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq $0x0, -0x68(%rbp)
movq $0x1, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq (%rcx), %rax
ja 0x85c44
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq (%rcx), %rax
je 0x85ae3
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jne 0x85c31
movq -0x58(%rbp), %rax
subq -0x68(%rbp), %rax
cmpq $0x1, %rax
jbe 0x85c29
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x85c29
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x85bfe
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movq -0xa0(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq -0xa0(%rbp), %rax
movl 0x18(%rax), %eax
addl $0x1, %eax
movq -0xa0(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x78(%rbp), %rax
ja 0x85b97
movq -0x70(%rbp), %rax
movq %rax, -0x168(%rbp)
jmp 0x85ba2
movq -0x78(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subl %ecx, %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdx
shlq $0x20, %rdx
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
orq %rax, %rdx
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x85b0e
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x68(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x58(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x85c33
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x85a94
movq 0x30(%rbp), %rax
movq $0x0, 0x20(%rax)
movq 0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x8(%rax)
movq $0xf4240, -0x98(%rbp) # imm = 0xF4240
movq -0x98(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
shlq $0x5, %rcx
cmpq %rcx, %rax
jbe 0x85c9d
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq $0x5, %rax
movq %rax, -0x98(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rcx
movq -0x40(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x169(%rbp)
jae 0x85cd2
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x98(%rbp), %rax
setbe %al
movb %al, -0x169(%rbp)
movb -0x169(%rbp), %al
testb $0x1, %al
jne 0x85ce1
jmp 0x85dfb
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x20(%rax)
movq 0x38(%rbp), %rax
movq (%rax), %rdi
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0x30(%rbp), %r8
callq 0x7aca0
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x150(%rbp), %rsi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %r8
callq 0x2c73f0
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq -0x150(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq 0x38(%rbp), %r8
callq 0x7b930
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0xa0(%rbp), %rcx
movl 0x20(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0xa0(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x85de8
movq -0xa0(%rbp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
jmp 0x85dea
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x85ca5
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x85e15
movq -0x18(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jbe 0x85f80
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x150(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq 0x30(%rbp), %r8
movq -0x30(%rbp), %r9
movq -0x38(%rbp), %r14
movq 0x10(%rbp), %rbx
movq 0x38(%rbp), %r11
movsd -0x48(%rbp), %xmm0
movq 0x28(%rbp), %r10
movq 0x20(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x823a0
cmpq $0x0, %rax
je 0x85f80
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movq 0x18(%rbp), %r11
movq 0x20(%rbp), %r10
movq 0x30(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x74490
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x85f7e
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq 0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jbe 0x85f6b
movq -0x150(%rbp), %rdi
movq 0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x58(%rbp), %r8
movq 0x30(%rbp), %rax
movq 0x18(%rax), %r9
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x58(%rbp), %r10
movq (%rax,%r10,8), %rax
shrq $0x20, %rax
imulq $0x1c, %rax, %rax
addq %rax, %r9
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x58(%rbp), %r10
movq (%rax,%r10,8), %rax
movl %eax, %eax
movl %eax, %r10d
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x58(%rbp), %r11
movq (%rax,%r11,8), %rax
shrq $0x20, %rax
subq %rax, %r10
movq -0x38(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x84830
jmp 0x85f6d
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x85eaf
jmp 0x85f80
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x861d2
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x58(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpl $-0x1, 0xc(%rax)
jne 0x85fdf
movq -0xa0(%rbp), %rax
movl $0x0, 0xc(%rax)
jmp 0x861c1
movq -0xa0(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movq -0xa0(%rbp), %rax
subl 0x4(%rax), %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0xa0(%rbp), %rax
movl $0x0, 0x30(%rax)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0xa0(%rbp), %rcx
movl 0x28(%rcx), %ecx
cmpq %rcx, %rax
jae 0x8614d
movq -0xa0(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0xa0(%rbp), %rax
movq 0x48(%rax), %rax
addq -0x60(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rcx
movq -0xa0(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x90(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq -0xa0(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x90(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jbe 0x8612a
movq -0xa0(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x90(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %ecx
movq -0xa0(%rbp), %rax
addl 0x30(%rax), %ecx
movl %ecx, 0x30(%rax)
movq -0xa0(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x90(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0xa0(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x90(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
subl (%rcx), %eax
cltq
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x8602c
movq -0x90(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0xa0(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x88(%rbp), %rax
movq -0xa0(%rbp), %rcx
movl 0x20(%rcx), %ecx
cmpq %rcx, %rax
ja 0x86185
jmp 0x861a4
leaq 0x2feb9e(%rip), %rdi    # 0x384d2a
leaq 0x2fc188(%rip), %rsi    # 0x38231b
movl $0x5597, %edx           # imm = 0x5597
leaq 0x2ff36b(%rip), %rcx    # 0x38550a
callq 0x2130
movq -0xa0(%rbp), %rax
movl 0x20(%rax), %eax
subq -0x88(%rbp), %rax
movl %eax, %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x85f94
addq $0x190, %rsp            # imm = 0x190
popq %rbx
popq %r14
popq %rbp
retq
nop