// File: /workspace/github_cpp_makefile_star2_O1/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 $0xb8, %rsp
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x90(%rsp)
movq %r9, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdx, %r8
movq %rdi, %rbx
movq 0x120(%rsp), %rcx
movl $0x0, 0x1c(%rsp)
testq %rsi, %rsi
je 0x5f20d
movl 0x118(%rsp), %eax
movl %eax, 0x1c(%rsp)
movb $0x0, 0x2c(%rbx)
testq %rcx, %rcx
je 0x5f21d
movq $0x1, (%rcx)
movq 0x48(%rbx), %rcx
testq %rcx, %rcx
je 0x5f90e
movq 0x108(%rsp), %rdi
movl 0x4(%rbx), %r9d
movl 0x8(%rbx), %r14d
leal 0x1(%r14), %r10d
movq %r9, %rax
xorl %edx, %edx
idivq %rdi
subq %r9, %rdx
leaq (%r10,%rdx), %rax
cqto
idivq %rdi
movq %rax, 0x30(%rsp)
testq %rdx, %rdx
setg 0x7(%rsp)
movl 0x10(%rbx), %r15d
movq %r10, 0x80(%rsp)
movl %r10d, %eax
movq %r9, 0x88(%rsp)
subl %r9d, %eax
testq %r8, %r8
je 0x5f296
movq (%r8), %rdx
movq 0x10(%rdx), %rdx
leaq (%r15,%r15,4), %rdi
movl (%rdx,%rdi,8), %edx
shrl %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
jmp 0x5f2be
testq %rsi, %rsi
je 0x5f2b1
movq (%rsi), %rdx
movq 0x10(%rdx), %rdx
leaq (%r15,%r15,4), %rdi
movl (%rdx,%rdi,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x5f2be
movq 0x40(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq (%rdx,%r15,8), %rdx
movq %rdx, 0x8(%rsp)
movq %rsi, 0x58(%rsp)
movq %r8, 0x60(%rsp)
movl 0x1c(%rbx), %edx
movq %rdx, 0x50(%rsp)
leaq -0x1(%rcx), %rsi
movl %eax, %eax
testq %rcx, %rcx
setg 0x78(%rsp)
movq %rax, 0x98(%rsp)
jle 0x5f4df
cvtsi2sd %rax, %xmm0
cvtsi2sd %rax, %xmm1
mulsd 0x1c61ed(%rip), %xmm1   # 0x2254f0
movsd %xmm1, 0xa8(%rsp)
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
movq %rsi, %rcx
movq %rsi, 0xb0(%rsp)
movq 0x58(%rbx), %rax
movq %rcx, 0x38(%rsp)
movq %rcx, %rsi
shlq $0x5, %rsi
movslq 0x4(%rax,%rsi), %r13
cmpq %r13, %r14
movq %r12, 0x28(%rsp)
movq %rsi, 0x48(%rsp)
jle 0x5f450
movl 0xc(%rax,%rsi), %ecx
movswl 0x10(%rax,%rsi), %eax
subl %eax, %ecx
incl %ecx
movslq %ecx, %r10
cmpq %r10, 0x8(%rsp)
jle 0x5f450
movq %r13, %rbp
leaq 0x1(%r13), %r11
movl 0x8(%rbx), %r13d
movl 0x4(%rbx), %ecx
movq %rcx, %rax
xorl %edx, %edx
movq %r15, %r12
movq 0x108(%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 %r13, %rax
cmovlq %rax, %r13
subq $0x8, %rsp
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0x98(%rsp), %xmm0
pushq $0x0
pushq %r15
movq %r12, %r15
pushq %r10
pushq %r13
pushq %r11
pushq %r12
pushq 0x88(%rsp)
pushq 0x138(%rsp)
pushq 0x138(%rsp)
callq 0x8a311
addq $0x50, %rsp
testl %eax, %eax
je 0x5f453
movq 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
shlq $0x5, %rax
leaq (%rcx,%rax), %rdx
addq $-0x20, %rdx
movq %rdx, 0x10(%rsp)
cmpq %r14, %r13
jge 0x5f450
movl -0x14(%rcx,%rax), %edx
movswl -0x10(%rcx,%rax), %eax
subl %eax, %edx
incl %edx
movslq %edx, %r10
movq %r13, %rbp
cmpq %r10, 0x8(%rsp)
jg 0x5f375
jmp 0x5f453
movq %r13, %rbp
movq 0x58(%rbx), %rax
movq 0x48(%rsp), %rcx
movslq (%rax,%rcx), %r14
movq 0xb0(%rsp), %rsi
movq 0x38(%rsp), %rdi
cmpq %rsi, %rdi
movq 0x28(%rsp), %r12
jne 0x5f4c8
movq 0x88(%rsp), %rcx
subq %rcx, %rbp
movq %rbp, %r12
incq %r12
sete %al
cmpl %ecx, 0x80(%rsp)
je 0x5f4eb
testb %al, %al
jne 0x5f4eb
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
cmpl $0x0, 0x1c(%rsp)
je 0x5f4bd
cmpq $0x1c2, %r12            # imm = 0x1C2
jl 0x5f4eb
ucomisd 0xa8(%rsp), %xmm0
jae 0x5f4c8
jmp 0x5f4eb
ucomisd 0xa0(%rsp), %xmm0
jb 0x5f4eb
decq %r14
leaq -0x1(%rdi), %rcx
testq %rdi, %rdi
setg 0x78(%rsp)
jg 0x5f332
jmp 0x5f4eb
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
movq 0x48(%rbx), %rcx
movq 0x58(%rbx), %rdi
shlq $0x5, %rsi
shlq $0x5, %rcx
movl 0x4(%rdi,%rsi), %eax
movl -0x1c(%rdi,%rcx), %ecx
cmpq $0x0, 0x120(%rsp)
je 0x5f521
cmpl %ecx, %eax
jle 0x5f521
movq 0x120(%rsp), %rsi
movq $0x0, (%rsi)
testb $0x1, 0x78(%rsp)
jne 0x5f90e
cmpl %ecx, %eax
jle 0x5f6bd
movq %r12, %r13
xorl %ecx, %ecx
movb 0x7(%rsp), %al
movb %al, %cl
movq 0x48(%rbx), %r14
movq %r14, %xmm0
punpckldq 0x1c5cf0(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
movq 0x30(%rsp), %rax
addq %rcx, %rax
subpd 0x1c5cf0(%rip), %xmm0   # 0x225250
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x1c5f04(%rip), %xmm0   # 0x225480
ucomisd %xmm1, %xmm0
jae 0x5f691
movq 0x100(%rsp), %r12
cmpq %rax, 0x8(%r12)
movq %rax, 0x30(%rsp)
jae 0x5f5f8
movq 0x30(%rsp), %rax
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r12)
movq 0x10(%r12), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq 0x30(%rsp), %rax
movq 0x10(%r12), %r12
leaq (,%rax,8), %rdx
movq %r12, %rdi
movl $0xff, %esi
callq 0x20e0
movq %r12, %r11
testq %r14, %r14
movq 0x108(%rsp), %r9
jle 0x5f65f
movq 0x58(%rbx), %rdi
xorl %r8d, %r8d
cmpl $-0x1, 0xc(%rdi)
je 0x5fbed
movslq (%rdi), %rcx
movl 0x4(%rbx), %esi
movq %rsi, %rax
xorl %edx, %edx
idivq %r9
addq %rdx, %rcx
subq %rsi, %rcx
movq %rcx, %rax
cqto
idivq %r9
movq %r8, (%r11,%rax,8)
incq %r8
addq $0x20, %rdi
cmpq %r8, %r14
jne 0x5f629
movl 0x4(%rbx), %ebp
movq (%r11), %rax
cmpq $-0x1, %rax
je 0x5f922
movq 0x58(%rbx), %rcx
shlq $0x5, %rax
movslq (%rcx,%rax), %rdx
addq %rbp, %r13
subq %rdx, %r13
movq %r13, %rdx
movslq 0x4(%rcx,%rax), %rbp
incq %rbp
jmp 0x5f925
shlq $0x5, %r14
addq %rdi, %r14
movq %r14, %rsi
callq 0x46b34
cmpq $0x0, 0x120(%rsp)
movq %r13, %r12
je 0x5f6bd
movq 0x120(%rsp), %rax
movq $0x1, (%rax)
movq 0x48(%rbx), %rax
movq %rax, 0x38(%rsp)
testq %rax, %rax
setg 0x28(%rsp)
jle 0x5f8e4
movq %r15, %r13
movl 0x4(%rbx), %ebp
xorps %xmm0, %xmm0
cvtsi2sdq 0x98(%rsp), %xmm0
movsd 0x1c5e01(%rip), %xmm1   # 0x2254f0
mulsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
movsd 0x20(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
xorl %ecx, %ecx
movq 0x58(%rbx), %r15
movq %rcx, 0x8(%rsp)
shlq $0x5, %rcx
movslq (%r15,%rcx), %r14
movq %rcx, 0x10(%rsp)
addq %rcx, %r15
cmpq %r14, %rbp
jge 0x5f787
cmpl $0x0, 0x1c(%r15)
jne 0x5f787
subq $0x8, %rsp
movq %r15, %rdi
movq %rbx, %rsi
movq 0x48(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq 0x60(%rsp), %r8
movq 0x70(%rsp), %r9
pushq %r13
pushq 0x60(%rsp)
pushq 0x110(%rsp)
pushq 0x110(%rsp)
pushq 0x98(%rsp)
callq 0x8ab12
addq $0x30, %rsp
cmpw $-0x1, 0x14(%r15)
je 0x5fc2b
movswl 0x10(%r15), %eax
addl %eax, 0xc(%r15)
addq %rbp, %r12
subq %r14, %r12
cmpq %r14, %rbp
jge 0x5f876
movl 0x8(%r15), %r10d
cmpl $0x2, %r10d
jl 0x5f876
decq %r10
movq %r14, %r15
movl 0x4(%rbx), %r14d
movq %r14, %rax
xorl %edx, %edx
movq 0x108(%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 %rbx, %rdi
movq 0x48(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0x98(%rsp), %xmm0
pushq $0x1
pushq %r11
pushq %r10
pushq %rax
pushq %r14
pushq %r13
pushq 0x88(%rsp)
pushq 0x138(%rsp)
pushq 0x138(%rsp)
callq 0x8a311
addq $0x50, %rsp
testl %eax, %eax
je 0x5f876
movq 0x48(%rbx), %rcx
movq 0x58(%rbx), %rdx
shlq $0x5, %rcx
movswq -0x10(%rdx,%rcx), %rsi
movslq -0x18(%rdx,%rcx), %rax
subq %rsi, %rax
movl %eax, -0x18(%rdx,%rcx)
addq %r15, %r12
cmpq %rbp, %r14
jle 0x5f876
movq %rax, %r10
decq %r10
cmpl $0x1, %eax
jg 0x5f7a7
movq 0x80(%rsp), %rax
cmpl 0x88(%rsp), %eax
je 0x5f8e4
testq %r12, %r12
je 0x5f8e4
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
cmpl $0x0, 0x1c(%rsp)
je 0x5f8b3
cmpq $0x1c2, %r12            # imm = 0x1C2
movq 0x8(%rsp), %rcx
jl 0x5f8e4
ucomisd 0x48(%rsp), %xmm0
jae 0x5f8c0
jmp 0x5f8e4
ucomisd 0x20(%rsp), %xmm0
movq 0x8(%rsp), %rcx
jb 0x5f8e4
movq 0x58(%rbx), %rax
movq 0x10(%rsp), %rsi
movslq 0x4(%rax,%rsi), %rbp
incq %rbp
incq %rcx
cmpq 0x38(%rsp), %rcx
setl 0x28(%rsp)
jne 0x5f70b
movq 0x120(%rsp), %rax
testq %rax, %rax
je 0x5f903
movq 0x38(%rsp), %rcx
cmpq 0x48(%rbx), %rcx
jge 0x5f903
movq $0x0, (%rax)
testb $0x1, 0x28(%rsp)
je 0x5fbe3
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdx
cmpq $0x2, 0x30(%rsp)
jl 0x5fbe3
xorps %xmm0, %xmm0
cvtsi2sdq 0x98(%rsp), %xmm0
movsd 0x1c5baa(%rip), %xmm1   # 0x2254f0
mulsd %xmm0, %xmm1
movsd %xmm1, 0x78(%rsp)
movsd 0x20(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movl $0x1, %r13d
movq %r11, 0x8(%rsp)
movq (%r11,%r13,8), %rax
cmpq $-0x1, %rax
je 0x5fbbb
cmpq $-0x1, -0x8(%r11,%r13,8)
jne 0x5fbbb
movq 0x58(%rbx), %rcx
shlq $0x5, %rax
movslq (%rcx,%rax), %r12
cmpl $0x0, 0x1c(%rcx,%rax)
jne 0x5fa0b
movq %rdx, %r14
addq %rax, %rcx
movq %rcx, 0x10(%rsp)
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq 0x48(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq 0x60(%rsp), %r8
movq 0x70(%rsp), %r9
pushq %r15
pushq 0x60(%rsp)
pushq 0x110(%rsp)
pushq 0x110(%rsp)
pushq 0x98(%rsp)
callq 0x8ab12
movq 0x40(%rsp), %rcx
addq $0x30, %rsp
cmpw $-0x1, 0x14(%rcx)
je 0x5fc4a
movswl 0x10(%rcx), %eax
addl %eax, 0xc(%rcx)
movq %rcx, 0x10(%rsp)
movq %r14, %rdx
movq 0x8(%rsp), %r11
addq %rbp, %rdx
subq %r12, %rdx
cmpq $-0x1, -0x8(%r11,%r13,8)
movq %rbp, 0x38(%rsp)
movq %r13, 0x48(%rsp)
jne 0x5fb54
movq 0x10(%rsp), %rax
movl 0x8(%rax), %r10d
cmpl $0x2, %r10d
jl 0x5fb54
decq %r13
decq %r10
movq %rdx, 0x28(%rsp)
leaq -0x1(%r12), %r11
movl 0x4(%rbx), %ecx
movq %rcx, %rax
xorl %edx, %edx
movq 0x108(%rsp), %r14
idivq %r14
movq %rcx, %rsi
subq %rdx, %rsi
movq %r11, %rax
subq %rsi, %rax
cqto
idivq %r14
movq %rax, %rbp
imulq %r14, %rbp
addq %rsi, %rbp
cmpq %rcx, %rbp
cmovleq %rcx, %rbp
cmpq %rax, %r13
jne 0x5fc0c
subq %rbp, %r12
subq %r12, %r10
incq %r10
subq $0x8, %rsp
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0x98(%rsp), %xmm0
pushq $0x1
pushq %r14
pushq %r10
pushq %r11
pushq %rbp
pushq %r15
pushq 0x88(%rsp)
pushq 0x138(%rsp)
pushq 0x138(%rsp)
callq 0x8a311
addq $0x50, %rsp
testl %eax, %eax
je 0x5fb4a
movq 0x48(%rbx), %rcx
movq 0x58(%rbx), %rax
movq %rcx, %rdx
shlq $0x5, %rdx
leaq (%rax,%rdx), %rsi
addq $-0x20, %rsi
movswq 0x10(%rsi), %rdx
movslq 0x8(%rsi), %rax
subq %rdx, %rax
movq %rsi, 0x10(%rsp)
movl %eax, 0x8(%rsi)
decq %rcx
movq 0x8(%rsp), %r11
movq %rcx, (%r11,%r13,8)
movq 0x28(%rsp), %rdx
addq %r12, %rdx
testq %r13, %r13
jle 0x5fb54
cmpq $-0x1, -0x8(%r11,%r13,8)
jne 0x5fb54
decq %r13
movq %rax, %r10
decq %r10
movq %rbp, %r12
cmpl $0x2, %eax
jge 0x5fa40
jmp 0x5fb54
movq 0x28(%rsp), %rdx
movq 0x8(%rsp), %r11
movq 0x80(%rsp), %rax
cmpl 0x88(%rsp), %eax
je 0x5f90e
movl $0x0, %eax
testq %rdx, %rdx
movq 0x38(%rsp), %rbp
movq 0x48(%rsp), %r13
je 0x5f910
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
cmpl $0x0, 0x1c(%rsp)
je 0x5fbaf
cmpq $0x1c2, %rdx            # imm = 0x1C2
jl 0x5f90e
ucomisd 0x78(%rsp), %xmm0
movl $0x0, %eax
jae 0x5fbbb
jmp 0x5f910
ucomisd 0x20(%rsp), %xmm0
jb 0x5f90e
movq (%r11,%r13,8), %rax
cmpq $-0x1, %rax
je 0x5fbd5
movq 0x58(%rbx), %rcx
shlq $0x5, %rax
movslq 0x4(%rcx,%rax), %rbp
incq %rbp
incq %r13
cmpq 0x30(%rsp), %r13
jne 0x5f96b
movl $0x1, %eax
jmp 0x5f910
leaq 0x1c6943(%rip), %rdi    # 0x226537
leaq 0x1c5a48(%rip), %rsi    # 0x225643
leaq 0x1c6950(%rip), %rcx    # 0x226552
movl $0x3667, %edx           # imm = 0x3667
callq 0x2110
leaq 0x1c6a0f(%rip), %rdi    # 0x226622
leaq 0x1c5a29(%rip), %rsi    # 0x225643
leaq 0x1c6931(%rip), %rcx    # 0x226552
movl $0x3686, %edx           # imm = 0x3686
callq 0x2110
leaq 0x1c69e1(%rip), %rdi    # 0x226613
leaq 0x1c5a0a(%rip), %rsi    # 0x225643
leaq 0x1c6912(%rip), %rcx    # 0x226552
movl $0x36a1, %edx           # imm = 0x36A1
callq 0x2110
leaq 0x1c69c2(%rip), %rdi    # 0x226613
leaq 0x1c59eb(%rip), %rsi    # 0x225643
leaq 0x1c68f3(%rip), %rcx    # 0x226552
movl $0x367a, %edx           # imm = 0x367A
callq 0x2110