// File: chhylp123[P]hifiasm/Correct.cpp
// Function: refine_ed_aln(overlap_region_alloc*, All_reads*, ul_idx_t const*, UC_Read*, Correct_dumy*, UC_Read*, kvec_t_u64_warp*, long, double, double)
inline void refine_ed_aln(overlap_region_alloc* overlap_list, All_reads *rref, const ul_idx_t *uref, 
                        UC_Read* g_read, Correct_dumy* dumy, UC_Read* overlap_read, kvec_t_u64_warp* v_idx, int64_t block_s, double e_rate, double e_rate_final)
{
    int64_t j, k, i, on, y_id, y_readLen, x_start, x_end, x_len, total_y_start, total_y_end;
    int32_t y_strand, real_y_start;
    int64_t nw, a_nw, w_id, w_s, w_e, is_srt, mm_we, mm_ws, mm_aln, ovl;
    double error_rate; uint64_t *w_idx; overlap_region *z; window_list *p = NULL;

    overlap_list->mapped_overlaps_length = 0; on = overlap_list->length;
    for (j = 0; j < on; ++j) {
        // z = &(overlap_list->list[j]); ovl = z->x_pos_e+1-z->x_pos_s;
        // if(!realign_ed(z, uref, NULL, rref, g_read->seq, 
        //         dumy->overlap_region, dumy->overlap_region_fix, dumy, v_idx, block_s, e_rate, NULL, 1, &is_srt)) {
        //     continue;
        // }
        z = &(overlap_list->list[j]); z->is_match = 0; is_srt = 1;
        if(z->w_list.n == 0) continue;///no alignment
        nw = get_num_wins(z->x_pos_s, z->x_pos_e+1, block_s); a_nw = z->w_list.n;
        kv_resize(uint64_t, v_idx->a, (uint64_t)nw); 
        memset(v_idx->a.a, -1, sizeof((*v_idx->a.a))*nw); w_idx = v_idx->a.a;
        for (i = 0; i < a_nw; i++) { ///w_idx[] == (uint64_t) if unmatched
            assert(z->w_list.a[i].y_end != -1);
            w_id = get_win_id_by_s(z, z->w_list.a[i].x_start, block_s, NULL);
            w_idx[w_id] = i;
        }

        y_id = z->y_id; y_strand = z->y_pos_strand; 
        ovl = z->x_pos_e+1-z->x_pos_s; mm_we = z->x_pos_s; mm_aln = 0; 
        y_readLen = (rref?(Get_READ_LENGTH((*rref), y_id)):(uref->ug->u.a[y_id].len));
        for (i = a_nw-1; i >= 0; i--) { //utilize the the end pos of pre-window in forward
            w_id = get_win_id_by_s(z, z->w_list.a[i].x_start, block_s, &w_e);
            assert(z->w_list.a[i].x_end == w_e);
            if(w_e > mm_we) mm_we = w_e;
            ///in most cases, extra_begin = 0
            total_y_start = z->w_list.a[i].y_end + 1 - z->w_list.a[i].extra_begin;
            for (k = w_id + 1; k < nw && total_y_start < y_readLen; k++) {
                if(w_idx[k] != (uint64_t)-1) break;
                w_s = w_e + 1;
                w_id = get_win_id_by_s(z, w_s, block_s, &w_e);
                assert(w_id == k);
                x_start = w_s; x_end = w_e;
                if(aln_wlst(z, rref, uref, g_read, dumy, y_strand, y_id, x_start, x_end, 
                                                            total_y_start, block_s, e_rate, 0)) {
                    p = &(z->w_list.a[z->w_list.n-1]);
                    w_idx[k] = z->w_list.n - 1;
                    if(x_end > mm_we) mm_we = x_end;
                    if(is_srt && z->w_list.n > 1 && p->x_start < z->w_list.a[z->w_list.n-2].x_start) is_srt = 0;
                } else {
                    break;
                }
                total_y_start = p->y_end + 1 - p->extra_begin;
            }
        }
        mm_ws = z->x_pos_s; mm_aln = mm_we+1-mm_ws; 
        if(!simi_pass(ovl, mm_aln, uref?1:0, OVERLAP_THRESHOLD_NOSI_FILTER, NULL)) continue;
        if(nw > 0 && w_idx[0] != (uint64_t)-1) mm_ws = z->w_list.a[w_idx[0]].x_end+1;
        
        for (i = 1; i < nw; i++) { //utilize the the start pos of next window in backward
            ///find the first matched window, which should not be the first window
            ///the pre-window of this matched window must be unmatched
            if(w_idx[i] != (uint64_t)-1 && w_idx[i-1] == (uint64_t)-1) {
                w_s = z->w_list.a[w_idx[i]].x_start; mm_aln -= (w_s-mm_ws);
                ///check if the start pos of this matched window has been calculated
                if(z->w_list.a[w_idx[i]].clen == 0) {
                    p = &(z->w_list.a[w_idx[i]]);
                    gen_backtrace(p, z, rref, uref, g_read, dumy, y_strand, y_id);
                    assert(p->error != -1);
                    p->y_end += p->extra_begin;
                } 
                real_y_start = p->y_start;

                ///the end pos for pre window is real_y_start - 1
                total_y_end = real_y_start - 1;
                ///find the unmatched window on the left of current matched window
                ///k starts from i - 1
                for (k = i - 1; k >= 0 && w_idx[k] == (uint64_t)-1 && total_y_end > 0; k--) {  
                    w_e = w_s - 1;
                    w_id = get_win_id_by_e(z, w_e, block_s, &w_s);
                    assert(w_id == k);
                    x_start = w_s; x_end = w_e; x_len = x_end + 1 - x_start;
                    if(aln_wlst(z, rref, uref, g_read, dumy, y_strand, y_id, x_start, x_end, total_y_end+1-x_len, block_s, e_rate, 1)) {
                        p = &(z->w_list.a[z->w_list.n-1]);
                        p->y_start -= p->extra_begin; ///y_start has no shift, but y_end has shift  
                        w_idx[k] = z->w_list.n - 1;
                        mm_aln += x_len;
                        if(is_srt && z->w_list.n > 1 && p->x_start < z->w_list.a[z->w_list.n-2].x_start) is_srt = 0;
                    } else {
                        break;
                    }
                    total_y_end = p->y_start - 1;
                }
                if(!simi_pass(ovl, mm_aln, uref?1:0, OVERLAP_THRESHOLD_NOSI_FILTER, NULL)) break;
            }
            if(w_idx[i] != (uint64_t)-1) mm_ws = z->w_list.a[w_idx[i]].x_end+1;
        }

        if(i < nw) continue;
        if(uref && simi_pass(ovl, z->align_length, uref?1:0, OVERLAP_THRESHOLD_NOSI_FILTER, NULL)) {
            z->is_match = 3; overlap_list->mapped_overlaps_length += z->align_length;
            ///sort for set_herror_win
            if(!is_srt) radix_sort_window_list_xs_srt(z->w_list.a, z->w_list.a + z->w_list.n);
        }
    }

    if(uref && overlap_list->mapped_overlaps_length > 0) {
        set_herror_win(overlap_list, dumy, v_idx, e_rate, g_read->length, block_s);
    }

    overlap_list->mapped_overlaps_length = 0;
    for (j = 0; j < (long long)overlap_list->length; j++) {
        z = &(overlap_list->list[j]);
        y_id = z->y_id; y_strand = z->y_pos_strand; 
        y_readLen = (rref?(Get_READ_LENGTH((*rref), y_id)):(uref->ug->u.a[y_id].len));
        ovl = z->x_pos_e + 1 - z->x_pos_s; //z->is_match = 0;
        // if(y_id == 4) {
        //     fprintf(stderr, "[M::%s::idx->%ld::] z::x_pos_s->%u, z::x_pos_e->%u, ovl->%ld, aln->%u\n", 
        //     __func__, j, z->x_pos_s, z->x_pos_e, ovl, z->align_length);
        // }
        ///debug_scan_cigar(&(overlap_list->list[j]));
        ///only calculate cigar for high quality overlaps
        // int64_t tt = 0;
        if(simi_pass(ovl, z->align_length, 0, OVERLAP_THRESHOLD_NOSI_FILTER, &e_rate)) {
            a_nw = z->w_list.n;
            for (i = 0, is_srt = 1; i < a_nw; i++) {
                p = &(z->w_list.a[i]);
                ///check if the cigar of this window has been got 
                if(p->clen == 0) {
                    gen_backtrace(p, z, rref, uref, g_read, dumy, y_strand, y_id);
                    assert(p->error != -1);
                    // if(y_id == 4) {
                    //     fprintf(stderr, "+[M::idx->%ld::] y_start->%d, y_end->%d, error->%d\n", 
                    //     j, p->y_start, p->y_end, p->error);
                    // }
                }
                else {
                    p->y_end -= p->extra_begin;
                    // if(y_id == 4) {
                    //     fprintf(stderr, "-[M::idx->%ld::] y_start->%d, y_end->%d, error->%d\n", 
                    //     j, p->y_start, p->y_end, p->error);
                    // }
                }
                // tt += p->error;
                if(is_srt && i > 0 && p->x_start < z->w_list.a[i-1].x_start) is_srt = 0;
            }
            if(!is_srt) radix_sort_window_list_xs_srt(z->w_list.a, z->w_list.a + z->w_list.n);
            error_rate = non_trim_error_rate(z, rref, uref, v_idx, dumy, g_read, e_rate, block_s);
            z->is_match = 0;///must be here;
            // if(y_id == 4) {
            //     fprintf(stderr, "[M::%s::idx->%ld::] block_s->%ld, z::x_pos_s->%u, z::x_pos_e->%u, ovl->%ld, aln->%u, error_rate->%f, e_rate_final->%f\n", 
            //     __func__, j, block_s, z->x_pos_s, z->x_pos_e, ovl, z->align_length, error_rate, e_rate_final);
            //     exit(1);
            // }
            if (error_rate <= e_rate_final) {
                overlap_list->mapped_overlaps_length += ovl;
                z->is_match = 1; append_unmatched_wins(z, block_s);
                if(rref) {
                    calculate_boundary_cigars(z, rref, dumy, g_read, e_rate);
                } else {
                    calculate_ul_boundary_cigars(z, uref, dumy, g_read, e_rate, block_s);
                }
                // assert(get_num_wins(z->x_pos_s, z->x_pos_e+1, block_s)==(int64_t)z->w_list.n);
                // assert((int64_t)z->x_pos_s==z->w_list.a[0].x_start && 
                //                             (int64_t)z->x_pos_e==z->w_list.a[z->w_list.n-1].x_end);
            } else if (error_rate <= e_rate_final * 1.5) {
                z->is_match = 3;
            }
        } else {///it impossible to be matched
            z->is_match = 0;
            // fprintf(stderr, "[M::%s::idx->%ld::is_match->%u] z::x_pos_s->%u, z::x_pos_e->%u, error_rate->-1, e_threshold->%f\n", 
            // __func__, j, z->is_match, z->x_pos_s, z->x_pos_e, e_rate);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x58(%rbp)
movq $0x0, -0x128(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x78(%rbp), %rax
jge 0xa5ef7
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x60(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
movb $0x0, 0x2c(%rax)
movq $0x1, -0xe8(%rbp)
movq -0x120(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0xa5325
jmp 0xa5ee6
movq -0x120(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
movq -0x120(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq 0x18(%rbp), %rdx
callq 0x340c0
movq %rax, -0xc0(%rbp)
movq -0x120(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0xc8(%rbp)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0xc0(%rbp), %rax
jae 0xa5443
movq -0xc0(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq 0x10(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq 0x10(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq 0x10(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq 0x10(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq 0x10(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0xa5445
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0xc0(%rbp), %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x2100
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x118(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0xc8(%rbp), %rax
jge 0xa5522
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
je 0xa54a8
jmp 0xa54c7
leaq 0x2ddd60(%rip), %rdi    # 0x38320f
leaq 0x2dce65(%rip), %rsi    # 0x38231b
movl $0x10ca, %edx           # imm = 0x10CA
leaq 0x2e11c0(%rip), %rcx    # 0x386682
callq 0x2130
movq -0x120(%rbp), %rdi
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rsi
movq 0x18(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x9e2e0
movq %rax, -0xd0(%rbp)
movq -0x70(%rbp), %rdx
movq -0x118(%rbp), %rax
movq -0xd0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xa5479
movq -0x120(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x120(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0xb4(%rbp)
movq -0x120(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movq -0x120(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x108(%rbp)
movq -0x120(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0xf0(%rbp)
movq $0x0, -0x100(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xa559c
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x130(%rbp)
jmp 0xa55bf
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0xc8(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jl 0xa5917
movq -0x120(%rbp), %rdi
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rsi
movq 0x18(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
callq 0x9e2e0
movq %rax, -0xd0(%rbp)
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
cmpq -0xe0(%rbp), %rax
jne 0xa5643
jmp 0xa5662
leaq 0x2e0f4d(%rip), %rdi    # 0x386597
leaq 0x2dccca(%rip), %rsi    # 0x38231b
movl $0x10d4, %edx           # imm = 0x10D4
leaq 0x2e1025(%rip), %rcx    # 0x386682
callq 0x2130
movq -0xe0(%rbp), %rax
cmpq -0xf0(%rbp), %rax
jle 0xa5680
movq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
movq -0x120(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x70(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movswl 0x10(%rcx), %ecx
subl %ecx, %eax
cltq
movq %rax, -0xa8(%rbp)
movq -0xd0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rcx
xorl %eax, %eax
cmpq -0xc0(%rbp), %rcx
movb %al, -0x131(%rbp)
jge 0xa56fc
movq -0xa8(%rbp), %rax
cmpq -0x88(%rbp), %rax
setl %al
movb %al, -0x131(%rbp)
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0xa570b
jmp 0xa5904
movq -0x118(%rbp), %rax
movq -0x68(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0xa5722
jmp 0xa5904
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd8(%rbp)
movq -0x120(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq 0x18(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
callq 0x9e2e0
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpq -0x68(%rbp), %rax
jne 0xa5768
jmp 0xa5787
leaq 0x2ddb8b(%rip), %rdi    # 0x3832fa
leaq 0x2dcba5(%rip), %rsi    # 0x38231b
movl $0x10dc, %edx           # imm = 0x10DC
leaq 0x2e0f00(%rip), %rcx    # 0x386682
callq 0x2130
movq -0xd8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x120(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movl -0xb4(%rbp), %r9d
movq -0x80(%rbp), %rax
movl %eax, %r14d
movq -0x90(%rbp), %rbx
movq -0x98(%rbp), %r11
movq -0xa8(%rbp), %r10
movq 0x18(%rbp), %rax
movsd -0x50(%rbp), %xmm0
xorl %r15d, %r15d
movl %r14d, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
callq 0xc5c60
cmpl $0x0, %eax
je 0xa58ce
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x120(%rbp), %rcx
movq 0x48(%rcx), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x128(%rbp)
movq -0x120(%rbp), %rax
movq 0x48(%rax), %rdx
subq $0x1, %rdx
movq -0x118(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x98(%rbp), %rax
cmpq -0xf0(%rbp), %rax
jle 0xa587b
movq -0x98(%rbp), %rax
movq %rax, -0xf0(%rbp)
cmpq $0x0, -0xe8(%rbp)
je 0xa58cc
movq -0x120(%rbp), %rax
cmpq $0x1, 0x48(%rax)
jbe 0xa58cc
movq -0x128(%rbp), %rax
movl (%rax), %eax
movq -0x120(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x120(%rbp), %rdx
movq 0x48(%rdx), %rdx
subq $0x2, %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jge 0xa58cc
movq $0x0, -0xe8(%rbp)
jmp 0xa58d0
jmp 0xa5904
movq -0x128(%rbp), %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
movq -0x128(%rbp), %rcx
movswl 0x10(%rcx), %ecx
subl %ecx, %eax
cltq
movq %rax, -0xa8(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0xa56d0
jmp 0xa5906
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xa55dc
movq -0x120(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0xf8(%rbp)
movq -0xf0(%rbp), %rax
addq $0x1, %rax
subq -0xf8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movq -0x30(%rbp), %rcx
xorl %edx, %edx
movl $0x1, %eax
cmpq $0x0, %rcx
cmovnel %eax, %edx
movsd 0x2dc8bf(%rip), %xmm0   # 0x382228
xorl %eax, %eax
movl %eax, %ecx
callq 0xa7100
cmpl $0x0, %eax
jne 0xa597c
jmp 0xa5ee6
cmpq $0x0, -0xc0(%rbp)
jle 0xa59be
movq -0x118(%rbp), %rax
cmpq $-0x1, (%rax)
je 0xa59be
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x118(%rbp), %rcx
movq (%rcx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0xf8(%rbp)
movq $0x1, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0xc0(%rbp), %rax
jge 0xa5e30
movq -0x118(%rbp), %rax
movq -0x70(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0xa5ddb
movq -0x118(%rbp), %rax
movq -0x70(%rbp), %rcx
subq $0x1, %rcx
cmpq $-0x1, (%rax,%rcx,8)
jne 0xa5ddb
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x118(%rbp), %rcx
movq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rcx
subq -0xf8(%rbp), %rcx
movq -0x100(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x100(%rbp)
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x118(%rbp), %rcx
movq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jne 0xa5b23
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x118(%rbp), %rcx
movq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movl -0xb4(%rbp), %r10d
movq -0x80(%rbp), %rax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0xc6410
movq -0x128(%rbp), %rax
movswl 0x14(%rax), %eax
cmpl $-0x1, %eax
je 0xa5aec
jmp 0xa5b0b
leaq 0x2dd7f8(%rip), %rdi    # 0x3832eb
leaq 0x2dc821(%rip), %rsi    # 0x38231b
movl $0x10f7, %edx           # imm = 0x10F7
leaq 0x2e0b7c(%rip), %rcx    # 0x386682
callq 0x2130
movq -0x128(%rbp), %rax
movswl 0x10(%rax), %ecx
movq -0x128(%rbp), %rax
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x128(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
subl $0x1, %eax
cltq
movq %rax, -0xb0(%rbp)
movq -0x70(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x68(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x68(%rbp)
movb %al, -0x132(%rbp)
jl 0xa5b8b
movq -0x118(%rbp), %rcx
movq -0x68(%rbp), %rdx
xorl %eax, %eax
cmpq $-0x1, (%rcx,%rdx,8)
movb %al, -0x132(%rbp)
jne 0xa5b8b
cmpq $0x0, -0xb0(%rbp)
setg %al
movb %al, -0x132(%rbp)
movb -0x132(%rbp), %al
testb $0x1, %al
jne 0xa5b9a
jmp 0xa5da1
movq -0xd8(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xe0(%rbp)
movq -0x120(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq 0x18(%rbp), %rdx
leaq -0xd8(%rbp), %rcx
callq 0x9e250
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpq -0x68(%rbp), %rax
jne 0xa5be0
jmp 0xa5bff
leaq 0x2dd713(%rip), %rdi    # 0x3832fa
leaq 0x2dc72d(%rip), %rsi    # 0x38231b
movl $0x1103, %edx           # imm = 0x1103
leaq 0x2e0a88(%rip), %rcx    # 0x386682
callq 0x2130
movq -0xd8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
addq $0x1, %rax
subq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x120(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movl -0xb4(%rbp), %r9d
movq -0x80(%rbp), %rax
movl %eax, %r14d
movq -0x90(%rbp), %rbx
movq -0x98(%rbp), %r11
movq -0xb0(%rbp), %r10
addq $0x1, %r10
subq -0xa0(%rbp), %r10
movq 0x18(%rbp), %rax
movsd -0x50(%rbp), %xmm0
movl %r14d, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl $0x1, 0x28(%rsp)
callq 0xc5c60
cmpl $0x0, %eax
je 0xa5d78
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x120(%rbp), %rcx
movq 0x48(%rcx), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
movswl 0x10(%rax), %edx
movq -0x128(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movq -0x120(%rbp), %rax
movq 0x48(%rax), %rdx
subq $0x1, %rdx
movq -0x118(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xa0(%rbp), %rax
addq -0x100(%rbp), %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, -0xe8(%rbp)
je 0xa5d76
movq -0x120(%rbp), %rax
cmpq $0x1, 0x48(%rax)
jbe 0xa5d76
movq -0x128(%rbp), %rax
movl (%rax), %eax
movq -0x120(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x120(%rbp), %rdx
movq 0x48(%rdx), %rdx
subq $0x2, %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jge 0xa5d76
movq $0x0, -0xe8(%rbp)
jmp 0xa5d7a
jmp 0xa5da1
movq -0x128(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
cltq
movq %rax, -0xb0(%rbp)
movq -0x68(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0xa5b51
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movq -0x30(%rbp), %rcx
xorl %edx, %edx
movl $0x1, %eax
cmpq $0x0, %rcx
cmovnel %eax, %edx
movsd 0x2dc45f(%rip), %xmm0   # 0x382228
xorl %eax, %eax
movl %eax, %ecx
callq 0xa7100
cmpl $0x0, %eax
jne 0xa5dd9
jmp 0xa5e30
jmp 0xa5ddb
movq -0x118(%rbp), %rax
movq -0x70(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0xa5e1d
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x118(%rbp), %rcx
movq -0x70(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0xf8(%rbp)
jmp 0xa5e1f
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xa59c6
movq -0x70(%rbp), %rax
cmpq -0xc0(%rbp), %rax
jge 0xa5e42
jmp 0xa5ee6
cmpq $0x0, -0x30(%rbp)
je 0xa5ee4
movq -0x108(%rbp), %rdi
movq -0x120(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %esi
movq -0x30(%rbp), %rcx
xorl %edx, %edx
movl $0x1, %eax
cmpq $0x0, %rcx
cmovnel %eax, %edx
movsd 0x2dc3ae(%rip), %xmm0   # 0x382228
xorl %eax, %eax
movl %eax, %ecx
callq 0xa7100
cmpl $0x0, %eax
je 0xa5ee4
movq -0x120(%rbp), %rax
movb $0x3, 0x2c(%rax)
movq -0x120(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
cmpq $0x0, -0xe8(%rbp)
jne 0xa5ee2
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x120(%rbp), %rax
movq 0x48(%rax), %rax
shlq $0x5, %rax
addq %rax, %rsi
callq 0x2f3b0
jmp 0xa5ee4
jmp 0xa5ee6
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0xa52d5
cmpq $0x0, -0x30(%rbp)
je 0xa5f2b
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jle 0xa5f2b
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq 0x10(%rbp), %rdx
movsd -0x50(%rbp), %xmm0
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
movq 0x18(%rbp), %r8
callq 0x37650
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0xa62aa
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x60(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x120(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0xb4(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xa5fa8
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x140(%rbp)
jmp 0xa5fcb
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x120(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movq -0x120(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rdi
movq -0x120(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %esi
xorl %edx, %edx
movsd 0x2dc212(%rip), %xmm0   # 0x382228
leaq -0x50(%rbp), %rcx
callq 0xa7100
cmpl $0x0, %eax
je 0xa628c
movq -0x120(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0xc8(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x1, -0xe8(%rbp)
movq -0x70(%rbp), %rax
cmpq -0xc8(%rbp), %rax
jge 0xa6161
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0xa60f1
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movl -0xb4(%rbp), %r10d
movq -0x80(%rbp), %rax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0xc6410
movq -0x128(%rbp), %rax
movswl 0x14(%rax), %eax
cmpl $-0x1, %eax
je 0xa60d0
jmp 0xa60ef
leaq 0x2dd214(%rip), %rdi    # 0x3832eb
leaq 0x2dc23d(%rip), %rsi    # 0x38231b
movl $0x1135, %edx           # imm = 0x1135
leaq 0x2e0598(%rip), %rcx    # 0x386682
callq 0x2130
jmp 0xa610b
movq -0x128(%rbp), %rax
movswl 0x10(%rax), %edx
movq -0x128(%rbp), %rax
movl 0xc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xc(%rax)
cmpq $0x0, -0xe8(%rbp)
je 0xa614e
cmpq $0x0, -0x70(%rbp)
jle 0xa614e
movq -0x128(%rbp), %rax
movl (%rax), %eax
movq -0x120(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x70(%rbp), %rdx
subq $0x1, %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jge 0xa614e
movq $0x0, -0xe8(%rbp)
jmp 0xa6150
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xa604d
cmpq $0x0, -0xe8(%rbp)
jne 0xa6198
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x120(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x120(%rbp), %rax
movq 0x48(%rax), %rax
shlq $0x5, %rax
addq %rax, %rsi
callq 0x2f3b0
movq -0x120(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x38(%rbp), %r9
movsd -0x50(%rbp), %xmm0
movq 0x18(%rbp), %rax
movq %rax, (%rsp)
callq 0xc3e90
movsd %xmm0, -0x110(%rbp)
movq -0x120(%rbp), %rax
movb $0x0, 0x2c(%rax)
movsd -0x110(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xa6262
movq -0x108(%rbp), %rcx
movq -0x20(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x120(%rbp), %rax
movb $0x1, 0x2c(%rax)
movq -0x120(%rbp), %rdi
movq 0x18(%rbp), %rsi
callq 0x34ab0
cmpq $0x0, -0x28(%rbp)
je 0xa623f
movq -0x120(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rcx
movsd -0x50(%rbp), %xmm0
callq 0x35990
jmp 0xa6260
movq -0x120(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rcx
movsd -0x50(%rbp), %xmm0
movq 0x18(%rbp), %r8
callq 0x36730
jmp 0xa628a
movsd -0x110(%rbp), %xmm1
movsd 0x2dbf8e(%rip), %xmm0   # 0x382200
mulsd -0x58(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xa6288
movq -0x120(%rbp), %rax
movb $0x3, 0x2c(%rax)
jmp 0xa628a
jmp 0xa6297
movq -0x120(%rbp), %rax
movb $0x0, 0x2c(%rax)
jmp 0xa6299
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0xa5f3f
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)