// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: rescue_bubbles_by_cmk_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*, unsigned char*)
void rescue_bubbles_by_cmk_reads(ma_ug_t *i_u_g, asg_t *rg, 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, uint8_t *cmk)
{
    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, 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, rg->n_seq);
    uint8_t* circle_vis = NULL; CALLOC(circle_vis, rg->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, &(rg->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, rg, l_bub, expect_vis, 1);
            set_rtg_flag_by_bubble(bub, ug, rg, r_bub, expect_vis, 1);
            set_rtg_flag_by_bubble(bub, ug, rg, 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++) {
                        ///h is the edge of endRid
                        h = &(x->buffer[k]);
                        ///means we found a contained read
                        if(get_chimeric_reads_chain_by_broken_bub(h, sources, coverage_cut, ruIndex, ug, rg, max_hang, min_ovlp, endRid, uId, &chain_edges, &ava_cur, &test_oLen, &ava_chainLen, expect_vis, circle_vis, utg_vis, chainLenThres, 1, cmk)) {
                            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_chimeric_reads_chain_by_broken_bub(h_max, sources, coverage_cut, ruIndex, ug, rg, max_hang, min_ovlp, endRid, uId, &chain_edges, &ava_cur, &test_oLen, &ava_chainLen, expect_vis, circle_vis, NULL, chainLenThres, 1, cmk);
                        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, rg, 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(rg, 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);
                            if((is_Unitig == 1) || (is_Unitig == ((uint32_t)-1))) contain_rId = ((uint32_t)-1);///shouldn't be possible
                            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);

                            rg->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, rg, l_bub, expect_vis, 0);
            set_rtg_flag_by_bubble(bub, ug, rg, r_bub, expect_vis, 0);
            set_rtg_flag_by_bubble(bub, ug, rg, m_bub, expect_vis, 0);
        }
    }

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

    if(new_edges.n != 0) {
        free(rg->idx);
        rg->idx = 0;
        rg->is_srt = 0;
        asg_cleanup(rg);
        asg_symm(rg);
    }

    pre_clean(sources, coverage_cut, rg, 0);

    lable_all_bubbles(rg, 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(rg->seq[v>>1].del) continue;
        if(rg->seq[w>>1].del) continue;
        ///if this edge is at a bubble
        if(rg->seq_vis[v]!=0 && rg->seq_vis[w^1]!=0) continue;

        asg_arc_del(rg, v, w, 1);
        asg_arc_del(rg, w^1, v^1, 1);
    }
    asg_cleanup(rg);
    asg_symm(rg);

    for (k = 0; k < u_vecs.a.n; k++) {
        w = (uint32_t)u_vecs.a.a[k];
        w = w<<1;
        if((!rg->seq[w>>1].del) && (get_real_length(rg, w, NULL)!=0 || get_real_length(rg, (w^1), NULL)!=0)) {
            w=w>>1;
            ruIndex->index[w] = (uint32_t)-1;
        } else {
            w=w>>1;
            rg->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 $0x298, %rsp            # imm = 0x298
movq 0x40(%rbp), %rax
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 0x1571b8
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 0x15717b
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 0x157369
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 0x1572ad
jmp 0x157355
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movl -0xb8(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1572cb
jmp 0x157355
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
movq -0xf0(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x157353
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 0x1572d5
jmp 0x157355
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x157255
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
movq 0x30(%rbp), %rcx
movq 0xc0(%rcx), %rcx
cmpq (%rcx), %rax
jae 0x158127
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 0x1573b9
jmp 0x158119
movl $0x1, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movq -0xf8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x158117
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 0x15742c
movq -0xd0(%rbp), %rax
movl 0x20(%rbp), %ecx
addl 0x28(%rbp), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jb 0x157431
jmp 0x158109
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 0x158094
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 0x157573
jmp 0x158086
movl $0x0, -0x84(%rbp)
cmpl $0x2, -0x84(%rbp)
jae 0x158084
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 0x1575bb
jmp 0x158070
movl -0xb8(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1575de
movq -0xf0(%rbp), %rax
movl 0x4(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x1575f1
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 0x157840
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, -0x204(%rbp)
movl -0x90(%rbp), %r10d
movl %r10d, -0x200(%rbp)
movl -0x8c(%rbp), %r10d
movl %r10d, -0x1fc(%rbp)
movq -0x118(%rbp), %r14
movq -0x120(%rbp), %rbx
movq -0x128(%rbp), %r11
movl 0x18(%rbp), %r10d
movq 0x40(%rbp), %r15
movq %r15, -0x1f0(%rbp)
leaq -0x1e0(%rbp), %r15
movq %r15, -0x1f8(%rbp)
leaq -0xa8(%rbp), %r13
leaq -0xac(%rbp), %r12
leaq -0xb0(%rbp), %r15
movl %eax, (%rsp)
movl -0x204(%rbp), %eax
movl %eax, 0x8(%rsp)
movl -0x200(%rbp), %eax
movl %eax, 0x10(%rsp)
movl -0x1fc(%rbp), %eax
movl %eax, 0x18(%rsp)
movq -0x1f8(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0x1f0(%rbp), %rax
movq %r13, 0x28(%rsp)
movq %r12, 0x30(%rsp)
movq %r15, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movq %rbx, 0x48(%rsp)
movq %r11, 0x50(%rsp)
movl %r10d, 0x58(%rsp)
movl $0x1, 0x60(%rsp)
movq %rax, 0x68(%rsp)
callq 0x152ce0
cmpl $0x0, %eax
je 0x15782a
movl $0x0, -0xb4(%rbp)
movl -0xa8(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jbe 0x157799
movl $0x1, -0xb4(%rbp)
jmp 0x1577ed
movl -0xa8(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jne 0x1577eb
movl -0xb0(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jae 0x1577c1
movl $0x1, -0xb4(%rbp)
jmp 0x1577e9
movl -0xb0(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jne 0x1577e7
movl -0xac(%rbp), %eax
cmpl -0xa0(%rbp), %eax
jbe 0x1577e7
movl $0x1, -0xb4(%rbp)
jmp 0x1577e9
jmp 0x1577eb
jmp 0x1577ed
cmpl $0x0, -0xb4(%rbp)
je 0x157828
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 0x15782a
jmp 0x15782c
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x157640
cmpl $0x0, -0x9c(%rbp)
jbe 0x15806e
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, -0x220(%rbp)
movl 0x10(%rbp), %eax
movl %eax, -0x21c(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x218(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x214(%rbp)
movq -0x118(%rbp), %rbx
movq -0x120(%rbp), %r11
movl 0x18(%rbp), %r10d
movq 0x40(%rbp), %rax
movq %rax, -0x210(%rbp)
leaq -0x1e0(%rbp), %r13
leaq -0xa8(%rbp), %r12
leaq -0xac(%rbp), %r15
leaq -0xb0(%rbp), %r14
xorl %eax, %eax
movl -0x220(%rbp), %eax
movl %eax, (%rsp)
movl -0x21c(%rbp), %eax
movl %eax, 0x8(%rsp)
movl -0x218(%rbp), %eax
movl %eax, 0x10(%rsp)
movl -0x214(%rbp), %eax
movl %eax, 0x18(%rsp)
movq -0x210(%rbp), %rax
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 $0x0, 0x50(%rsp)
movl %r10d, 0x58(%rsp)
movl $0x1, 0x60(%rsp)
movq %rax, 0x68(%rsp)
callq 0x152ce0
cmpq $0x1, -0x1e0(%rbp)
jae 0x15794b
jmp 0x158070
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 0x157aae
jmp 0x157a02
movq -0x1a0(%rbp), %rax
cmpq -0x198(%rbp), %rax
jne 0x157a66
cmpq $0x0, -0x198(%rbp)
je 0x157a2f
movq -0x198(%rbp), %rax
shlq %rax
movq %rax, -0x228(%rbp)
jmp 0x157a3d
movl $0x2, %eax
movq %rax, -0x228(%rbp)
jmp 0x157a3d
movq -0x228(%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 0x157999
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 0x157e5d
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
cmpl $0x1, -0x94(%rbp)
je 0x157b49
cmpl $-0x1, -0x94(%rbp)
jne 0x157b53
movl $0xffffffff, -0x98(%rbp) # imm = 0xFFFFFFFF
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 0x157bf4
cmpq $0x0, -0x1b8(%rbp)
je 0x157bba
movq -0x1b8(%rbp), %rax
shlq %rax
movq %rax, -0x230(%rbp)
jmp 0x157bc8
movl $0x2, %eax
movq %rax, -0x230(%rbp)
jmp 0x157bc8
movq -0x230(%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 0x157d18
cmpq $0x0, -0x180(%rbp)
je 0x157ce1
movq -0x180(%rbp), %rax
shlq %rax
movq %rax, -0x238(%rbp)
jmp 0x157cef
movl $0x2, %eax
movq %rax, -0x238(%rbp)
jmp 0x157cef
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)
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 0x157e04
cmpq $0x0, -0x180(%rbp)
je 0x157dcd
movq -0x180(%rbp), %rax
shlq %rax
movq %rax, -0x240(%rbp)
jmp 0x157ddb
movl $0x2, %eax
movq %rax, -0x240(%rbp)
jmp 0x157ddb
movq -0x240(%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 0x157e49
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x157ad1
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpq -0x1a0(%rbp), %rax
jae 0x15806c
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 0x157ec1
jmp 0x158058
jmp 0x157ec3
movq -0x188(%rbp), %rax
cmpq -0x180(%rbp), %rax
jne 0x157f27
cmpq $0x0, -0x180(%rbp)
je 0x157ef0
movq -0x180(%rbp), %rax
shlq %rax
movq %rax, -0x248(%rbp)
jmp 0x157efe
movl $0x2, %eax
movq %rax, -0x248(%rbp)
jmp 0x157efe
movq -0x248(%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 0x158013
cmpq $0x0, -0x180(%rbp)
je 0x157fdc
movq -0x180(%rbp), %rax
shlq %rax
movq %rax, -0x250(%rbp)
jmp 0x157fea
movl $0x2, %eax
movq %rax, -0x250(%rbp)
jmp 0x157fea
movq -0x250(%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 0x158058
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x157e67
jmp 0x15806e
jmp 0x158070
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x15757d
jmp 0x158086
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x157524
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 0x1573c0
jmp 0x158119
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x157370
movq $0x0, -0x1e8(%rbp)
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpq -0x188(%rbp), %rax
jae 0x15819d
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 0x15813c
cmpq $0x0, -0x188(%rbp)
je 0x1581e5
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 0x158324
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 0x158282
jmp 0x158310
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 0x1582a1
jmp 0x158310
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movl -0xb8(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1582d6
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 0x1582d6
jmp 0x158310
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 0x15820f
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 0x158452
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 0x1583ed
movq -0x38(%rbp), %rdi
movl -0xbc(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
jne 0x1583c8
movq -0x38(%rbp), %rdi
movl -0xbc(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
je 0x1583ed
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 0x15843c
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 0x15843e
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x158340
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1584b9
movq -0x50(%rbp), %rdi
movl -0xb8(%rbp), %esi
leaq -0x8c(%rbp), %rdx
leaq -0x94(%rbp), %rcx
callq 0xd3d50
cmpl $0x1, -0x94(%rbp)
jne 0x1584a6
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movl -0xb8(%rbp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x1584a8
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x15845c
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 $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop