// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_raln(ul_idx_t const*, char*, UC_Read*, overlap_region*, bit_extz_t*, long, long, long, long, long, long, long, double, unsigned long, rtrace_t*, ul_ov_t*)
void gen_raln(const ul_idx_t *uref, char* qstr, UC_Read *tu, overlap_region *o, bit_extz_t *exz, 
int64_t wsid, int64_t weid, int64_t ts, int64_t te, int64_t ql, int64_t id, int64_t rev, double e_rate, 
uint64_t rid, rtrace_t *tc, ul_ov_t *res)
{
    // fprintf(stderr, "\n[M::%s::] ii::[%ld, %ld), t::[%ld, %ld), ql::%ld, id::%ld\n", 
    //         __func__, wsid, weid, ts, te, ql, id);
    int64_t k, q[2], t[2], c[2], ct[2], cq[2], mode, qwl, twl, aln_e = 0, cur_e, is_aln; 
    bit_extz_t aux; window_list *wa = o->w_list.a; 
    memset(res, 0, sizeof((*res))); 
    res->qs = res->ts = UINT32_MAX; res->qe = res->te = 0;
    memset(tc, 0, sizeof((*tc)));
    tc->c_qs = tc->c_ts = INT32_MAX; tc->c_qe = tc->c_te = -1;
    tc->pfx_e = tc->mid_e = tc->sfx_e = 0;

    q[0] = q[1] = -1; t[0] = ts; t[1] = te;///[q[0], q[1]) && [t[0], t[1])
    for (k = wsid; k < weid; k++) {
        q[1] = wa[k].x_start; t[1] = wa[k].y_start; 
        mode = - 1; cur_e = 0; is_aln = 1;
        // if(rid == 53 && id == 6) {
        //     fprintf(stderr, "0-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld)\n", __func__, k, q[0], q[1], t[0], t[1]);
        // }
        //before window; there are gaps before the window that need to be filled
        if(t[0] < t[1] && q[0] < q[1]) {
            if(q[0] < 0) { ///backward extension
                mode = 2;
                adjust_ext_offset_fixed_t(&(q[0]), &(q[1]), &(t[0]), &(t[1]), 0, q[1], t[0], t[1], 0, mode);
            } else {
                mode = 0;
            }
            // if(rid == 53 && id == 6) {
            //     fprintf(stderr, "1-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), mode::%ld\n", 
            //     __func__, k, q[0], q[1], t[0], t[1], mode);
            // }
            qwl = q[1] - q[0]; twl = t[1] - t[0];
            if(qwl || twl) {
                if(qwl == 0 && twl > 0) {
                    cur_e = twl;
                    // tot_e += twl;
                } else if(twl == 0 && qwl > 0) {
                    cur_e = qwl;
                    // tot_e += qwl;
                } else {
                    if(hc_aln_exz_simi_adv(id, rev, uref, NULL, NULL, qstr, tu, q[0], q[1], t[0], t[1], 
                            0, ql, ts, te, mode, exz, ql, e_rate, MAX_CNS_L, MAX_CNS_E, FORCE_CNS_L, -1, NULL, 0)) {
                        cur_e = exz->err; 
                        // tot_e += exz->err; 
                        q[0] = exz->ts; q[1] = exz->te + 1; t[0] = exz->ps; t[1] = exz->pe + 1;
                        // if(rid == 53 && id == 6) {
                        //     fprintf(stderr, "2-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), mode::%ld, cur_e::%ld\n", 
                        //     __func__, k, q[0], q[1], t[0], t[1], mode, cur_e);
                        // }
                    } else {
                        cur_e = gen_err_unaligned(qwl, twl); is_aln = 0;
                        // tot_e += gen_err_unaligned(qwl, twl); 
                        // if(rid == 53 && id == 6) {
                        //     fprintf(stderr, "2-b[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), mode::%ld, cur_e::%ld\n", 
                        //     __func__, k, q[0], q[1], t[0], t[1], mode, cur_e);
                        // }
                    }
                }
                aln_e += cur_e;
                update_ul_ov_t_coor((*res), q[0], q[1], t[0], t[1]);
                if(k == wsid) tc->pfx_e = cur_e*(is_aln?1:-1);
            }
        } 
        
        ///within window
        q[0] = wa[k].x_start; t[0] = wa[k].y_start;
        q[1] = wa[k].x_end+1; t[1] = wa[k].y_end+1;
        qwl = q[1] - q[0]; twl = t[1] - t[0]; cur_e = 0; is_aln = 1;
        // if(rid == 53 && id == 6) {
        //     fprintf(stderr, "3-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld)\n", 
        //     __func__, k, q[0], q[1], t[0], t[1]);
        // }
        if((ts <= t[0]) && (te >= t[1])) {///cover the whole window
            if(!is_ualn_win(wa[k])) cur_e = wa[k].error;
            else cur_e = gen_err_unaligned(qwl, twl); 
            update_trace_idx(tc, k, 0, wa[k].clen, q[0], q[1], t[0], t[1]);
            // if(rid == 53 && id == 6) {
            //     fprintf(stderr, "4-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), cur_e::%ld\n", 
            //     __func__, k, q[0], q[1], t[0], t[1], cur_e);
            // }
        } else {///te < t[1]->cover a part of window
            if(ts > t[0]) {
                t[0] = ts; q[0] = -1;
            }
            if(te < t[1]) {
                t[1] = te; q[1] = -1;
            }

            if((q[0] != -1) && (q[1] != -1)) {
                mode = 0;//global
            } else if((q[0] != -1) && (q[1] == -1)) {
                mode = 1;///forward extension
            } else if((q[0] == -1) && (q[1] != -1)) {
                mode = 2;///backward extension
            } else {
                mode = 3;///no primary hit within [ibeg, iend] 
            }
            // if(rid == 53 && id == 6) {
            //     fprintf(stderr, "5-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), mode::%ld\n", 
            //     __func__, k, q[0], q[1], t[0], t[1], mode);
            // }
            if(!is_ualn_win(wa[k])) {///scan cigar by the coordinates of y/t
                set_bit_extz_t(aux, (*o), k); 
                cur_e = hc_aln_exz_by_exist_cigar_with_p(&aux, mode, t[0], t[1], &(q[0]), &(q[1]), 
                &(c[0]), &(c[1]), &(ct[0]), &(ct[1]), &(cq[0]), &(cq[1]));
                update_trace_idx(tc, k, c[0], c[1], cq[0], cq[1], ct[0], ct[1]);
                // if(rid == 53 && id == 6) {
                //     fprintf(stderr, "6-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), cur_e::%ld, c_q::[%ld, %ld), c_t::[%ld, %ld)\n", 
                //     __func__, k, q[0], q[1], t[0], t[1], cur_e, cq[0], cq[1], ct[0], ct[1]);
                // }
            } else {
                assert(mode == 1 || mode == 2);
                adjust_ext_offset_fixed_t(&(q[0]), &(q[1]), &(t[0]), &(t[1]), q[0], q[1], t[0], t[1], 0, mode);
                qwl = q[1] - q[0]; twl = t[1] - t[0];
                // if(rid == 53 && id == 6) {
                //     fprintf(stderr, "7-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), cur_e::%ld\n", 
                //     __func__, k, q[0], q[1], t[0], t[1], cur_e);
                // }
                if(qwl || twl) {
                    if(qwl == 0 && twl > 0) {
                        cur_e = twl;
                    } else if(twl == 0 && qwl > 0) {
                        cur_e = qwl;
                    } else {
                        if(hc_aln_exz_simi_adv(id, rev, uref, NULL, NULL, qstr, tu, q[0], q[1], t[0], t[1], 
                                0, ql, ts, te, mode, exz, ql, e_rate, MAX_CNS_L, MAX_CNS_E, FORCE_CNS_L, -1, NULL, 0)) {
                            cur_e = exz->err; 
                            q[0] = exz->ts; q[1] = exz->te + 1; t[0] = exz->ps; t[1] = exz->pe + 1;
                            // if(rid == 53 && id == 6) {
                            //     fprintf(stderr, "7-b[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), cur_e::%ld\n", 
                            //     __func__, k, q[0], q[1], t[0], t[1], cur_e);
                            // }
                        } else {
                            cur_e = gen_err_unaligned(qwl, twl); is_aln = 0;
                            // if(rid == 53 && id == 6) {
                            //     fprintf(stderr, "7-c[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), cur_e::%ld\n", 
                            //     __func__, k, q[0], q[1], t[0], t[1], cur_e);
                            // }
                        }
                    }
                    tc->sfx_e = cur_e*(is_aln?1:-1);
                }
            }
        }
        aln_e += cur_e;
        update_ul_ov_t_coor((*res), q[0], q[1], t[0], t[1]);

        q[0] = q[1]; t[0] = t[1];
    }
    // if(ts == 8087 && te == 28530 && ql == 127662) {
    //     fprintf(stderr, "8-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), cur_e::%ld, ql::%ld\n", 
    //     __func__, k, q[0], q[1], t[0], t[1], cur_e, ql);
    // }
    if(q[0] >= 0 && q[0] < ql) {///forward extension
        q[1] = ql; t[1] = te; cur_e = 0; mode = 1;///forward extension
        adjust_ext_offset_fixed_t(&(q[0]), &(q[1]), &(t[0]), &(t[1]), q[0], q[1], t[0], t[1], 0, mode);
        qwl = q[1] - q[0]; twl = t[1] - t[0]; is_aln = 1;
        // if(rid == 53 && id == 6) {
        //     fprintf(stderr, "9-a[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), cur_e::%ld\n", 
        //     __func__, k, q[0], q[1], t[0], t[1], cur_e);
        // }
        if(qwl || twl) {
            if(qwl == 0 && twl > 0) {
                cur_e = twl;
            } else if(twl == 0 && qwl > 0) {
                cur_e = qwl;
            } else {
                if(hc_aln_exz_simi_adv(id, rev, uref, NULL, NULL, qstr, tu, q[0], q[1], t[0], t[1], 
                        0, ql, ts, te, mode, exz, ql, e_rate, MAX_CNS_L, MAX_CNS_E, FORCE_CNS_L, -1, NULL, 0)) {
                    cur_e = exz->err; 
                    q[0] = exz->ts; q[1] = exz->te + 1; t[0] = exz->ps; t[1] = exz->pe + 1;
                    // if(rid == 53 && id == 6) {
                    //     fprintf(stderr, "9-b[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), cur_e::%ld, thre::%d\n", 
                    //     __func__, k, q[0], q[1], t[0], t[1], cur_e, exz->thre);
                    // }
                } else {
                    cur_e = gen_err_unaligned(qwl, twl); is_aln = 0;
                    // if(rid == 53 && id == 6) {
                    //     fprintf(stderr, "9-c[M::%s::k->%ld] q::[%ld, %ld), t::[%ld, %ld), cur_e::%ld\n", 
                    //     __func__, k, q[0], q[1], t[0], t[1], cur_e);
                    // }
                }
            }
            update_ul_ov_t_coor((*res), q[0], q[1], t[0], t[1]);
            tc->sfx_e = cur_e*(is_aln?1:-1);
        }
        aln_e += cur_e;
    }
    tc->mid_e = aln_e - abs(tc->pfx_e) - abs(tc->sfx_e); 
    if(aln_e <= MAX_SEC_ERR) res->sec = aln_e;
    else res->sec = MAX_SEC_ERR;
    // fprintf(stderr, "10-a[M::%s::k->%ld] q::[%u, %u), t::[%u, %u), tot_e::%u\n\n", 
    //                 __func__, k, res->qs, res->qe, res->ts, res->te, res->sec);


    // aln_e = get_sub_cigar_err(res, tc, uref, qstr, tu, o, exz, e_rate);
    // if(aln_e != (int64_t)res->sec) {
    //     fprintf(stderr, "[M::%s::rid->%lu] tot_e::%u, aln_e::%ld, id::%ld\n", 
    //     __func__, rid, res->sec, aln_e, id);
    //     exit(1);
    // }
    
    // assert(aln_e == get_sub_cigar_err(res, tc, uref, qstr, tu, o, exz, e_rate, 0));
    // assert(aln_e == get_sub_cigar_err(res, tc, uref, qstr, tu, o, exz, e_rate, 1));
    // debug_backtrace_step_err(rid, res, tc, uref, qstr, tu, o, exz, e_rate);
    // if(rid == 42 && res->sec == 706 && res->qs == 63686 && res->qe == 75773 
    //                     && res->ts == 9404 && res->te == 21663) {
    //     debug_backtrace_step_err(rid, res, tc, uref, qstr, tu, o, exz, e_rate);
    // }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movsd %xmm0, 0x78(%rsp)
movq %r9, %r13
movq %r8, 0x50(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdi, 0x68(%rsp)
movq 0x210(%rsp), %r15
movq 0x208(%rsp), %rdx
movq 0x1e0(%rsp), %r8
movq 0x1d8(%rsp), %rbp
movq %rcx, 0xa0(%rsp)
movq 0x58(%rcx), %r12
xorps %xmm0, %xmm0
movups %xmm0, 0xc(%r15)
movups %xmm0, (%r15)
orl $-0x1, 0x10(%r15)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x4(%r15)
andl $0x0, 0x30(%rdx)
movups %xmm0, 0x20(%rdx)
movups %xmm0, 0x10(%rdx)
movapd 0x195d1e(%rip), %xmm0   # 0x1e34b0
movupd %xmm0, (%rdx)
andl $0x0, 0x2c(%rdx)
movq %r9, 0xa8(%rsp)
shlq $0x5, %r13
orq $0x1c, %r13
pushq $-0x1
popq %rbx
xorl %edx, %edx
xorl %edi, %edi
movq %r12, 0x38(%rsp)
movq 0xa8(%rsp), %rax
leaq (%rax,%rdx), %rsi
cmpq 0x1d0(%rsp), %rsi
jge 0x4e039
movslq -0x14(%r12,%r13), %r14
movq %r14, %rax
subq %rbp, %rax
movq %rdx, 0x10(%rsp)
jle 0x4d8ca
movslq -0x1c(%r12,%r13), %r9
cmpq %r9, %rbx
jge 0x4d8ca
testq %rbx, %rbx
js 0x4d7fd
xorl %eax, %eax
jmp 0x4d82d
movq %r9, %rbx
subq %rax, %rbx
jle 0x4d816
testq %rbx, %rbx
movl $0x0, %eax
cmovleq %rax, %rbx
movq %rbp, %rax
jmp 0x4d823
movq %r14, %rax
subq %r9, %rax
movq %rax, 0x40(%rsp)
xorl %ebx, %ebx
cmpq %rbp, %rax
cmovgq %rax, %rbp
pushq $0x2
popq %rax
movq %r9, %r15
subq %rbx, %r15
movq %r14, %r12
subq %rbp, %r12
movq %r15, %rcx
orq %r12, %rcx
je 0x4d8bd
testq %r15, %r15
movq 0x50(%rsp), %rcx
jne 0x4d850
testq %r12, %r12
jg 0x4d865
testq %r15, %r15
jle 0x4dbbd
testq %r12, %r12
jne 0x4dbbd
movq %r15, %r12
pushq $0x1
popq %rax
movq 0x210(%rsp), %r15
movl 0x4(%r15), %ecx
cmpq %rcx, %rbx
jge 0x4d87d
movl %ebx, 0x4(%r15)
movl 0x8(%r15), %ecx
cmpq %rcx, %r9
jle 0x4d88a
movl %r9d, 0x8(%r15)
movl 0x10(%r15), %ecx
cmpq %rcx, %rbp
jge 0x4d897
movl %ebp, 0x10(%r15)
movl 0x14(%r15), %ecx
cmpq %rcx, %r14
jle 0x4d8a4
movl %r14d, 0x14(%r15)
addq %r12, %rdi
testq %rdx, %rdx
jne 0x4d8c5
imull %r12d, %eax
movq 0x208(%rsp), %rcx
movl %eax, 0x28(%rcx)
jmp 0x4d8c5
movq 0x210(%rsp), %r15
movq 0x38(%rsp), %r12
movslq -0x1c(%r12,%r13), %rbx
movq %rbx, 0x20(%rsp)
movslq -0x14(%r12,%r13), %r10
movq %r10, 0x40(%rsp)
movslq -0x18(%r12,%r13), %r9
incq %r9
movq %r9, 0x28(%rsp)
movslq -0x10(%r12,%r13), %rbp
incq %rbp
movq %rbp, 0x48(%rsp)
cmpq 0x1d8(%rsp), %r10
jl 0x4d968
cmpq %r8, %rbp
jg 0x4d968
movswq -0x8(%r12,%r13), %r14
movl (%r12,%r13), %eax
cmpq $0x7fff, %r14           # imm = 0x7FFF
jne 0x4d92d
testl %eax, %eax
jne 0x4d92d
xorl %eax, %eax
cmpw $0x0, -0xa(%r12,%r13)
js 0x4db94
movq %rdi, %r12
movl %eax, %ecx
movq 0x208(%rsp), %rdi
xorl %edx, %edx
movq %rbx, %r8
pushq %rbp
movq %r10, 0x20(%rsp)
pushq %r10
callq 0x62f7e
popq %rax
popq %rcx
movq %r12, %rdi
movq 0x1e0(%rsp), %r8
movq 0x38(%rsp), %r12
movq 0x10(%rsp), %rdx
jmp 0x4db3d
cmpq 0x1d8(%rsp), %r10
jge 0x4d988
orq $-0x1, 0x20(%rsp)
movq 0x1d8(%rsp), %r10
movq %r10, 0x40(%rsp)
pushq $-0x1
popq %rbx
cmpq %r8, %rbp
jle 0x4d9c0
movq %r8, 0x48(%rsp)
orq $-0x1, 0x28(%rsp)
cmpq $-0x1, %rbx
setne %cl
xorl %eax, %eax
pushq $-0x1
popq %r9
movq %r8, %rbp
testb %cl, %cl
je 0x4d9df
cmpq $-0x1, %r9
jne 0x4d9df
movb $0x1, %al
xorl %ecx, %ecx
pushq $-0x1
popq %r9
pushq $0x1
popq %r14
jmp 0x4d9f2
cmpl $-0x1, %r9d
setne %al
cmpq $-0x1, %rbx
setne %cl
je 0x4d9a8
cmpl $-0x1, %r9d
je 0x4d9a8
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r14d, %r14d
jmp 0x4d9f2
cmpq $-0x1, %rbx
sete %cl
andb %al, %cl
movzbl %cl, %r14d
xorq $0x3, %r14
xorl %eax, %eax
cmpw $0x7fff, -0x8(%r12,%r13) # imm = 0x7FFF
jne 0x4da10
cmpl $0x0, (%r12,%r13)
jne 0x4da10
cmpw $0x0, -0xa(%r12,%r13)
js 0x4dd3a
movq 0xa0(%rsp), %rdx
movq 0x58(%rdx), %rax
movl -0x4(%rax,%r13), %ecx
addq %rcx, %rcx
addq 0x70(%rdx), %rcx
movq %rcx, 0x178(%rsp)
movl (%rax,%r13), %ecx
movq %rcx, 0x170(%rsp)
movq %rcx, 0x168(%rsp)
movq -0x1c(%rax,%r13), %rcx
movq %rcx, 0xdc(%rsp)
movq -0x14(%rax,%r13), %rcx
movq %rcx, 0xd0(%rsp)
movswl -0x8(%rax,%r13), %eax
movl %eax, 0xec(%rsp)
movl %eax, 0xe8(%rsp)
movq %rdi, %rbx
leaq 0xc0(%rsp), %rdi
movq %rsi, %r15
movq %r14, %rsi
movq %r10, 0x18(%rsp)
movq %r10, %rdx
movq %rbp, %rcx
leaq 0x20(%rsp), %r8
leaq 0x28(%rsp), %r9
leaq 0x88(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
leaq 0xc8(%rsp), %rax
pushq %rax
leaq 0xc8(%rsp), %rax
pushq %rax
leaq 0xb8(%rsp), %rax
pushq %rax
leaq 0xb8(%rsp), %rax
pushq %rax
callq 0x4aa37
addq $0x30, %rsp
movq %rax, %r14
movq 0x90(%rsp), %rdx
movq 0x98(%rsp), %rcx
movq 0x80(%rsp), %r8
movq 0x88(%rsp), %r9
movapd 0xb0(%rsp), %xmm0
subq $0x10, %rsp
movupd %xmm0, (%rsp)
movq 0x218(%rsp), %rdi
movq %r15, %rsi
callq 0x62f7e
movq 0x20(%rsp), %rdx
movq 0x1f0(%rsp), %r8
movq %rbx, %rdi
addq $0x10, %rsp
movq 0x20(%rsp), %rbx
movq 0x210(%rsp), %r15
movl 0x4(%r15), %eax
cmpq %rax, %rbx
jge 0x4db4a
movl %ebx, 0x4(%r15)
movl 0x8(%r15), %eax
movq 0x28(%rsp), %rbx
cmpq %rax, %rbx
movq 0x18(%rsp), %rcx
jle 0x4db61
movl %ebx, 0x8(%r15)
movl 0x10(%r15), %eax
cmpq %rax, %rcx
jge 0x4db6e
movl %ecx, 0x10(%r15)
movl 0x14(%r15), %eax
cmpq %rax, %rbp
jle 0x4db7b
movl %ebp, 0x14(%r15)
addq %r14, %rdi
movq %rbx, 0x20(%rsp)
movq %rbp, 0x40(%rsp)
addq $0x20, %r13
incq %rdx
jmp 0x4d7b6
movq %r9, %rax
subq %rbx, %rax
movq %rbp, %rcx
subq %r10, %rcx
cmpq $0x200, %rax            # imm = 0x200
jg 0x4dcf5
cmpq %rcx, %rax
cmovgq %rax, %rcx
cvtsi2sd %rcx, %xmm0
jmp 0x4dd2b
movq %rsi, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
subq $0x90, %rsp
movq %rcx, 0x50(%rsp)
movq %rax, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq 0x268(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x278(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %r14, 0x20(%rsp)
movq %rbp, 0x18(%rsp)
movq %r9, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
andq $0x0, 0x88(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, (%rsp)
andq $0x0, 0x80(%rsp)
orq $-0x1, 0x78(%rsp)
movq $0x100, 0x70(%rsp)      # imm = 0x100
movq $0x3ff, 0x68(%rsp)      # imm = 0x3FF
andq $0x0, 0x28(%rsp)
movq $0xc00, 0x60(%rsp)      # imm = 0xC00
movq 0x280(%rsp), %rdi
movq 0x288(%rsp), %rsi
movq 0xf8(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r9, 0xe8(%rsp)
movq 0x100(%rsp), %r9
movsd 0x108(%rsp), %xmm0
callq 0x4a3ee
addq $0x90, %rsp
testq %rax, %rax
je 0x4ddf5
movq 0x50(%rsp), %rax
movslq 0x2c(%rax), %r12
movslq 0x1c(%rax), %rbx
movq %rbx, 0x20(%rsp)
movslq 0x20(%rax), %r9
incq %r9
movq %r9, 0x28(%rsp)
movslq 0x10(%rax), %rbp
movq %rbp, 0x40(%rsp)
movslq 0x14(%rax), %r14
incq %r14
movq %r14, 0x48(%rsp)
pushq $0x1
popq %rax
movq 0x210(%rsp), %r15
movq 0x8(%rsp), %rdi
movq 0x1e0(%rsp), %r8
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
jmp 0x4d870
cmpq %rcx, %rax
cmovlq %rax, %rcx
cvtsi2sd %rcx, %xmm1
cvtsi2sd %rax, %xmm2
mulsd 0x19588a(%rip), %xmm2   # 0x1e3598
addsd 0x19558a(%rip), %xmm2   # 0x1e32a0
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq %rdi, %r12
cvttsd2si %xmm0, %r14
xorl %ecx, %ecx
jmp 0x4d932
movq %rdi, 0x8(%rsp)
orb %cl, %al
je 0x4e2cb
leaq 0x20(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x48(%rsp), %rcx
movq %rbx, %r8
pushq %r14
pushq $0x0
pushq %rbp
pushq %r10
callq 0x341a2
addq $0x20, %rsp
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rax
movq %rax, %rdi
subq %rbx, %rdi
movq 0x40(%rsp), %r10
movq 0x48(%rsp), %rbp
movq %rbp, %rsi
subq %r10, %rsi
movq %rdi, %rcx
orq %rsi, %rcx
movq %r10, 0x18(%rsp)
je 0x4de11
testq %rdi, %rdi
sete %cl
testq %rsi, %rsi
setg %dl
testb %dl, %cl
movq 0x1e0(%rsp), %r8
jne 0x4ddca
testq %rsi, %rsi
sete %cl
testq %rdi, %rdi
setg %dl
testb %cl, %dl
je 0x4de87
movq %rdi, %rsi
pushq $0x1
popq %rax
movq 0x210(%rsp), %r15
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq %rsi, %r14
imull %esi, %eax
movq 0x208(%rsp), %rcx
movl %eax, 0x24(%rcx)
jmp 0x4db3d
movq 0x58(%rsp), %r9
cmpq $0x200, %r15            # imm = 0x200
jg 0x4de2e
cmpq %r12, %r15
cmovgq %r15, %r12
cvtsi2sd %r12, %xmm0
jmp 0x4de64
xorl %r14d, %r14d
movq 0x210(%rsp), %r15
movq 0x8(%rsp), %rdi
movq 0x1e0(%rsp), %r8
jmp 0x4d95e
cmpq %r12, %r15
cmovlq %r15, %r12
cvtsi2sd %r12, %xmm1
cvtsi2sd %r15, %xmm2
mulsd 0x195751(%rip), %xmm2   # 0x1e3598
addsd 0x195451(%rip), %xmm2   # 0x1e32a0
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq 0x8(%rsp), %rdi
movq 0x1e0(%rsp), %r8
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
cvttsd2si %xmm0, %r12
pushq $-0x1
jmp 0x4d867
movq %rdi, 0x58(%rsp)
movq %r14, %rcx
movq %rsi, %r14
subq $0x90, %rsp
movq 0xe0(%rsp), %r12
movq %r12, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq 0x268(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movq 0x278(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movq %rbp, 0x20(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
andq $0x0, 0x88(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, (%rsp)
andq $0x0, 0x80(%rsp)
orq $-0x1, 0x78(%rsp)
movq $0x100, 0x70(%rsp)      # imm = 0x100
movq $0x3ff, 0x68(%rsp)      # imm = 0x3FF
andq $0x0, 0x28(%rsp)
movq $0xc00, 0x60(%rsp)      # imm = 0xC00
movq 0x280(%rsp), %rdi
movq 0x288(%rsp), %rsi
movq 0xf8(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x100(%rsp), %r9
movsd 0x108(%rsp), %xmm0
callq 0x4a3ee
addq $0x90, %rsp
testq %rax, %rax
je 0x4dfbc
movslq 0x2c(%r12), %rsi
movslq 0x1c(%r12), %rbx
movq %rbx, 0x20(%rsp)
movslq 0x20(%r12), %rax
incq %rax
movq %rax, 0x28(%rsp)
movslq 0x10(%r12), %rax
movq %rax, 0x18(%rsp)
movq %rax, 0x40(%rsp)
movslq 0x14(%r12), %rbp
incq %rbp
movq %rbp, 0x48(%rsp)
pushq $0x1
popq %rax
movq 0x210(%rsp), %r15
movq 0x8(%rsp), %rdi
movq 0x1e0(%rsp), %r8
movq 0x38(%rsp), %r12
jmp 0x4ddda
movq 0x58(%rsp), %rax
cmpq $0x200, %rax            # imm = 0x200
movq 0x210(%rsp), %r15
jg 0x4dfdf
cmpq %r14, %rax
cmovgq %rax, %r14
cvtsi2sd %r14, %xmm0
jmp 0x4e015
cmpq %r14, %rax
cmovlq %rax, %r14
cvtsi2sd %r14, %xmm1
cvtsi2sd %rax, %xmm2
mulsd 0x1955a0(%rip), %xmm2   # 0x1e3598
addsd 0x1952a0(%rip), %xmm2   # 0x1e32a0
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq 0x8(%rsp), %rdi
movq 0x1e0(%rsp), %r8
movq 0x38(%rsp), %r12
movq 0x10(%rsp), %rdx
cvttsd2si %xmm0, %rsi
pushq $-0x1
popq %rax
jmp 0x4dddf
testq %rbx, %rbx
sets %cl
movq 0x1e8(%rsp), %rsi
movq %rsi, %rax
subq %rbx, %rax
setle %dl
orb %cl, %dl
jne 0x4e270
movq %r8, %rcx
subq %rbp, %rcx
leaq (%rcx,%rbx), %r13
leaq (%rax,%rbp), %r14
cmpq %rcx, %rax
cmovgq %r8, %r14
cmovleq %rsi, %r13
cmpq %rsi, %r13
cmovgeq %rsi, %r13
cmpq %r8, %r14
cmovgeq %r8, %r14
movq %r13, %r15
subq %rbx, %r15
movq %r14, %r12
subq %rbp, %r12
movq %r15, %rax
orq %r12, %rax
je 0x4e0b6
pushq $0x1
popq %rcx
testq %r15, %r15
jne 0x4e0a4
testq %r12, %r12
jg 0x4e222
testq %r15, %r15
jle 0x4e0c6
testq %r12, %r12
jne 0x4e0c6
movq %r15, %r12
jmp 0x4e222
xorl %r12d, %r12d
movq 0x210(%rsp), %r15
jmp 0x4e26d
movq %rdi, 0x8(%rsp)
subq $0x90, %rsp
movq 0xe0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %r8, 0x40(%rsp)
movq 0x268(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %r14, 0x20(%rsp)
andq $0x0, 0x88(%rsp)
movq %rbp, 0x18(%rsp)
andq $0x0, 0x80(%rsp)
movq %r13, 0x10(%rsp)
orq $-0x1, 0x78(%rsp)
movq %rbx, 0x8(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, (%rsp)
movq $0x100, 0x70(%rsp)      # imm = 0x100
movq $0x3ff, 0x68(%rsp)      # imm = 0x3FF
movq $0xc00, 0x60(%rsp)      # imm = 0xC00
andq $0x0, 0x28(%rsp)
movq $0x1, 0x48(%rsp)
movq 0x280(%rsp), %rdi
movq 0x288(%rsp), %rsi
movq 0xf8(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x100(%rsp), %r9
movsd 0x108(%rsp), %xmm0
callq 0x4a3ee
addq $0x90, %rsp
testq %rax, %rax
je 0x4e1c8
movq 0x50(%rsp), %rax
movslq 0x2c(%rax), %r12
movslq 0x1c(%rax), %rbx
movslq 0x20(%rax), %r13
incq %r13
movslq 0x10(%rax), %rbp
movslq 0x14(%rax), %r14
incq %r14
movq 0x210(%rsp), %r15
movq 0x8(%rsp), %rdi
pushq $0x1
popq %rcx
jmp 0x4e22a
cmpq $0x200, %r15            # imm = 0x200
jg 0x4e1df
cmpq %r12, %r15
cmovgq %r15, %r12
cvtsi2sd %r12, %xmm0
jmp 0x4e215
cmpq %r12, %r15
cmovlq %r15, %r12
cvtsi2sd %r12, %xmm1
cvtsi2sd %r15, %xmm2
mulsd 0x1953a0(%rip), %xmm2   # 0x1e3598
addsd 0x1950a0(%rip), %xmm2   # 0x1e32a0
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq 0x8(%rsp), %rdi
cvttsd2si %xmm0, %r12
pushq $-0x1
popq %rcx
movq 0x210(%rsp), %r15
movl 0x4(%r15), %eax
cmpq %rax, %rbx
jge 0x4e237
movl %ebx, 0x4(%r15)
movl 0x8(%r15), %eax
cmpq %rax, %r13
jle 0x4e244
movl %r13d, 0x8(%r15)
movl 0x10(%r15), %eax
cmpq %rax, %rbp
jge 0x4e251
movl %ebp, 0x10(%r15)
movl 0x14(%r15), %eax
cmpq %rax, %r14
jle 0x4e25e
movl %r14d, 0x14(%r15)
imull %r12d, %ecx
movq 0x208(%rsp), %rax
movl %ecx, 0x24(%rax)
addq %r12, %rdi
movq 0x208(%rsp), %rsi
movl 0x24(%rsi), %eax
movl 0x28(%rsi), %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
addl %edx, %ecx
movl %edi, %eax
subl %ecx, %eax
movl %eax, 0x2c(%rsi)
movl 0x18(%r15), %eax
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %eax, %edx
orl %ecx, %edx
andl %edi, %ecx
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
cmpq $0x40000000, %rdi       # imm = 0x40000000
cmovgel %edx, %eax
movl %eax, 0x18(%r15)
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x199124(%rip), %rdi    # 0x1e73f6
leaq 0x1953ca(%rip), %rsi    # 0x1e36a3
leaq 0x19912d(%rip), %rcx    # 0x1e740d
movl $0x5fcd, %edx           # imm = 0x5FCD
callq 0x2110