// File: /workspace/github_cpp_makefile_star2_O2/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, 0x78(%rsp)
movsd %xmm0, 0x88(%rsp)
movq %r9, 0x60(%rsp)
movq %r8, 0x58(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, %rcx
movq 0x110(%rsp), %rax
movl $0x0, 0x14(%rsp)
testq %rsi, %rsi
je 0x2eb77
movq %rax, %rdx
movl 0x108(%rsp), %eax
movl %eax, 0x14(%rsp)
movq %rdx, %rax
movb $0x0, 0x2c(%rdi)
testq %rax, %rax
je 0x2eb87
movq $0x1, (%rax)
movq 0x48(%rdi), %rax
testq %rax, %rax
je 0x2ee18
movq %rdi, %r11
movq %rax, %r9
movq 0xf8(%rsp), %rdi
movl 0x4(%r11), %r10d
movl 0x8(%r11), %r15d
leal 0x1(%r15), %r8d
movq %r10, %rax
xorl %edx, %edx
idivq %rdi
subq %r10, %rdx
leaq (%r8,%rdx), %rax
cqto
idivq %rdi
movq %rax, 0x18(%rsp)
xorl %eax, %eax
testq %rdx, %rdx
setg %al
movq %r11, (%rsp)
movl 0x10(%r11), %edx
movq %r10, 0x98(%rsp)
subl %r10d, %r8d
movq %r8, 0x70(%rsp)
testq %rcx, %rcx
movq %rcx, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
je 0x2ec13
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rdx, %rdx
movl (%rcx,%rdx), %ecx
shrl %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
jmp 0x2ec3b
testq %rsi, %rsi
je 0x2ec2e
movq (%rsi), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rdx, %rdx
movl (%rcx,%rdx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x2ec3b
movq 0x30(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x20(%rsp)
addq %rax, 0x18(%rsp)
movq (%rsp), %rsi
movl 0x1c(%rsi), %eax
movq %rax, 0x38(%rsp)
decq %r9
movq $0x0, 0x8(%rsp)
movq %r9, 0x90(%rsp)
movq %r9, %rbx
movq $0x0, 0x28(%rsp)
movq 0x58(%rsi), %rdi
testq %rbx, %rbx
js 0x2eddc
movq %rbx, 0x80(%rsp)
shlq $0x5, %rbx
movslq 0x4(%rdi,%rbx), %r12
movq %r12, 0x68(%rsp)
movl 0xc(%rdi,%rbx), %eax
movq %rbx, 0xa0(%rsp)
movswl 0x10(%rdi,%rbx), %ecx
subl %ecx, %eax
incl %eax
movq %r12, %rbp
cmpq %r15, %r12
jge 0x2ed7a
movslq %eax, %r14
cmpq %r14, 0x20(%rsp)
jle 0x2ed7a
movq %r15, %rbx
incq %r12
movq %rsi, %rdi
movq %r12, %rsi
movq 0xf8(%rsp), %r15
movq %r15, %rdx
leaq 0x68(%rsp), %rcx
callq 0x51f8b
movq 0x68(%rsp), %r13
subq $0x8, %rsp
movq 0x8(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x60(%rsp), %r8
movq 0x68(%rsp), %r9
movsd 0x90(%rsp), %xmm0
pushq $0x0
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq 0x128(%rsp)
pushq 0x128(%rsp)
callq 0x56321
movq 0x50(%rsp), %rsi
addq $0x50, %rsp
movq 0x58(%rsi), %rdi
testl %eax, %eax
je 0x2ed7a
movq 0x48(%rsi), %rax
shlq $0x5, %rax
leaq (%rdi,%rax), %rdx
addq $-0x20, %rdx
movl 0xc(%rdx), %eax
movq %rdx, 0x28(%rsp)
movswl 0x10(%rdx), %ecx
subl %ecx, %eax
incl %eax
movq 0x68(%rsp), %r12
movq %r13, %rbp
movq %rbx, %r15
jmp 0x2ecac
movq 0xa0(%rsp), %rax
movslq (%rdi,%rax), %r15
movq 0x80(%rsp), %rbx
cmpq 0x90(%rsp), %rbx
jne 0x2edc9
subq 0x98(%rsp), %rbp
incq %rbp
movq 0x70(%rsp), %rdi
movq %rbp, 0x8(%rsp)
movq %rbp, %rsi
movl 0x14(%rsp), %edx
movsd 0x78(%rsp), %xmm0
xorl %ecx, %ecx
callq 0x56b28
testl %eax, %eax
je 0x2edd4
movq (%rsp), %rsi
decq %r15
decq %rbx
jmp 0x2ec71
movq (%rsp), %rsi
movq 0x58(%rsi), %rdi
movq 0x90(%rsp), %rax
shlq $0x5, %rax
movq 0x48(%rsi), %rcx
shlq $0x5, %rcx
movl 0x4(%rdi,%rax), %eax
movl -0x1c(%rdi,%rcx), %ecx
cmpq $0x0, 0x110(%rsp)
je 0x2ee13
cmpl %ecx, %eax
jle 0x2ee13
movq 0x110(%rsp), %rdx
andq $0x0, (%rdx)
testq %rbx, %rbx
js 0x2ee2c
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %ecx, %eax
jle 0x2ef16
movq 0x48(%rsi), %r12
movq %r12, %xmm0
punpckldq 0x1b442b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1b4433(%rip), %xmm0   # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq 0x18(%rsp), %rax
cvtsi2sd %rax, %xmm0
mulsd 0x1b4665(%rip), %xmm0   # 0x1e34d0
ucomisd %xmm1, %xmm0
jae 0x2eee9
movq 0xf0(%rsp), %rdx
cmpq %rax, 0x8(%rdx)
jae 0x2f119
movq 0x18(%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(%rdx)
movq %rdx, %r14
movq 0x10(%rdx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, %r15
movq 0x18(%rsp), %rax
movq %r15, 0x10(%r14)
jmp 0x2f11d
shlq $0x5, %r12
addq %rdi, %r12
movq %r12, %rsi
callq 0x19dc0
movq (%rsp), %rsi
cmpq $0x0, 0x110(%rsp)
je 0x2ef16
movq 0x110(%rsp), %rax
movq $0x1, (%rax)
movq 0x48(%rsi), %rax
movl 0x4(%rsi), %r14d
xorl %ecx, %ecx
testq %rax, %rax
movl $0x0, %edx
movq %rax, 0x28(%rsp)
cmovgq %rax, %rdx
movq %rdx, 0x20(%rsp)
cmpq 0x20(%rsp), %rcx
je 0x2f0ef
movq 0x58(%rsi), %r15
movq %rcx, %rbx
movq %rcx, %r13
shlq $0x5, %r13
movslq (%r15,%r13), %rbp
addq %r13, %r15
cmpq %rbp, %r14
jge 0x2efbc
cmpl $0x0, 0x1c(%r15)
jne 0x2efbc
subq $0x8, %rsp
movq %r15, %rdi
movq 0x38(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x60(%rsp), %r9
pushq 0x48(%rsp)
pushq 0x48(%rsp)
pushq 0x100(%rsp)
pushq 0x100(%rsp)
pushq 0x88(%rsp)
callq 0x567ea
addq $0x30, %rsp
cmpw $-0x1, 0x14(%r15)
je 0x2f447
movswl 0x10(%r15), %eax
addl %eax, 0xc(%r15)
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
addq %r14, %rax
subq %rbp, %rax
movq %rax, 0x8(%rsp)
movslq 0x8(%r15), %r10
decq %r10
cmpq %r14, %rbp
jle 0x2f0b5
testq %r10, %r10
jle 0x2f0b5
leaq -0x1(%rbp), %r11
movq %r11, 0x68(%rsp)
movl 0x4(%rsi), %r15d
movq %r15, %rax
xorl %edx, %edx
movq 0xf8(%rsp), %r12
idivq %r12
subq %r15, %rdx
leaq (%rdx,%rbp), %rax
decq %rax
cqto
idivq %r12
negq %rdx
leaq (%rdx,%rbp), %rax
decq %rax
cmpq %r15, %rax
cmovgq %rax, %r15
subq %r15, %rbp
subq %rbp, %r10
incq %r10
subq $0x8, %rsp
movq %rsi, %rdi
movq 0x38(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x60(%rsp), %r8
movq 0x68(%rsp), %r9
movsd 0x90(%rsp), %xmm0
pushq $0x1
pushq %r12
pushq %r10
pushq %r11
pushq %r15
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq 0x128(%rsp)
pushq 0x128(%rsp)
callq 0x56321
movq 0x50(%rsp), %rsi
addq $0x50, %rsp
testl %eax, %eax
je 0x2f0b5
movq 0x48(%rsi), %rax
movq 0x58(%rsi), %rcx
shlq $0x5, %rax
movswq -0x10(%rcx,%rax), %rdx
movslq -0x18(%rcx,%rax), %r10
subq %rdx, %r10
movl %r10d, -0x18(%rcx,%rax)
addq %rbp, 0x8(%rsp)
decq %r10
movq %r15, %rbp
jmp 0x2efd3
movq 0x70(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x14(%rsp), %edx
movsd 0x78(%rsp), %xmm0
xorl %ecx, %ecx
callq 0x56b28
movq (%rsp), %rsi
testl %eax, %eax
movq %rbx, %rcx
je 0x2f0ef
movq 0x58(%rsi), %rax
movslq 0x4(%rax,%r13), %r14
incq %r14
incq %rcx
jmp 0x2ef36
movq 0x110(%rsp), %rax
testq %rax, %rax
movq 0x28(%rsp), %rdx
je 0x2f10b
cmpq 0x48(%rsi), %rdx
jge 0x2f10b
andq $0x0, (%rax)
cmpq %rdx, %rcx
jl 0x2ee18
jmp 0x2f401
movq 0x10(%rdx), %r15
pushq $0x1
popq %r13
leaq (,%rax,8), %rdx
movq %r15, %rdi
movl $0xff, %esi
callq 0x20e0
xorl %edi, %edi
testq %r12, %r12
cmovleq %rdi, %r12
xorl %r8d, %r8d
cmpq %r8, %r12
movq (%rsp), %r9
je 0x2f18d
movq 0x58(%r9), %rax
cmpl $-0x1, 0xc(%rax,%rdi)
je 0x2f428
movslq (%rax,%rdi), %rcx
movl 0x4(%r9), %esi
movq %rsi, %rax
xorl %edx, %edx
movq 0xf8(%rsp), %r9
idivq %r9
addq %rdx, %rcx
subq %rsi, %rcx
movq %rcx, %rax
cqto
idivq %r9
movq %r8, (%r15,%rax,8)
incq %r8
addq $0x20, %rdi
jmp 0x2f142
movl 0x4(%r9), %ebp
movq (%r15), %rax
cmpq $-0x1, %rax
je 0x2f3f3
movq 0x58(%r9), %rcx
shlq $0x5, %rax
movslq (%rcx,%rax), %rdx
movq 0x8(%rsp), %rsi
addq %rbp, %rsi
subq %rdx, %rsi
movq %rsi, 0x8(%rsp)
movslq 0x4(%rcx,%rax), %rbp
incq %rbp
jmp 0x2f3f3
movq (%r15,%r13,8), %rax
cmpq $-0x1, %rax
je 0x2f3f0
cmpq $-0x1, -0x8(%r15,%r13,8)
jne 0x2f3e0
movq 0x58(%r9), %r12
shlq $0x5, %rax
movslq (%r12,%rax), %r14
cmpl $0x0, 0x1c(%r12,%rax)
jne 0x2f25d
addq %rax, %r12
subq $0x8, %rsp
movq %r12, %rdi
movq %r9, %rsi
movq 0x38(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x60(%rsp), %r9
pushq 0x48(%rsp)
pushq 0x48(%rsp)
pushq 0x100(%rsp)
pushq 0x100(%rsp)
pushq 0x88(%rsp)
callq 0x567ea
addq $0x30, %rsp
cmpw $-0x1, 0x14(%r12)
je 0x2f466
movswl 0x10(%r12), %eax
addl %eax, 0xc(%r12)
movq %r12, 0x28(%rsp)
movq (%rsp), %r9
movq %r13, 0x20(%rsp)
leaq -0x1(%r13), %r12
movq 0x8(%rsp), %rax
movq %rbp, 0x80(%rsp)
addq %rbp, %rax
subq %r14, %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movslq 0x8(%rax), %r10
decq %r10
testq %r12, %r12
js 0x2f39d
cmpq $-0x1, (%r15,%r12,8)
jne 0x2f39d
testq %r10, %r10
jle 0x2f39d
movq %r15, %r13
leaq -0x1(%r14), %r11
movq %r11, 0x68(%rsp)
movl 0x4(%r9), %ecx
movq %rcx, %rax
xorl %edx, %edx
movq 0xf8(%rsp), %r15
idivq %r15
movq %rcx, %rsi
subq %rdx, %rsi
movq %r11, %rax
subq %rsi, %rax
cqto
idivq %r15
movq %rax, %rbp
imulq %r15, %rbp
addq %rsi, %rbp
cmpq %rcx, %rbp
cmovleq %rcx, %rbp
cmpq %rax, %r12
jne 0x2f409
subq %rbp, %r14
subq %r14, %r10
incq %r10
subq $0x8, %rsp
movq %r9, %rdi
movq 0x38(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x60(%rsp), %r8
movq 0x68(%rsp), %r9
movsd 0x90(%rsp), %xmm0
pushq $0x1
pushq %r15
pushq %r10
pushq %r11
pushq %rbp
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq 0x128(%rsp)
pushq 0x128(%rsp)
callq 0x56321
movq 0x50(%rsp), %r9
addq $0x50, %rsp
testl %eax, %eax
movq %r13, %r15
je 0x2f39d
movq 0x48(%r9), %rax
movq 0x58(%r9), %rcx
movq %rax, %rdx
shlq $0x5, %rdx
addq %rcx, %rdx
addq $-0x20, %rdx
movswq 0x10(%rdx), %rcx
movslq 0x8(%rdx), %r10
subq %rcx, %r10
movq %rdx, 0x28(%rsp)
movl %r10d, 0x8(%rdx)
decq %rax
movq %rax, (%r15,%r12,8)
addq %r14, 0x8(%rsp)
decq %r10
decq %r12
movq %rbp, %r14
jmp 0x2f28a
movq 0x70(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x14(%rsp), %edx
movsd 0x78(%rsp), %xmm0
xorl %ecx, %ecx
callq 0x56b28
testl %eax, %eax
movl $0x0, %eax
je 0x2ee1a
movq 0x20(%rsp), %r13
movq (%r15,%r13,8), %rax
cmpq $-0x1, %rax
movq 0x80(%rsp), %rbp
movq (%rsp), %r9
je 0x2f3f0
movq 0x58(%r9), %rcx
shlq $0x5, %rax
movslq 0x4(%rcx,%rax), %rbp
incq %rbp
incq %r13
movq 0x18(%rsp), %rax
cmpq %rax, %r13
jl 0x2f1c7
pushq $0x1
popq %rax
jmp 0x2ee1a
leaq 0x1b5272(%rip), %rdi    # 0x1e4682
leaq 0x1b428c(%rip), %rsi    # 0x1e36a3
leaq 0x1b5194(%rip), %rcx    # 0x1e45b2
movl $0x3686, %edx           # imm = 0x3686
callq 0x2110
leaq 0x1b5168(%rip), %rdi    # 0x1e4597
leaq 0x1b426d(%rip), %rsi    # 0x1e36a3
leaq 0x1b5175(%rip), %rcx    # 0x1e45b2
movl $0x3667, %edx           # imm = 0x3667
callq 0x2110
leaq 0x1b5225(%rip), %rdi    # 0x1e4673
leaq 0x1b424e(%rip), %rsi    # 0x1e36a3
leaq 0x1b5156(%rip), %rcx    # 0x1e45b2
movl $0x36a1, %edx           # imm = 0x36A1
callq 0x2110
leaq 0x1b5206(%rip), %rdi    # 0x1e4673
leaq 0x1b422f(%rip), %rsi    # 0x1e36a3
leaq 0x1b5137(%rip), %rcx    # 0x1e45b2
movl $0x367a, %edx           # imm = 0x367A
callq 0x2110