// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movsd %xmm1, 0xb0(%rsp)
movsd %xmm0, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rsi, %rbx
movq %rdi, %r15
movq 0x108(%rsp), %r11
movq 0x100(%rsp), %r8
andq $0x0, 0x18(%rdi)
movq 0x10(%rdi), %rax
xorl %ecx, %ecx
movq %rdx, 0x20(%rsp)
testq %rdx, %rdx
setne %cl
movl %ecx, 0x7c(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
cmovleq %rcx, %rax
movq %rax, 0xc0(%rsp)
xorl %eax, %eax
xorl %r14d, %r14d
movq %rsi, 0x50(%rsp)
movq %rdi, 0x88(%rsp)
cmpq 0xc0(%rsp), %rax
je 0x55f91
movq (%r15), %rdx
movq %rax, 0x28(%rsp)
imulq $0xa8, %rax, %rax
movb $0x0, 0x2c(%rdx,%rax)
movq 0x48(%rdx,%rax), %rbp
testq %rbp, %rbp
je 0x55f74
movq %r14, %r15
addq %rax, %rdx
movq %rdx, 0x18(%rsp)
movl 0x4(%rdx), %ecx
movl 0x8(%rdx), %esi
incl %esi
movq %rcx, %rax
xorl %edx, %edx
idivq %r11
subq %rcx, %rdx
addq %rdx, %rsi
movq %rsi, %rax
cqto
idivq %r11
xorl %r13d, %r13d
testq %rdx, %rdx
setg %r13b
addq %rax, %r13
movq 0x100(%rsp), %r14
movq 0x10(%r14), %rdi
cmpq %r13, 0x8(%r14)
jae 0x5595b
leaq -0x1(%r13), %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(%r14)
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%r14)
leaq (,%r13,8), %rdx
movl $0xff, %esi
callq 0x20e0
movq 0x10(%r14), %r12
testq %rbp, %rbp
movl $0x0, %edi
cmovgq %rbp, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movq 0x108(%rsp), %r10
movq %r15, %r14
cmpq %r9, %rdi
je 0x559d2
movq 0x18(%rsp), %rdx
movq 0x58(%rdx), %rax
cmpl $-0x1, 0xc(%rax,%r8)
je 0x5627e
movslq (%rax,%r8), %rcx
movl 0x4(%rdx), %esi
movq %rsi, %rax
xorl %edx, %edx
idivq %r10
addq %rdx, %rcx
subq %rsi, %rcx
movq %rcx, %rax
cqto
idivq %r10
movq %r9, (%r12,%rax,8)
incq %r9
addq $0x20, %r8
jmp 0x5598e
movq 0x18(%rsp), %rdi
movl 0x10(%rdi), %ecx
testq %rbx, %rbx
movq %rcx, 0x68(%rsp)
je 0x559ee
movq 0x18(%rbx), %rax
movq (%rax,%rcx,8), %rax
jmp 0x55a06
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x60(%rsp)
movl 0x4(%rdi), %ecx
movl 0x8(%rdi), %eax
incl %eax
movl %eax, 0xac(%rsp)
subl %ecx, %eax
movq %rax, 0x90(%rsp)
movl 0x1c(%rdi), %eax
movq %rax, 0x48(%rsp)
pushq $0x1
popq %rax
movq %rax, 0x10(%rsp)
movq %rcx, 0xb8(%rsp)
movq %rcx, 0x8(%rsp)
movq %r12, 0x58(%rsp)
movq %r13, 0x98(%rsp)
testq %rbp, %rbp
jle 0x55c14
decq %rbp
movq 0x58(%rdi), %rax
movq %rbp, 0x80(%rsp)
movq %rbp, %rbx
shlq $0x5, %rbx
movslq (%rax,%rbx), %rsi
movq %r10, %rdx
leaq 0x70(%rsp), %rcx
callq 0x51f8b
movq 0x18(%rsp), %rdi
movq %rax, %r15
movq 0x58(%rdi), %rax
movslq 0x4(%rax,%rbx), %rcx
cmpq %rcx, 0x70(%rsp)
jne 0x5629d
movq 0x8(%rsp), %rdx
cmpq %rdx, %rcx
cmovgq %rcx, %rdx
movq %rdx, 0x8(%rsp)
addq %rbx, %rax
incq %r15
movq 0x108(%rsp), %r10
movl 0xc(%rax), %ecx
movswl 0x10(%rax), %eax
subl %eax, %ecx
incl %ecx
movslq %ecx, %rbx
cmpq %r13, %r15
jge 0x55c07
cmpq %rbx, 0x60(%rsp)
jle 0x55c07
cmpq $-0x1, (%r12,%r15,8)
jne 0x55c07
movq %r14, 0xa0(%rsp)
movq 0x70(%rsp), %r12
incq %r12
movq %r12, %rsi
movq %r10, %rdx
leaq 0x70(%rsp), %rcx
movq %r10, %r14
movq %rdi, %r13
callq 0x51f8b
cmpq %rax, %r15
jne 0x56240
movq 0x70(%rsp), %rbp
movq %r13, %rdi
movq 0x50(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
movq 0x48(%rsp), %r9
movsd 0x40(%rsp), %xmm0
pushq $0x0
pushq %r14
pushq %rbx
pushq %rbp
pushq %r12
pushq 0x90(%rsp)
callq 0x64ea2
addq $0x30, %rsp
testl %eax, %eax
je 0x55be7
movq 0x48(%r13), %rax
movq 0x58(%r13), %rcx
decq %rax
movq 0x58(%rsp), %r12
movq %rax, (%r12,%r15,8)
shlq $0x5, %rax
addq %rcx, %rax
movq 0x8(%rsp), %rdx
cmpq %rdx, %rbp
cmovgq %rbp, %rdx
movq %rdx, 0x8(%rsp)
cmpq $0x0, 0x10(%rsp)
movq %r13, %rdi
je 0x55bc4
movq 0x48(%rdi), %rdx
pushq $0x1
popq %r8
cmpq $0x2, %rdx
movq 0x108(%rsp), %r10
movq 0x98(%rsp), %r13
jb 0x55bd7
movl (%rax), %esi
shlq $0x5, %rdx
xorl %r8d, %r8d
cmpl -0x40(%rcx,%rdx), %esi
setge %r8b
jmp 0x55bd7
xorl %r8d, %r8d
movq 0x108(%rsp), %r10
movq 0x98(%rsp), %r13
movq %r8, 0x10(%rsp)
incq %r15
movq %rax, %r14
jmp 0x55ab9
movq 0x108(%rsp), %r10
movq 0xa0(%rsp), %r14
movq %r13, %rdi
movq 0x98(%rsp), %r13
movq 0x58(%rsp), %r12
movq 0x80(%rsp), %rbp
jmp 0x55a4e
movl 0x4(%rdi), %ebp
movq 0x8(%rsp), %rsi
subq %rbp, %rsi
incq %rsi
movq 0x90(%rsp), %rdi
movq %rsi, %rbx
movl 0x7c(%rsp), %edx
movsd 0x18d8b7(%rip), %xmm0   # 0x1e34f0
xorl %ecx, %ecx
callq 0x56b28
testl %eax, %eax
je 0x55c72
testq %r13, %r13
jle 0x55c89
movq (%r12), %rax
cmpq $-0x1, %rax
movq 0x108(%rsp), %r11
movq 0x18(%rsp), %r8
je 0x55c96
movq 0x58(%r8), %rcx
shlq $0x5, %rax
movslq 0x4(%rcx,%rax), %rbp
incq %rbp
jmp 0x55c96
movq 0x108(%rsp), %r11
movq 0x28(%rsp), %rax
movq 0x50(%rsp), %rbx
jmp 0x55f79
movq 0x108(%rsp), %r11
movq 0x18(%rsp), %r8
pushq $0x1
popq %rdx
cmpq %r13, %rdx
jge 0x55ee1
movq (%r12,%rdx,8), %rax
cmpq $-0x1, %rax
je 0x55ec7
cmpq $-0x1, -0x8(%r12,%rdx,8)
jne 0x55eb7
movq 0x58(%r8), %r15
shlq $0x5, %rax
movslq (%r15,%rax), %r12
cmpl $0x0, 0x1c(%r15,%rax)
movq %rdx, 0x8(%rsp)
jne 0x55d2b
addq %rax, %r15
movq %r15, %rdi
movq %r8, %rsi
movq 0x50(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
pushq 0x68(%rsp)
pushq 0x50(%rsp)
callq 0x65318
popq %rcx
popq %rdx
cmpw $-0x1, 0x14(%r15)
je 0x562db
movswl 0x10(%r15), %eax
addl %eax, 0xc(%r15)
movq %r15, %r14
movq 0x108(%rsp), %r11
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %rdx
leaq -0x1(%rdx), %r15
movq %rbp, 0x60(%rsp)
addq %rbp, %rbx
subq %r12, %rbx
movl 0x8(%r14), %esi
testq %r15, %r15
js 0x55e6f
movq 0x58(%rsp), %rax
cmpq $-0x1, (%rax,%r15,8)
jne 0x55e6f
cmpl $0x2, %esi
jl 0x55e6f
leaq -0x1(%r12), %r10
movq %r10, 0x70(%rsp)
movl 0x4(%r8), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r11
movq %rcx, %rdi
subq %rdx, %rdi
movq %r10, %rax
subq %rdi, %rax
cqto
idivq %r11
movq %rax, %rbp
imulq %r11, %rbp
addq %rdi, %rbp
cmpq %rcx, %rbp
cmovleq %rcx, %rbp
cmpq %rax, %r15
jne 0x5625f
subq %rbp, %r12
movl %esi, %eax
subq %r12, %rax
movq %r8, %rdi
movq 0x50(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
movq 0x48(%rsp), %r9
movsd 0x40(%rsp), %xmm0
pushq $0x1
pushq %r11
pushq %rax
pushq %r10
pushq %rbp
pushq 0x90(%rsp)
callq 0x64ea2
movq 0x48(%rsp), %r8
movq 0x138(%rsp), %r11
addq $0x30, %rsp
testl %eax, %eax
je 0x55e6f
movq 0x48(%r8), %rcx
movq 0x58(%r8), %rax
movq %rcx, %rdx
shlq $0x5, %rdx
leaq (%rax,%rdx), %r14
addq $-0x20, %r14
movswl 0x10(%r14), %edx
movl 0x8(%r14), %esi
subl %edx, %esi
movl %esi, 0x8(%r14)
decq %rcx
movq 0x58(%rsp), %rdx
movq %rcx, (%rdx,%r15,8)
cmpq $0x0, 0x10(%rsp)
je 0x55e58
movq 0x48(%r8), %rcx
pushq $0x1
popq %rdx
movq %rdx, 0x10(%rsp)
cmpq $0x2, %rcx
jb 0x55e61
movl (%r14), %edx
shlq $0x5, %rcx
xorl %edi, %edi
cmpl -0x40(%rax,%rcx), %edx
setge %dil
movq %rdi, 0x10(%rsp)
jmp 0x55e61
movq $0x0, 0x10(%rsp)
addq %r12, %rbx
decq %r15
movq %rbp, %r12
jmp 0x55d3e
movq 0x90(%rsp), %rdi
movq %rbx, %rsi
movl 0x7c(%rsp), %edx
movsd 0x18d66a(%rip), %xmm0   # 0x1e34f0
xorl %ecx, %ecx
callq 0x56b28
testl %eax, %eax
je 0x55ecf
movq 0x58(%rsp), %r12
movq 0x8(%rsp), %rdx
movq (%r12,%rdx,8), %rax
cmpq $-0x1, %rax
movq 0x108(%rsp), %r11
movq 0x18(%rsp), %r8
movq 0x60(%rsp), %rbp
je 0x55ec7
movq 0x58(%r8), %rcx
shlq $0x5, %rax
movslq 0x4(%rcx,%rax), %rbp
incq %rbp
incq %rdx
jmp 0x55c99
movq 0x108(%rsp), %r11
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %rdx
cmpq $0x0, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x50(%rsp), %rbx
je 0x55f79
cmpq %r13, %rdx
jl 0x55f79
movl 0x28(%r8), %eax
testq %rax, %rax
sete %cl
movl 0xac(%rsp), %edx
cmpl 0xb8(%rsp), %edx
sete %dl
orb %cl, %dl
jne 0x55f74
cvtsi2sdq 0x90(%rsp), %xmm0
mulsd 0x18d61b(%rip), %xmm0   # 0x1e3548
cmpl $0x1c2, %eax            # imm = 0x1C2
jb 0x55f74
cvtsi2sd %rax, %xmm1
ucomisd %xmm0, %xmm1
jb 0x55f74
movb $0x3, 0x2c(%r8)
movq 0x88(%rsp), %rcx
addq %rax, 0x18(%rcx)
cmpq $0x0, 0x10(%rsp)
jne 0x55f74
movq 0x48(%r8), %rsi
movq 0x58(%r8), %rdi
shlq $0x5, %rsi
addq %rdi, %rsi
callq 0x19dc0
movq 0x108(%rsp), %r11
movq 0x28(%rsp), %rax
incq %rax
movq 0x88(%rsp), %r15
movq 0x100(%rsp), %r8
jmp 0x55892
cmpq $0x0, 0x20(%rsp)
je 0x55fc7
cmpq $0x0, 0x18(%r15)
jle 0x55fc7
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rcx
movq %r15, %rdi
movq 0x38(%rsp), %rsi
movq %r8, %rdx
movsd 0x40(%rsp), %xmm0
movq 0x108(%rsp), %r8
callq 0x1e2db
andq $0x0, 0x18(%r15)
movsd 0x18d2cc(%rip), %xmm0   # 0x1e32a0
subsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x18d4d8(%rip), %xmm0   # 0x1e34c0
mulsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
xorl %r8d, %r8d
cmpq 0x10(%r15), %r8
jge 0x5622e
movq (%r15), %rax
imulq $0xa8, %r8, %rcx
leaq (%rax,%rcx), %r11
movl 0x8(%rax,%rcx), %r9d
incl %r9d
movl 0x28(%rax,%rcx), %edx
testl %edx, %edx
sete %sil
subl 0x4(%rax,%rcx), %r9d
sete %dil
orb %sil, %dil
jne 0x5604d
cvtsi2sd %r9, %xmm0
mulsd 0x68(%rsp), %xmm0
movl %edx, %edx
cvtsi2sd %rdx, %xmm1
ucomisd %xmm0, %xmm1
jae 0x56057
movb $0x0, 0x2c(%r11)
incq %r8
jmp 0x55ffd
movq %r9, 0x60(%rsp)
movq %r8, 0x48(%rsp)
movl 0x10(%rax,%rcx), %edx
movq %rdx, 0x8(%rsp)
movq 0x48(%r11), %rbx
testq %rbx, %rbx
movl $0x0, %edx
cmovleq %rdx, %rbx
movl 0x1c(%rax,%rcx), %eax
movq %rax, 0x58(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
pushq $0x1
popq %rbp
movq 0x108(%rsp), %r10
movq %r11, 0x10(%rsp)
cmpq %r13, %rbx
je 0x5612c
movq 0x58(%r11), %r12
leaq (%r12,%r15), %r14
cmpl $0x0, 0x1c(%r12,%r15)
je 0x560bf
movswl 0x10(%r12,%r15), %eax
subl %eax, 0xc(%r12,%r15)
jmp 0x56104
movq %r14, %rdi
movq %r11, %rsi
movq 0x50(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
pushq 0x8(%rsp)
pushq 0x60(%rsp)
callq 0x65318
movq 0x20(%rsp), %r11
movq 0x118(%rsp), %r10
addq $0x10, %rsp
cmpw $-0x1, 0x14(%r12,%r15)
je 0x562bc
testq %r13, %r13
je 0x56120
testq %rbp, %rbp
je 0x56120
movl (%r14), %eax
movq 0x58(%r11), %rcx
xorl %ebp, %ebp
cmpl -0x20(%rcx,%r15), %eax
setge %bpl
incq %r13
addq $0x20, %r15
jmp 0x56099
testq %rbp, %rbp
jne 0x56152
movq 0x48(%r11), %rsi
movq 0x58(%r11), %rdi
shlq $0x5, %rsi
addq %rdi, %rsi
callq 0x19dc0
movq 0x10(%rsp), %r11
movq 0x108(%rsp), %r10
subq $0x8, %rsp
movq %r11, %rdi
movq 0x58(%rsp), %r14
movq %r14, %rsi
movq 0x28(%rsp), %rdx
movq 0x108(%rsp), %rcx
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %r9
movsd 0x48(%rsp), %xmm0
pushq %r10
movq %r10, %r12
callq 0x63c7b
movq 0x20(%rsp), %rbx
addq $0x10, %rsp
movb $0x0, 0x2c(%rbx)
movsd 0xb0(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq 0x88(%rsp), %r15
jae 0x561cd
movsd 0xa0(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq 0x48(%rsp), %r8
jb 0x56052
movb $0x3, 0x2c(%rbx)
jmp 0x56052
movq 0x60(%rsp), %rax
addq %rax, 0x18(%r15)
movb $0x1, 0x2c(%rbx)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1cf34
movq %rbx, %rdi
testq %r14, %r14
je 0x56207
movq %r14, %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
movsd 0x40(%rsp), %xmm0
callq 0x1d5df
jmp 0x56224
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
movsd 0x40(%rsp), %xmm0
movq %r12, %r8
callq 0x1dbea
movq 0x48(%rsp), %r8
jmp 0x56052
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18e43b(%rip), %rdi    # 0x1e4682
leaq 0x18d455(%rip), %rsi    # 0x1e36a3
leaq 0x1917b5(%rip), %rcx    # 0x1e7a0a
movl $0x10dc, %edx           # imm = 0x10DC
callq 0x2110
leaq 0x18e41c(%rip), %rdi    # 0x1e4682
leaq 0x18d436(%rip), %rsi    # 0x1e36a3
leaq 0x191796(%rip), %rcx    # 0x1e7a0a
movl $0x1103, %edx           # imm = 0x1103
callq 0x2110
leaq 0x18e312(%rip), %rdi    # 0x1e4597
leaq 0x18d417(%rip), %rsi    # 0x1e36a3
leaq 0x191777(%rip), %rcx    # 0x1e7a0a
movl $0x10ca, %edx           # imm = 0x10CA
callq 0x2110
leaq 0x19167b(%rip), %rdi    # 0x1e791f
leaq 0x18d3f8(%rip), %rsi    # 0x1e36a3
leaq 0x191758(%rip), %rcx    # 0x1e7a0a
movl $0x10d4, %edx           # imm = 0x10D4
callq 0x2110
leaq 0x18e3b0(%rip), %rdi    # 0x1e4673
leaq 0x18d3d9(%rip), %rsi    # 0x1e36a3
leaq 0x191739(%rip), %rcx    # 0x1e7a0a
movl $0x1135, %edx           # imm = 0x1135
callq 0x2110
leaq 0x18e391(%rip), %rdi    # 0x1e4673
leaq 0x18d3ba(%rip), %rsi    # 0x1e36a3
leaq 0x19171a(%rip), %rcx    # 0x1e7a0a
movl $0x10f7, %edx           # imm = 0x10F7
callq 0x2110