// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: get_rid_backward_cigar_err(rtrace_iter*, ul_ov_t*, kv_rtrace_t*, rtrace_t*, ul_idx_t const*, char*, UC_Read*, overlap_region_alloc*, overlap_region*, bit_extz_t*, double, long)
int64_t get_rid_backward_cigar_err(rtrace_iter *it, ul_ov_t *aln, kv_rtrace_t *trace, rtrace_t *tc,
const ul_idx_t *uref, char* qstr, UC_Read *tu, overlap_region_alloc *ol, overlap_region *o, 
bit_extz_t *exz, double e_rate, int64_t qs)
{
    //this is not right
    // if(qs == aln->qe) return 0;
    if(!tc) tc = &(trace->a[aln->qn]);
    if(!o) o = &(ol->list[tc->oid]);
    if(it->k < tc->c_wsid && qs > ((int64_t)aln->qs)) it->k = INT32_MAX;

    if(it->k == INT32_MAX) {
        it->k = tc->c_weid;
        it->q[1] = MAX(tc->c_qe, ((int64_t)aln->qe)); 
        it->t[1] = MAX(tc->c_te, ((int64_t)aln->te));
        it->qoff = MAX(tc->c_qe, ((int64_t)aln->qe));
        it->toff = MAX(tc->c_te, ((int64_t)aln->te));
        it->cur_qoff = MAX(tc->c_qe, ((int64_t)aln->qe));

        it->werr = it->werr0 = it->cerr = 0; 
        it->f = 0;
        it->coff = INT32_MAX; 
        clear_align(*exz); 
        exz->ps = exz->pe = exz->ts = exz->te = INT32_MAX;
    }
    // if(qs == 45766) {
    //     fprintf(stderr, "\n[M::%s::] q::[%u, %u), t::[%u, %u), tot_e::%u, cid::[%d, %d], cq::[%u, %u), ct::[%u, %u), pfx_e::%d, sfx_e::%d, mid_e::%d\n", 
    //                     __func__, aln->qs, aln->qe, aln->ts, aln->te, aln->sec, tc->c_wsid, tc->c_weid,
    //                     tc->c_qs, tc->c_qe, tc->c_ts, tc->c_te, tc->pfx_e, tc->sfx_e, tc->mid_e);
    // }
    
    window_list *wa = o->w_list.a; int64_t qwl, twl, sub_err; bit_extz_t aux; 
    assert(qs <= it->qoff);
    if(qs == it->cur_qoff) return it->werr0;

    // if(qs == 166327) {
        // fprintf(stderr, "\n-*-[M::%s::k->%ld] qoff::%ld, toff::%ld, coff::%ld, inner_q::[%ld, %ld), inner_t::[%ld, %ld), werr::%ld, qs::%ld, cur_qoff::%ld, werr0::%ld\n", 
        //     __func__, it->k, it->qoff, it->toff, it->coff, it->q[0], it->q[1], it->t[0], it->t[1], it->werr, qs, 
        //     it->cur_qoff, it->werr0);
    // }

    for (; it->k >= tc->c_wsid; it->k--) {
        it->q[0] = wa[it->k].x_end+1; 
        it->t[0] = wa[it->k].y_end+1;
        // if(qs == 166327) {
            // fprintf(stderr, "-0-[M::%s::k->%ld] qoff::%ld, toff::%ld, coff::%ld, inner_q::[%ld, %ld), inner_t::[%ld, %ld), werr::%ld, qs::%ld, cur_qoff::%ld, werr0::%ld, f::%ld\n", 
            //     __func__, it->k, it->qoff, it->toff, it->coff, it->q[0], it->q[1], it->t[0], it->t[1], it->werr, qs, 
            //     it->cur_qoff, it->werr0, it->f);
        // }
        ///now qs >= it->qoff -> qs >= q[0]
        if(it->f == 0) {
            if(it->qoff >= it->q[0]) {///[it->qoff, ql) has been calculated
                if(it->q[0] <= it->q[1] && it->t[0] <= it->t[1]) {
                    if((exz->ps != it->t[0]) || (exz->pe != it->t[1]) || (exz->ts != it->q[0]) || (exz->te == it->q[1])) {
                        ///calculate on-the-fly
                        gen_clip_win_err(o, it->q[0], it->q[1], it->t[0], it->t[1], e_rate, it->k==tc->c_weid?tc->sfx_e:-1, uref, qstr, tu, exz);
                    }
                    sub_err = INT32_MAX;
                    ///if there are indels at either ends of t, qs == it->q[0] || qs == it->q[1]
                    if(qs >= it->q[0] && qs <= it->q[1]) {
                        ///phrase cigar
                        sub_err = extract_sub_werr(exz, 0, exz->cigar.n, exz->ps, exz->pe+1, exz->ts, exz->te+1, 
                                exz->ps, exz->pe+1, exz->ts, exz->te+1, qs, it);
                        if(sub_err != INT32_MAX) {///find the coordinate for qs
                            if((it->cur_qoff != qs) || ((it->werr+sub_err) > it->werr0)) {
                                it->werr0 = it->werr+sub_err;
                            }
                            it->cur_qoff = qs;
                            if(qs > it->q[0] && qs <= it->q[1]) return it->werr0;
                        } else {///happen when qs == it->q[1] and no indels at the right end
                            it->qoff = it->q[1]; 
                            it->toff = it->t[1]; 
                            // assert(it->cur_qoff == qs);
                            it->cur_qoff = qs;
                            return it->werr0;
                        } 
                    } 

                    if(qs <= it->q[0]) {
                        it->qoff = it->q[0]; 
                        it->toff = it->t[0]; 
                        it->werr += exz->err;
                        it->f = 1;
                        if((it->cur_qoff != it->q[0]) || (it->werr > it->werr0)) {
                            it->werr0 = it->werr;
                        }
                        it->cur_qoff = it->q[0];
                    }
                } else {
                    it->f = 1;
                }
            } else {
                it->f = 1;
            }
        }
        
        it->cq[0] = it->q[0] = wa[it->k].x_start; it->cq[1] = it->q[1] = wa[it->k].x_end+1; 
        it->ct[0] = it->t[0] = wa[it->k].y_start; it->ct[1] = it->t[1] = wa[it->k].y_end+1; 
        it->ci[0] = 0; it->ci[1] = wa[it->k].clen; qwl = it->q[1] - it->q[0]; twl = it->t[1] - it->t[0];
        // if(qs == 166327) {
            // fprintf(stderr, "-1-[M::%s::k->%ld] qoff::%ld, toff::%ld, coff::%ld, inner_q::[%ld, %ld), inner_t::[%ld, %ld), werr::%ld, qs::%ld, cur_qoff::%ld, werr0::%ld, f::%ld\n", 
            //     __func__, it->k, it->qoff, it->toff, it->coff, it->q[0], it->q[1], it->t[0], it->t[1], 
            //     it->werr, qs, it->cur_qoff, it->werr0, it->f);
        // }
        if(is_ualn_win(wa[it->k])) {
            if(it->qoff >= it->q[0] && it->f == 1) {
                ///ignore indels of t at both ends; so ignore qs == it->q[0] and qs == it->q[1]
                if(qs == it->q[1]) {
                    // assert(it->cur_qoff == qs);
                    it->cur_qoff = qs;
                    return it->werr0;
                }
                if(qs > it->q[0] && qs < it->q[1]) {
                    sub_err = ((((double)(it->q[1]-qs))/((double)(it->q[1]-it->q[0])))*
                                                                    (gen_err_unaligned(qwl, twl))); 
                    return it->werr+sub_err;
                }
                ///qs <= it->q[0]
                it->qoff = it->q[0]; 
                it->toff = it->t[0]; 
                it->werr += gen_err_unaligned(qwl, twl); 
                it->f = 0;
                if((it->cur_qoff != it->q[0]) || (it->werr > it->werr0)) {
                    it->werr0 = it->werr;
                }
                it->cur_qoff = it->q[0];
            }
        } else {
            set_bit_extz_t(aux, (*o), it->k); 
            if(it->k == tc->c_wsid) {
                it->cq[0] = tc->c_qs; it->ct[0] = tc->c_ts; it->ci[0] = tc->c_wsii;
                it->q[0] = MAX((int32_t)aln->qs, tc->c_qs);
                it->t[0] = MAX((int32_t)aln->ts, tc->c_ts);
            }
            if(it->k == tc->c_weid) {
                it->cq[1] = tc->c_qe; it->ct[1] = tc->c_te; it->ci[1] = tc->c_weii;
                it->q[1] = MIN((int32_t)aln->qe, tc->c_qe);
                it->t[1] = MIN((int32_t)aln->te, tc->c_te);
            }

            if(it->qoff >= it->q[0] && it->f == 1) {
                sub_err = INT32_MAX;
                ///if there are indels at either ends of t, qs == it->q[0] || qs == it->q[1]
                if(qs >= it->q[0] && qs <= it->q[1]) {
                    sub_err = extract_sub_werr(&aux, it->ci[0], it->ci[1], it->ct[0], it->ct[1], 
                        it->cq[0], it->cq[1], it->t[0], it->t[1], it->q[0], it->q[1], qs, it);
                    // if(qs == 166327) {
                        // fprintf(stderr, "-3-[M::%s::k->%ld] qoff::%ld, toff::%ld, coff::%ld, inner_q::[%ld, %ld), inner_t::[%ld, %ld), werr::%ld, qs::%ld, cur_qoff::%ld, werr0::%ld, f::%ld, sub_err::%ld\n", 
                        //     __func__, it->k, it->qoff, it->toff, it->coff, it->q[0], it->q[1], it->t[0], it->t[1], it->werr, qs, 
                        //     it->cur_qoff, it->werr0, it->f, sub_err);
                    // }
                    if(sub_err != INT32_MAX) {///find the coordinate for qs
                        if((it->cur_qoff != qs) || ((it->werr+sub_err) > it->werr0)) {
                            it->werr0 = it->werr+sub_err;
                        }
                        it->cur_qoff = qs;
                        if(qs > it->q[0] && qs <= it->q[1]) return it->werr0;
                    } else {///happen when qs == it->q[1] and no indels at the right end
                        it->qoff = it->q[1]; 
                        it->toff = it->t[1]; 
                        // if(!(it->cur_qoff == qs)) {
                        //     fprintf(stderr, "\n[M::%s::] q::[%u, %u), t::[%u, %u), tot_e::%u, cid::[%d, %d], cq::[%u, %u), ct::[%u, %u), pfx_e::%d, sfx_e::%d, mid_e::%d\n", 
                        //     __func__, aln->qs, aln->qe, aln->ts, aln->te, aln->sec, tc->c_wsid, tc->c_weid,
                        //     tc->c_qs, tc->c_qe, tc->c_ts, tc->c_te, tc->pfx_e, tc->sfx_e, tc->mid_e);
                        // }
                        // assert(it->cur_qoff == qs);
                        it->cur_qoff = qs;
                        return it->werr0;
                    } 
                }
                // if(qs == 166327) {
                    // fprintf(stderr, "-4-[M::%s::k->%ld] qoff::%ld, toff::%ld, coff::%ld, inner_q::[%ld, %ld), inner_t::[%ld, %ld), werr::%ld, qs::%ld, cur_qoff::%ld, werr0::%ld, f::%ld, sub_err::%ld\n", 
                    //     __func__, it->k, it->qoff, it->toff, it->coff, it->q[0], it->q[1], it->t[0], it->t[1], it->werr, qs, 
                    //     it->cur_qoff, it->werr0, it->f, sub_err);
                // }
                ///qs <= it->q[0]
                if(qs <= it->q[0]) {
                    it->werr += ((qs==it->q[0])?(sub_err):(extract_sub_werr(&aux, it->ci[0], it->ci[1], it->ct[0], it->ct[1], 
                                    it->cq[0], it->cq[1], it->t[0], it->t[1], it->q[0], it->q[1], it->q[0], it)));
                    it->qoff = it->q[0]; 
                    it->toff = it->t[0]; 
                    it->f = 0;
                    if((it->cur_qoff != it->q[0]) || (it->werr > it->werr0)) {
                        it->werr0 = it->werr;
                    }
                    it->cur_qoff = it->q[0];
                }
            }
        }
        it->q[1] = it->q[0]; it->t[1] = it->t[0];
        // if(qs == 166327) {
            // fprintf(stderr, "-#-[M::%s::k->%ld] qoff::%ld, toff::%ld, coff::%ld, inner_q::[%ld, %ld), inner_t::[%ld, %ld), werr::%ld, qs::%ld, cur_qoff::%ld, werr0::%ld, f::%ld\n", 
            //     __func__, it->k, it->qoff, it->toff, it->coff, it->q[0], it->q[1], it->t[0], it->t[1], it->werr, qs, 
            //     it->cur_qoff, it->werr0, it->f);
        // }
    }

    it->q[0] = aln->qs; it->t[0] = aln->ts;
    if(it->qoff >= it->q[0] && it->f == 0) {
        if(it->q[0] <= it->q[1] && it->t[0] <= it->t[1]) {
            if((exz->ps != it->t[0]) || (exz->pe != it->t[1]) || (exz->ts != it->q[0]) || (exz->te == it->q[1])) {
                ///calculate on-the-fly
                gen_clip_win_err(o, it->q[0], it->q[1], it->t[0], it->t[1], e_rate, tc->pfx_e, uref, qstr, tu, exz);
            }
            sub_err = INT32_MAX;
            ///if there are indels at either ends of t, qs == it->q[0] || qs == it->q[1]
            if(qs >= it->q[0] && qs <= it->q[1]) {
                ///phrase cigar
                sub_err = extract_sub_werr(exz, 0, exz->cigar.n, exz->ps, exz->pe+1, exz->ts, exz->te+1, 
                            exz->ps, exz->pe+1, exz->ts, exz->te+1, qs, it);
                if(sub_err != INT32_MAX) {///find the coordinate for qs
                    if((it->cur_qoff != qs) || ((it->werr+sub_err) > it->werr0)) {
                        it->werr0 = it->werr+sub_err;
                    }
                    it->cur_qoff = qs;
                    if(qs > it->q[0] && qs <= it->q[1]) return it->werr0;
                } else {///happen when qs == it->q[1] and no indels at the right end
                    it->qoff = it->q[1]; 
                    it->toff = it->t[1]; 
                    // assert(it->cur_qoff == qs);
                    it->cur_qoff = qs;
                    return it->werr0;
                } 
            } 

            if(qs <= it->q[0]) {
                it->qoff = it->q[0]; 
                it->toff = it->t[0]; 
                it->werr += exz->err;
                it->f = 1;
                if((it->cur_qoff != it->q[0]) || (it->werr > it->werr0)) {
                    it->werr0 = it->werr;
                }
                it->cur_qoff = it->q[0];
            }
        }
    } 
    // if(it->k < tc->c_wsid) it->werr = aln->sec;
    return it->werr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movsd %xmm0, 0x18(%rsp)
movq %r9, 0x20(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, %r13
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movq 0x150(%rsp), %r15
testq %rcx, %rcx
jne 0x7feef
movq 0x8(%rsp), %rax
movl (%rax), %eax
imulq $0x34, %rax, %r13
addq (%rdx), %r13
testq %r15, %r15
jne 0x7ff0a
movq 0x148(%rsp), %rax
movslq 0x30(%r13), %rcx
imulq $0xa8, %rcx, %r15
addq (%rax), %r15
movq 0x160(%rsp), %r14
movq 0x158(%rsp), %rbp
movq (%rbx), %rax
movslq 0x10(%r13), %rcx
cmpq %rcx, %rax
jge 0x7ff3c
movq 0x8(%rsp), %rdx
movl 0x4(%rdx), %edx
cmpq %r14, %rdx
jl 0x7ff44
movq 0x70(%rbx), %rdx
jmp 0x7ffbd
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jne 0x7ff33
movslq 0x14(%r13), %rax
movq %rax, (%rbx)
movslq 0x4(%r13), %rsi
movq 0x8(%rsp), %rdi
movl 0x8(%rdi), %edx
cmpq %rdx, %rsi
cmovgq %rsi, %rdx
movq %rdx, 0x10(%rbx)
movslq 0xc(%r13), %rsi
movl 0x14(%rdi), %edi
cmpq %rdi, %rsi
cmovgq %rsi, %rdi
movq %rdi, 0x20(%rbx)
movq %rdx, 0x70(%rbx)
movq %rdi, 0x80(%rbx)
movq %rdx, 0x90(%rbx)
xorl %esi, %esi
movq %rsi, 0x78(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x58(%rbx)
movq %rsi, 0x68(%rbx)
movq $0x7fffffff, 0x88(%rbx) # imm = 0x7FFFFFFF
movl $0x7fffffff, 0x2c(%rbp) # imm = 0x7FFFFFFF
movabsq $0x7fffffff7fffffff, %rsi # imm = 0x7FFFFFFF7FFFFFFF
movq %rsi, 0x1c(%rbp)
movq %rsi, 0x10(%rbp)
cmpq %r14, %rdx
jl 0x8078a
cmpq %r14, 0x90(%rbx)
jne 0x7ffd8
movq 0x60(%rbx), %rcx
jmp 0x80615
cmpq %rcx, %rax
jl 0x80529
movq 0x58(%r15), %r14
movq %r15, 0x10(%rsp)
movq %rax, %rcx
shlq $0x5, %rcx
movslq 0x4(%r14,%rcx), %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movslq 0xc(%r14,%rcx), %rcx
incq %rcx
movq %rcx, 0x18(%rbx)
cmpq $0x0, 0x78(%rbx)
jne 0x80034
cmpq %rsi, 0x70(%rbx)
jl 0x8002c
movq 0x10(%rbx), %rdx
cmpq %rsi, %rdx
jl 0x8002c
movq 0x20(%rbx), %r8
cmpq %rcx, %r8
jge 0x8033f
movq $0x1, 0x78(%rbx)
movq (%rbx), %rax
movq %rax, %rsi
shlq $0x5, %rsi
movslq (%r14,%rsi), %r9
movq %r9, 0x8(%rbx)
movq %r9, 0x28(%rbx)
movslq 0x4(%r14,%rsi), %r10
incq %r10
movq %r10, 0x10(%rbx)
movq %r10, 0x30(%rbx)
movslq 0x8(%r14,%rsi), %rcx
movq %rcx, 0x18(%rbx)
movq %rcx, 0x38(%rbx)
movslq 0xc(%r14,%rsi), %r11
incq %r11
movq %r11, 0x20(%rbx)
movq %r11, 0x40(%rbx)
movq $0x0, 0x48(%rbx)
movl 0x1c(%r14,%rsi), %edi
movl %edi, %edx
movq %rdx, 0x50(%rbx)
cmpw $0x7fff, 0x14(%r14,%rsi) # imm = 0x7FFF
sete %r8b
testl %edi, %edi
sete %dil
andb %r8b, %dil
cmpb $0x1, %dil
jne 0x800b4
leaq (%r14,%rsi), %rdi
cmpw $0x0, 0x12(%rdi)
js 0x80248
movq 0x58(%r15), %rdi
movl 0x18(%rdi,%rsi), %r8d
addq %r8, %r8
addq 0x70(%r15), %r8
movq %r8, 0xe8(%rsp)
movl 0x1c(%rdi,%rsi), %r8d
movq %r8, 0xe0(%rsp)
movq %r8, 0xd8(%rsp)
movq (%rdi,%rsi), %r8
movq %r8, 0x4c(%rsp)
movq 0x8(%rdi,%rsi), %r8
movq %r8, 0x40(%rsp)
movswl 0x14(%rdi,%rsi), %esi
movl %esi, 0x5c(%rsp)
movl %esi, 0x58(%rsp)
movslq 0x10(%r13), %rsi
cmpq %rsi, %rax
jne 0x8014d
movslq (%r13), %rcx
movq %rcx, 0x28(%rbx)
movslq 0x8(%r13), %rdi
movq %rdi, 0x38(%rbx)
movslq 0x18(%r13), %rsi
movq %rsi, 0x48(%rbx)
movq 0x8(%rsp), %r12
movl 0x4(%r12), %r8d
cmpl %ecx, %r8d
cmovlel %ecx, %r8d
movslq %r8d, %r9
movq %r9, 0x8(%rbx)
movl 0x10(%r12), %ecx
cmpl %edi, %ecx
cmovlel %edi, %ecx
movslq %ecx, %rcx
movq %rcx, 0x18(%rbx)
jmp 0x8014f
xorl %esi, %esi
movslq 0x14(%r13), %rdi
movq %r11, %r8
movq %r10, %r12
cmpq %rdi, %rax
jne 0x8019d
movslq 0x4(%r13), %r10
movq %r10, 0x30(%rbx)
movslq 0xc(%r13), %r8
movq %r8, 0x40(%rbx)
movslq 0x1c(%r13), %rdx
movq %rdx, 0x50(%rbx)
movq 0x8(%rsp), %rdi
movl 0x8(%rdi), %eax
cmpl %r10d, %eax
cmovgel %r10d, %eax
movslq %eax, %r12
movq %r12, 0x10(%rbx)
movl 0x14(%rdi), %eax
cmpl %r8d, %eax
cmovgel %r8d, %eax
movslq %eax, %r11
movq %r11, 0x20(%rbx)
cmpq %r9, 0x70(%rbx)
jl 0x804fe
cmpq $0x1, 0x78(%rbx)
jne 0x804fe
movq %rbp, %r15
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x160(%rsp), %rbp
cmpq %rbp, %r9
jg 0x802ad
cmpq %rbp, %r12
jl 0x802ad
subq $0x8, %rsp
leaq 0x38(%rsp), %rdi
pushq %rbx
pushq %rbp
pushq %r12
pushq %r9
pushq %r11
pushq %rcx
pushq %r10
callq 0x7f2bb
addq $0x40, %rsp
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
je 0x8062a
movq 0x58(%rbx), %rdx
addq %rax, %rdx
cmpq %rbp, 0x90(%rbx)
jne 0x80216
movq 0x60(%rbx), %rcx
cmpq %rcx, %rdx
jle 0x8021d
movq %rdx, 0x60(%rbx)
movq %rdx, %rcx
movq 0x160(%rsp), %rdx
movq %rdx, 0x90(%rbx)
movq 0x8(%rbx), %r9
cmpq %rdx, %r9
movq %r15, %rbp
jge 0x802b0
cmpq %rdx, 0x10(%rbx)
movq 0x10(%rsp), %r15
jl 0x802b5
jmp 0x80615
cmpq %r9, 0x70(%rbx)
jl 0x804fe
cmpq $0x1, 0x78(%rbx)
jne 0x804fe
movq 0x160(%rsp), %rdx
cmpq %rdx, %r10
je 0x80649
movq %r10, %rax
subq %r9, %rax
subq %rcx, %r11
cmpq %rdx, %r9
jge 0x80285
subq %rdx, %r10
jg 0x80655
movq %r9, 0x70(%rbx)
movq %rcx, 0x80(%rbx)
cmpq $0x200, %rax            # imm = 0x200
jg 0x80490
cmpq %r11, %rax
cmovgq %rax, %r11
cvtsi2sd %r11, %xmm0
jmp 0x804c6
movq %r15, %rbp
movq 0x10(%rsp), %r15
movq 0x18(%rbx), %rcx
cmpq 0x160(%rsp), %r9
jl 0x804fe
jne 0x802d3
movq 0x160(%rsp), %r9
jmp 0x80308
movq 0x48(%rbx), %rsi
movq 0x50(%rbx), %rdx
movq 0x40(%rbx), %r8
subq $0x8, %rsp
leaq 0x38(%rsp), %rdi
pushq %rbx
pushq %r9
pushq 0x10(%rbx)
pushq %r9
pushq 0x20(%rbx)
pushq %rcx
pushq 0x30(%rbx)
callq 0x7f2bb
addq $0x40, %rsp
movq 0x8(%rbx), %r9
movq 0x18(%rbx), %rcx
addq 0x58(%rbx), %rax
movq %rax, 0x58(%rbx)
movq %r9, 0x70(%rbx)
movq %rcx, 0x80(%rbx)
movq $0x0, 0x78(%rbx)
cmpq %r9, 0x90(%rbx)
jne 0x804f3
cmpq 0x60(%rbx), %rax
jg 0x804f3
jmp 0x804f7
cmpl %ecx, 0x10(%rbp)
jne 0x8035b
movslq 0x14(%rbp), %rdi
cmpq %rdi, %r8
jne 0x8035b
cmpl 0x1c(%rbp), %esi
jne 0x8035b
movslq 0x20(%rbp), %rdi
cmpq %rdi, %rdx
jne 0x80395
movslq 0x14(%r13), %rdi
movq $-0x1, %r9
cmpq %rdi, %rax
jne 0x8036f
movslq 0x24(%r13), %r9
movq %r15, %rdi
movsd 0x18(%rsp), %xmm0
pushq %rbp
pushq 0x148(%rsp)
pushq 0x30(%rsp)
pushq 0x40(%rsp)
callq 0x7f0d2
addq $0x20, %rsp
movq 0x8(%rbx), %rsi
movq 0x160(%rsp), %rax
cmpq %rax, %rsi
jg 0x8043d
cmpq %rax, 0x10(%rbx)
jl 0x8043d
movq 0xa8(%rbp), %rdx
movslq 0x10(%rbp), %rax
movslq 0x14(%rbp), %r8
incq %r8
movslq 0x1c(%rbp), %rcx
movslq 0x20(%rbp), %r9
incq %r9
subq $0x8, %rsp
movq %rbp, %rdi
xorl %esi, %esi
pushq %rbx
movq 0x170(%rsp), %r12
pushq %r12
pushq %r9
pushq %rcx
pushq %r8
pushq %rax
pushq %r9
callq 0x7f2bb
addq $0x40, %rsp
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
je 0x8076b
addq 0x58(%rbx), %rax
cmpq %r12, 0x90(%rbx)
jne 0x80414
movq 0x60(%rbx), %rcx
cmpq %rcx, %rax
jle 0x8041b
movq %rax, 0x60(%rbx)
movq %rax, %rcx
movq 0x160(%rsp), %rax
movq %rax, 0x90(%rbx)
movq 0x8(%rbx), %rsi
cmpq %rax, %rsi
jge 0x8043d
cmpq %rax, 0x10(%rbx)
jge 0x80615
cmpq 0x160(%rsp), %rsi
jl 0x80034
movq %rsi, 0x70(%rbx)
movq 0x18(%rbx), %rax
movq 0x90(%rbx), %rcx
movq %rax, 0x80(%rbx)
movslq 0x2c(%rbp), %rax
addq 0x58(%rbx), %rax
movq %rax, 0x58(%rbx)
movq $0x1, 0x78(%rbx)
cmpq %rsi, %rcx
jne 0x80480
cmpq 0x60(%rbx), %rax
jle 0x80484
movq %rax, 0x60(%rbx)
movq %rsi, 0x90(%rbx)
jmp 0x80034
cmpq %r11, %rax
cmovlq %rax, %r11
cvtsi2sd %r11, %xmm1
cvtsi2sd %rax, %xmm2
mulsd 0x1b119f(%rip), %xmm2   # 0x231648
addsd 0x1b0e5f(%rip), %xmm2   # 0x231310
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x58(%rbx), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, 0x58(%rbx)
movq $0x0, 0x78(%rbx)
cmpq %r9, 0x90(%rbx)
jne 0x804f3
cmpq %rax, 0x60(%rbx)
jge 0x804f7
movq %rax, 0x60(%rbx)
movq %r9, 0x90(%rbx)
movq %r9, 0x10(%rbx)
movq %rcx, 0x20(%rbx)
movq (%rbx), %rcx
leaq -0x1(%rcx), %rax
movq %rax, (%rbx)
movslq 0x10(%r13), %rdx
cmpq %rdx, %rcx
jg 0x7ffea
movq 0x70(%rbx), %rdx
movq 0x160(%rsp), %r14
movq 0x8(%rsp), %rax
movl 0x4(%rax), %esi
movq %rsi, 0x8(%rbx)
movl 0x10(%rax), %ecx
movq %rcx, 0x18(%rbx)
cmpq %rsi, %rdx
jl 0x80611
cmpq $0x0, 0x78(%rbx)
jne 0x80611
movq 0x10(%rbx), %rdx
cmpq %rsi, %rdx
jl 0x80611
movq 0x20(%rbx), %r8
cmpq %rcx, %r8
jl 0x80611
movslq 0x10(%rbp), %rax
cmpq %rcx, %rax
jne 0x8058e
movslq 0x14(%rbp), %rax
cmpq %rax, %r8
jne 0x8058e
movslq 0x1c(%rbp), %rax
cmpq %rax, %rsi
jne 0x8058e
movslq 0x20(%rbp), %rax
cmpq %rax, %rdx
jne 0x805b8
movslq 0x28(%r13), %r9
movq %r15, %rdi
movsd 0x18(%rsp), %xmm0
pushq %rbp
pushq 0x148(%rsp)
pushq 0x30(%rsp)
pushq 0x40(%rsp)
callq 0x7f0d2
addq $0x20, %rsp
movq 0x8(%rbx), %rsi
cmpq %r14, %rsi
jg 0x805c7
cmpq %r14, 0x10(%rbx)
jge 0x8067f
cmpq 0x160(%rsp), %rsi
jl 0x80611
movq %rsi, 0x70(%rbx)
movq 0x18(%rbx), %rax
movq 0x90(%rbx), %rcx
movq %rax, 0x80(%rbx)
movslq 0x2c(%rbp), %rax
addq 0x58(%rbx), %rax
movq %rax, 0x58(%rbx)
movq $0x1, 0x78(%rbx)
cmpq %rsi, %rcx
jne 0x80606
cmpq 0x60(%rbx), %rax
jle 0x8060a
movq %rax, 0x60(%rbx)
movq %rsi, 0x90(%rbx)
movq 0x58(%rbx), %rcx
movq %rcx, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rbx), %rax
movq 0x20(%rbx), %rcx
movq %rax, 0x70(%rbx)
movq %rcx, 0x80(%rbx)
movq %rbp, 0x90(%rbx)
jmp 0x7ffcf
movq %rdx, 0x90(%rbx)
jmp 0x7ffcf
xorps %xmm0, %xmm0
cvtsi2sd %r10, %xmm0
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
cmpq $0x200, %rax            # imm = 0x200
jg 0x806e8
cmpq %r11, %rax
cmovgq %rax, %r11
cvtsi2sd %r11, %xmm2
jmp 0x80719
movq 0xa8(%rbp), %rdx
movslq 0x10(%rbp), %rax
movslq 0x14(%rbp), %r8
incq %r8
movslq 0x1c(%rbp), %rcx
movslq 0x20(%rbp), %r9
incq %r9
subq $0x8, %rsp
movq %rbp, %rdi
xorl %esi, %esi
pushq %rbx
movq 0x170(%rsp), %r14
pushq %r14
pushq %r9
pushq %rcx
pushq %r8
pushq %rax
pushq %r9
callq 0x7f2bb
addq $0x40, %rsp
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jne 0x8072b
movq 0x10(%rbx), %rax
movq 0x20(%rbx), %rcx
movq %rax, 0x70(%rbx)
movq %rcx, 0x80(%rbx)
movq %r14, 0x90(%rbx)
jmp 0x7ffcf
cmpq %r11, %rax
cmovlq %rax, %r11
cvtsi2sd %r11, %xmm3
mulsd 0x1b0f4c(%rip), %xmm1   # 0x231648
addsd 0x1b0c0c(%rip), %xmm1   # 0x231310
movapd %xmm1, %xmm2
cmplesd %xmm3, %xmm2
andpd %xmm2, %xmm3
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %rcx
addq 0x58(%rbx), %rcx
jmp 0x80615
addq 0x58(%rbx), %rax
cmpq %r14, 0x90(%rbx)
jne 0x80741
movq 0x60(%rbx), %rcx
cmpq %rcx, %rax
jle 0x80748
movq %rax, 0x60(%rbx)
movq %rax, %rcx
movq %r14, 0x90(%rbx)
movq 0x8(%rbx), %rsi
cmpq %r14, %rsi
jge 0x805c7
cmpq %r14, 0x10(%rbx)
jl 0x805c7
jmp 0x80615
movq 0x10(%rbx), %rax
movq 0x20(%rbx), %rcx
movq %rax, 0x70(%rbx)
movq %rcx, 0x80(%rbx)
movq %r12, 0x90(%rbx)
jmp 0x7ffcf
leaq 0x1b4a0f(%rip), %rdi    # 0x2351a0
leaq 0x1b0fbb(%rip), %rsi    # 0x231753
leaq 0x1b4adb(%rip), %rcx    # 0x23527a
movl $0x5e5e, %edx           # imm = 0x5E5E
callq 0x2110