// File: /workspace/github_cpp_makefile_star2_O3/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 $0x218, %rsp            # imm = 0x218
movsd %xmm0, 0xf8(%rsp)
movq %rdx, 0xe0(%rsp)
movq %rsi, 0xf0(%rsp)
movq %rdi, 0xe8(%rsp)
movq 0x290(%rsp), %r10
movq 0x288(%rsp), %rbp
movq 0x250(%rsp), %rdx
movq %rcx, 0x130(%rsp)
movq 0x58(%rcx), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0xc(%r10)
movups %xmm0, (%r10)
movl $0xffffffff, 0x10(%r10) # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x4(%r10)
movups %xmm0, 0x20(%rbp)
xorl %eax, %eax
movl %eax, 0x30(%rbp)
movups %xmm0, 0x10(%rbp)
movapd 0x1b0a30(%rip), %xmm0   # 0x231560
movupd %xmm0, (%rbp)
movl %eax, 0x2c(%rbp)
subq %r9, %rdx
movq %rdx, 0x138(%rsp)
jle 0x8155c
movq %r9, %rbx
movq %r8, 0xd0(%rsp)
movq 0x260(%rsp), %r9
movq 0x258(%rsp), %r13
movq %rbx, 0xd8(%rsp)
shlq $0x5, %rbx
orq $0x1c, %rbx
movq $-0x1, %r12
xorl %edi, %edi
xorl %r8d, %r8d
movq %r13, %r11
movq %r14, 0xa8(%rsp)
movq %r14, %rcx
movslq -0x14(%r14,%rbx), %r14
movq %r14, %rax
subq %r11, %rax
movq %rdi, 0x90(%rsp)
jle 0x80bbb
movslq -0x1c(%rcx,%rbx), %r13
cmpq %r13, %r12
jge 0x80bb6
testq %r12, %r12
js 0x80bc6
xorl %eax, %eax
jmp 0x80bf6
movq %r8, %r15
jmp 0x80c3a
movq %r8, %r15
movq %rcx, %r14
jmp 0x80e61
movq %r13, %r12
subq %rax, %r12
jle 0x80be1
testq %r12, %r12
movl $0x0, %eax
cmovleq %rax, %r12
movl $0x2, %eax
jmp 0x80bf6
movq %r14, %rax
subq %r13, %rax
cmpq %r11, %rax
cmovgq %rax, %r11
movl $0x2, %eax
xorl %r12d, %r12d
movq %r13, %rbp
subq %r12, %rbp
movq %r14, %r15
subq %r11, %r15
movq %rbp, %rcx
orq %r15, %rcx
je 0x80c2f
movl $0x1, %ecx
testq %rbp, %rbp
jne 0x80c1d
testq %r15, %r15
jg 0x80e03
testq %r15, %r15
jne 0x80c47
testq %rbp, %rbp
jle 0x80c47
movq %rbp, %r15
jmp 0x80e03
movq %r8, %r15
movq 0x288(%rsp), %rbp
movq 0x258(%rsp), %r13
jmp 0x80e59
movq %r8, 0x98(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
movq 0xd0(%rsp), %rdx
movq %rdx, 0x50(%rsp)
movq %rax, 0x48(%rsp)
movq %r9, 0x40(%rsp)
movq 0x258(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x268(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %r14, 0x20(%rsp)
movq %r11, 0x18(%rsp)
movq %r13, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, (%rsp)
movq $-0x1, 0x78(%rsp)
movq $0x100, 0x70(%rsp)      # imm = 0x100
movq $0x3ff, 0x68(%rsp)      # imm = 0x3FF
movq $0xc00, 0x60(%rsp)      # imm = 0xC00
movq 0x270(%rsp), %rdi
movq 0x278(%rsp), %rsi
movq 0xe8(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0xf0(%rsp), %r9
movsd 0xf8(%rsp), %xmm0
movq %r11, 0xa0(%rsp)
callq 0x7d60e
testq %rax, %rax
je 0x80d7f
movq 0xd0(%rsp), %rax
movslq 0x2c(%rax), %r15
movslq 0x1c(%rax), %r12
movq %r12, 0xb0(%rsp)
movslq 0x20(%rax), %r13
incq %r13
movq %r13, 0xb8(%rsp)
movslq 0x10(%rax), %r11
movslq 0x14(%rax), %r14
incq %r14
movq 0x290(%rsp), %r10
movq 0x288(%rsp), %rbp
movq 0x260(%rsp), %r9
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %r8
movl $0x1, %ecx
jmp 0x80e0b
movq 0xa0(%rsp), %r11
cmpq $0x200, %rbp            # imm = 0x200
movq 0x90(%rsp), %rdi
jg 0x80da9
cmpq %r15, %rbp
cmovgq %rbp, %r15
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
jmp 0x80ddf
cmpq %r15, %rbp
cmovlq %rbp, %r15
cvtsi2sd %r15, %xmm1
cvtsi2sd %rbp, %xmm2
mulsd 0x1b0886(%rip), %xmm2   # 0x231648
addsd 0x1b0546(%rip), %xmm2   # 0x231310
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq 0x290(%rsp), %r10
movq 0x260(%rsp), %r9
movq 0x98(%rsp), %r8
cvttsd2si %xmm0, %r15
movq $-0x1, %rcx
movq 0x288(%rsp), %rbp
movl 0x4(%r10), %eax
cmpq %rax, %r12
jge 0x80e18
movl %r12d, 0x4(%r10)
movl 0x8(%r10), %eax
cmpq %rax, %r13
jle 0x80e25
movl %r13d, 0x8(%r10)
movl 0x10(%r10), %eax
cmpq %rax, %r11
jge 0x80e32
movl %r11d, 0x10(%r10)
movl 0x14(%r10), %eax
cmpq %rax, %r14
movq 0x258(%rsp), %r13
jle 0x80e47
movl %r14d, 0x14(%r10)
addq %r15, %r8
testq %rdi, %rdi
jne 0x80e56
imull %r15d, %ecx
movl %ecx, 0x28(%rbp)
movq %r8, %r15
movq 0xa8(%rsp), %r14
movl -0x1c(%r14,%rbx), %edi
movslq %edi, %rcx
movq %rcx, 0xb0(%rsp)
movl -0x14(%r14,%rbx), %r8d
movslq %r8d, %r12
movslq -0x18(%r14,%rbx), %rsi
leaq 0x1(%rsi), %rax
movq %rax, 0xb8(%rsp)
movslq -0x10(%r14,%rbx), %rdx
leaq 0x1(%rdx), %r11
cmpq %r13, %r12
jl 0x80f47
cmpq %r9, %r11
jg 0x80f47
movq %r12, 0xc8(%rsp)
movq %r11, 0xa0(%rsp)
movq %r10, %r11
movq %r15, %r10
movq %r13, %r15
movswq -0x8(%r14,%rbx), %r13
movl (%r14,%rbx), %r9d
movq %r13, %r12
cmpq $0x7fff, %r13           # imm = 0x7FFF
jne 0x80ee9
testl %r9d, %r9d
jne 0x80ee9
xorl %r9d, %r9d
cmpw $0x0, -0xa(%r14,%rbx)
js 0x81215
movq %r15, %r13
movq %r10, %r15
cmpl %edi, (%rbp)
movq %r11, %r10
jg 0x80efd
cmpl %r8d, 0x8(%rbp)
jle 0x80f20
movl %edi, (%rbp)
movl %r8d, 0x8(%rbp)
movq 0x90(%rsp), %rcx
movq 0xd8(%rsp), %rdi
addl %edi, %ecx
movl %ecx, 0x10(%rbp)
movl $0x0, 0x18(%rbp)
cmpl %esi, 0x4(%rbp)
movq 0xa0(%rsp), %r11
jle 0x80fa4
cmpl %edx, 0xc(%rbp)
jle 0x80fa4
movq 0x260(%rsp), %r9
movq 0x90(%rsp), %rdi
jmp 0x80fcc
cmpq %r13, %r12
jge 0x80f62
movq $-0x1, 0xb0(%rsp)
movq $-0x1, %rcx
movq %r13, %r12
cmpq %r9, %r11
jle 0x80fd4
movq $-0x1, 0xb8(%rsp)
cmpq $-0x1, %rcx
setne %sil
movq $-0x1, %rax
xorl %edx, %edx
movq %r9, %r11
testb %sil, %sil
je 0x80ff1
cmpq $-0x1, %rax
jne 0x80ff1
movl $0x1, %esi
movb $0x1, %dl
movq $-0x1, %rax
xorl %edi, %edi
jmp 0x81006
movl %eax, 0x4(%rbp)
movl %r11d, 0xc(%rbp)
movq 0x90(%rsp), %rdi
movq 0xd8(%rsp), %rax
addl %edi, %eax
movl %eax, 0x14(%rbp)
movl %r9d, 0x1c(%rbp)
movq 0x260(%rsp), %r9
movq %r12, %r8
jmp 0x811a4
cmpl $-0x1, %eax
setne %dl
cmpq $-0x1, %rcx
setne %sil
je 0x80f87
cmpl $-0x1, %eax
je 0x80f87
xorl %edx, %edx
xorl %edi, %edi
xorl %esi, %esi
jmp 0x81006
cmpq $-0x1, %rcx
sete %dil
andb %dl, %dil
movzbl %dil, %esi
xorq $0x3, %rsi
xorl %edx, %edx
cmpw $0x7fff, -0x8(%r14,%rbx) # imm = 0x7FFF
jne 0x81024
cmpl $0x0, (%r14,%rbx)
jne 0x81024
cmpw $0x0, -0xa(%r14,%rbx)
js 0x8128b
movq 0x130(%rsp), %rdx
movq 0x58(%rdx), %rax
movl -0x4(%rax,%rbx), %ecx
addq %rcx, %rcx
addq 0x70(%rdx), %rcx
movq %rcx, 0x1f8(%rsp)
movl (%rax,%rbx), %ecx
movq %rcx, 0x1f0(%rsp)
movq %rcx, 0x1e8(%rsp)
movq -0x1c(%rax,%rbx), %rcx
movq %rcx, 0x15c(%rsp)
movq -0x14(%rax,%rbx), %rcx
movq %rcx, 0x150(%rsp)
movswl -0x8(%rax,%rbx), %eax
movl %eax, 0x16c(%rsp)
movl %eax, 0x168(%rsp)
leaq 0x108(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x100(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x118(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x128(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, (%rsp)
leaq 0x140(%rsp), %rdi
movq %r12, %rdx
movq %r11, %r14
movq %r11, %rcx
leaq 0xb0(%rsp), %r8
leaq 0xb8(%rsp), %r9
callq 0x7dbfa
movq %rax, %r8
movq 0x120(%rsp), %rax
movq 0x100(%rsp), %rdx
movq 0x110(%rsp), %rcx
movslq (%rbp), %rsi
cmpq %rsi, %rdx
movq 0x90(%rsp), %rdi
jl 0x8112b
movslq 0x8(%rbp), %rsi
cmpq %rsi, %rcx
jge 0x81141
movl %edx, (%rbp)
movl %ecx, 0x8(%rbp)
movq 0xd8(%rsp), %rcx
addl %edi, %ecx
movl %ecx, 0x10(%rbp)
movl %eax, 0x18(%rbp)
movq %r12, 0xc8(%rsp)
movq 0x128(%rsp), %rax
movq 0x108(%rsp), %rdx
movq 0x118(%rsp), %rcx
movslq 0x4(%rbp), %rsi
cmpq %rsi, %rdx
movq 0x290(%rsp), %r10
movq 0x260(%rsp), %r9
jg 0x81183
movslq 0xc(%rbp), %rsi
cmpq %rsi, %rcx
jle 0x81199
movl %edx, 0x4(%rbp)
movl %ecx, 0xc(%rbp)
movq 0xd8(%rsp), %rcx
addl %edi, %ecx
movl %ecx, 0x14(%rbp)
movl %eax, 0x1c(%rbp)
movq %r14, %r11
movq 0xa8(%rsp), %r14
movl 0x4(%r10), %ecx
movq 0xb0(%rsp), %rax
cmpq %rcx, %rax
jge 0x811b9
movl %eax, 0x4(%r10)
movl 0x8(%r10), %eax
movq 0xb8(%rsp), %r12
cmpq %rax, %r12
jle 0x811ce
movl %r12d, 0x8(%r10)
movl 0x10(%r10), %eax
movq 0xc8(%rsp), %rcx
cmpq %rax, %rcx
jge 0x811e3
movl %ecx, 0x10(%r10)
movl 0x14(%r10), %eax
cmpq %rax, %r11
jle 0x811f0
movl %r11d, 0x14(%r10)
addq %r15, %r8
movq %r12, 0xb0(%rsp)
addq $0x20, %rbx
incq %rdi
cmpq %rdi, 0x138(%rsp)
jne 0x80b8b
jmp 0x81564
movq %rax, %r9
subq %rcx, %r9
movq 0xa0(%rsp), %rcx
subq 0xc8(%rsp), %rcx
cmpq $0x200, %r9             # imm = 0x200
jg 0x81245
cmpq %rcx, %r9
cmovgq %r9, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
jmp 0x8127b
cmpq %rcx, %r9
cmovlq %r9, %rcx
cvtsi2sd %rcx, %xmm1
cvtsi2sd %r9, %xmm2
mulsd 0x1b03ea(%rip), %xmm2   # 0x231648
addsd 0x1b00aa(%rip), %xmm2   # 0x231310
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq %r15, %r13
cvttsd2si %xmm0, %r12
xorl %r9d, %r9d
jmp 0x80eec
orb %dil, %dl
je 0x81806
movq %rax, %rdx
cmpl $0x2, %esi
je 0x812c3
movq %rcx, %r8
movq %r11, %rdi
movq %r12, %r9
cmpl $0x1, %esi
jne 0x812fc
movq %rax, %rdi
subq %rcx, %rdi
movq %r11, %rdx
subq %r12, %rdx
cmpq %rdx, %rdi
jle 0x812df
addq %rcx, %rdx
movq %rcx, %r8
jmp 0x812da
subq %rcx, %rdx
movq %r11, %rdi
subq %r12, %rdi
cmpq %rdi, %rdx
jle 0x812ed
movq %rax, %r8
subq %rdi, %r8
movq %rax, %rdx
movq %r11, %rdi
jmp 0x812e8
addq %r12, %rdi
movq %rax, %rdx
movq %rcx, %r8
movq %r12, %r9
jmp 0x812fc
movq %r11, %r9
subq %rdx, %r9
movq %rax, %rdx
movq %rcx, %r8
movq %r11, %rdi
cmpq %rcx, %r8
cmovgq %r8, %rcx
movq %rcx, 0xb0(%rsp)
cmpq %r12, %r9
cmovgq %r9, %r12
cmpq %rax, %rdx
cmovlq %rdx, %rax
movq %rax, 0xb8(%rsp)
cmpq %r11, %rdi
cmovlq %rdi, %r11
movq %r12, %rdx
movq %rax, %r12
subq %rcx, %r12
movq %r11, %r8
movq %rdx, 0xc8(%rsp)
subq %rdx, %r8
movq %r12, %rdx
orq %r8, %rdx
je 0x81375
movl $0x1, %r14d
testq %r12, %r12
movq 0x260(%rsp), %r9
jne 0x81363
testq %r8, %r8
jg 0x814ae
testq %r8, %r8
jne 0x8138d
testq %r12, %r12
jle 0x8138d
movq %r12, %r8
jmp 0x814ae
xorl %r8d, %r8d
movq 0x260(%rsp), %r9
movq 0x90(%rsp), %rdi
jmp 0x811a4
movq %r8, 0x98(%rsp)
xorl %edi, %edi
movq %rdi, 0x88(%rsp)
movq %rdi, 0x80(%rsp)
movq %r13, %rdx
movq 0xd0(%rsp), %r13
movq %r13, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %r9, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq 0x268(%rsp), %rdx
movq %rdx, 0x30(%rsp)
movq %rdi, 0x28(%rsp)
movq %r11, 0x20(%rsp)
movq 0xc8(%rsp), %rdx
movq %rdx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, (%rsp)
movq $-0x1, 0x78(%rsp)
movq $0x100, 0x70(%rsp)      # imm = 0x100
movq $0x3ff, 0x68(%rsp)      # imm = 0x3FF
movq $0xc00, 0x60(%rsp)      # imm = 0xC00
movq 0x270(%rsp), %rdi
movq 0x278(%rsp), %rsi
movq 0xe8(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0xf0(%rsp), %r9
movsd 0xf8(%rsp), %xmm0
movq %r11, 0xa0(%rsp)
callq 0x7d60e
testq %rax, %rax
je 0x814c3
movslq 0x2c(%r13), %r8
movslq 0x1c(%r13), %rax
movq %rax, 0xb0(%rsp)
movslq 0x20(%r13), %rax
incq %rax
movq %rax, 0xb8(%rsp)
movslq 0x10(%r13), %rax
movq %rax, 0xc8(%rsp)
movslq 0x14(%r13), %r11
incq %r11
movq 0x290(%rsp), %r10
movq 0x258(%rsp), %r13
movq 0x260(%rsp), %r9
movq 0x90(%rsp), %rdi
imull %r8d, %r14d
movl %r14d, 0x24(%rbp)
jmp 0x8119c
movq 0xa0(%rsp), %r11
cmpq $0x200, %r12            # imm = 0x200
movq 0x290(%rsp), %r10
jg 0x814f5
movq 0x98(%rsp), %rax
cmpq %rax, %r12
cmovgq %r12, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
jmp 0x81533
movq 0x98(%rsp), %rax
cmpq %rax, %r12
cmovlq %r12, %rax
cvtsi2sd %rax, %xmm1
cvtsi2sd %r12, %xmm2
mulsd 0x1b0132(%rip), %xmm2   # 0x231648
addsd 0x1afdf2(%rip), %xmm2   # 0x231310
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq 0x258(%rsp), %r13
movq 0x260(%rsp), %r9
movq 0x90(%rsp), %rdi
cvttsd2si %xmm0, %r8
movq $-0x1, %r14
jmp 0x814b6
xorl %r8d, %r8d
jmp 0x817b1
testq %r12, %r12
sets %cl
movq 0x268(%rsp), %rsi
movq %rsi, %rax
subq %r12, %rax
setle %dl
orb %cl, %dl
jne 0x817b1
movq %r9, %rcx
subq %r11, %rcx
leaq (%r12,%rcx), %rbp
leaq (%rax,%r11), %rbx
cmpq %rcx, %rax
cmovleq %rsi, %rbp
cmovgq %r9, %rbx
cmpq %rsi, %rbp
cmovgeq %rsi, %rbp
cmpq %r9, %rbx
cmovgeq %r9, %rbx
movq %rbp, %r14
subq %r12, %r14
movq %rbx, %r15
subq %r11, %r15
movq %r14, %rax
orq %r15, %rax
je 0x815e3
movl $0x1, %ecx
testq %r14, %r14
jne 0x815d1
testq %r15, %r15
jg 0x8176b
testq %r15, %r15
jne 0x815f3
testq %r14, %r14
jle 0x815f3
movq %r14, %r15
jmp 0x8176b
xorl %r15d, %r15d
movq 0x288(%rsp), %rbp
jmp 0x817ae
movq %r8, 0x98(%rsp)
xorl %eax, %eax
movq %rax, 0x88(%rsp)
movq %rax, 0x80(%rsp)
movq %r13, %rcx
movq 0xd0(%rsp), %r13
movq %r13, 0x50(%rsp)
movq %r9, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq 0x268(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x18(%rsp)
movq %rbp, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, (%rsp)
movq $-0x1, 0x78(%rsp)
movq $0x100, 0x70(%rsp)      # imm = 0x100
movq $0x3ff, 0x68(%rsp)      # imm = 0x3FF
movq $0xc00, 0x60(%rsp)      # imm = 0xC00
movq $0x1, 0x48(%rsp)
movq 0x270(%rsp), %rdi
movq 0x278(%rsp), %rsi
movq 0xe8(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0xf0(%rsp), %r9
movsd 0xf8(%rsp), %xmm0
movq %r11, 0xa0(%rsp)
callq 0x7d60e
testq %rax, %rax
je 0x816f7
movslq 0x2c(%r13), %r15
movslq 0x1c(%r13), %r12
movslq 0x20(%r13), %rbp
incq %rbp
movslq 0x10(%r13), %r11
movslq 0x14(%r13), %rbx
incq %rbx
movq 0x290(%rsp), %r10
movq 0x98(%rsp), %r8
movl $0x1, %ecx
jmp 0x8176b
movq 0xa0(%rsp), %r11
cmpq $0x200, %r14            # imm = 0x200
jg 0x81719
cmpq %r15, %r14
cmovgq %r14, %r15
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
jmp 0x8174f
cmpq %r15, %r14
cmovlq %r14, %r15
cvtsi2sd %r15, %xmm1
cvtsi2sd %r14, %xmm2
mulsd 0x1aff16(%rip), %xmm2   # 0x231648
addsd 0x1afbd6(%rip), %xmm2   # 0x231310
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq 0x290(%rsp), %r10
movq 0x98(%rsp), %r8
cvttsd2si %xmm0, %r15
movq $-0x1, %rcx
movl 0x4(%r10), %eax
cmpq %rax, %r12
jge 0x81778
movl %r12d, 0x4(%r10)
movl 0x8(%r10), %eax
cmpq %rax, %rbp
jle 0x81785
movl %ebp, 0x8(%r10)
movl 0x10(%r10), %eax
cmpq %rax, %r11
jge 0x81792
movl %r11d, 0x10(%r10)
movl 0x14(%r10), %eax
cmpq %rax, %rbx
movq 0x288(%rsp), %rbp
jle 0x817a7
movl %ebx, 0x14(%r10)
imull %r15d, %ecx
movl %ecx, 0x24(%rbp)
addq %r15, %r8
movl 0x24(%rbp), %eax
movl 0x28(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
addl %edx, %ecx
movl %r8d, %eax
subl %ecx, %eax
movl %eax, 0x2c(%rbp)
movl 0x18(%r10), %eax
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %eax, %edx
orl %ecx, %edx
andl %r8d, %ecx
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
cmpq $0x40000000, %r8        # imm = 0x40000000
cmovgel %edx, %eax
movl %eax, 0x18(%r10)
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b3c99(%rip), %rdi    # 0x2354a6
leaq 0x1aff3f(%rip), %rsi    # 0x231753
leaq 0x1b3ca2(%rip), %rcx    # 0x2354bd
movl $0x5fcd, %edx           # imm = 0x5FCD
callq 0x2110