// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: rescue_missing_overlaps_backward(ma_ug_t*, asg_t*, ma_hit_t_alloc*, ma_sub_t*, R_to_U*, int, int, unsigned int, unsigned int, unsigned int, bub_label_t*)
void rescue_missing_overlaps_backward(ma_ug_t *i_ug, asg_t *r_g, ma_hit_t_alloc* sources, ma_sub_t *coverage_cut,
R_to_U* ruIndex, int max_hang, int min_ovlp, uint32_t backward_steps, uint32_t is_bubble_check, uint32_t is_primary_check, bub_label_t* b_mask_t)
{
    uint32_t v, vId, dir, k, cur_backward_steps, round, is_Unitig, uId, rId, endRid, oLen, w, max_oLen, max_oLen_i, mode, nv;
    uint64_t tmp;
    long long init, step = 0;
    asg_t* nsg = NULL;
    ma_utg_t* nsu = NULL;
    ma_ug_t *ug = NULL;
    asg_arc_t *av = NULL;
    asg_arc_t t, r_edge;
    kvec_t(asg_arc_t) new_edges;
    kv_init(new_edges);

    kvec_asg_arc_t_warp recover_edges;
    kv_init(recover_edges.a);

    kvec_t(asg_arc_t) rbub_edges;
    kv_init(rbub_edges);

    kvec_t_u64_warp u_vecs;
    kv_init(u_vecs.a);

    if(i_ug != NULL)
    {
        ug = i_ug;
    }
    else
    {
        ug = ma_ug_gen(r_g);
        for (v = 0; v < ug->g->n_seq; v++)
        {
            ug->g->seq[v].c = PRIMARY_LABLE;
        }
    }
    nsg = ug->g;
    
    for (v = 0; v < nsg->n_seq; v++)
    {
        uId = v;
        nsu = &(ug->u.a[uId]);
        if(nsu->m == 0) continue;
        if(nsg->seq[v].del) continue;
        if(is_primary_check && nsg->seq[v].c==ALTER_LABLE) continue;

        for (k = 0; k < nsu->n; k++)
        {
            rId = nsu->a[k]>>33;
            set_R_to_U(ruIndex, rId, uId, 1, &(r_g->seq[rId].c));
        }
    }



    for (vId = 0; vId < nsg->n_seq; vId++)
    {
        rbub_edges.n = round = 0;
        for (dir = 0; dir < 2; dir++)
        {
            if(rbub_edges.n > 0)
            {
                cur_backward_steps = nsu->n - round - 1;
                if(cur_backward_steps > backward_steps)
                {
                    cur_backward_steps = backward_steps;
                }
            }
            else
            {
                cur_backward_steps = backward_steps;
            }
            
            

            v = vId; v = v<<1; v = v | dir;
            uId = v>>1;
            if(nsg->seq[uId].del) continue;
            if(is_primary_check && nsg->seq[uId].c == ALTER_LABLE) continue;

            nsu = &(ug->u.a[uId]);
            if(nsu->m == 0) continue;
            if(nsu->circ || nsu->start == UINT32_MAX || nsu->end == UINT32_MAX) continue;
            if(get_real_length(nsg, v, NULL) != 0) continue;
            ////if(get_real_length(nsg, v^1, NULL) == 0) continue;
            ///that means this unitig has been changed
            if(nsu->start!=((uint64_t)(nsu->a[0])>>32)) continue;
            if((nsu->end^1)!=((uint64_t)(nsu->a[nsu->n-1])>>32)) continue;
            
            if(v&1)
            {
                init = 0;
                step = 1;
                mode = 1;
                //endRid = nsu->start^1;
            }
            else
            {
                init = nsu->n - 1;
                step = -1;
                mode = 0;
                ///endRid = nsu->end^1;
            }


            rbub_edges.n = 0;
            for (round = 0; round < cur_backward_steps && init >= 0 && init < (long long)nsu->n; 
                                                                    init = init + step, round++)
            {
                endRid = ((uint64_t)(nsu->a[init]))>>32;
                endRid = endRid^mode;

                k = 0;
                rbub_edges.n = 0;
                while(get_edge2existing_node_advance(ug, r_g, sources, coverage_cut, ruIndex, 
                    max_hang, min_ovlp, endRid, &uId, 1, &k, &r_edge, 1))
                {
                    kv_push(asg_arc_t, rbub_edges, r_edge);
                }
                if(rbub_edges.n > 0) break;
            }

            if(rbub_edges.n > 0)
            {
                if(mode == 1) nsu->start = endRid^1;
                if(mode == 0) nsu->end = endRid^1;
                //save for revert
                tmp = mode; tmp = tmp <<31; tmp = tmp | (uint64_t)(init); tmp = tmp << 32; tmp = tmp | uId;
                kv_push(uint64_t, u_vecs.a, tmp);



                ///need to do transitive reduction
                ///note here is different to standard transitive reduction
                minor_transitive_reduction(ug, ruIndex, rbub_edges.a, rbub_edges.n);
                if(is_primary_check)
                {
                    max_oLen = 0; max_oLen_i = (uint32_t)-1;
                    for (k = 0; k < rbub_edges.n; k++)
                    {
                        t = rbub_edges.a[k];
                        if(t.del) continue;
                        if(t.ol > max_oLen)
                        {
                            max_oLen = t.ol;
                            max_oLen_i = k;
                        }
                    }

                    if(max_oLen_i == (uint32_t)-1) continue;
                    t = rbub_edges.a[max_oLen_i];
                    w = get_corresponding_uId(ug, ruIndex, t.v);
                    if(w == ((uint32_t)(-1))) continue;
                    if(get_real_length(nsg, w^1, NULL)!=0) continue;

                    kv_push(asg_arc_t, new_edges, t);
                    oLen = t.ol;
                    asg_append_edges_to_srt(nsg, v, ug->u.a[v>>1].len, w, oLen, t.strong, t.el, t.no_l_indel);


                    get_edge_from_source(sources, coverage_cut, ruIndex, max_hang, min_ovlp, 
                    (t.v^1), ((t.ul>>32)^1), &t);
                    kv_push(asg_arc_t, new_edges, t);
                    oLen = t.ol;
                    asg_append_edges_to_srt(nsg, w^1, ug->u.a[w>>1].len, v^1, oLen, t.strong, t.el, t.no_l_indel);
                }
                else
                {
                    ///modify read graph
                    for (init = init - step; init >= 0 && init < (long long)nsu->n; init = init - step)
                    {
                        w = ((uint64_t)(nsu->a[init]))>>32;
                        nv = asg_arc_n(r_g, w);
                        av = asg_arc_a(r_g, w);
                        for (k = 0; k < nv; k++)
                        {
                            if(av[k].del) continue;
                            kv_push(asg_arc_t, recover_edges.a, av[k]);
                            if(asg_get_arc(r_g, av[k].v^1, av[k].ul>>32^1, &t)==0)
                            {
                                fprintf(stderr, "error\n");
                            } 
                            kv_push(asg_arc_t, recover_edges.a, t);
                        }
                        

                        nv = asg_arc_n(r_g, w^1);
                        av = asg_arc_a(r_g, w^1);
                        for (k = 0; k < nv; k++)
                        {
                            if(av[k].del) continue;
                            kv_push(asg_arc_t, recover_edges.a, av[k]);
                            if(asg_get_arc(r_g, av[k].v^1, av[k].ul>>32^1, &t)==0)
                            {
                                fprintf(stderr, "error\n");
                            } 
                            kv_push(asg_arc_t, recover_edges.a, t);
                        }

                        ///w = ((uint64_t)(nsu->a[init]))>>32;
                        asg_seq_del(r_g, w>>1);
                    }


                    
                    for (k = 0; k < rbub_edges.n; k++)
                    {
                        t = rbub_edges.a[k];
                        if(t.del) continue;
                        w = get_corresponding_uId(ug, ruIndex, t.v);
                        if(w == ((uint32_t)(-1))) continue;
                        // get_R_to_U(ruIndex, t.v>>1, &uId, &is_Unitig);
                        // w = (uint32_t)-1;
                        // if(t.v == ug->u.a[uId].start) w = uId<<1;
                        // if(t.v == ug->u.a[uId].end) w = (uId<<1)^1;
                        kv_push(asg_arc_t, new_edges, t);
                        oLen = t.ol;
                        asg_append_edges_to_srt(nsg, v, ug->u.a[v>>1].len, w, oLen, t.strong, t.el, t.no_l_indel);


                        get_edge_from_source(sources, coverage_cut, ruIndex, max_hang, min_ovlp, 
                        (t.v^1), ((t.ul>>32)^1), &t);
                        kv_push(asg_arc_t, new_edges, t);
                        oLen = t.ol;
                        asg_append_edges_to_srt(nsg, w^1, ug->u.a[w>>1].len, v^1, oLen, t.strong, t.el, t.no_l_indel);
                    }
                }

            }
        }
    }
    
    
    if(is_bubble_check)
    {
        asg_arc_t* p = NULL;
        for (k = 0; k < new_edges.n; k++)
        {
            p = asg_arc_pushp(r_g);
            *p = new_edges.a[k];
        }

        if(new_edges.n != 0)
        {
            free(r_g->idx);
            r_g->idx = 0;
            r_g->is_srt = 0;
            asg_cleanup(r_g);
        }
        
        pre_clean(sources, coverage_cut, r_g, 0);

        lable_all_bubbles(r_g, b_mask_t);


        for (k = 0; k < new_edges.n; k++)
        {
            v = new_edges.a[k].ul>>32;
            w = new_edges.a[k].v;

            if(r_g->seq[v>>1].del) continue;
            if(r_g->seq[w>>1].del) continue;
            ///if this edge is at a bubble
            if(r_g->seq_vis[v]!=0 && r_g->seq_vis[w^1]!=0) continue;

            asg_arc_del(r_g, v, w, 1);
            asg_arc_del(r_g, w^1, v^1, 1);
        }

        asg_cleanup(r_g);
        

        for (k = 0; k < recover_edges.a.n; k++)
        {
            recover_edges.a.a[k].del = 1;
        }

        for (k = 0; k < u_vecs.a.n; k++)
        {
            mode = (uint64_t)u_vecs.a.a[k]>>63;
            if(mode == 1) step = 1;
            if(mode == 0) step = -1;
            init = (uint64_t)((uint64_t)u_vecs.a.a[k]>>32)&((uint64_t)(0x7fffffff));
            uId = (uint32_t)u_vecs.a.a[k];
            nsu = &(ug->u.a[uId]);

            endRid = ((uint64_t)(nsu->a[init]))>>32;
            endRid = endRid^mode;
            /********************for debug**********************/
            // fprintf(stderr, "n: %u, k: %u, mode: %u, init: %lld, step: %lld, uId: %u, endRid: %u\n", 
            // (uint32_t)u_vecs.a.n, k, mode, init, step, uId, endRid);
            // fprintf(stderr, "nsu->start: %u, nsu->end: %u\n", 
            // nsu->start, nsu->end);
            // if(mode == 1 && nsu->start != (endRid^1)) fprintf(stderr, "ERROR\n");
            // if(mode == 0 && nsu->end != (endRid^1)) fprintf(stderr, "ERROR\n");
            // update_unitig(step, init, nsu, r_g, &recover_edges, 0);
            /********************for debug**********************/
            if(get_real_length(r_g, endRid, NULL) > 0)
            {
                update_unitig(step, init, nsu, r_g, &recover_edges, 1);
                // fprintf(stderr, "endRid: %u, %.*s, uId: %u\n", 
                // endRid>>1, (int)Get_NAME_LENGTH((R_INF), v>>1), Get_NAME((R_INF), v>>1), uId);
            }
            else
            {
                update_unitig(step, init, nsu, r_g, &recover_edges, 0);
            }
        }

        uint64_t recov_occ = 0;
        for (k = 0; k < recover_edges.a.n; k++)
        {
            if(recover_edges.a.a[k].del) continue;
            p = asg_arc_pushp(r_g);
            *p = recover_edges.a.a[k];
            recov_occ++;
        }

        if(recov_occ != 0)
        {
            free(r_g->idx);
            r_g->idx = 0;
            r_g->is_srt = 0;
        }

        asg_cleanup(r_g);
    }

    if(is_primary_check)
    {
        for (k = 0; k < u_vecs.a.n; k++)
        {
            mode = (uint64_t)u_vecs.a.a[k]>>63;
            if(mode == 1) step = 1;
            if(mode == 0) step = -1;
            init = (uint64_t)((uint64_t)u_vecs.a.a[k]>>32)&((uint64_t)(0x7fffffff));
            uId = (uint32_t)u_vecs.a.a[k];
            nsu = &(ug->u.a[uId]);

            endRid = ((uint64_t)(nsu->a[init]))>>32;
            endRid = endRid^mode;

            update_unitig(step, init, nsu, r_g, &recover_edges, 1);
        }
    }


    for (v = 0; v < ruIndex->len; v++)
    {
        get_R_to_U(ruIndex, v, &uId, &is_Unitig);
        if(is_Unitig == 1) ruIndex->index[v] = (uint32_t)-1;
    }

    if(i_ug == NULL) ma_ug_destroy(ug);

    kv_destroy(new_edges);
    kv_destroy(recover_edges.a);
    kv_destroy(rbub_edges);
    kv_destroy(u_vecs.a);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %r9d, 0xb4(%rsp)
movq %r8, 0xa8(%rsp)
movq %rcx, 0xf8(%rsp)
movq %rdx, 0xe8(%rsp)
movq %rsi, %r12
andq $0x0, 0x80(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
testq %rdi, %rdi
movq %rdi, 0x108(%rsp)
je 0xbd41d
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
movq %rbx, 0x18(%rsp)
movl 0x188(%rsp), %r15d
xorl %r14d, %r14d
xorl %edx, %edx
movq %rdi, 0x10(%rsp)
movl 0x14(%rdi), %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %r14
jae 0xbc416
movl %r14d, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
imulq $0x28, %r14, %rcx
leaq (%rax,%rcx), %rdx
cmpl $0x0, 0xc(%rax,%rcx)
je 0xbc3c7
movq 0x20(%rdi), %rax
cmpl $0x0, (%rax,%r14,8)
js 0xbc3c7
testl %r15d, %r15d
je 0xbc3cc
cmpb $0x1, 0x4(%rax,%r14,8)
jne 0xbc3cc
incq %r14
jmp 0xbc37e
xorl %ebx, %ebx
movl %ebx, 0x8(%rsp)
movl 0x10(%rdx), %eax
cmpq %rax, %rbx
jae 0xbc3c7
movq 0x18(%rdx), %rax
movq (%rax,%rbx,8), %rsi
shrq $0x21, %rsi
movq 0x20(%r12), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq 0xa8(%rsp), %rdi
movq %rdx, %rbp
movl %r14d, %edx
pushq $0x1
popq %rcx
callq 0x6ab56
movq %rbp, %rdx
movq 0x10(%rsp), %rdi
incq %rbx
jmp 0xbc3ce
xorl %esi, %esi
movq $0x0, 0x58(%rsp)
movq $0x0, 0x98(%rsp)
movq $0x0, 0x60(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
movq $0x0, 0xc0(%rsp)
movq $0x0, 0x100(%rsp)
movq $0x0, 0xd8(%rsp)
movl 0x178(%rsp), %ecx
movq %r12, 0xf0(%rsp)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rsi
jae 0xbd0a9
leaq (%rsi,%rsi), %rax
movq %rax, 0x118(%rsp)
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %r14d, %r14d
movq %rsi, 0x50(%rsp)
cmpq $0x2, %r8
je 0xbd09e
movl %ecx, %ebx
testq %r14, %r14
je 0xbc4b4
movl %r9d, %ebx
notl %ebx
addl 0x10(%rdx), %ebx
cmpl %ecx, %ebx
cmovael %ecx, %ebx
movl %esi, 0xc(%rsp)
movq 0x20(%rdi), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0xbc753
testl %r15d, %r15d
je 0xbc4d6
cmpb $0x1, 0x4(%rax,%rsi,8)
je 0xbc753
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
imulq $0x28, %rsi, %r10
leaq (%rax,%r10), %rdx
cmpl $0x0, 0xc(%rax,%r10)
je 0xbc753
cmpl $0x0, (%rdx)
js 0xbc753
cmpl $-0x1, 0x4(%rdx)
je 0xbc753
cmpl $-0x1, 0x8(%rdx)
je 0xbc753
movq %r10, 0xc8(%rsp)
movq %r9, %r12
movq %rdx, 0x48(%rsp)
movq %r8, 0x20(%rsp)
movq %r8, %r15
orq 0x118(%rsp), %r15
movl %r15d, %esi
xorl %edx, %edx
callq 0xc2e7a
testl %eax, %eax
je 0xbc561
movq 0x10(%rsp), %rdi
movl 0x178(%rsp), %ecx
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rsi
movq 0x20(%rsp), %r8
movq %r12, %r9
jmp 0xbc743
movq %r15, 0xb8(%rsp)
movq 0x48(%rsp), %rdx
movq 0x18(%rdx), %rax
movl 0x4(%rax), %ecx
cmpl 0x4(%rdx), %ecx
movq 0x10(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq %r12, %r9
jne 0xbc737
movl 0x8(%rdx), %ecx
movl 0x10(%rdx), %r10d
xorl $0x1, %ecx
decl %r10d
cmpl %ecx, 0x4(%rax,%r10,8)
movq 0x20(%rsp), %r8
movq 0xf0(%rsp), %r12
jne 0xbc75b
xorl %r9d, %r9d
xorl %eax, %eax
testq %r8, %r8
setne %al
cmovneq %r9, %r10
leaq -0x1(,%rax,2), %rax
movq %rax, 0xd0(%rsp)
movl 0x178(%rsp), %ecx
movl 0x188(%rsp), %r15d
cmpl %ebx, %r9d
jae 0xbc764
testq %r10, %r10
js 0xbc764
movl 0x10(%rdx), %eax
cmpq %rax, %r10
jae 0xbc764
movq %r9, 0xa0(%rsp)
movq %rbp, 0x28(%rsp)
movq %r12, %rbp
movq 0x18(%rdx), %rax
movq %r10, 0x68(%rsp)
movq (%rax,%r10,8), %rax
shrq $0x20, %rax
andl $0x0, 0x8(%rsp)
movl %r8d, %r12d
movq %rax, 0xe0(%rsp)
xorl %eax, %r12d
xorl %r15d, %r15d
xorl %r14d, %r14d
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
movq 0xf0(%rsp), %rdx
movq 0x100(%rsp), %rcx
movq 0xb0(%rsp), %r8
movl 0xbc(%rsp), %r9d
pushq $0x1
popq %rax
pushq %rax
leaq 0x130(%rsp), %r10
pushq %r10
leaq 0x20(%rsp), %r10
pushq %r10
pushq %rax
leaq 0x34(%rsp), %rax
pushq %rax
pushq %r12
movl 0x1a8(%rsp), %eax
pushq %rax
callq 0xc47e9
addq $0x40, %rsp
testl %eax, %eax
je 0xbc6ea
cmpq %r13, %r14
jne 0xbc6ba
movq %r13, %rax
addq %r13, %r13
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r13
imulq $0x18, %r13, %rsi
movq 0x28(%rsp), %rdi
callq 0x2370
jmp 0xbc6bf
movq 0x28(%rsp), %rax
incq %r14
movq 0x130(%rsp), %rcx
movq %rcx, 0x10(%rax,%r15)
movups 0x120(%rsp), %xmm0
movq %rax, 0x28(%rsp)
movups %xmm0, (%rax,%r15)
addq $0x18, %r15
jmp 0xbc636
testq %r14, %r14
movq 0xa0(%rsp), %r9
jne 0xbc769
movq 0x68(%rsp), %r10
addq 0xd0(%rsp), %r10
incl %r9d
movq %rbp, %r12
movq 0x28(%rsp), %rbp
movl 0x188(%rsp), %r15d
movq 0x10(%rsp), %rdi
movl 0x178(%rsp), %ecx
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rsi
movq 0x20(%rsp), %r8
jmp 0xbc5de
movl 0x178(%rsp), %ecx
movq 0x20(%rsp), %r8
movq 0xf0(%rsp), %r12
movl 0x188(%rsp), %r15d
incq %r8
jmp 0xbc496
movl 0x178(%rsp), %ecx
jmp 0xbc74b
xorl %r14d, %r14d
jmp 0xbc753
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
movl 0x188(%rsp), %r15d
movq 0x48(%rsp), %rax
je 0xbc78a
xorl $0x1, %r12d
movl %r12d, 0x4(%rax)
jmp 0xbc798
movq 0xe0(%rsp), %rcx
xorl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq %rbp, %r12
movl 0xc(%rsp), %ebx
movq 0x100(%rsp), %rax
cmpq %rax, 0xd8(%rsp)
leaq 0x30(%rsp), %rbp
jne 0xbc7f0
leaq (%rax,%rax), %r15
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r15
leaq (,%r15,8), %rsi
movq 0xc0(%rsp), %rdi
callq 0x2370
movq 0x20(%rsp), %rsi
movq %r15, 0x100(%rsp)
movl 0x188(%rsp), %r15d
jmp 0xbc7f8
movq 0xc0(%rsp), %rax
movq 0x28(%rsp), %rdx
shlq $0x3f, %rsi
movq 0x68(%rsp), %rcx
shlq $0x20, %rcx
orq %rsi, %rcx
orq %rcx, %rbx
movq %rax, 0xc0(%rsp)
movq 0xd8(%rsp), %rcx
movq %rbx, (%rax,%rcx,8)
incq %rcx
movq %rcx, 0xd8(%rsp)
movq 0x18(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movl %r14d, %ecx
callq 0xb5486
testl %r15d, %r15d
je 0xbcb83
xorl %eax, %eax
xorl %edx, %edx
pushq $-0x1
popq %rcx
movq 0x28(%rsp), %rbp
movl %eax, %esi
cmpq %rsi, %r14
jbe 0xbce37
imulq $0x18, %rsi, %rsi
movups (%rbp,%rsi), %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x10(%rbp,%rsi), %rsi
movq %rsi, 0x40(%rsp)
movl 0x3c(%rsp), %esi
testl %esi, %esi
setns %r8b
cmpl %edx, %esi
seta %r9b
movl %eax, %edi
testb %r9b, %r8b
jne 0xbc897
movl %edx, %esi
movl %ecx, %edi
incl %eax
movl %esi, %edx
movl %edi, %ecx
jmp 0xbc859
movq 0x18(%rdx), %rax
movq %rcx, 0x68(%rsp)
movq (%rax,%rcx,8), %rax
movq %rax, 0xe0(%rsp)
movq %rax, %rcx
shrq $0x20, %rcx
movq 0x28(%r12), %rax
movq %rcx, 0x110(%rsp)
movq (%rax,%rcx,8), %rbx
movq %rbx, %rax
shrq $0x20, %rax
imulq $0x18, %rax, %r15
addq 0x8(%r12), %r15
xorl %eax, %eax
movl %eax, 0x8(%rsp)
cmpl %ebx, %eax
jae 0xbca0f
movl %eax, %ecx
imulq $0x18, %rcx, %rdx
cmpl $0x0, 0xc(%r15,%rdx)
js 0xbc9e7
movq 0x70(%rsp), %rdx
movq 0x80(%rsp), %rax
cmpq 0x78(%rsp), %rdx
jne 0xbc940
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rcx
movq %rcx, 0x78(%rsp)
imulq $0x18, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x80(%rsp)
movl 0x8(%rsp), %ecx
movq 0x70(%rsp), %rdx
imulq $0x18, %rcx, %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x70(%rsp)
imulq $0x18, %rdx, %rdx
movq 0x10(%r15,%rcx), %rsi
movq %rsi, 0x10(%rax,%rdx)
movups (%r15,%rcx), %xmm0
movups %xmm0, (%rax,%rdx)
movl 0x4(%r15,%rcx), %edx
movl 0x8(%r15,%rcx), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %r12, %rdi
movq %rbp, %rcx
callq 0xbb2b9
testl %eax, %eax
je 0xbc9ee
movq 0x70(%rsp), %rcx
movq 0x80(%rsp), %rax
cmpq 0x78(%rsp), %rcx
jne 0xbc9c3
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x78(%rsp)
imulq $0x18, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x80(%rsp)
movq 0x70(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x70(%rsp)
imulq $0x18, %rcx, %rcx
movq 0x40(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rax,%rcx)
movl 0x8(%rsp), %eax
incl %eax
jmp 0xbc8de
movq 0x1965eb(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x126f6e(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xbc983
movq 0x28(%r12), %rax
movq 0x110(%rsp), %rcx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rbx
movq %rbx, %rax
shrq $0x20, %rax
imulq $0x18, %rax, %r15
addq 0x8(%r12), %r15
xorl %eax, %eax
movl %eax, 0x8(%rsp)
cmpl %ebx, %eax
jae 0xbcb67
movl %eax, %ecx
imulq $0x18, %rcx, %rdx
cmpl $0x0, 0xc(%r15,%rdx)
js 0xbcb3f
movq 0x70(%rsp), %rdx
movq 0x80(%rsp), %rax
cmpq 0x78(%rsp), %rdx
jne 0xbca98
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rcx
movq %rcx, 0x78(%rsp)
imulq $0x18, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x80(%rsp)
movl 0x8(%rsp), %ecx
movq 0x70(%rsp), %rdx
imulq $0x18, %rcx, %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x70(%rsp)
imulq $0x18, %rdx, %rdx
movq 0x10(%r15,%rcx), %rsi
movq %rsi, 0x10(%rax,%rdx)
movups (%r15,%rcx), %xmm0
movups %xmm0, (%rax,%rdx)
movl 0x4(%r15,%rcx), %edx
movl 0x8(%r15,%rcx), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %r12, %rdi
movq %rbp, %rcx
callq 0xbb2b9
testl %eax, %eax
je 0xbcb46
movq 0x70(%rsp), %rcx
movq 0x80(%rsp), %rax
cmpq 0x78(%rsp), %rcx
jne 0xbcb1b
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x78(%rsp)
imulq $0x18, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x80(%rsp)
movq 0x70(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x70(%rsp)
imulq $0x18, %rcx, %rcx
movq 0x40(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rax,%rcx)
movl 0x8(%rsp), %eax
incl %eax
jmp 0xbca36
movq 0x196493(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x126e16(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xbcadb
movq 0xe0(%rsp), %rsi
shrq $0x21, %rsi
movq %r12, %rdi
callq 0x6f8da
movl 0x188(%rsp), %r15d
movq 0x68(%rsp), %rcx
subq 0xd0(%rsp), %rcx
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rsi
movq 0xa0(%rsp), %r9
js 0xbcbb0
movl 0x10(%rdx), %eax
cmpq %rax, %rcx
jb 0xbc89f
movq 0xb8(%rsp), %rax
xorl $0x1, %eax
movl %eax, 0xe0(%rsp)
xorl %ebx, %ebx
movq 0x28(%rsp), %rbp
movq 0x10(%rsp), %rdi
movl 0x178(%rsp), %ecx
movq 0x20(%rsp), %r8
movl %ebx, 0x8(%rsp)
movl %ebx, %eax
cmpq %rax, %r14
jbe 0xbc753
imulq $0x18, %rax, %rax
movups (%rbp,%rax), %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x10(%rbp,%rax), %rax
movq %rax, 0x40(%rsp)
cmpl $0x0, 0x3c(%rsp)
js 0xbce30
movl 0x38(%rsp), %edx
movq 0x18(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0xb542c
cmpl $-0x1, %eax
je 0xbcc60
movl %eax, %r11d
movq 0x98(%rsp), %rax
cmpq %rax, 0x60(%rsp)
jne 0xbcc6f
leaq (%rax,%rax), %rbx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rbx
imulq $0x18, %rbx, %rsi
movq 0x58(%rsp), %rdi
movq %r11, %rbp
callq 0x2370
movq %rbp, %r11
movq %rax, %rbp
jmp 0xbcc77
movq 0x28(%rsp), %rbp
movq 0x10(%rsp), %rdi
jmp 0xbce12
movq 0x58(%rsp), %rbp
movq %rax, %rbx
movq 0xb8(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq 0x60(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0xd0(%rsp)
imulq $0x18, %rax, %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rbp,%rax)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rbp,%rax)
movl 0x3c(%rsp), %r8d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %r8d
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%rdx), %edx
andl %ecx, %edx
movzwl 0x40(%rsp), %eax
movl %eax, %r9d
shrl $0xe, %r9d
movzbl 0x42(%rsp), %r10d
shrl $0xf, %eax
andl $0x1, %r9d
movq 0x10(%rsp), %rdi
movq %r11, 0x68(%rsp)
movl %r11d, %ecx
pushq %rax
pushq %r10
callq 0xac072
popq %rcx
popq %rdx
movl 0x34(%rsp), %eax
movl 0x38(%rsp), %r9d
xorl $0x1, %r9d
xorl $0x1, %eax
movq 0xe8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
movl 0xb4(%rsp), %ecx
movl 0x170(%rsp), %r8d
leaq 0x30(%rsp), %rdx
pushq %rdx
pushq %rax
callq 0x79204
movq 0xe0(%rsp), %rax
addq $0x10, %rsp
cmpq %rbx, %rax
jne 0xbcd7c
leaq (%rbx,%rbx), %r15
testq %rbx, %rbx
movq %rax, %rbx
pushq $0x2
popq %rax
cmoveq %rax, %r15
imulq $0x18, %r15, %rsi
movq %rbp, %rdi
callq 0x2370
movq %rax, %rbp
movq %rbx, %rax
movq %r15, 0x98(%rsp)
movl 0x188(%rsp), %r15d
jmp 0xbcd84
movq %rbx, 0x98(%rsp)
addq $0x2, 0x60(%rsp)
imulq $0x18, %rax, %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rbp,%rax)
movaps 0x30(%rsp), %xmm0
movq %rbp, 0x58(%rsp)
movups %xmm0, (%rbp,%rax)
movl 0x3c(%rsp), %r8d
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %r8d
movq 0x68(%rsp), %rcx
movl %ecx, %esi
xorl $0x1, %esi
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
shrl %ecx
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %edx
andl %edi, %edx
movzwl 0x40(%rsp), %eax
movl %eax, %r9d
shrl $0xe, %r9d
movzbl 0x42(%rsp), %r10d
shrl $0xf, %eax
andl $0x1, %r9d
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl 0xe0(%rsp), %ecx
pushq %rax
pushq %r10
callq 0xac072
movq %rbx, %rdi
addq $0x10, %rsp
movl 0x8(%rsp), %ebx
movq 0x28(%rsp), %rbp
movl 0x178(%rsp), %ecx
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rsi
movq 0x20(%rsp), %r8
movq 0xa0(%rsp), %r9
incl %ebx
jmp 0xbcbda
movl %eax, 0x8(%rsp)
cmpl $-0x1, %ecx
je 0xbce93
movl %ecx, %eax
imulq $0x18, %rax, %rax
movups (%rbp,%rax), %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x10(%rbp,%rax), %rax
movq %rax, 0x40(%rsp)
movl 0x38(%rsp), %edx
movq 0x18(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0xb542c
cmpl $-0x1, %eax
je 0xbce8e
movl %eax, %ebp
movl %eax, %ebx
xorl $0x1, %ebx
movq 0x10(%rsp), %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0xc2e7a
testl %eax, %eax
je 0xbcebb
movq 0x28(%rsp), %rbp
movq 0x10(%rsp), %rdi
movl 0x178(%rsp), %ecx
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rsi
movq 0x20(%rsp), %r8
movq 0xa0(%rsp), %r9
jmp 0xbc753
movq %rbp, 0x68(%rsp)
movl %ebx, 0xd0(%rsp)
movq 0x98(%rsp), %rax
cmpq %rax, 0x60(%rsp)
jne 0xbceff
leaq (%rax,%rax), %rbx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rbx
imulq $0x18, %rbx, %rsi
movq 0x58(%rsp), %rdi
callq 0x2370
movq %rax, %rbp
movq %rbx, 0x98(%rsp)
jmp 0xbcf0c
movq 0x58(%rsp), %rbp
movq %rax, 0x98(%rsp)
movq 0xb8(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq 0x60(%rsp), %rax
leaq 0x1(%rax), %rbx
imulq $0x18, %rax, %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rbp,%rax)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rbp,%rax)
movl 0x3c(%rsp), %r8d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %r8d
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%rdx), %edx
andl %ecx, %edx
movzwl 0x40(%rsp), %eax
movl %eax, %r9d
shrl $0xe, %r9d
movzbl 0x42(%rsp), %r10d
shrl $0xf, %eax
andl $0x1, %r9d
movq 0x10(%rsp), %rdi
movq 0x68(%rsp), %rcx
pushq %rax
pushq %r10
callq 0xac072
popq %rcx
popq %rdx
movl 0x34(%rsp), %eax
movl 0x38(%rsp), %r9d
xorl $0x1, %r9d
xorl $0x1, %eax
movq 0xe8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
movl 0xb4(%rsp), %ecx
movl 0x170(%rsp), %r8d
leaq 0x30(%rsp), %rdx
pushq %rdx
pushq %rax
callq 0x79204
popq %rcx
popq %rdx
movq %rbx, 0xc8(%rsp)
movq 0x98(%rsp), %rax
cmpq %rax, %rbx
jne 0xbd004
leaq (%rax,%rax), %r15
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r15
imulq $0x18, %r15, %rsi
movq %rbp, %rdi
callq 0x2370
movq %rax, %rbp
movq %r15, 0x98(%rsp)
movl 0x188(%rsp), %r15d
addq $0x2, 0x60(%rsp)
imulq $0x18, 0xc8(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rbp,%rax)
movaps 0x30(%rsp), %xmm0
movq %rbp, 0x58(%rsp)
movups %xmm0, (%rbp,%rax)
movl 0x3c(%rsp), %r8d
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %r8d
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x68(%rsp), %rcx
shrl %ecx
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %edx
andl %esi, %edx
movq 0xb8(%rsp), %rcx
xorl $0x1, %ecx
movzwl 0x40(%rsp), %eax
movl %eax, %r9d
shrl $0xe, %r9d
movzbl 0x42(%rsp), %r10d
shrl $0xf, %eax
andl $0x1, %r9d
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl 0xd0(%rsp), %esi
pushq %rax
pushq %r10
callq 0xac072
movq %rbx, %rdi
addq $0x10, %rsp
movq 0x28(%rsp), %rbp
jmp 0xbce98
incq %rsi
movl 0x14(%rdi), %eax
jmp 0xbc46e
cmpl $0x0, 0x180(%rsp)
je 0xbd30e
xorl %eax, %eax
movq 0x58(%rsp), %rbx
movl %eax, 0x8(%rsp)
movl %eax, %eax
cmpq %rax, 0x60(%rsp)
jbe 0xbd0f0
movq %r12, %rdi
callq 0x6c45d
movl 0x8(%rsp), %ecx
imulq $0x18, %rcx, %rdx
movq 0x10(%rbx,%rdx), %rsi
movq %rsi, 0x10(%rax)
movups (%rbx,%rdx), %xmm0
movups %xmm0, (%rax)
leal 0x1(%rcx), %eax
jmp 0xbd0be
cmpq $0x0, 0x60(%rsp)
je 0xbd116
movq 0x28(%r12), %rdi
callq 0x2220
andq $0x0, 0x28(%r12)
andb $0x7f, 0x7(%r12)
movq %r12, %rdi
callq 0x694eb
xorl %r15d, %r15d
movq 0xe8(%rsp), %rdi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xb4c38
movq %r12, %rdi
movq 0x190(%rsp), %rsi
callq 0xb5068
pushq $0x1
popq %rbx
movl %r15d, 0x8(%rsp)
movl %r15d, %eax
cmpq %rax, 0x60(%rsp)
jbe 0xbd1c6
imulq $0x18, %rax, %rcx
movq 0x58(%rsp), %rsi
movq (%rsi,%rcx), %r14
movq 0x20(%r12), %rax
movq %r14, %rdx
shrq $0x21, %rdx
cmpl $0x0, (%rax,%rdx,8)
js 0xbd1be
movl 0x8(%rsi,%rcx), %edx
movl %edx, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xbd1be
shrq $0x20, %r14
movq 0x30(%r12), %rax
movq %rdx, %r13
xorq $0x1, %r13
cmpb $0x0, (%rax,%r14)
je 0xbd198
cmpb $0x0, (%rax,%r13)
jne 0xbd1be
movq %r12, %rdi
movl %r14d, %esi
movl %ebx, %ecx
callq 0x6db50
xorl $0x1, %r14d
movq %r12, %rdi
movl %r13d, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0x6db50
movl 0x8(%rsp), %r15d
incl %r15d
jmp 0xbd13e
movq %r12, %rdi
callq 0x694eb
xorl %eax, %eax
movl 0x188(%rsp), %r15d
movl %eax, 0x8(%rsp)
movl %eax, %eax
cmpq %rax, 0x70(%rsp)
jbe 0xbd201
movq 0x80(%rsp), %rcx
imulq $0x18, %rax, %rax
orl $0x80000000, 0xc(%rcx,%rax) # imm = 0x80000000
movl 0x8(%rsp), %eax
incl %eax
jmp 0xbd1d8
xorl %eax, %eax
movl %eax, 0x8(%rsp)
movl %eax, %eax
cmpq %rax, 0xd8(%rsp)
jbe 0xbd298
movq 0xc0(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %rsi, %r14
movq %rsi, %r13
movl %esi, 0xc(%rsp)
movl %esi, %eax
shrq $0x3f, %rsi
notq %r14
sarq $0x3f, %r14
orq $0x1, %r14
shrq $0x20, %r13
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rax, %rax
leaq (%rcx,%rax), %rbx
movq 0x18(%rcx,%rax), %rax
xorl 0x4(%rax,%r13,8), %esi
movq %r12, %rdi
xorl %edx, %edx
callq 0xc2e7a
xorl %r9d, %r9d
testl %eax, %eax
setg %r9b
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r12, %rcx
leaq 0x70(%rsp), %r8
callq 0xbb311
movl 0x8(%rsp), %eax
incl %eax
jmp 0xbd203
xorl %ecx, %ecx
xorl %ebx, %ebx
movl %ecx, 0x8(%rsp)
movl %ecx, %eax
cmpq %rax, 0x70(%rsp)
jbe 0xbd2eb
movq 0x80(%rsp), %rdx
imulq $0x18, %rax, %rax
cmpl $0x0, 0xc(%rdx,%rax)
js 0xbd2e7
movq %r12, %rdi
callq 0x6c45d
movq 0x80(%rsp), %rdx
movl 0x8(%rsp), %ecx
imulq $0x18, %rcx, %rsi
movq 0x10(%rdx,%rsi), %rdi
movq %rdi, 0x10(%rax)
movups (%rdx,%rsi), %xmm0
movups %xmm0, (%rax)
incq %rbx
incl %ecx
jmp 0xbd29c
testq %rbx, %rbx
je 0xbd306
movq 0x28(%r12), %rdi
callq 0x2220
andq $0x0, 0x28(%r12)
andb $0x7f, 0x7(%r12)
movq %r12, %rdi
callq 0x694eb
testl %r15d, %r15d
je 0xbd37b
xorl %eax, %eax
leaq 0x70(%rsp), %rbx
pushq $0x1
popq %r14
movl %eax, 0x8(%rsp)
movl %eax, %eax
cmpq %rax, 0xd8(%rsp)
jbe 0xbd37b
movq 0xc0(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
movq %rdi, %rsi
movl %edi, 0xc(%rsp)
movl %edi, %eax
notq %rdi
sarq $0x3f, %rdi
orq $0x1, %rdi
shrq $0x20, %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
imulq $0x28, %rax, %rdx
movq 0x18(%rsp), %rax
addq 0x10(%rax), %rdx
movq %r12, %rcx
movq %rbx, %r8
movl %r14d, %r9d
callq 0xbb311
movl 0x8(%rsp), %eax
incl %eax
jmp 0xbd31e
movq 0xa8(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
movq 0x108(%rsp), %rdi
movq 0xc0(%rsp), %rbx
movq 0x58(%rsp), %r14
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0xbd3d7
movq 0xa8(%rsp), %rdx
movq 0x8(%rdx), %rdx
movl (%rdx,%rcx,4), %esi
cmpl $-0x1, %esi
je 0xbd3ce
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl %esi, 0xc(%rsp)
cmpl $0x0, (%rdx,%rcx,4)
jns 0xbd3d3
orl $-0x1, (%rdx,%rcx,4)
jmp 0xbd3d3
orl $-0x1, 0xc(%rsp)
incl %ecx
jmp 0xbd39d
testq %rdi, %rdi
jne 0xbd3e6
movq 0x18(%rsp), %rdi
callq 0x6921d
movq %r14, %rdi
callq 0x2220
movq 0x80(%rsp), %rdi
callq 0x2220
movq %rbp, %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2220
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x76d91
movq %rax, 0x18(%rsp)
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl 0x14(%rdi), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rax
jae 0xbc36c
movq 0x20(%rdi), %rcx
movb $0x0, 0x4(%rcx,%rax,8)
incq %rax
jmp 0xbd430