// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: rescue_bubbles_by_contained_reads(ma_ug_t*, asg_t*, ma_hit_t_alloc*, ma_sub_t*, R_to_U*, int, int, unsigned int, unsigned int, unsigned int, bubble_type*, bub_label_t*)
void rescue_bubbles_by_contained_reads(ma_ug_t *i_u_g, 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 chainLenThres, uint32_t beg_idx, uint32_t occ, bubble_type* bub, 
bub_label_t* b_mask_t)
{
    asg_t* nsg = NULL;
    uint32_t beg_utg, sink_utg, *a = NULL, n, i, bub_i, k_i, k_v, k, uId, endRid, is_Unitig, contain_rId;
    uint32_t ava_max, ava_ol_max, ava_min_chain, ava_cur, test_oLen, ava_chainLen, is_update, v, w;
    uint64_t l_bub, m_bub, r_bub, /**bub_0, bub_1,**/ a_nodes;
    ma_ug_t* ug = i_u_g;
    ma_utg_t *nsu = NULL, *u = NULL;
    ma_hit_t_alloc* x = NULL;
    ma_hit_t *h = NULL, *h_max = NULL;
    uint8_t* expect_vis = NULL; CALLOC(expect_vis, r_g->n_seq);
    uint8_t* circle_vis = NULL; CALLOC(circle_vis, r_g->n_seq);
    uint8_t* utg_vis = NULL; CALLOC(utg_vis, ug->g->n_seq);
    asg_arc_t t, t_max, r_edge;

    for (v = 0; v < ug->u.n; v++) ug->g->seq[v].c = PRIMARY_LABLE;
    
    kvec_t(asg_arc_t) new_edges;
    kv_init(new_edges);

    kvec_t(asg_arc_t) rbub_edges;
    kv_init(rbub_edges);

    kvec_t_u64_warp u_vecs;
    kv_init(u_vecs.a);

    kvec_asg_arc_t_warp chain_edges;
    kv_init(chain_edges.a);

    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++) 
        {
            set_R_to_U(ruIndex, nsu->a[k]>>33, uId, 1, &(r_g->seq[nsu->a[k]>>33].c));
        }
    }


    for (i = 0; i < bub->b_ug->u.n; i++)
    {
        u = &(bub->b_ug->u.a[i]);
        if(u->n < 3) continue; ///should be at least 3
        for (bub_i = 1; bub_i+1 < u->n; bub_i++)
        {
            m_bub = u->a[bub_i]>>33; l_bub = r_bub = (uint64_t)-1;
            if(m_bub < beg_idx || m_bub >= beg_idx + occ) continue;
            l_bub = u->a[bub_i-1]>>33;
            r_bub = u->a[bub_i+1]>>33;

            set_rtg_flag_by_bubble(bub, ug, r_g, l_bub, expect_vis, 1);
            set_rtg_flag_by_bubble(bub, ug, r_g, r_bub, expect_vis, 1);
            set_rtg_flag_by_bubble(bub, ug, r_g, m_bub, expect_vis, 1);

            get_bubbles(bub, m_bub, &beg_utg, &sink_utg, &a, &n, NULL);
            for (k_i = 0; k_i < n; k_i++)
            {
                uId = a[k_i]>>1;
                nsu = &(ug->u.a[uId]);
                if(nsu->m == 0) continue;
                for (k_v = 0; k_v < 2; k_v++)
                {
                    v = (uId<<1) + k_v;
                    if(get_real_length(nsg, v, NULL) != 0) continue;

                    if(v&1)
                    {
                        endRid = nsu->start^1;
                    }
                    else
                    {
                        endRid = nsu->end^1;
                    }

                    //x is the end read of a tip
                    ///find all overlap of x
                    x = &(sources[(endRid>>1)]);
                    ava_ol_max = ava_max = 0; ava_min_chain = (uint32_t)-1;
                    h_max = NULL;
                    for (k = 0; k < x->length; k++)
                    {
                        ///fprintf(stderr, "k: %u\n", k);
                        ///h is the edge of endRid
                        h = &(x->buffer[k]);
                        ///means we found a contained read
                        if(get_contained_reads_chain_by_broken_bub(h, sources, coverage_cut, ruIndex, ug, r_g, 
                        max_hang, min_ovlp, endRid, uId, &chain_edges, &ava_cur, &test_oLen, &ava_chainLen, 
                        expect_vis, circle_vis, utg_vis, chainLenThres, 1))
                        {
                            is_update = 0;

                            if(ava_cur > ava_max)
                            {
                                is_update = 1;
                            }
                            else if(ava_cur == ava_max)
                            {
                                if(ava_chainLen < ava_min_chain)
                                {
                                    is_update = 1;
                                }
                                else if(ava_chainLen == ava_min_chain && test_oLen > ava_ol_max)
                                {
                                    is_update = 1;
                                }
                            }

                            if(is_update)
                            {
                                ava_min_chain = ava_chainLen;
                                ava_max = ava_cur;
                                ava_ol_max = test_oLen;
                                h_max = h;
                            }
                        }
                    }

                    if(ava_max > 0)
                    {
                        ///fprintf(stderr, "ava_max: %u\n", ava_max);
                        get_contained_reads_chain_by_broken_bub(h_max, sources, coverage_cut, ruIndex, ug, r_g, 
                        max_hang, min_ovlp, endRid, uId, &chain_edges, &ava_cur, &test_oLen, &ava_chainLen, 
                        expect_vis, circle_vis, NULL, chainLenThres, 1);
                        if(chain_edges.a.n < 1) continue;
                        ///the last cantained read
                        t_max = chain_edges.a.a[chain_edges.a.n-1];

                        k = 0; rbub_edges.n = 0;
                        ///edges from the last contained read to other unitigs

                        while(get_edge2existing_node_advance_by_broken_bub(ug, r_g, sources, coverage_cut, 
                        ruIndex, expect_vis, max_hang, min_ovlp, t_max.v, &k, &r_edge, 1))
                        {
                            kv_push(asg_arc_t, rbub_edges, r_edge);
                        }

                        ///need to do transitive reduction
                        ///note here is different to standard transitive reduction
                        minor_transitive_reduction_r_g(r_g, rbub_edges.a, rbub_edges.n);

                        for (k = 0; k < chain_edges.a.n; k++)
                        {
                            t_max = chain_edges.a.a[k];
                            ///save all infor for reverting
                            get_R_to_U(ruIndex, t_max.v>>1, &contain_rId, &is_Unitig);
                            a_nodes=contain_rId; 
                            a_nodes=a_nodes<<32; 
                            a_nodes=a_nodes|((uint64_t)(t_max.v>>1));
                            kv_push(uint64_t, u_vecs.a, a_nodes);

                            r_g->seq[t_max.v>>1].del = 0;
                            coverage_cut[t_max.v>>1].del = 0;
                            coverage_cut[t_max.v>>1].c = PRIMARY_LABLE;

                            get_edge_from_source(sources, coverage_cut, ruIndex, max_hang, min_ovlp, 
                            (t_max.ul>>32), t_max.v, &t);
                            kv_push(asg_arc_t, new_edges, t);

                            get_edge_from_source(sources, coverage_cut, ruIndex, max_hang, min_ovlp, 
                            (t_max.v^1), ((t_max.ul>>32)^1), &t);
                            kv_push(asg_arc_t, new_edges, t);
                        }


                        for (k = 0; k < rbub_edges.n; k++)
                        {
                            t = rbub_edges.a[k];
                            if(t.del) continue;
                    
                            kv_push(asg_arc_t, new_edges, t);
                            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);
                        }

                    }
                }
            }
            

            set_rtg_flag_by_bubble(bub, ug, r_g, l_bub, expect_vis, 0);
            set_rtg_flag_by_bubble(bub, ug, r_g, r_bub, expect_vis, 0);
            set_rtg_flag_by_bubble(bub, ug, r_g, m_bub, expect_vis, 0);
        }
    }

    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);
        asg_symm(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);
    asg_symm(r_g);

    for (k = 0; k < u_vecs.a.n; k++)
    {
        w = (uint32_t)u_vecs.a.a[k];
        w = w<<1;
        if((!r_g->seq[w>>1].del) && 
                    (get_real_length(r_g, w, NULL)!=0 || get_real_length(r_g, (w^1), NULL)!=0))
        {
            w=w>>1;
            ruIndex->index[w] = (uint32_t)-1;
        }
        else
        {
            w=w>>1;
            r_g->seq[w].del = 1;
            coverage_cut[w].del = 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;
    }

    // fprintf(stderr, "M::%s has done!\n", __func__);
    // print_bubble_filling_status(ug, r_g, ruIndex, bub, beg_idx, occ, new_edges.a, new_edges.n);

    kv_destroy(new_edges);
    kv_destroy(rbub_edges);
    kv_destroy(u_vecs.a);
    kv_destroy(chain_edges.a);
    free(expect_vis);
    free(circle_vis);
    free(utg_vis);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movl %r9d, -0x54(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq $0x0, -0xf0(%rbp)
movq $0x0, -0xf8(%rbp)
movq $0x0, -0x100(%rbp)
movq $0x0, -0x108(%rbp)
movq $0x0, -0x110(%rbp)
movq $0x0, -0x118(%rbp)
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x118(%rbp)
movq $0x0, -0x120(%rbp)
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x120(%rbp)
movq $0x0, -0x128(%rbp)
movq -0xe8(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x128(%rbp)
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movq -0xe8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x155d34
movq -0xe8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0xb8(%rbp), %ecx
movb $0x0, 0x4(%rax,%rcx,8)
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x155cf7
movq $0x0, -0x180(%rbp)
movq $0x0, -0x188(%rbp)
movq $0x0, -0x178(%rbp)
movq $0x0, -0x198(%rbp)
movq $0x0, -0x1a0(%rbp)
movq $0x0, -0x190(%rbp)
movq $0x0, -0x1b8(%rbp)
movq $0x0, -0x1c0(%rbp)
movq $0x0, -0x1b0(%rbp)
movq $0x0, -0x1d8(%rbp)
movq $0x0, -0x1e0(%rbp)
movq $0x0, -0x1d0(%rbp)
movq -0xe8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movq -0x60(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x155ee5
movl -0xb8(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0xe8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x8c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x155e29
jmp 0x155ed1
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movl -0xb8(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x155e47
jmp 0x155ed1
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
movq -0xf0(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x155ecf
movq -0x50(%rbp), %rdi
movq -0xf0(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x88(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, %esi
movl -0x8c(%rbp), %edx
movq -0x38(%rbp), %rax
movq 0x20(%rax), %r8
movq -0xf0(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x88(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
shlq $0x3, %rax
addq %rax, %r8
addq $0x4, %r8
movl $0x1, %ecx
callq 0xd0e20
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x155e51
jmp 0x155ed1
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x155dd1
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
movq 0x30(%rbp), %rcx
movq 0xc0(%rcx), %rcx
cmpq (%rcx), %rax
jae 0x156c57
movq 0x30(%rbp), %rax
movq 0xc0(%rax), %rax
movq 0x10(%rax), %rax
movl -0x78(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
cmpl $0x3, 0x10(%rax)
jae 0x155f35
jmp 0x156c49
movl $0x1, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movq -0xf8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x156c47
movq -0xf8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x7c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq %rax, -0xd0(%rbp)
movq $-0x1, -0xd8(%rbp)
movq $-0x1, -0xc8(%rbp)
movq -0xd0(%rbp), %rax
movl 0x20(%rbp), %ecx
cmpq %rcx, %rax
jb 0x155fa8
movq -0xd0(%rbp), %rax
movl 0x20(%rbp), %ecx
addl 0x28(%rbp), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jb 0x155fad
jmp 0x156c39
movq -0xf8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x7c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq %rax, -0xc8(%rbp)
movq -0xf8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x7c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq %rax, -0xd8(%rbp)
movq 0x30(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0xc8(%rbp), %rax
movl %eax, %ecx
movq -0x118(%rbp), %r8
movl $0x1, %r9d
callq 0x154b80
movq 0x30(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0xd8(%rbp), %rax
movl %eax, %ecx
movq -0x118(%rbp), %r8
movl $0x1, %r9d
callq 0x154b80
movq 0x30(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0xd0(%rbp), %rax
movl %eax, %ecx
movq -0x118(%rbp), %r8
movl $0x1, %r9d
callq 0x154b80
movq 0x30(%rbp), %rdi
movq -0xd0(%rbp), %rsi
leaq -0x64(%rbp), %rdx
leaq -0x68(%rbp), %rcx
leaq -0x70(%rbp), %r8
leaq -0x74(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0x156bc4
movq -0x70(%rbp), %rax
movl -0x80(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, -0x8c(%rbp)
movq -0xe8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x8c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x1560ef
jmp 0x156bb6
movl $0x0, -0x84(%rbp)
cmpl $0x2, -0x84(%rbp)
jae 0x156bb4
movl -0x8c(%rbp), %eax
shll %eax
addl -0x84(%rbp), %eax
movl %eax, -0xb8(%rbp)
movq -0x60(%rbp), %rdi
movl -0xb8(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
je 0x156137
jmp 0x156ba0
movl -0xb8(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x15615a
movq -0xf0(%rbp), %rax
movl 0x4(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x15616d
movq -0xf0(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x90(%rbp)
movq -0x40(%rbp), %rax
movl -0x90(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x100(%rbp)
movl $0x0, -0x9c(%rbp)
movl $0x0, -0xa0(%rbp)
movl $0xffffffff, -0xa4(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x110(%rbp)
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
movq -0x100(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x1563a3
movq -0x100(%rbp), %rax
movq (%rax), %rax
movl -0x88(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0xe8(%rbp), %r8
movq -0x38(%rbp), %r9
movl -0x54(%rbp), %eax
movl 0x10(%rbp), %r10d
movl %r10d, -0x1f8(%rbp)
movl -0x90(%rbp), %r10d
movl %r10d, -0x1f4(%rbp)
movl -0x8c(%rbp), %r10d
movl %r10d, -0x1f0(%rbp)
movq -0x118(%rbp), %rbx
movq -0x120(%rbp), %r11
movq -0x128(%rbp), %r10
movl 0x18(%rbp), %r14d
movl %r14d, -0x1ec(%rbp)
leaq -0x1e0(%rbp), %r13
leaq -0xa8(%rbp), %r12
leaq -0xac(%rbp), %r15
leaq -0xb0(%rbp), %r14
movl %eax, (%rsp)
movl -0x1f8(%rbp), %eax
movl %eax, 0x8(%rsp)
movl -0x1f4(%rbp), %eax
movl %eax, 0x10(%rsp)
movl -0x1f0(%rbp), %eax
movl %eax, 0x18(%rsp)
movl -0x1ec(%rbp), %eax
movq %r13, 0x20(%rsp)
movq %r12, 0x28(%rsp)
movq %r15, 0x30(%rsp)
movq %r14, 0x38(%rsp)
movq %rbx, 0x40(%rsp)
movq %r11, 0x48(%rsp)
movq %r10, 0x50(%rsp)
movl %eax, 0x58(%rsp)
movl $0x1, 0x60(%rsp)
callq 0x152780
cmpl $0x0, %eax
je 0x15638d
movl $0x0, -0xb4(%rbp)
movl -0xa8(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jbe 0x1562fc
movl $0x1, -0xb4(%rbp)
jmp 0x156350
movl -0xa8(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jne 0x15634e
movl -0xb0(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jae 0x156324
movl $0x1, -0xb4(%rbp)
jmp 0x15634c
movl -0xb0(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jne 0x15634a
movl -0xac(%rbp), %eax
cmpl -0xa0(%rbp), %eax
jbe 0x15634a
movl $0x1, -0xb4(%rbp)
jmp 0x15634c
jmp 0x15634e
jmp 0x156350
cmpl $0x0, -0xb4(%rbp)
je 0x15638b
movl -0xb0(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xa0(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x110(%rbp)
jmp 0x15638d
jmp 0x15638f
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x1561bc
cmpl $0x0, -0x9c(%rbp)
jbe 0x156b9e
movq -0x110(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0xe8(%rbp), %r8
movq -0x38(%rbp), %r9
movl -0x54(%rbp), %eax
movl %eax, -0x208(%rbp)
movl 0x10(%rbp), %eax
movl %eax, -0x204(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x200(%rbp)
movl -0x8c(%rbp), %r13d
movq -0x118(%rbp), %r11
movq -0x120(%rbp), %r10
movl 0x18(%rbp), %eax
movl %eax, -0x1fc(%rbp)
leaq -0x1e0(%rbp), %r12
leaq -0xa8(%rbp), %r15
leaq -0xac(%rbp), %r14
leaq -0xb0(%rbp), %rbx
xorl %eax, %eax
movl -0x208(%rbp), %eax
movl %eax, (%rsp)
movl -0x204(%rbp), %eax
movl %eax, 0x8(%rsp)
movl -0x200(%rbp), %eax
movl %eax, 0x10(%rsp)
movl -0x1fc(%rbp), %eax
movl %r13d, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r15, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
movq %r11, 0x40(%rsp)
movq %r10, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
movl %eax, 0x58(%rsp)
movl $0x1, 0x60(%rsp)
callq 0x152780
cmpq $0x1, -0x1e0(%rbp)
jae 0x156497
jmp 0x156ba0
movq -0x1d0(%rbp), %rax
movq -0x1e0(%rbp), %rcx
subq $0x1, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x158(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x150(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x148(%rbp)
movl $0x0, -0x88(%rbp)
movq $0x0, -0x1a0(%rbp)
movq -0xe8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x118(%rbp), %r9
movl -0x54(%rbp), %r14d
movl 0x10(%rbp), %ebx
movl -0x150(%rbp), %r11d
leaq -0x88(%rbp), %r10
leaq -0x170(%rbp), %rax
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl $0x1, 0x28(%rsp)
callq 0x169ca0
cmpl $0x0, %eax
je 0x1565fa
jmp 0x15654e
movq -0x1a0(%rbp), %rax
cmpq -0x198(%rbp), %rax
jne 0x1565b2
cmpq $0x0, -0x198(%rbp)
je 0x15657b
movq -0x198(%rbp), %rax
shlq %rax
movq %rax, -0x210(%rbp)
jmp 0x156589
movl $0x2, %eax
movq %rax, -0x210(%rbp)
jmp 0x156589
movq -0x210(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x190(%rbp), %rdi
imulq $0x18, -0x198(%rbp), %rsi
callq 0x2360
movq %rax, -0x190(%rbp)
movq -0x190(%rbp), %rax
movq -0x1a0(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x1a0(%rbp)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq -0x170(%rbp), %rcx
movq %rcx, (%rax)
movq -0x168(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x160(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x1564e5
movq -0x38(%rbp), %rdi
movq -0x190(%rbp), %rsi
movq -0x1a0(%rbp), %rax
movl %eax, %edx
callq 0x1553d0
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpq -0x1e0(%rbp), %rax
jae 0x15698d
movq -0x1d0(%rbp), %rax
movl -0x88(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x158(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x150(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x148(%rbp)
movq -0x50(%rbp), %rdi
movl -0x150(%rbp), %esi
shrl %esi
leaq -0x98(%rbp), %rdx
leaq -0x94(%rbp), %rcx
callq 0xd3d50
movl -0x98(%rbp), %eax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movl -0x150(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
orq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0x1c0(%rbp), %rax
cmpq -0x1b8(%rbp), %rax
jne 0x156724
cmpq $0x0, -0x1b8(%rbp)
je 0x1566ea
movq -0x1b8(%rbp), %rax
shlq %rax
movq %rax, -0x218(%rbp)
jmp 0x1566f8
movl $0x2, %eax
movq %rax, -0x218(%rbp)
jmp 0x1566f8
movq -0x218(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq -0x1b0(%rbp), %rdi
movq -0x1b8(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x1b0(%rbp)
movq -0xe0(%rbp), %rdx
movq -0x1b0(%rbp), %rax
movq -0x1c0(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x1c0(%rbp)
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x150(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x0, %edx
movl %edx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movl -0x150(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
movl -0x150(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x8(%rax)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movl -0x54(%rbp), %ecx
movl 0x10(%rbp), %r8d
movq -0x158(%rbp), %rax
shrq $0x20, %rax
movl %eax, %r9d
movl -0x150(%rbp), %r10d
leaq -0x140(%rbp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xe9560
movq -0x188(%rbp), %rax
cmpq -0x180(%rbp), %rax
jne 0x156848
cmpq $0x0, -0x180(%rbp)
je 0x156811
movq -0x180(%rbp), %rax
shlq %rax
movq %rax, -0x220(%rbp)
jmp 0x15681f
movl $0x2, %eax
movq %rax, -0x220(%rbp)
jmp 0x15681f
movq -0x220(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x178(%rbp), %rdi
imulq $0x18, -0x180(%rbp), %rsi
callq 0x2360
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
movq -0x188(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x188(%rbp)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq -0x140(%rbp), %rcx
movq %rcx, (%rax)
movq -0x138(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movl -0x54(%rbp), %ecx
movl 0x10(%rbp), %r8d
movl -0x150(%rbp), %r9d
xorl $0x1, %r9d
movq -0x158(%rbp), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %r10d
leaq -0x140(%rbp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xe9560
movq -0x188(%rbp), %rax
cmpq -0x180(%rbp), %rax
jne 0x156934
cmpq $0x0, -0x180(%rbp)
je 0x1568fd
movq -0x180(%rbp), %rax
shlq %rax
movq %rax, -0x228(%rbp)
jmp 0x15690b
movl $0x2, %eax
movq %rax, -0x228(%rbp)
jmp 0x15690b
movq -0x228(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x178(%rbp), %rdi
imulq $0x18, -0x180(%rbp), %rsi
callq 0x2360
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
movq -0x188(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x188(%rbp)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq -0x140(%rbp), %rcx
movq %rcx, (%rax)
movq -0x138(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x156979
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x15661d
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpq -0x1a0(%rbp), %rax
jae 0x156b9c
movq -0x190(%rbp), %rax
movl -0x88(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x140(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x138(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x130(%rbp)
movl -0x134(%rbp), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1569f1
jmp 0x156b88
jmp 0x1569f3
movq -0x188(%rbp), %rax
cmpq -0x180(%rbp), %rax
jne 0x156a57
cmpq $0x0, -0x180(%rbp)
je 0x156a20
movq -0x180(%rbp), %rax
shlq %rax
movq %rax, -0x230(%rbp)
jmp 0x156a2e
movl $0x2, %eax
movq %rax, -0x230(%rbp)
jmp 0x156a2e
movq -0x230(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x178(%rbp), %rdi
imulq $0x18, -0x180(%rbp), %rsi
callq 0x2360
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
movq -0x188(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x188(%rbp)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq -0x140(%rbp), %rcx
movq %rcx, (%rax)
movq -0x138(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movl -0x54(%rbp), %ecx
movl 0x10(%rbp), %r8d
movl -0x138(%rbp), %r9d
xorl $0x1, %r9d
movq -0x140(%rbp), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %r10d
leaq -0x140(%rbp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xe9560
movq -0x188(%rbp), %rax
cmpq -0x180(%rbp), %rax
jne 0x156b43
cmpq $0x0, -0x180(%rbp)
je 0x156b0c
movq -0x180(%rbp), %rax
shlq %rax
movq %rax, -0x238(%rbp)
jmp 0x156b1a
movl $0x2, %eax
movq %rax, -0x238(%rbp)
jmp 0x156b1a
movq -0x238(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x178(%rbp), %rdi
imulq $0x18, -0x180(%rbp), %rsi
callq 0x2360
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
movq -0x188(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x188(%rbp)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq -0x140(%rbp), %rcx
movq %rcx, (%rax)
movq -0x138(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x156b88
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x156997
jmp 0x156b9e
jmp 0x156ba0
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x1560f9
jmp 0x156bb6
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x1560a0
movq 0x30(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0xc8(%rbp), %rax
movl %eax, %ecx
movq -0x118(%rbp), %r8
xorl %r9d, %r9d
callq 0x154b80
movq 0x30(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0xd8(%rbp), %rax
movl %eax, %ecx
movq -0x118(%rbp), %r8
xorl %r9d, %r9d
callq 0x154b80
movq 0x30(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0xd0(%rbp), %rax
movl %eax, %ecx
movq -0x118(%rbp), %r8
xorl %r9d, %r9d
callq 0x154b80
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x155f3c
jmp 0x156c49
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x155eec
movq $0x0, -0x1e8(%rbp)
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpq -0x188(%rbp), %rax
jae 0x156ccd
movq -0x38(%rbp), %rdi
callq 0xd4050
movq %rax, -0x1e8(%rbp)
movq -0x178(%rbp), %rcx
movl -0x88(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rcx
movq -0x1e8(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x156c6c
cmpq $0x0, -0x188(%rbp)
je 0x156d15
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2210
movq -0x38(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x38(%rbp), %rax
movl 0x4(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x4(%rax)
movq -0x38(%rbp), %rdi
callq 0xcdd10
movq -0x38(%rbp), %rdi
callq 0xce020
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x38(%rbp), %rdx
xorl %ecx, %ecx
callq 0x150830
movq -0x38(%rbp), %rdi
movq 0x38(%rbp), %rsi
callq 0x151020
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpq -0x188(%rbp), %rax
jae 0x156e54
movq -0x178(%rbp), %rax
movl -0x88(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0xb8(%rbp)
movq -0x178(%rbp), %rax
movl -0x88(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0xbc(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0xb8(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x156db2
jmp 0x156e40
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0xbc(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x156dd1
jmp 0x156e40
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movl -0xb8(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x156e06
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movl -0xbc(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x156e06
jmp 0x156e40
movq -0x38(%rbp), %rdi
movl -0xb8(%rbp), %esi
movl -0xbc(%rbp), %edx
movl $0x1, %ecx
callq 0xd6530
movq -0x38(%rbp), %rdi
movl -0xbc(%rbp), %esi
xorl $0x1, %esi
movl -0xb8(%rbp), %edx
xorl $0x1, %edx
movl $0x1, %ecx
callq 0xd6530
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x156d3f
movq -0x38(%rbp), %rdi
callq 0xcdd10
movq -0x38(%rbp), %rdi
callq 0xce020
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpq -0x1c0(%rbp), %rax
jae 0x156f82
movq -0x1b0(%rbp), %rax
movl -0x88(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
shll %eax
movl %eax, -0xbc(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0xbc(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x156f1d
movq -0x38(%rbp), %rdi
movl -0xbc(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
jne 0x156ef8
movq -0x38(%rbp), %rdi
movl -0xbc(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
je 0x156f1d
movl -0xbc(%rbp), %eax
shrl %eax
movl %eax, -0xbc(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movl -0xbc(%rbp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x156f6c
movl -0xbc(%rbp), %eax
shrl %eax
movl %eax, -0xbc(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0xbc(%rbp), %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movl -0xbc(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
jmp 0x156f6e
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x156e70
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x156fe9
movq -0x50(%rbp), %rdi
movl -0xb8(%rbp), %esi
leaq -0x8c(%rbp), %rdx
leaq -0x94(%rbp), %rcx
callq 0xd3d50
cmpl $0x1, -0x94(%rbp)
jne 0x156fd6
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movl -0xb8(%rbp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x156fd8
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x156f8c
movq -0x178(%rbp), %rdi
callq 0x2210
movq -0x190(%rbp), %rdi
callq 0x2210
movq -0x1b0(%rbp), %rdi
callq 0x2210
movq -0x1d0(%rbp), %rdi
callq 0x2210
movq -0x118(%rbp), %rdi
callq 0x2210
movq -0x120(%rbp), %rdi
callq 0x2210
movq -0x128(%rbp), %rdi
callq 0x2210
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop