// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: update_bubble_chain(ma_ug_t*, bubble_type*, unsigned int, unsigned int)
void update_bubble_chain(ma_ug_t* ug, bubble_type* bub, uint32_t is_middle, uint32_t is_end)
{
    // double index_time = yak_realtime();
    if(bub->b_ug) ma_ug_destroy(bub->b_ug);
    if(bub->chain_weight.a) kv_destroy(bub->chain_weight);
    kvec_t_u32_warp broken;
    kv_init(broken.a);
    kvec_asg_arc_t_warp edges;
    kv_init(edges.a);
    ma_utg_t *u = NULL;
    asg_arc_t *t = NULL;
    asg_t *sg = ug->g;
    pdq pq;
    init_pdq(&pq, sg->n_seq<<1);
    asg_t *bsg = bub->b_g;
    ma_ug_t *bub_ug = NULL;
    bub_ug = ma_ug_gen(bub->b_g);
    uint32_t i, j, k_i, rId_0, ori_0, root_0, rId_1, ori_1, root_1, n_vtx = sg->n_seq<<1, new_bub;
    uint32_t *pre = NULL; MALLOC(pre, n_vtx); 
    uint8_t* vis_flag = NULL; MALLOC(vis_flag, ug->g->n_seq*2);
    kvec_t_u32_warp stack; kv_init(stack.a);
    ///chain_w_type x;
    ///uint64_t end_thres;

    uint8_t *bsg_idx = NULL; CALLOC(bsg_idx, n_vtx>>1); 
    for (i = 0; i < bub_ug->u.n; i++)///label all unitigs within the bubble chains
    {
        u = &(bub_ug->u.a[i]);///a bubble chain
        if(u->n == 0) continue;
        for (k_i = 0; k_i < u->n; k_i++)
        {
            uint32_t *a, n;
            get_bubbles(bub, u->a[k_i]>>33, &root_0, &root_1, &a, &n, NULL);
            for (j = 0; j < n; j++)
            {
                bsg_idx[a[j]>>1] = 1;
            }
            bsg_idx[root_0>>1] = 1;
            bsg_idx[root_1>>1] = 1;
        }
    }

    if(bub->num.n > 0) bub->num.n--;
    new_bub = bub->b_g->n_seq;
    for (i = 0; i < bub_ug->u.n; i++)
    {
        u = &(bub_ug->u.a[i]);///bubble chain
        if(u->n == 0) continue;
        ///end_thres = calculate_chain_weight(u, bub, ug, &x);
        if(is_middle)
        {
            for (k_i = 0; k_i < u->n; k_i++)
            {
                if(k_i+1 >= u->n) continue;
                ///note: must igore .del here, since bsg might be changed
                t = &(arc_first(bsg, u->a[k_i]>>32));
                if(t->el == 1) continue;///if a[k_i] and a[k_i+1] are directly connected without any tangle involoved

                rId_0 = u->a[k_i]>>33;
                ori_0 = u->a[k_i]>>32&1;
                get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);
                
                rId_1 = u->a[k_i+1]>>33;
                ori_1 = (u->a[k_i+1]>>32&1)^1;
                get_bubbles(bub, rId_1, ori_1 == 1?&root_1:NULL, ori_1 == 0?&root_1:NULL, NULL, NULL, NULL);

                broken.a.n = 0;///just collect all nodes between root_0 and root_1
                get_related_bub_nodes(&broken, bub, &pq, sg, pre, root_0, root_1, NULL);
                get_related_bub_nodes(&broken, bub, &pq, sg, pre, root_1, root_0, NULL);
                ///no need to cut the edge, we still have chance to flip by chain
                if(double_check_broken_bubble(ug->g, &broken, root_0^1, root_1^1, vis_flag, 
                                                                    ug->g->n_seq*2, &stack, NULL, NULL/**bsg, t**/) == 0)
                {
                    continue;
                }
                if(!IF_HOM(root_0>>1, *bub)) kv_push(uint32_t, broken.a, root_0);
                if(!IF_HOM(root_1>>1, *bub)) kv_push(uint32_t, broken.a, root_1);
                if(broken.a.n > 0)
                {
                    update_bubble_graph(&broken, root_0^1, rId_0, root_1^1, rId_1, bub, &edges, bsg, t, bsg_idx, ug, NULL, 1);
                }
            }
        }


        if(is_end)
        {
            if(u->n >0 && arc_cnt(bub_ug->g, (i<<1)+1) == 0)
            {
                rId_0 = u->a[0]>>33;
                ori_0 = (u->a[0]>>32&1)^1;
                get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);
                broken.a.n = 0;
                get_related_bub_nodes(&broken, bub, &pq, sg, pre, root_0, (uint32_t)-1, NULL);

                if(double_check_broken_bubble(ug->g, &broken, root_0^1, (uint32_t)-1, vis_flag, 
                                                                    ug->g->n_seq*2, &stack, NULL, NULL))
                {
                    if(!IF_HOM(root_0>>1, *bub)) kv_push(uint32_t, broken.a, root_0);
                    if(broken.a.n > 0)
                    {
                        ///fprintf(stderr, "root_0: utg%.6ul, broken.a.n: %u\n", (root_0>>1)+1, (uint32_t)broken.a.n);
                        update_bubble_graph(&broken, root_0^1, rId_0, (uint32_t)-1, (uint32_t)-1, bub, &edges, bsg, NULL, bsg_idx, ug, NULL, 0);
                    }
                }   
            }

        
            if(u->n >0 && arc_cnt(bub_ug->g, i<<1) == 0)
            {
                rId_1 = u->a[u->n-1]>>33;
                ori_1 = u->a[u->n-1]>>32&1;
                get_bubbles(bub, rId_1, ori_1 == 1?&root_1:NULL, ori_1 == 0?&root_1:NULL, NULL, NULL, NULL);
                broken.a.n = 0;
                get_related_bub_nodes(&broken, bub, &pq, sg, pre, root_1, (uint32_t)-1, bsg_idx);

                if(double_check_broken_bubble(ug->g, &broken, root_1^1, (uint32_t)-1, vis_flag, 
                                                                    ug->g->n_seq*2, &stack, NULL, NULL))
                {
                    if(!IF_HOM(root_1>>1, *bub)) kv_push(uint32_t, broken.a, root_1);
                    if(broken.a.n > 0)
                    {
                        ///fprintf(stderr, "root_1: utg%.6ul, broken.a.n: %u\n", (root_1>>1)+1, (uint32_t)broken.a.n);
                        update_bubble_graph(&broken, (uint32_t)-1, (uint32_t)-1, root_1^1, rId_1, bub, &edges, bsg, NULL, bsg_idx, ug, NULL, 0);
                    }

                }
            }
        }
    }
    kv_push(uint32_t, bub->num, bub->list.n);
    new_bub = bub->b_g->n_seq - new_bub;
    if(is_end) bub->b_end_bub += new_bub;
    ///actually not useful, and may have bug when one bubble at multipe chains
    if(new_bub) update_bub_b_s_idx(bub);


    for (i = 0; i < edges.a.n; i++)
    {        
        t = asg_arc_pushp(bsg);
        *t = edges.a.a[i];
    }

    bsg->is_srt = 0; free(bsg->idx); bsg->idx = 0;
    asg_cleanup(bsg);
    ma_ug_destroy(bub_ug);
    destory_pdq(&pq);
    free(pre);
    kv_destroy(broken.a);
    kv_destroy(edges.a);
    free(bsg_idx);
    kv_destroy(stack.a); 
    free(vis_flag);

    bub->b_ug = ma_ug_gen(bub->b_g);
    bub_ug = bub->b_ug;
    kv_malloc(bub->chain_weight, bub_ug->u.n); bub->chain_weight.n = bub_ug->u.n;
    for (i = 0; i < bub_ug->u.n; i++)
    {
        u = &(bub_ug->u.a[i]);
        bub->chain_weight.a[i].id = i;
        // if(u->n <= 1) ///not a chain
        // {
        //     bub->chain_weight.a[i].b_occ = bub->chain_weight.a[i].g_occ = 0;
        //     bub->chain_weight.a[i].del = 1;
        // } 
        // else
        {
            bub->chain_weight.a[i].del = 0;
            calculate_chain_weight(u, bub, ug, &(bub->chain_weight.a[i]));
        }
    }

    qsort(bub->chain_weight.a, bub->chain_weight.n, sizeof(chain_w_type), cmp_chain_weight);



    /**
    uint32_t d_v, d_u, v;
    for (i = 0; i < bsg->n_arc; i++)
    {
        d_v = (uint32_t)(bsg->arc[i].ul>>32);
        d_u = bsg->arc[i].v;
        for (v = 0; v < bsg->n_arc; v++)
        {
            if(((bsg->arc[v].ul>>32) == (d_u^1)) && (bsg->arc[v].v == (d_v^1))) break;      
        }

        if(v == bsg->n_arc)
        {
            fprintf(stderr, "hahaha, el: %u, ul>>33: %lu, ul&1: %lu, v>>1: %u, v&1: %u\n", 
                    bsg->arc[i].el, bsg->arc[i].ul>>33, (bsg->arc[i].ul>>32)&1, bsg->arc[i].v>>1, bsg->arc[i].v&1);
        }
        // else
        // {
        //     fprintf(stderr, "hehehe, el: %u, ul>>33: %lu, ul&1: %lu, v>>1: %u, v&1: %u\n", 
        //             bsg->arc[i].el, bsg->arc[i].ul>>33, (bsg->arc[i].ul>>32)&1, bsg->arc[i].v>>1, bsg->arc[i].v&1);
        // }
    }

    asg_arc_t *av = NULL, *au = NULL;
    uint32_t nv, nu;
    for (v = 0; v < (uint32_t)(bsg->n_seq<<1); v++)
    {
        av = asg_arc_a(bsg, v);
        nv = asg_arc_n(bsg, v);
        for (i = 0; i < nv; i++)
        {
            if(av[i].del) continue;

            au = asg_arc_a(bsg, av[i].v^1);
            nu = asg_arc_n(bsg, av[i].v^1);
            for (k_i = 0; k_i < nu; k_i++)
            {
                if(au[k_i].del) continue;
                if(au[k_i].v == (v^1)) break;
            }
            if(k_i == nu) fprintf(stderr, "hahaha: v: %u, u: %u\n", v, av[i].v);
        }        
    }
    **/
    // fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movl %ecx, 0x74(%rsp)
movl %edx, 0xb8(%rsp)
movq %rsi, %rbx
movq %rdi, 0x68(%rsp)
movq 0xc0(%rsi), %rdi
testq %rdi, %rdi
je 0x1072df
callq 0x6921d
movq 0xd8(%rbx), %rdi
callq 0x2220
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0xf0(%rsp)
andq $0x0, 0x100(%rsp)
movq 0x68(%rsp), %r15
movq 0x18(%r15), %r14
movl 0x14(%r14), %eax
addl %eax, %eax
movslq %eax, %rsi
leaq 0x130(%rsp), %rdi
callq 0xfa585
movq %rbx, 0xa8(%rsp)
movq 0xb8(%rbx), %rdi
movq %rdi, 0x78(%rsp)
callq 0x76d91
movq %rax, 0x88(%rsp)
movq %r14, 0xb0(%rsp)
movl 0x14(%r14), %r14d
leal (%r14,%r14), %edi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x90(%rsp)
movq 0x18(%r15), %rax
movl 0x14(%rax), %edi
addl %edi, %edi
callq 0x2280
movq %rax, 0x98(%rsp)
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x2120
andq $0x0, 0x120(%rsp)
movq %rax, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x110(%rsp)
xorl %ebx, %ebx
leaq 0xbc(%rsp), %r13
movb $0x1, %bpl
movl %ebx, %ebx
movq 0x88(%rsp), %r14
movq (%r14), %rax
cmpq %rbx, %rax
jbe 0x10746b
movq 0x10(%r14), %r14
imulq $0x28, %rbx, %rcx
movl 0x10(%r14,%rcx), %eax
testl %eax, %eax
je 0x107464
addq %rcx, %r14
xorl %r12d, %r12d
movl %eax, %eax
cmpq %rax, %r12
jae 0x107464
movq 0x18(%r14), %rax
movq (%rax,%r12,8), %rsi
shrq $0x21, %rsi
andq $0x0, (%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x3c(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0xe8(%rsp), %r8
movq %r13, %r9
callq 0xf6ab5
movl 0xbc(%rsp), %eax
movq 0xe8(%rsp), %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x107447
movl (%rcx,%rdx,4), %esi
shrl %esi
movb $0x1, (%r15,%rsi)
incq %rdx
jmp 0x107433
movl 0x3c(%rsp), %eax
shrl %eax
movb %bpl, (%r15,%rax)
movl 0x38(%rsp), %eax
shrl %eax
movb %bpl, (%r15,%rax)
incq %r12
movl 0x10(%r14), %eax
jmp 0x1073e8
incl %ebx
jmp 0x1073b7
movq 0xa8(%rsp), %r13
movq 0x30(%r13), %rcx
testq %rcx, %rcx
je 0x107483
decq %rcx
movq %rcx, 0x30(%r13)
movq 0xb8(%r13), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x84(%rsp)
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x107b6e
movq 0x10(%r14), %rdx
movq %rcx, 0xc0(%rsp)
imulq $0x28, %rcx, %rcx
movl 0x10(%rdx,%rcx), %eax
testl %eax, %eax
je 0x107834
movq %rdx, %rbx
addq %rcx, %rbx
cmpl $0x0, 0xb8(%rsp)
movq %rbx, 0xa0(%rsp)
je 0x1077f0
xorl %r14d, %r14d
movl %eax, %eax
cmpq %rax, %r14
jae 0x1077db
movq %r14, %r12
incq %r14
cmpq %rax, %r14
jae 0x1077d3
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x28(%rax), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%r12,8), %rdx
movq %rdx, %rcx
shrq $0x20, %rcx
movl 0x4(%rax,%rcx,8), %eax
imulq $0x18, %rax, %rax
movq %rax, 0xe0(%rsp)
cmpb $0x1, 0x12(%rdi,%rax)
je 0x1077d3
movq %rdx, %rsi
shrq $0x21, %rsi
movabsq $0x100000000, %rbp      # imm = 0x100000000
movq %rdi, 0xd8(%rsp)
andq %rbp, %rdx
leaq 0x3c(%rsp), %rax
cmovneq %rax, %rdx
movl $0x0, %ecx
cmoveq %rax, %rcx
andq $0x0, (%rsp)
movq %r13, %rdi
movq %rsi, 0xd0(%rsp)
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xf6ab5
movq 0x18(%rbx), %rax
movq 0x8(%rax,%r12,8), %rcx
movq %rcx, %rsi
shrq $0x21, %rsi
andq %rbp, %rcx
movl $0x0, %edx
leaq 0x38(%rsp), %rax
cmoveq %rax, %rdx
cmovneq %rax, %rcx
andq $0x0, (%rsp)
movq %r13, %rdi
movq %rsi, 0xc8(%rsp)
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xf6ab5
andq $0x0, 0x40(%rsp)
movl 0x3c(%rsp), %r9d
movl 0x38(%rsp), %eax
movl %eax, (%rsp)
andq $0x0, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x130(%rsp), %rbx
movq %rbx, %rdx
movq 0xb0(%rsp), %rbp
movq %rbp, %rcx
movq %r13, %r12
movq 0x90(%rsp), %r13
movq %r13, %r8
callq 0x104ab6
movl 0x38(%rsp), %r9d
movl 0x3c(%rsp), %eax
movl %eax, (%rsp)
andq $0x0, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
movq %rbx, %rdx
movq 0xa0(%rsp), %rbx
movq %rbp, %rcx
movq 0xd8(%rsp), %rbp
movq %r13, %r8
movq %r12, %r13
callq 0x104ab6
movq 0x68(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x3c(%rsp), %edx
xorl $0x1, %edx
movl 0x38(%rsp), %ecx
xorl $0x1, %ecx
movl 0x14(%rdi), %r9d
addl %r9d, %r9d
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, (%rsp)
leaq 0x40(%rsp), %rsi
movq 0x98(%rsp), %r8
callq 0x104025
testl %eax, %eax
je 0x1077d3
movq (%r13), %rdx
movq 0x80(%r13), %rcx
movl 0x3c(%rsp), %esi
movl %esi, %eax
shrl %eax
movl (%rdx,%rax,4), %eax
incq %rcx
cmpq %rax, %rcx
jb 0x1076fd
movq 0x40(%rsp), %r13
movq 0x50(%rsp), %rax
cmpq 0x48(%rsp), %r13
jne 0x1076f0
leaq (,%r13,2), %rsi
testq %r13, %r13
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x48(%rsp)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x50(%rsp)
movl 0x3c(%rsp), %esi
movq 0xa8(%rsp), %rcx
movq (%rcx), %rdx
movq 0x80(%rcx), %rcx
incq %rcx
leaq 0x1(%r13), %rdi
movq %rdi, 0x40(%rsp)
movl %esi, (%rax,%r13,4)
movl 0x38(%rsp), %esi
movl %esi, %eax
shrl %eax
movl (%rdx,%rax,4), %eax
movq 0x40(%rsp), %r13
cmpq %rax, %rcx
jb 0x10775a
movq 0x50(%rsp), %rax
cmpq 0x48(%rsp), %r13
jne 0x10774a
leaq (,%r13,2), %rsi
testq %r13, %r13
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x48(%rsp)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x50(%rsp)
movl 0x38(%rsp), %esi
leaq 0x1(%r13), %rcx
movq %rcx, 0x40(%rsp)
movl %esi, (%rax,%r13,4)
movq %rcx, %r13
testq %r13, %r13
movq 0xa8(%rsp), %r13
je 0x1077d3
addq 0xe0(%rsp), %rbp
movl 0x3c(%rsp), %esi
xorl $0x1, %esi
movl 0x38(%rsp), %ecx
xorl $0x1, %ecx
movq 0x68(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movq %rbp, 0x10(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x28(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, (%rsp)
movq $0x1, 0x30(%rsp)
leaq 0x40(%rsp), %rdi
movq 0xd0(%rsp), %rdx
movq 0xc8(%rsp), %r8
movq %r13, %r9
callq 0x10441e
movl 0x10(%rbx), %eax
jmp 0x1074dc
cmpl $0x0, 0x74(%rsp)
movq 0x88(%rsp), %r14
je 0x107834
testl %eax, %eax
jne 0x1077f7
jmp 0x107834
cmpl $0x0, 0x74(%rsp)
je 0x107834
movq 0x18(%r14), %rax
movq 0x28(%rax), %rax
movq 0xc0(%rsp), %rcx
leal (%rcx,%rcx), %ebx
cmpl $0x0, 0x8(%rax,%rbx,8)
je 0x107846
movq 0xa0(%rsp), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
je 0x107834
movq 0x18(%r14), %rcx
movq 0x28(%rcx), %rcx
movl %ebx, %edx
cmpl $0x0, (%rcx,%rdx,8)
je 0x1079de
movq 0xc0(%rsp), %rcx
incl %ecx
movq (%r14), %rax
jmp 0x107496
movq 0xa0(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rcx
movq %rcx, %r12
shrq $0x21, %r12
movabsq $0x100000000, %rax      # imm = 0x100000000
andq %rax, %rcx
movl $0x0, %edx
leaq 0x3c(%rsp), %rax
cmoveq %rax, %rdx
cmovneq %rax, %rcx
andq $0x0, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xf6ab5
andq $0x0, 0x40(%rsp)
movl 0x3c(%rsp), %r9d
andq $0x0, 0x8(%rsp)
orl $-0x1, (%rsp)
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
leaq 0x130(%rsp), %rdx
movq 0xb0(%rsp), %rcx
movq 0x90(%rsp), %r8
callq 0x104ab6
movq 0x68(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x3c(%rsp), %edx
xorl $0x1, %edx
movl 0x14(%rdi), %r9d
addl %r9d, %r9d
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rsi
pushq $-0x1
popq %rcx
movq 0x98(%rsp), %r8
callq 0x104025
testl %eax, %eax
je 0x107811
movl 0x3c(%rsp), %ecx
movl %ecx, %eax
shrl %eax
movq (%r13), %rdx
movq 0x80(%r13), %rsi
movl (%rdx,%rax,4), %eax
incq %rsi
movq 0x40(%rsp), %r14
cmpq %rax, %rsi
jb 0x107978
movq 0x50(%rsp), %rax
cmpq 0x48(%rsp), %r14
jne 0x107968
leaq (%r14,%r14), %rsi
testq %r14, %r14
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x48(%rsp)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x50(%rsp)
movl 0x3c(%rsp), %ecx
leaq 0x1(%r14), %rdx
movq %rdx, 0x40(%rsp)
movl %ecx, (%rax,%r14,4)
movq %rdx, %r14
testq %r14, %r14
movq 0x88(%rsp), %r14
je 0x107811
movl 0x3c(%rsp), %esi
xorl $0x1, %esi
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r15, 0x18(%rsp)
andq $0x0, 0x10(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x40(%rsp), %rdi
movl %r12d, %edx
pushq $-0x1
popq %rcx
movl %ecx, %r8d
movq %r13, %r9
callq 0x10441e
jmp 0x107811
movq 0xa0(%rsp), %rcx
movq 0x18(%rcx), %rcx
decl %eax
movq (%rcx,%rax,8), %rdx
movq %rdx, %r12
shrq $0x21, %r12
movabsq $0x100000000, %rax      # imm = 0x100000000
andq %rax, %rdx
leaq 0x38(%rsp), %rax
cmovneq %rax, %rdx
movl $0x0, %ecx
cmoveq %rax, %rcx
andq $0x0, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xf6ab5
andq $0x0, 0x40(%rsp)
movl 0x38(%rsp), %r9d
movq %r15, 0x8(%rsp)
orl $-0x1, (%rsp)
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
leaq 0x130(%rsp), %rdx
movq 0xb0(%rsp), %rcx
movq 0x90(%rsp), %r8
callq 0x104ab6
movq 0x68(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x38(%rsp), %edx
xorl $0x1, %edx
movl 0x14(%rdi), %r9d
addl %r9d, %r9d
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rsi
pushq $-0x1
popq %rcx
movq 0x98(%rsp), %r8
callq 0x104025
testl %eax, %eax
je 0x107834
movl 0x38(%rsp), %ecx
movl %ecx, %eax
shrl %eax
movq (%r13), %rdx
movq 0x80(%r13), %rsi
movl (%rdx,%rax,4), %eax
incq %rsi
movq 0x40(%rsp), %rbx
cmpq %rax, %rsi
jb 0x107b11
movq 0x50(%rsp), %rax
cmpq 0x48(%rsp), %rbx
jne 0x107b02
leaq (%rbx,%rbx), %rsi
testq %rbx, %rbx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x48(%rsp)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x50(%rsp)
movl 0x38(%rsp), %ecx
leaq 0x1(%rbx), %rdx
movq %rdx, 0x40(%rsp)
movl %ecx, (%rax,%rbx,4)
movq %rdx, %rbx
testq %rbx, %rbx
je 0x107834
movl 0x38(%rsp), %ecx
xorl $0x1, %ecx
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r15, 0x18(%rsp)
andq $0x0, 0x10(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x40(%rsp), %rdi
pushq $-0x1
popq %rdx
movl %edx, %esi
movl %r12d, %r8d
movq %r13, %r9
callq 0x10441e
jmp 0x107834
movq 0x30(%r13), %rcx
cmpq 0x38(%r13), %rcx
jne 0x107ba1
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x38(%r13)
movq 0x40(%r13), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x40(%r13)
movq 0x30(%r13), %rcx
jmp 0x107ba5
movq 0x40(%r13), %rax
movl 0x84(%rsp), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl 0x18(%r13), %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x30(%r13)
movl %edx, (%rax,%rcx,4)
movq 0xb8(%r13), %rcx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x14(%rcx), %eax
cmpl $0x0, 0x74(%rsp)
je 0x107be2
movl %eax, %ecx
subl %edi, %ecx
addq %rcx, 0x90(%r13)
cmpl %edi, %eax
je 0x107bee
movq %r13, %rdi
callq 0xf7cab
movq 0xf0(%rsp), %rbx
movq 0x100(%rsp), %r14
xorl %eax, %eax
movl %eax, %r12d
cmpq %r12, %rbx
jbe 0x107c2e
movq 0x78(%rsp), %rdi
callq 0xfbf83
imulq $0x18, %r12, %rcx
movups (%r14,%rcx), %xmm0
movups %xmm0, (%rax)
movq 0x10(%r14,%rcx), %rcx
movq %rcx, 0x10(%rax)
leal 0x1(%r12), %eax
jmp 0x107c00
movq 0x78(%rsp), %rbx
andb $0x7f, 0x7(%rbx)
movq 0x28(%rbx), %rdi
callq 0x2220
andq $0x0, 0x28(%rbx)
movq %rbx, %rdi
callq 0x694eb
movq 0x88(%rsp), %rdi
callq 0x6921d
leaq 0x130(%rsp), %rdi
callq 0xfa60b
movq 0x90(%rsp), %rdi
callq 0x2220
movq 0x50(%rsp), %rdi
callq 0x2220
movq %r14, %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2220
movq 0x120(%rsp), %rdi
callq 0x2220
movq 0x98(%rsp), %rdi
callq 0x2220
movq 0xb8(%r13), %rdi
callq 0x76d91
movq %rax, %r14
movq %rax, 0xc0(%r13)
movq (%rax), %r15
movq %r15, 0xd0(%r13)
movq %r15, %rdi
shlq $0x5, %rdi
callq 0x2280
movq %rax, 0xd8(%r13)
movq %r15, 0xc8(%r13)
xorl %eax, %eax
movl %eax, %ebx
cmpq %rbx, %r15
jbe 0x107d24
imulq $0x28, %rbx, %rdi
addq 0x10(%r14), %rdi
movq 0xd8(%r13), %rax
movq %rbx, %rdx
shlq $0x5, %rdx
leaq (%rax,%rdx), %rcx
movq %rbx, 0x10(%rax,%rdx)
movb $0x0, 0x18(%rax,%rdx)
movq %r13, %rsi
movq 0x68(%rsp), %rdx
callq 0x104bf5
leal 0x1(%rbx), %eax
movq (%r14), %r15
jmp 0x107ce4
movq 0xc8(%r13), %rsi
movq 0xd8(%r13), %rdi
leaq -0x2ff0(%rip), %rcx     # 0x104d49
pushq $0x20
popq %rdx
callq 0x23f0
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq