// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: rescue_wrong_overlaps_to_unitigs(ma_ug_t*, asg_t*, ma_hit_t_alloc*, ma_hit_t_alloc*, ma_sub_t*, R_to_U*, int, int, long long, kvec_asg_arc_t_warp*, bub_label_t*)
void rescue_wrong_overlaps_to_unitigs(ma_ug_t *i_ug, asg_t *r_g,  ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, 
ma_sub_t *coverage_cut, R_to_U* ruIndex, int max_hang, int min_ovlp, long long bubble_dist,
kvec_asg_arc_t_warp* keep_edges, bub_label_t* b_mask_t)
{
    uint32_t n_vtx, v, k, is_Unitig, uId, rId, endRid, oLen, w;
    asg_t* nsg = NULL;
    ma_utg_t* nsu = NULL;
    ma_ug_t *ug = NULL;
    asg_arc_t t, r_edge;
    ma_hit_t_alloc* x = NULL;
    ma_hit_t *h = NULL;
    ma_sub_t *sq = NULL;
    ma_sub_t *st = NULL;
    int32_t r;

    kvec_t(asg_arc_t) new_utg_edges;
    kv_init(new_utg_edges);

    kvec_t(asg_arc_t) new_rtg_edges;
    kv_init(new_rtg_edges);

    kvec_t(asg_arc_t) rbub_edges;
    kv_init(rbub_edges);

    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;

        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));
        }
    }

    n_vtx = nsg->n_seq * 2;
    for (v = 0; v < n_vtx; v++)
    {
        uId = v>>1;
        if(nsg->seq[uId].del) 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(v&1)
        {
            endRid = nsu->start^1;
        }
        else
        {
            endRid = nsu->end^1;
        }



        /****************************may have bugs********************************/
        x = &(sources[(endRid>>1)]);
        for (k = 0; k < x->length; k++)
        {
            ///h is the edge of endRid
            h = &(x->buffer[k]);
            sq = &(coverage_cut[Get_qn(*h)]);
            st = &(coverage_cut[Get_tn(*h)]);
            ///sq, st, and h cannot be deleted
            if(sq->del || st->del || h->del) continue;
            r = ma_hit2arc(h, sq->e - sq->s, st->e - st->s, max_hang, 
                                            asm_opt.max_hang_rate, min_ovlp, &t);
            if(r < 0) continue;
            if((t.ul>>32) != endRid) continue;
            break;
        }
        ///means there is >0 edges
        if(k != x->length) continue;
        /****************************may have bugs********************************/




        k = 0;
        rbub_edges.n = 0;
        ///note here use reverse_sources instead of sources
        while(get_edge2existing_node_advance(ug, r_g, reverse_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)
        {
            ///need to do transitive reduction
            ///note here is different to standard transitive reduction
            minor_transitive_reduction(ug, ruIndex, rbub_edges.a, rbub_edges.n);

            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;
                ///if(uId == 2474) fprintf(stderr, "###uId: %u, v: %u, r_edge.v>>1: %u\n", uId, v, r_edge.v>>1);
                kv_push(asg_arc_t, new_rtg_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(reverse_sources, coverage_cut, ruIndex, max_hang, min_ovlp, 
                (t.v^1), ((t.ul>>32)^1), &t);
                kv_push(asg_arc_t, new_rtg_edges, t);
                ///if edge does not exist in reverse, oLen won't change, it is what we want
                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);

                t.ul = v; t.ul = t.ul<<32; t.v = w;
                kv_push(asg_arc_t, new_utg_edges, t);


                t.ul = w^1; t.ul = t.ul<<32; t.v = v^1;
                kv_push(asg_arc_t, new_utg_edges, t);
            }
        }
        
    }


    nsg->seq_vis = (uint8_t*)calloc(nsg->n_seq*2, sizeof(uint8_t));    
    lable_all_bubbles(nsg, b_mask_t);

    /*********************************for debug**************************************/
    // uint32_t v_uId, w_uId;
    // if(new_utg_edges.n != new_rtg_edges.n) fprintf(stderr, "ERROR 1\n");
    // for (k = 0; k < new_utg_edges.n; k++)
    // {
    //     v = new_rtg_edges.a[k].ul>>32;
    //     v_uId = (get_corresponding_uId(ug, ruIndex, v^1)^1);
    //     w = new_rtg_edges.a[k].v;
    //     w_uId = get_corresponding_uId(ug, ruIndex, w);

    //     v = new_utg_edges.a[k].ul>>32;
    //     w = new_utg_edges.a[k].v;

    //     if(v!=v_uId || w!= w_uId)
    //     {
    //         fprintf(stderr, "\n(%u) ERROR 2\n", k);
    //         fprintf(stderr, "v>>1: %u, v&1: %u, ug->u.a[v>>1].n: %u\n", 
    //                                                     v>>1, v&1, ug->u.a[v>>1].n);
    //         fprintf(stderr, "ug->u.a[v>>1].start>>1: %u, ug->u.a[v>>1].start&1: %u\n", 
    //                                         ug->u.a[v>>1].start>>1, ug->u.a[v>>1].start&1);
    //         fprintf(stderr, "ug->u.a[v>>1].end>>1: %u, ug->u.a[v>>1].end&1: %u\n", 
    //                                         ug->u.a[v>>1].end>>1, ug->u.a[v>>1].end&1);
    //         fprintf(stderr, "w>>1: %u, w&1: %u, ug->u.a[w>>1].n: %u\n", 
    //                                                     w>>1, w&1, ug->u.a[w>>1].n);
    //         fprintf(stderr, "ug->u.a[w>>1].start>>1: %u, ug->u.a[w>>1].start&1: %u\n", 
    //                                         ug->u.a[w>>1].start>>1, ug->u.a[w>>1].start&1);
    //         fprintf(stderr, "ug->u.a[w>>1].end>>1: %u, ug->u.a[w>>1].end&1: %u\n", 
    //                                         ug->u.a[w>>1].end>>1, ug->u.a[w>>1].end&1);
    //         fprintf(stderr, "v_uId>>1: %u, v_uId&1: %u\n", v_uId>>1, v_uId&1);
    //         fprintf(stderr, "w_uId>>1: %u, w_uId&1: %u\n", w_uId>>1, w_uId&1);
    //         v = new_rtg_edges.a[k].ul>>32;
    //         w = new_rtg_edges.a[k].v;
    //         get_R_to_U(ruIndex, v>>1, &uId, &is_Unitig);
    //         fprintf(stderr, "v(read)>>1: %u, v(read)&1: %u, uId: %u, is_Unitig: %u\n", 
    //                                     v>>1, v&1, uId, is_Unitig);
    //         get_R_to_U(ruIndex, w>>1, &uId, &is_Unitig);
    //         fprintf(stderr, "w(read)>>1: %u, w(read)&1: %u, uId: %u, is_Unitig: %u\n", 
    //                                     w>>1, w&1, uId, is_Unitig);

            
    //     }
    // }
    /*********************************for debug**************************************/

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

        if(nsg->seq[v>>1].del) continue;
        if(nsg->seq[w>>1].del) continue;
        ///if this edge is at a bubble
        if(nsg->seq_vis[v]!=0 && nsg->seq_vis[w^1]!=0)
        {
            ///fprintf(stderr, "v>>1: %u, w>>1: %u\n", v>>1, w>>1);
            continue;
        } 

        asg_arc_del(nsg, v, w, 1);
        asg_arc_del(nsg, w^1, v^1, 1);
        new_rtg_edges.a[k].del = 1;
    }
    asg_cleanup(nsg);
    free(nsg->seq_vis); nsg->seq_vis = NULL;

    /*********************************for debug**************************************/
    asg_arc_t* p = NULL;
    uint32_t e_occ = 0;
    for (k = 0; k < new_rtg_edges.n; k++)
    {
        if(new_rtg_edges.a[k].del) continue;
        p = asg_arc_pushp(r_g);
        *p = new_rtg_edges.a[k];
        e_occ++;
        if(keep_edges) kv_push(asg_arc_t, keep_edges->a, new_rtg_edges.a[k]);
    }

    if(e_occ != 0)
    {
        free(r_g->idx);
        r_g->idx = 0;
        r_g->is_srt = 0;
        asg_cleanup(r_g);
    }
    /*********************************for debug**************************************/

    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_utg_edges);
    kv_destroy(new_rtg_edges);
    kv_destroy(rbub_edges);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %r9, %rbx
movq %r8, 0x80(%rsp)
movq %rcx, 0xb0(%rsp)
movq %rdx, 0xc8(%rsp)
movq %rsi, %r12
testq %rdi, %rdi
movq %rdi, 0xc0(%rsp)
je 0xbddb1
movq 0x18(%rdi), %rbp
movq %rdi, 0x30(%rsp)
xorl %r14d, %r14d
movl 0x14(%rbp), %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
cmpq %r15, %r14
jae 0xbd516
movl %r14d, 0x3c(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %r15
imulq $0x28, %r14, %rax
cmpl $0x0, 0xc(%r15,%rax)
je 0xbd511
movq 0x20(%rbp), %rcx
cmpl $0x0, (%rcx,%r14,8)
js 0xbd511
addq %rax, %r15
xorl %r13d, %r13d
movl %r13d, 0xc(%rsp)
movl 0x10(%r15), %eax
cmpq %rax, %r13
jae 0xbd511
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rsi
shrq $0x21, %rsi
movq 0x20(%r12), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq %rbx, %rdi
movl %r14d, %edx
pushq $0x1
popq %rcx
callq 0x6ab56
incq %r13
jmp 0xbd4d7
incq %r14
jmp 0xbd49c
addl %r15d, %r15d
xorl %r13d, %r13d
xorl %edi, %edi
movq $0x0, 0xa8(%rsp)
movq $0x0, 0x88(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0xa0(%rsp)
movq $0x0, 0x90(%rsp)
xorl %edx, %edx
xorl %r14d, %r14d
movq %rbp, 0x68(%rsp)
cmpq %r15, %r13
je 0xbdb5a
movl %r13d, %eax
shrl %eax
movl %eax, 0x3c(%rsp)
movq 0x20(%rbp), %rcx
cmpl $0x0, (%rcx,%rax,8)
js 0xbd5e0
movq %r14, 0x28(%rsp)
movq 0x30(%rsp), %rcx
movq 0x10(%rcx), %r14
imulq $0x28, %rax, %rax
cmpl $0x0, 0xc(%r14,%rax)
je 0xbd5db
addq %rax, %r14
cmpl $0x0, (%r14)
js 0xbd5db
cmpl $-0x1, 0x4(%r14)
je 0xbd5db
cmpl $-0x1, 0x8(%r14)
je 0xbd5db
movq %rax, 0xb8(%rsp)
movq %rdi, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %rbp, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0xc2e7a
testl %eax, %eax
je 0xbd5e8
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %r14
incq %r13
jmp 0xbd561
leaq 0x4(%r14), %rax
addq $0x8, %r14
movq %r13, 0x70(%rsp)
testb $0x1, %r13b
cmovneq %rax, %r14
movl (%r14), %eax
movq %rax, %rcx
xorq $0x1, %rcx
movq %rcx, 0x78(%rsp)
shrl %eax
imulq $0x18, %rax, %rax
movq 0xc8(%rsp), %rcx
leaq (%rcx,%rax), %rsi
movl 0xc(%rcx,%rax), %r13d
leaq 0x19612e(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movss %xmm0, 0x98(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
movq %rsi, 0x20(%rsp)
movl %r14d, 0xc(%rsp)
cmpq %r14, %r13
je 0xbd6ee
movq (%rsi), %rdi
movl 0x4(%rdi,%rbp), %eax
imulq $0xc, %rax, %rcx
movq 0x80(%rsp), %rax
movl (%rax,%rcx), %eax
testl %eax, %eax
js 0xbd6d9
movl 0xc(%rdi,%rbp), %edx
imulq $0xc, %rdx, %rdx
addq 0x80(%rsp), %rdx
movl (%rdx), %r8d
testl %r8d, %r8d
js 0xbd6d9
cmpq $0x0, 0x18(%rdi,%rbp)
js 0xbd6d9
addq %rbp, %rdi
addq 0x80(%rsp), %rcx
movl 0x4(%rcx), %esi
subl %eax, %esi
movl 0x4(%rdx), %edx
subl %r8d, %edx
movl 0x120(%rsp), %ecx
movss 0x98(%rsp), %xmm0
movl 0x128(%rsp), %r8d
leaq 0x40(%rsp), %r9
callq 0x6a4a7
movq 0x20(%rsp), %rsi
testl %eax, %eax
js 0xbd6d9
movq 0x78(%rsp), %rax
cmpl %eax, 0x44(%rsp)
je 0xbd6e5
incq %r14
addq $0x28, %rbp
jmp 0xbd645
cmpl %r14d, %r13d
jne 0xbdb41
andl $0x0, 0xc(%rsp)
xorl %r13d, %r13d
movq $0x0, 0x20(%rsp)
movq 0xb0(%rsp), %rbp
movq 0x28(%rsp), %r14
subq $0x8, %rsp
movq 0x38(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq 0x88(%rsp), %rcx
movq %rbx, %r8
movl 0x128(%rsp), %r9d
pushq $0x1
popq %rax
pushq %rax
leaq 0xe0(%rsp), %r10
pushq %r10
leaq 0x24(%rsp), %r10
pushq %r10
pushq %rax
leaq 0x64(%rsp), %rax
pushq %rax
pushq 0xa8(%rsp)
movl 0x160(%rsp), %eax
pushq %rax
callq 0xc47e9
addq $0x40, %rsp
testl %eax, %eax
je 0xbd7ca
movq 0x20(%rsp), %rcx
cmpq %r14, %rcx
jne 0xbd795
movq %r14, %rax
addq %r14, %r14
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r14
imulq $0x18, %r14, %rsi
movq 0x18(%rsp), %rdi
callq 0x2370
movq 0x20(%rsp), %rcx
jmp 0xbd79a
movq 0x18(%rsp), %rax
incq %rcx
movq %rcx, 0x20(%rsp)
movq 0xe0(%rsp), %rcx
movq %rcx, 0x10(%rax,%r13)
movups 0xd0(%rsp), %xmm0
movq %rax, 0x18(%rsp)
movups %xmm0, (%rax,%r13)
addq $0x18, %r13
jmp 0xbd70c
movq 0x20(%rsp), %rcx
testq %rcx, %rcx
movq 0x68(%rsp), %rbp
je 0xbdb2d
movq %r14, 0x28(%rsp)
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %r14
movq %r14, %rdx
callq 0xb5486
movq 0x20(%rsp), %rsi
movq %r14, %rdx
movq 0x70(%rsp), %r13
movl %r13d, %eax
xorl $0x1, %eax
movl %eax, 0x78(%rsp)
movq %r13, %rax
shlq $0x20, %rax
movq %rax, 0x98(%rsp)
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
movl %r14d, 0xc(%rsp)
movl %r14d, %eax
cmpq %rax, %rsi
jbe 0xbd5db
imulq $0x18, %rax, %rax
movups (%rdx,%rax), %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x10(%rdx,%rax), %rax
movq %rax, 0x50(%rsp)
cmpl $0x0, 0x4c(%rsp)
js 0xbdb25
movq %rdi, 0x10(%rsp)
movl 0x48(%rsp), %edx
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0xb542c
cmpl $-0x1, %eax
je 0xbd8ab
movl %eax, %r13d
movq 0xa0(%rsp), %r14
cmpq %r14, 0x90(%rsp)
jne 0xbd8c4
movq %r14, %rax
addq %r14, %r14
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r14
imulq $0x18, %r14, %rsi
movq 0x60(%rsp), %rdi
callq 0x2370
movq %rax, %rbp
jmp 0xbd8c9
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq 0x70(%rsp), %r13
movq 0x20(%rsp), %rsi
jmp 0xbdb25
movq 0x60(%rsp), %rbp
movq 0xb8(%rsp), %rdx
movq 0x90(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x60(%rsp)
imulq $0x18, %rax, %rax
movq 0x50(%rsp), %rcx
movq %rcx, 0x10(%rbp,%rax)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rbp,%rax)
movl 0x4c(%rsp), %r8d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %r8d
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%rdx), %edx
andl %ecx, %edx
movzwl 0x50(%rsp), %eax
movl %eax, %r9d
shrl $0xe, %r9d
movzbl 0x52(%rsp), %r10d
shrl $0xf, %eax
andl $0x1, %r9d
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl %r13d, %ecx
pushq %rax
pushq %r10
callq 0xac072
popq %rcx
popq %rdx
movl 0x44(%rsp), %eax
movl 0x48(%rsp), %r9d
xorl $0x1, %r9d
xorl $0x1, %eax
movq 0xb0(%rsp), %rdi
movq 0x80(%rsp), %rsi
movl 0x120(%rsp), %ecx
movl 0x128(%rsp), %r8d
leaq 0x40(%rsp), %rdx
pushq %rdx
pushq %rax
callq 0x79204
movq 0x70(%rsp), %rax
addq $0x10, %rsp
cmpq %r14, %rax
jne 0xbd9b2
movq %r14, %rax
addq %r14, %r14
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r14
imulq $0x18, %r14, %rsi
movq %rbp, %rdi
callq 0x2370
movq %rax, %rbp
movq 0x60(%rsp), %rax
movq %r14, 0xa0(%rsp)
imulq $0x18, %rax, %rax
movq 0x50(%rsp), %rcx
movq %rcx, 0x10(%rbp,%rax)
movaps 0x40(%rsp), %xmm0
movq %rbp, 0x60(%rsp)
movups %xmm0, (%rbp,%rax)
movl 0x4c(%rsp), %r8d
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %r8d
movl %r13d, %r14d
xorl $0x1, %r14d
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movl %r13d, %ecx
shrl %ecx
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %edx
andl %esi, %edx
movzwl 0x50(%rsp), %eax
movl %eax, %r9d
shrl $0xe, %r9d
movzbl 0x52(%rsp), %r10d
shrl $0xf, %eax
andl $0x1, %r9d
movq 0x68(%rsp), %rbp
movq %rbp, %rdi
movl %r14d, %esi
movl 0x78(%rsp), %ecx
pushq %rax
pushq %r10
callq 0xac072
addq $0x10, %rsp
movq 0x98(%rsp), %rax
movq %rax, 0x40(%rsp)
movl %r13d, 0x48(%rsp)
movq 0xa8(%rsp), %rdx
cmpq %rdx, 0x88(%rsp)
jne 0xbda7e
leaq (%rdx,%rdx), %r13
testq %rdx, %rdx
pushq $0x2
popq %rax
cmoveq %rax, %r13
imulq $0x18, %r13, %rsi
movq 0x10(%rsp), %rdi
callq 0x2370
movq %rax, %rdi
movq %r13, %rdx
jmp 0xbda83
movq 0x10(%rsp), %rdi
movq 0x88(%rsp), %rax
leaq 0x1(%rax), %r13
imulq $0x18, %rax, %rax
movq 0x50(%rsp), %rcx
movq %rcx, 0x10(%rdi,%rax)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rdi,%rax)
shlq $0x20, %r14
movq %r14, 0x40(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0x48(%rsp)
cmpq %rdx, %r13
jne 0xbdae0
leaq (%rdx,%rdx), %r14
testq %rdx, %rdx
pushq $0x2
popq %rax
cmoveq %rax, %r14
imulq $0x18, %r14, %rsi
callq 0x2370
movq %rax, %rdi
movq %r14, 0xa8(%rsp)
jmp 0xbdae8
movq %rdx, 0xa8(%rsp)
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rsi
addq $0x2, 0x90(%rsp)
addq $0x2, 0x88(%rsp)
imulq $0x18, %r13, %rax
movq 0x50(%rsp), %rcx
movq %rcx, 0x10(%rdi,%rax)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rdi,%rax)
movl 0xc(%rsp), %r14d
movq 0x70(%rsp), %r13
incl %r14d
jmp 0xbd825
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq 0x70(%rsp), %r13
jmp 0xbd5e0
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq 0x68(%rsp), %rbp
movq 0x70(%rsp), %r13
jmp 0xbd5db
movq %rdx, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movl 0x14(%rbp), %edi
addl %edi, %edi
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, 0x30(%rbp)
movq %rbp, %rdi
movq 0x140(%rsp), %rsi
callq 0xb5068
movq 0x10(%rsp), %rdi
xorl %eax, %eax
pushq $0x1
popq %rbp
movq 0x68(%rsp), %r13
movl %eax, 0xc(%rsp)
movl %eax, %ecx
cmpq %rcx, 0x88(%rsp)
movq 0x138(%rsp), %r14
movq 0x60(%rsp), %r15
jbe 0xbdc49
imulq $0x18, %rcx, %rdx
movq (%rdi,%rdx), %r14
movq 0x68(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq %r14, %rsi
shrq $0x21, %rsi
cmpl $0x0, (%rcx,%rsi,8)
js 0xbdc42
movl 0x8(%rdi,%rdx), %edx
movl %edx, %esi
shrl %esi
cmpl $0x0, (%rcx,%rsi,8)
js 0xbdc42
shrq $0x20, %r14
movq 0x68(%rsp), %rcx
movq 0x30(%rcx), %rcx
movq %rdx, %r15
xorq $0x1, %r15
cmpb $0x0, (%rcx,%r14)
je 0xbdc03
cmpb $0x0, (%rcx,%r15)
jne 0xbdc42
movq %r13, %rdi
movl %r14d, %esi
movl %ebp, %ecx
callq 0x6db50
xorl $0x1, %r14d
movq %r13, %rdi
movl %r15d, %esi
movl %r14d, %edx
movl %ebp, %ecx
callq 0x6db50
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %eax
imulq $0x18, %rax, %rax
movq 0x60(%rsp), %rcx
orl $0x80000000, 0xc(%rcx,%rax) # imm = 0x80000000
movl 0xc(%rsp), %eax
incl %eax
jmp 0xbdb94
movq 0x68(%rsp), %r13
movq %r13, %rdi
callq 0x694eb
movq 0x30(%r13), %rdi
callq 0x2220
andq $0x0, 0x30(%r13)
xorl %ecx, %ecx
xorl %ebp, %ebp
movl %ecx, 0xc(%rsp)
movl %ecx, %eax
cmpq %rax, 0x90(%rsp)
jbe 0xbdd13
imulq $0x18, %rax, %rax
cmpl $0x0, 0xc(%r15,%rax)
js 0xbdd0c
movq %r12, %rdi
callq 0x6c45d
movl 0xc(%rsp), %ecx
imulq $0x18, %rcx, %rdx
incl %ebp
movups (%r15,%rdx), %xmm0
movups %xmm0, (%rax)
movq 0x10(%r15,%rdx), %rdx
movq %rdx, 0x10(%rax)
testq %r14, %r14
je 0xbdd0c
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0xbdcea
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%r14)
imulq $0x18, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movl 0xc(%rsp), %ecx
movq (%r14), %rdx
imulq $0x18, %rcx, %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%r14)
imulq $0x18, %rdx, %rdx
movq 0x10(%r15,%rsi), %rdi
movq %rdi, 0x10(%rax,%rdx)
movups (%r15,%rsi), %xmm0
movups %xmm0, (%rax,%rdx)
incl %ecx
jmp 0xbdc68
testl %ebp, %ebp
je 0xbdd35
movq 0x28(%r12), %rdi
callq 0x2220
andq $0x0, 0x28(%r12)
andb $0x7f, 0x7(%r12)
movq %r12, %rdi
callq 0x694eb
movq (%rbx), %rax
xorl %ecx, %ecx
movq 0xc0(%rsp), %rdi
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0xbdd74
movq 0x8(%rbx), %rdx
movl (%rdx,%rcx,4), %esi
cmpl $-0x1, %esi
je 0xbdd6b
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl %esi, 0x3c(%rsp)
cmpl $0x0, (%rdx,%rcx,4)
jns 0xbdd70
orl $-0x1, (%rdx,%rcx,4)
jmp 0xbdd70
orl $-0x1, 0x3c(%rsp)
incl %ecx
jmp 0xbdd42
testq %rdi, %rdi
jne 0xbdd83
movq 0x30(%rsp), %rdi
callq 0x6921d
movq 0x10(%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2220
movq 0x18(%rsp), %rdi
callq 0x2220
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x76d91
movq %rax, 0x30(%rsp)
movq 0x18(%rax), %rbp
xorl %eax, %eax
movl 0x14(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rax
jae 0xbd499
movq 0x20(%rbp), %rcx
movb $0x0, 0x4(%rcx,%rax,8)
incq %rax
jmp 0xbddc4