// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movsd %xmm1, 0x58(%rsp)
movsd %xmm0, 0x98(%rsp)
movq %r9, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, %r12
movq %rsi, %r8
movq 0x110(%rsp), %rcx
movl $0x0, 0x34(%rsp)
testq %rsi, %rsi
je 0x5ea3e
movl 0x108(%rsp), %eax
movl %eax, 0x34(%rsp)
movb $0x0, 0x2c(%rdi)
testq %rcx, %rcx
je 0x5ea4e
movq $0x1, (%rcx)
movq 0x48(%rdi), %rcx
testq %rcx, %rcx
je 0x5ed6b
movq %rdi, (%rsp)
movq 0xf8(%rsp), %rsi
movq (%rsp), %rax
movl 0x4(%rax), %edi
movq (%rsp), %rax
movl 0x8(%rax), %r14d
leal 0x1(%r14), %r9d
movq %rdi, %rax
xorl %edx, %edx
idivq %rsi
subq %rdi, %rdx
leaq (%r9,%rdx), %rax
cqto
idivq %rsi
movq (%rsp), %rsi
movq %rax, %rbp
testq %rdx, %rdx
setg 0xf(%rsp)
movl 0x10(%rsi), %r15d
movq %r9, 0x80(%rsp)
movl %r9d, %eax
movq %rdi, 0x88(%rsp)
subl %edi, %eax
testq %r12, %r12
je 0x5ead8
movq (%r12), %rdx
movq 0x10(%rdx), %rdx
leaq (%r15,%r15,4), %rsi
movl (%rdx,%rsi,8), %edx
movq (%rsp), %rsi
shrl %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
jmp 0x5eb04
testq %r8, %r8
je 0x5eaf7
movq (%r8), %rdx
movq 0x10(%rdx), %rdx
leaq (%r15,%r15,4), %rsi
movl (%rdx,%rsi,8), %edx
movq (%rsp), %rsi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x5eb04
movq 0x50(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq (%rdx,%r15,8), %rdx
movq %rdx, 0x20(%rsp)
movl 0x1c(%rsi), %edx
movq %rdx, 0x60(%rsp)
leaq -0x1(%rcx), %r10
movl %eax, %eax
cvtsi2sd %rax, %xmm1
movsd 0x58(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
testq %rcx, %rcx
movq %r12, 0x48(%rsp)
movq %r8, 0x10(%rsp)
movsd %xmm1, 0x18(%rsp)
jle 0x5ed2d
movq %rbp, 0x78(%rsp)
movsd 0x1d2a9e(%rip), %xmm0   # 0x2315f0
mulsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movq 0x58(%rsi), %rdi
xorl %ebx, %ebx
xorl %r9d, %r9d
movq %r10, %rax
movq %r10, 0x90(%rsp)
movq %rax, %rcx
shlq $0x5, %rcx
movslq 0x4(%rdi,%rcx), %rbp
cmpq %rbp, %r14
movq %r9, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq %rcx, 0x28(%rsp)
jle 0x5ec8d
movl 0xc(%rdi,%rcx), %eax
movswl 0x10(%rdi,%rcx), %ecx
subl %ecx, %eax
incl %eax
movslq %eax, %r10
cmpq %r10, 0x20(%rsp)
jle 0x5ec8d
leaq 0x1(%rbp), %r11
movl 0x8(%rsi), %r12d
movl 0x4(%rsi), %ecx
movq %rcx, %rax
xorl %edx, %edx
movq %r15, %r13
movq 0xf8(%rsp), %r15
idivq %r15
subq %rdx, %rcx
movq %r11, %rax
subq %rcx, %rax
cqto
idivq %r15
incq %rax
imulq %r15, %rax
addq %rcx, %rax
decq %rax
cmpq %r12, %rax
cmovlq %rax, %r12
subq $0x8, %rsp
movq %rsi, %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %r8, %rcx
movq 0x70(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0xa0(%rsp), %xmm0
pushq $0x0
pushq %r15
movq %r13, %r15
pushq %r10
pushq %r12
pushq %r11
pushq %r13
pushq 0x98(%rsp)
pushq 0x128(%rsp)
pushq 0x128(%rsp)
callq 0x896ad
movq 0x50(%rsp), %rsi
addq $0x50, %rsp
movq 0x58(%rsi), %rdi
testl %eax, %eax
je 0x5ec92
movq 0x48(%rsi), %rax
shlq $0x5, %rax
leaq (%rdi,%rax), %rbx
addq $-0x20, %rbx
cmpq %r14, %r12
jge 0x5ec95
movl -0x14(%rdi,%rax), %ecx
movswl -0x10(%rdi,%rax), %eax
subl %eax, %ecx
incl %ecx
movslq %ecx, %r10
movq %r12, %rbp
cmpq %r10, 0x20(%rsp)
movq 0x10(%rsp), %r8
jg 0x5ebb2
jmp 0x5ec9a
movq %rbp, %r12
jmp 0x5ec9a
movq %rbp, %r12
movq 0x10(%rsp), %r8
movq 0x28(%rsp), %rax
movslq (%rdi,%rax), %r14
movq 0x90(%rsp), %r10
movq 0x40(%rsp), %r11
cmpq %r10, %r11
movsd 0x18(%rsp), %xmm1
movq 0x38(%rsp), %r9
jne 0x5ed10
movq 0x88(%rsp), %rdx
subq %rdx, %r12
movq %r12, %r9
incq %r9
sete %cl
movb $0x1, %al
cmpl %edx, 0x80(%rsp)
je 0x5ed22
testb %cl, %cl
jne 0x5ed22
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
cmpl $0x0, 0x34(%rsp)
je 0x5ed08
cmpq $0x1c2, %r9             # imm = 0x1C2
jl 0x5ed22
ucomisd 0xa0(%rsp), %xmm0
jae 0x5ed10
jmp 0x5ed22
ucomisd 0x58(%rsp), %xmm0
jb 0x5ed22
decq %r14
leaq -0x1(%r11), %rax
testq %r11, %r11
jg 0x5eb73
xorl %eax, %eax
movq 0x48(%rsi), %rcx
movq 0x78(%rsp), %rbp
jmp 0x5ed38
movq 0x58(%rsi), %rdi
xorl %eax, %eax
xorl %r9d, %r9d
xorl %ebx, %ebx
shlq $0x5, %r10
shlq $0x5, %rcx
movl 0x4(%rdi,%r10), %edx
movl -0x1c(%rdi,%rcx), %ecx
cmpq $0x0, 0x110(%rsp)
je 0x5ed67
cmpl %ecx, %edx
jle 0x5ed67
movq 0x110(%rsp), %r10
movq $0x0, (%r10)
testb %al, %al
je 0x5ed72
xorl %eax, %eax
jmp 0x5f464
cmpl %ecx, %edx
jle 0x5ee71
xorl %eax, %eax
movb 0xf(%rsp), %cl
movb %cl, %al
movq 0x48(%rsi), %r14
movq %r14, %xmm0
punpckldq 0x1d24ed(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
addq %rax, %rbp
subpd 0x1d24f2(%rip), %xmm0   # 0x231290
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
mulsd 0x1d27c6(%rip), %xmm0   # 0x231580
ucomisd %xmm1, %xmm0
jae 0x5ee33
movq 0xf0(%rsp), %r12
cmpq %rbp, 0x8(%r12)
jae 0x5f0cf
movq %r9, %r13
leaq -0x1(%rbp), %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(%r12)
movq 0x10(%r12), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq %rax, %r12
jmp 0x5f0d7
shlq $0x5, %r14
addq %rdi, %r14
movq %r14, %rsi
movq %r9, %r14
callq 0x46146
movq (%rsp), %rsi
movq %r14, %r9
movq 0x10(%rsp), %r8
cmpq $0x0, 0x110(%rsp)
movsd 0x18(%rsp), %xmm1
je 0x5ee71
movq 0x110(%rsp), %rax
movq $0x1, (%rax)
movq 0x48(%rsi), %rax
movq %rax, 0x40(%rsp)
testq %rax, %rax
jle 0x5f45f
movq %r15, 0x20(%rsp)
mulsd 0x1d2760(%rip), %xmm1   # 0x2315f0
movsd %xmm1, 0x18(%rsp)
movl 0x4(%rsi), %r13d
movq 0x58(%rsi), %r15
movb $0x1, 0x28(%rsp)
xorl %ebp, %ebp
movq %rbp, %rbx
shlq $0x5, %rbx
movslq (%r15,%rbx), %r14
addq %r13, %r9
subq %r14, %r9
cmpq %r14, %r13
movq %rbx, 0x38(%rsp)
jge 0x5f033
addq %rbx, %r15
cmpl $0x0, 0x1c(%r15)
jne 0x5ef2e
movq %r9, %r12
subq $0x8, %rsp
movq %r15, %rdi
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x70(%rsp), %r9
pushq 0x28(%rsp)
pushq 0x70(%rsp)
pushq 0x100(%rsp)
pushq 0x100(%rsp)
pushq 0x98(%rsp)
callq 0x89ef9
addq $0x30, %rsp
cmpw $-0x1, 0x14(%r15)
je 0x5f4b4
movswl 0x10(%r15), %eax
addl %eax, 0xc(%r15)
movq 0x10(%rsp), %r8
movq %r12, %r9
movq (%rsp), %rsi
movslq 0x8(%r15), %r10
cmpq $0x2, %r10
jl 0x5f033
decq %r10
movq %r9, %r12
movq %r14, %r15
movl 0x4(%rsi), %r14d
movq %r14, %rax
xorl %edx, %edx
movq 0xf8(%rsp), %r11
idivq %r11
subq %r14, %rdx
leaq (%r15,%rdx), %rax
decq %rax
cqto
idivq %r11
negq %rdx
leaq (%r15,%rdx), %rax
decq %rax
cmpq %r14, %rax
cmovgq %rax, %r14
leaq -0x1(%r15), %rax
subq %r14, %r15
subq %r15, %r10
incq %r10
subq $0x8, %rsp
movq %rsi, %rdi
movq %rsi, %rbx
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %r8, %rcx
movq 0x70(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0xa0(%rsp), %xmm0
pushq $0x1
pushq %r11
pushq %r10
pushq %rax
pushq %r14
pushq 0x50(%rsp)
pushq 0x98(%rsp)
pushq 0x128(%rsp)
pushq 0x128(%rsp)
callq 0x896ad
addq $0x50, %rsp
testl %eax, %eax
je 0x5f01d
movq 0x48(%rbx), %rcx
movq 0x58(%rbx), %rdx
shlq $0x5, %rcx
movswl -0x10(%rdx,%rcx), %esi
movl -0x18(%rdx,%rcx), %eax
subl %esi, %eax
movl %eax, -0x18(%rdx,%rcx)
movq %r12, %r9
addq %r15, %r9
cmpq %r13, %r14
jle 0x5f02a
leal -0x1(%rax), %r10d
cmpl $0x1, %eax
movq 0x10(%rsp), %r8
movq (%rsp), %rsi
jg 0x5ef3f
jmp 0x5f033
movq 0x10(%rsp), %r8
movq %r12, %r9
movq %rbx, %rsi
jmp 0x5f033
movq 0x10(%rsp), %r8
movq (%rsp), %rsi
movq 0x80(%rsp), %rax
cmpl 0x88(%rsp), %eax
je 0x5f0a0
testq %r9, %r9
je 0x5f0a0
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
cmpl $0x0, 0x34(%rsp)
je 0x5f074
cmpq $0x1c2, %r9             # imm = 0x1C2
movsd 0x18(%rsp), %xmm1
movq 0x38(%rsp), %rax
jl 0x5f0a0
ucomisd %xmm1, %xmm0
jae 0x5f081
jmp 0x5f0a0
ucomisd 0x58(%rsp), %xmm0
movq 0x38(%rsp), %rax
jb 0x5f0a0
movq 0x58(%rsi), %r15
movslq 0x4(%r15,%rax), %r13
incq %r13
incq %rbp
cmpq 0x40(%rsp), %rbp
setl 0x28(%rsp)
jne 0x5eea5
movq 0x110(%rsp), %rax
testq %rax, %rax
je 0x5f0bf
movq 0x40(%rsp), %rcx
cmpq 0x48(%rsi), %rcx
jge 0x5f0bf
movq $0x0, (%rax)
testb $0x1, 0x28(%rsp)
jne 0x5ed6b
jmp 0x5f45f
movq %r9, %r13
movq 0x10(%r12), %r12
leaq (,%rbp,8), %rdx
movq %r12, %rdi
movl $0xff, %esi
callq 0x20e0
testq %r14, %r14
movq 0x48(%rsp), %rcx
movq 0xf8(%rsp), %r11
jle 0x5f153
movq (%rsp), %rax
movq 0x58(%rax), %rdi
xorl %r8d, %r8d
movsd 0x18(%rsp), %xmm1
cmpl $-0x1, 0xc(%rdi)
je 0x5f476
movslq (%rdi), %r10
movq (%rsp), %rax
movl 0x4(%rax), %r9d
movl %r9d, %esi
movq %rsi, %rax
xorl %edx, %edx
idivq %r11
addq %rdx, %r10
subq %rsi, %r10
movq %r10, %rax
cqto
idivq %r11
movq %r8, (%r12,%rax,8)
incq %r8
addq $0x20, %rdi
cmpq %r8, %r14
jne 0x5f10f
movq (%rsp), %rsi
jmp 0x5f161
movq (%rsp), %rsi
movl 0x4(%rsi), %r9d
movsd 0x18(%rsp), %xmm1
movl %r9d, %r9d
movq (%r12), %rax
cmpq $-0x1, %rax
je 0x5f19a
movq (%rsp), %rdx
movq 0x58(%rdx), %rsi
shlq $0x5, %rax
movslq (%rsi,%rax), %rdx
movq %r13, %r11
addq %r9, %r11
subq %rdx, %r11
movslq 0x4(%rsi,%rax), %r9
movq (%rsp), %rsi
incq %r9
movq 0x10(%rsp), %r8
jmp 0x5f1a2
movq 0x10(%rsp), %r8
movq %r13, %r11
cmpq $0x2, %rbp
jl 0x5f45f
mulsd 0x1d243c(%rip), %xmm1   # 0x2315f0
movl $0x1, %r10d
movsd %xmm1, 0x18(%rsp)
movq %rbp, 0x78(%rsp)
movq %r12, 0x20(%rsp)
movq (%r12,%r10,8), %rax
cmpq $-0x1, %rax
je 0x5f453
cmpq $-0x1, -0x8(%r12,%r10,8)
jne 0x5f439
movq 0x58(%rsi), %rdi
shlq $0x5, %rax
movslq (%rdi,%rax), %r13
cmpl $0x0, 0x1c(%rdi,%rax)
movq %r10, 0x28(%rsp)
jne 0x5f266
movq %r9, %rbp
movq %r11, %r14
addq %rax, %rdi
subq $0x8, %rsp
movq %rdi, %rbx
movq 0x58(%rsp), %rdx
movq 0x70(%rsp), %r9
pushq %r15
pushq 0x70(%rsp)
pushq 0x100(%rsp)
pushq 0x100(%rsp)
pushq 0x98(%rsp)
callq 0x89ef9
addq $0x30, %rsp
cmpw $-0x1, 0x14(%rbx)
je 0x5f4d3
movswl 0x10(%rbx), %eax
addl %eax, 0xc(%rbx)
movq 0x10(%rsp), %r8
movsd 0x18(%rsp), %xmm1
movq %r14, %r11
movq (%rsp), %rsi
movq %rbp, %r9
movq 0x28(%rsp), %r10
movq %r9, 0x90(%rsp)
addq %r9, %r11
subq %r13, %r11
cmpq $-0x1, -0x8(%r12,%r10,8)
jne 0x5f3c9
movl 0x8(%rbx), %r10d
cmpl $0x2, %r10d
jl 0x5f3c9
movq 0x28(%rsp), %rax
leaq -0x1(%rax), %r12
decq %r10
movq %rbx, 0x40(%rsp)
movq %r11, 0x38(%rsp)
leaq -0x1(%r13), %r11
movl 0x4(%rsi), %ecx
movq %rcx, %rax
xorl %edx, %edx
movq 0xf8(%rsp), %rbx
idivq %rbx
movq %rsi, %r14
movq %rcx, %rsi
subq %rdx, %rsi
movq %r11, %rax
subq %rsi, %rax
cqto
idivq %rbx
movq %rax, %rbp
imulq %rbx, %rbp
addq %rsi, %rbp
cmpq %rcx, %rbp
cmovleq %rcx, %rbp
cmpq %rax, %r12
jne 0x5f495
subq %rbp, %r13
subq %r13, %r10
incq %r10
subq $0x8, %rsp
movq %r14, %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %r8, %rcx
movq 0x70(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0xa0(%rsp), %xmm0
pushq $0x1
pushq %rbx
pushq %r10
pushq %r11
pushq %rbp
pushq %r15
pushq 0x98(%rsp)
pushq 0x128(%rsp)
pushq 0x128(%rsp)
callq 0x896ad
addq $0x50, %rsp
testl %eax, %eax
je 0x5f3b1
movq 0x48(%r14), %rcx
movq 0x58(%r14), %rax
movq %rcx, %rdx
shlq $0x5, %rdx
leaq (%rax,%rdx), %rbx
addq $-0x20, %rbx
movswq 0x10(%rbx), %rdx
movslq 0x8(%rbx), %rax
subq %rdx, %rax
movl %eax, 0x8(%rbx)
decq %rcx
movq 0x20(%rsp), %rdx
movq %rcx, (%rdx,%r12,8)
movq 0x38(%rsp), %r11
addq %r13, %r11
testq %r12, %r12
movq 0x10(%rsp), %r8
movsd 0x18(%rsp), %xmm1
movq %r14, %rsi
jle 0x5f3c9
cmpq $-0x1, -0x8(%rdx,%r12,8)
jne 0x5f3c9
decq %r12
movq %rax, %r10
decq %r10
movq %rbp, %r13
cmpl $0x2, %eax
jge 0x5f29a
jmp 0x5f3c9
movq 0x10(%rsp), %r8
movsd 0x18(%rsp), %xmm1
movq 0x38(%rsp), %r11
movq 0x40(%rsp), %rbx
movq %r14, %rsi
movq 0x80(%rsp), %rax
cmpl 0x88(%rsp), %eax
je 0x5ed6b
movl $0x0, %eax
testq %r11, %r11
movq 0x48(%rsp), %rcx
movq 0x78(%rsp), %rbp
movq 0x20(%rsp), %r12
movq 0x90(%rsp), %r9
movq 0x28(%rsp), %r10
je 0x5f464
xorps %xmm0, %xmm0
cvtsi2sd %r11, %xmm0
cmpl $0x0, 0x34(%rsp)
je 0x5f42d
cmpq $0x1c2, %r11            # imm = 0x1C2
jl 0x5ed6b
ucomisd %xmm1, %xmm0
movl $0x0, %eax
jae 0x5f439
jmp 0x5f464
ucomisd 0x58(%rsp), %xmm0
jb 0x5ed6b
movq (%r12,%r10,8), %rax
cmpq $-0x1, %rax
je 0x5f453
movq 0x58(%rsi), %rdx
shlq $0x5, %rax
movslq 0x4(%rdx,%rax), %r9
incq %r9
incq %r10
cmpq %rbp, %r10
jne 0x5f1ca
movl $0x1, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d31ca(%rip), %rdi    # 0x232647
leaq 0x1d22cf(%rip), %rsi    # 0x231753
leaq 0x1d31d7(%rip), %rcx    # 0x232662
movl $0x3667, %edx           # imm = 0x3667
callq 0x2110
leaq 0x1d3296(%rip), %rdi    # 0x232732
leaq 0x1d22b0(%rip), %rsi    # 0x231753
leaq 0x1d31b8(%rip), %rcx    # 0x232662
movl $0x3686, %edx           # imm = 0x3686
callq 0x2110
leaq 0x1d3268(%rip), %rdi    # 0x232723
leaq 0x1d2291(%rip), %rsi    # 0x231753
leaq 0x1d3199(%rip), %rcx    # 0x232662
movl $0x36a1, %edx           # imm = 0x36A1
callq 0x2110
leaq 0x1d3249(%rip), %rdi    # 0x232723
leaq 0x1d2272(%rip), %rsi    # 0x231753
leaq 0x1d317a(%rip), %rcx    # 0x232662
movl $0x367a, %edx           # imm = 0x367A
callq 0x2110