// File: chhylp123[P]hifiasm/Correct.cpp
// Function: realign_ed(overlap_region*, ul_idx_t const*, hpc_t*, All_reads*, char*, char*, char*, Correct_dumy*, kvec_t_u64_warp*, long, double, double*, unsigned int, double, long*)
uint64_t realign_ed(overlap_region *z, const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, char* qstr, 
char *tstr, char *tstr_1, Correct_dumy* dumy, kvec_t_u64_warp* v_idx, int64_t block_s, double e_rate, 
double *e_rate_final, uint32_t sec_check, double ovlp_cut, int64_t *is_sort)
{
    int64_t i, k, nw, a_nw, w_id, y_id, y_strand, real_y_start, x_start, x_end, x_len, ce, cs;
    int64_t w_s, w_e, mm_we, mm_ws, mm_aln, ovl, y_readLen, total_y_start, total_y_end;
    uint64_t *w_idx = NULL, srt = 1; window_list *p = NULL; if(sec_check && (!uref)) sec_check = 0;
    z->is_match = 0; if(is_sort) (*is_sort) = 1;
    if(z->w_list.n == 0) return 0;
    nw = get_num_wins(z->x_pos_s, z->x_pos_e+1, block_s); a_nw = z->w_list.n;
    y_id = z->y_id; y_strand = z->y_pos_strand; 
    ovl = z->x_pos_e+1-z->x_pos_s; mm_ws = mm_we = z->x_pos_s; mm_aln = 0; 

    if(hpc_g) y_readLen = hpc_len(*hpc_g, y_id);
    else if(uref) y_readLen = uref->ug->u.a[y_id].len;
    else y_readLen = Get_READ_LENGTH((*rref), y_id);
    
    for (i = a_nw-1, ce = z->x_pos_e; i >= 0; i--) { //utilize the the end pos of pre-window in forward
        w_e = mm_we = z->w_list.a[i].x_end; 
        total_y_start = z->w_list.a[i].y_end + 1 - z->w_list.a[i].extra_begin;
        while ((w_e < ce) && (total_y_start < y_readLen)) {
            w_s = w_e + 1;
            w_id = get_win_id_by_s(z, w_s, block_s, &w_e);
            x_start = w_s; x_end = w_e;
            if(aln_wlst_adv(z, rref, hpc_g, uref, qstr, tstr, tstr_1, 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]);
                mm_we = x_end;
            } else {
                break;
            }
            total_y_start = p->y_end + 1 - p->extra_begin;
        }
        ce = z->w_list.a[i].x_start-1;
        if(i == a_nw-1) {///only possiblity with the largest end pos
            mm_aln = mm_we+1-mm_ws;
            if(!simi_pass(ovl, mm_aln, sec_check, ovlp_cut, NULL)) break;
        }
    }
     
    if(z->w_list.a[a_nw-1].x_end > z->w_list.a[z->w_list.n-1].x_end) {
        srt = 0; if(is_sort) (*is_sort) = 0;
    }
    if(i >= 0) return 0;
    if((!srt) && (z->w_list.n <= (nw*0.2))) {///if very few windows are mapped
        radix_sort_window_list_xs_srt(z->w_list.a, z->w_list.a + z->w_list.n);
        srt = 1; if(is_sort) (*is_sort) = 1;
    }
    if(!srt) {///need sort
        a_nw = z->w_list.n; 
        kv_resize(uint64_t, v_idx->a, (uint64_t)nw); w_idx = v_idx->a.a;
        memset(v_idx->a.a, -1, sizeof((*v_idx->a.a))*nw); 
        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;
        }
        ///deal with first window
        mm_ws = z->x_pos_s; 
        if(w_idx[0] != (uint64_t)-1) {
            w_s = z->w_list.a[w_idx[0]].x_start; mm_aln -= (w_s-mm_ws);
            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_adv(p, z, rref, hpc_g, uref, qstr, tstr, tstr_1, 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_adv(z, rref, hpc_g, uref, qstr, tstr, tstr_1, 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_sort && (*is_sort) && z->w_list.n > 1 && p->x_start < z->w_list.a[z->w_list.n-2].x_start) (*is_sort) = 0;
                    } else {
                        break;
                    }
                    total_y_end = p->y_start - 1;
                }
                if(!simi_pass(ovl, mm_aln, sec_check, ovlp_cut, NULL)) break;
            }
            if(w_idx[i] != (uint64_t)-1) mm_ws = z->w_list.a[w_idx[i]].x_end+1;
        }
        if(i < nw) return 0;
    } else {//sorted
        a_nw = z->w_list.n; mm_ws = z->x_pos_s; 
        for (i = 0, cs = z->x_pos_s; i < a_nw; i++) {
            p = &(z->w_list.a[i]);
            w_s = p->x_start; mm_aln -= (w_s-mm_ws);
            ///check if the start pos of this matched window has been calculated
            if((w_s > cs) && (p->clen == 0)) {
                gen_backtrace_adv(p, z, rref, hpc_g, uref, qstr, tstr, tstr_1, 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;
            while ((w_s > cs) && (total_y_end > 0)) {
                w_e = w_s - 1;
                w_id = get_win_id_by_e(z, w_e, block_s, &w_s);
                x_start = w_s; x_end = w_e; x_len = x_end + 1 - x_start;
                if(aln_wlst_adv(z, rref, hpc_g, uref, qstr, tstr, tstr_1, 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  
                    mm_aln += x_len;
                    // if(is_sort && (*is_sort) && z->w_list.n > 1 && p->x_start < z->w_list.a[z->w_list.n-2].x_start) (*is_sort) = 0;
                } else {
                    break;
                }
                total_y_end = p->y_start - 1;
            }
            if(!simi_pass(ovl, mm_aln, sec_check, ovlp_cut, NULL)) break;
            mm_ws = cs = z->w_list.a[i].x_end+1;
        }
        if(a_nw < (int64_t)z->w_list.n) {
            srt = 0; if(is_sort) (*is_sort) = 0;
        }
        if(i < a_nw) return 0;
    }

    if(e_rate_final) {
        /**
        if(simi_pass(ovl, z->align_length, 0, &e_rate)) {
            a_nw = z->w_list.n;
            for (i = 0; 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_adv(p, z, rref, hpc_g, uref, qstr, tstr, tstr_1, dumy, y_strand, y_id);
                    assert(p->error != -1);
                } else {
                    p->y_end -= p->extra_begin;
                }
            }
            if(!srt) radix_sort_window_list_xs_srt(z->w_list.a, z->w_list.a + z->w_list.n);
            ///note: this function will change tstr/qstr
            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 (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;
            }
        }
        **/
       return 1;
    } else {
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq 0x40(%rbp), %rax
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movq %r9, -0x60(%rbp)
movsd %xmm0, -0x68(%rbp)
movsd %xmm1, -0x70(%rbp)
movq $0x0, -0x128(%rbp)
movq $0x1, -0x130(%rbp)
movq $0x0, -0x138(%rbp)
cmpl $0x0, 0x38(%rbp)
je 0x55cf6
cmpq $0x0, -0x40(%rbp)
jne 0x55cf6
movl $0x0, 0x38(%rbp)
movq -0x38(%rbp), %rax
movb $0x0, 0x2c(%rax)
cmpq $0x0, 0x40(%rbp)
je 0x55d10
movq 0x40(%rbp), %rax
movq $0x1, (%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x55d28
movq $0x0, -0x30(%rbp)
jmp 0x56c51
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq 0x28(%rbp), %rdx
callq 0x340c0
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0xa0(%rbp)
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0xa8(%rbp)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movq -0x38(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x108(%rbp)
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0xf0(%rbp)
movq %rax, -0xf8(%rbp)
movq $0x0, -0x100(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x55de5
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0xa0(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
sarl %eax
cltq
movq %rax, -0x110(%rbp)
jmp 0x55e30
cmpq $0x0, -0x40(%rbp)
je 0x55e14
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0xa0(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x110(%rbp)
jmp 0x55e2e
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movq -0xa0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x110(%rbp)
jmp 0x55e30
movq -0x90(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0xd0(%rbp)
cmpq $0x0, -0x78(%rbp)
jl 0x560c6
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
movq %rax, -0xf0(%rbp)
movq %rax, -0xe8(%rbp)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
movq -0x38(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x78(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movswl 0x10(%rcx), %ecx
subl %ecx, %eax
cltq
movq %rax, -0x118(%rbp)
movq -0xe8(%rbp), %rcx
xorl %eax, %eax
cmpq -0xd0(%rbp), %rcx
movb %al, -0x139(%rbp)
jge 0x55ee7
movq -0x118(%rbp), %rax
cmpq -0x110(%rbp), %rax
setl %al
movb %al, -0x139(%rbp)
movb -0x139(%rbp), %al
testb $0x1, %al
jne 0x55ef6
jmp 0x5603d
movq -0xe8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq 0x28(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
callq 0x9e2e0
movq %rax, -0x98(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %r8
movq -0x60(%rbp), %r9
movq 0x10(%rbp), %r13
movq 0x18(%rbp), %r12
movq -0xa8(%rbp), %rax
movl %eax, %r15d
movq -0xa0(%rbp), %rax
movl %eax, %r14d
movq -0xb8(%rbp), %rbx
movq -0xc0(%rbp), %r11
movq -0x118(%rbp), %r10
movq 0x28(%rbp), %rax
movq %rax, -0x148(%rbp)
movsd -0x68(%rbp), %xmm0
xorl %eax, %eax
movq -0x148(%rbp), %rax
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movl %r15d, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movl $0x0, 0x40(%rsp)
callq 0xa6310
cmpl $0x0, %eax
je 0x56013
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x48(%rcx), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x138(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xf0(%rbp)
jmp 0x56015
jmp 0x5603d
movq -0x138(%rbp), %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
movq -0x138(%rbp), %rcx
movswl 0x10(%rcx), %ecx
subl %ecx, %eax
cltq
movq %rax, -0x118(%rbp)
jmp 0x55eb8
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
subl $0x1, %eax
cltq
movq %rax, -0xd0(%rbp)
movq -0x78(%rbp), %rax
movq -0x90(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x560b3
movq -0xf0(%rbp), %rax
addq $0x1, %rax
subq -0xf8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movl 0x38(%rbp), %edx
movsd -0x70(%rbp), %xmm0
xorl %eax, %eax
movl %eax, %ecx
callq 0xa7100
cmpl $0x0, %eax
jne 0x560b1
jmp 0x560c6
jmp 0x560b3
jmp 0x560b5
movq -0x78(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x55e4d
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x90(%rbp), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x38(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq 0x48(%rdx), %rdx
subq $0x1, %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jle 0x56122
movq $0x0, -0x130(%rbp)
cmpq $0x0, 0x40(%rbp)
je 0x56120
movq 0x40(%rbp), %rax
movq $0x0, (%rax)
jmp 0x56122
cmpq $0x0, -0x78(%rbp)
jl 0x56136
movq $0x0, -0x30(%rbp)
jmp 0x56c51
cmpq $0x0, -0x130(%rbp)
jne 0x561cd
movq -0x38(%rbp), %rax
movq 0x48(%rax), %xmm1
movaps 0x32bebc(%rip), %xmm0   # 0x382010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x32bec0(%rip), %xmm0   # 0x382020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
cvtsi2sdq -0x88(%rbp), %xmm0
movsd 0x328e90(%rip), %xmm2   # 0x37f010
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x561cd
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
shlq $0x5, %rax
addq %rax, %rsi
callq 0x2f3b0
movq $0x1, -0x130(%rbp)
cmpq $0x0, 0x40(%rbp)
je 0x561cb
movq 0x40(%rbp), %rax
movq $0x1, (%rax)
jmp 0x561cd
cmpq $0x0, -0x130(%rbp)
jne 0x56874
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x90(%rbp)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x88(%rbp), %rax
jae 0x562c9
movq -0x88(%rbp), %rcx
movq 0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x562cb
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x128(%rbp)
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x88(%rbp), %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x2100
movq $0x0, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x90(%rbp), %rax
jge 0x5639f
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
je 0x5632b
jmp 0x5634a
leaq 0x32cedd(%rip), %rdi    # 0x38320f
leaq 0x32bfe2(%rip), %rsi    # 0x38231b
movl $0x3667, %edx           # imm = 0x3667
leaq 0x32cee5(%rip), %rcx    # 0x38322a
callq 0x2130
movq -0x38(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rsi
movq 0x28(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x9e2e0
movq %rax, -0x98(%rbp)
movq -0x78(%rbp), %rdx
movq -0x128(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x562ff
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0xf8(%rbp)
movq -0x128(%rbp), %rax
cmpq $-0x1, (%rax)
je 0x56424
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x128(%rbp), %rcx
movq (%rcx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rcx
subq -0xf8(%rbp), %rcx
movq -0x100(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x100(%rbp)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x128(%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, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x88(%rbp), %rax
jge 0x56855
movq -0x128(%rbp), %rax
movq -0x78(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0x56803
movq -0x128(%rbp), %rax
movq -0x78(%rbp), %rcx
subq $0x1, %rcx
cmpq $-0x1, (%rax,%rcx,8)
jne 0x56803
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x128(%rbp), %rcx
movq -0x78(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rcx
subq -0xf8(%rbp), %rcx
movq -0x100(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x100(%rbp)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x128(%rbp), %rcx
movq -0x78(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jne 0x5659e
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x128(%rbp), %rcx
movq -0x78(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x58(%rbp), %r9
movq -0x60(%rbp), %r14
movq 0x10(%rbp), %rbx
movq 0x18(%rbp), %r11
movq -0xa8(%rbp), %rax
movl %eax, %r10d
movq -0xa0(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0xa6b10
movq -0x138(%rbp), %rax
movswl 0x14(%rax), %eax
cmpl $-0x1, %eax
je 0x56567
jmp 0x56586
leaq 0x32cd7d(%rip), %rdi    # 0x3832eb
leaq 0x32bda6(%rip), %rsi    # 0x38231b
movl $0x367a, %edx           # imm = 0x367A
leaq 0x32cca9(%rip), %rcx    # 0x38322a
callq 0x2130
movq -0x138(%rbp), %rax
movswl 0x10(%rax), %ecx
movq -0x138(%rbp), %rax
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x138(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x120(%rbp)
movq -0x78(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x80(%rbp)
movb %al, -0x149(%rbp)
jl 0x56608
movq -0x128(%rbp), %rcx
movq -0x80(%rbp), %rdx
xorl %eax, %eax
cmpq $-0x1, (%rcx,%rdx,8)
movb %al, -0x149(%rbp)
jne 0x56608
cmpq $0x0, -0x120(%rbp)
setg %al
movb %al, -0x149(%rbp)
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x56617
jmp 0x567db
movq -0xe0(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xe8(%rbp)
movq -0x38(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq 0x28(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
callq 0x9e250
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x80(%rbp), %rax
jne 0x5665a
jmp 0x56679
leaq 0x32cc99(%rip), %rdi    # 0x3832fa
leaq 0x32bcb3(%rip), %rsi    # 0x38231b
movl $0x3686, %edx           # imm = 0x3686
leaq 0x32cbb6(%rip), %rcx    # 0x38322a
callq 0x2130
movq -0xe0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
addq $0x1, %rax
subq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %r8
movq -0x60(%rbp), %r9
movq 0x10(%rbp), %r13
movq 0x18(%rbp), %r12
movq -0xa8(%rbp), %rax
movl %eax, %r15d
movq -0xa0(%rbp), %rax
movl %eax, %r14d
movq -0xb8(%rbp), %rbx
movq -0xc0(%rbp), %r11
movq -0x120(%rbp), %r10
addq $0x1, %r10
subq -0xc8(%rbp), %r10
movq 0x28(%rbp), %rax
movsd -0x68(%rbp), %xmm0
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movl %r15d, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movl $0x1, 0x40(%rsp)
callq 0xa6310
cmpl $0x0, %eax
je 0x567b2
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x48(%rcx), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
movswl 0x10(%rax), %edx
movq -0x138(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rdx
subq $0x1, %rdx
movq -0x128(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xc8(%rbp), %rax
addq -0x100(%rbp), %rax
movq %rax, -0x100(%rbp)
jmp 0x567b4
jmp 0x567db
movq -0x138(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
cltq
movq %rax, -0x120(%rbp)
movq -0x80(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x565ce
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movl 0x38(%rbp), %edx
movsd -0x70(%rbp), %xmm0
xorl %eax, %eax
movl %eax, %ecx
callq 0xa7100
cmpl $0x0, %eax
jne 0x56801
jmp 0x56855
jmp 0x56803
movq -0x128(%rbp), %rax
movq -0x78(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0x56842
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x128(%rbp), %rcx
movq -0x78(%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 0x56844
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x5642c
movq -0x78(%rbp), %rax
cmpq -0x88(%rbp), %rax
jge 0x5686f
movq $0x0, -0x30(%rbp)
jmp 0x56c51
jmp 0x56c38
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0xf8(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0xd8(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x90(%rbp), %rax
jge 0x56bef
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
movslq (%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rcx
subq -0xf8(%rbp), %rcx
movq -0x100(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x100(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0xd8(%rbp), %rax
jle 0x569c4
movq -0x138(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x569c4
movq -0x138(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x58(%rbp), %r9
movq -0x60(%rbp), %r14
movq 0x10(%rbp), %rbx
movq 0x18(%rbp), %r11
movq -0xa8(%rbp), %rax
movl %eax, %r10d
movq -0xa0(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0xa6b10
movq -0x138(%rbp), %rax
movswl 0x14(%rax), %eax
cmpl $-0x1, %eax
je 0x5698d
jmp 0x569ac
leaq 0x32c957(%rip), %rdi    # 0x3832eb
leaq 0x32b980(%rip), %rsi    # 0x38231b
movl $0x36a1, %edx           # imm = 0x36A1
leaq 0x32c883(%rip), %rcx    # 0x38322a
callq 0x2130
movq -0x138(%rbp), %rax
movswl 0x10(%rax), %ecx
movq -0x138(%rbp), %rax
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x138(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x120(%rbp)
movq -0xe0(%rbp), %rcx
xorl %eax, %eax
cmpq -0xd8(%rbp), %rcx
movb %al, -0x14a(%rbp)
jle 0x56a11
cmpq $0x0, -0x120(%rbp)
setg %al
movb %al, -0x14a(%rbp)
movb -0x14a(%rbp), %al
testb $0x1, %al
jne 0x56a20
jmp 0x56b8f
movq -0xe0(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xe8(%rbp)
movq -0x38(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq 0x28(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
callq 0x9e250
movq %rax, -0x98(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
addq $0x1, %rax
subq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %r8
movq -0x60(%rbp), %r9
movq 0x10(%rbp), %r13
movq 0x18(%rbp), %r12
movq -0xa8(%rbp), %rax
movl %eax, %r15d
movq -0xa0(%rbp), %rax
movl %eax, %r14d
movq -0xb8(%rbp), %rbx
movq -0xc0(%rbp), %r11
movq -0x120(%rbp), %r10
addq $0x1, %r10
subq -0xc8(%rbp), %r10
movq 0x28(%rbp), %rax
movsd -0x68(%rbp), %xmm0
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movl %r15d, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movl $0x1, 0x40(%rsp)
callq 0xa6310
cmpl $0x0, %eax
je 0x56b72
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x48(%rcx), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
movswl 0x10(%rax), %edx
movq -0x138(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movq -0xc8(%rbp), %rax
addq -0x100(%rbp), %rax
movq %rax, -0x100(%rbp)
jmp 0x56b74
jmp 0x56b8f
movq -0x138(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
cltq
movq %rax, -0x120(%rbp)
jmp 0x569e8
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movl 0x38(%rbp), %edx
movsd -0x70(%rbp), %xmm0
xorl %eax, %eax
movl %eax, %ecx
callq 0xa7100
cmpl $0x0, %eax
jne 0x56bb5
jmp 0x56bef
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0xd8(%rbp)
movq %rax, -0xf8(%rbp)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x568a7
movq -0x90(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jge 0x56c1f
movq $0x0, -0x130(%rbp)
cmpq $0x0, 0x40(%rbp)
je 0x56c1d
movq 0x40(%rbp), %rax
movq $0x0, (%rax)
jmp 0x56c1f
movq -0x78(%rbp), %rax
cmpq -0x90(%rbp), %rax
jge 0x56c36
movq $0x0, -0x30(%rbp)
jmp 0x56c51
jmp 0x56c38
cmpq $0x0, 0x30(%rbp)
je 0x56c49
movq $0x1, -0x30(%rbp)
jmp 0x56c51
movq $0x1, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)