// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: clean_bubble_chain_by_hic(ma_ug_t*, kv_u_trans_t*, bubble_type*)
void clean_bubble_chain_by_hic(ma_ug_t* ug, kv_u_trans_t *ta, bubble_type* bub)
{   
    double index_time = yak_realtime();
    ma_ug_t *bs_ug = bub->b_ug;
    uint32_t v, u, i, m, max_i, nv, rv, n_vx, root, flag_pri = 1, flag_aux = 2, flag_ava = 4, occ;
    double w, cutoff = 2;
    uint32_t max_w_occ = 4;
    asg_arc_t *av = NULL;
    n_vx = bs_ug->g->n_seq << 1;
    uint8_t *vis = NULL; CALLOC(vis, ug->g->n_seq<<1);
    uint8_t *is_vis = NULL; CALLOC(is_vis, ug->g->n_seq<<1);
    uint8_t *is_used = NULL; CALLOC(is_used, n_vx);
    uint8_t *dedup = NULL; CALLOC(dedup, ug->g->n_seq<<1);
    buf_t b; memset(&b, 0, sizeof(buf_t));
    kvec_t_u32_warp stack, result, res_utg;
    kv_init(stack.a); kv_init(result.a); kv_init(res_utg.a);
    double *e_w = NULL; MALLOC(e_w, bs_ug->g->n_arc);
    uint32_t *e_occ = NULL, *a_occ = NULL; CALLOC(e_occ, bs_ug->g->n_arc);
    double *aw = NULL, max_w = 0;
    kvec_asg_arc_t_warp edges; kv_init(edges.a);
    ma_ug_t *back_bs_ug = copy_untig_graph(bs_ug);

    for (i = 0; i < bs_ug->g->n_arc; i++)///weight of bs_ug's edges
    {
        e_w[i] = -1;
    }

    for (i = 0; i < bs_ug->g->n_seq; i++)///init all chain with flag_aux 
    {
        set_b_utg_weight_flag(bub, &b, i<<1, vis, flag_aux, NULL);
    }


    for (v = 0; v < n_vx; v++)
    {
        av = asg_arc_a(bs_ug->g, v);
        nv = asg_arc_n(bs_ug->g, v);
        aw = (&e_w[bs_ug->g->idx[v]>>32]);
        a_occ = (&e_occ[bs_ug->g->idx[v]>>32]);
        if(nv <= 1 || get_real_length(bs_ug->g, v, NULL) <= 1) continue;
        set_b_utg_weight_flag_xor(bub, bs_ug, &b, v^1, vis, flag_pri, NULL);

        for (i = 0; i < nv; i++)
        {
            if(av[i].del) continue;
            w = get_chain_weight_hic(bub, bs_ug, &b, av[i].v, v, ta, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, NULL, &occ);
            aw[i] = w;
            a_occ[i] = occ;
        }

        set_b_utg_weight_flag_xor(bub, bs_ug, &b, v^1, vis, flag_pri, NULL);
    }


    for (v = 0; v < n_vx; v++)
    {
        av = asg_arc_a(bs_ug->g, v);
        nv = asg_arc_n(bs_ug->g, v);
        aw = (&e_w[bs_ug->g->idx[v]>>32]);
        a_occ = (&e_occ[bs_ug->g->idx[v]>>32]);
        if(nv <= 1 || get_real_length(bs_ug->g, v, NULL) <= 1) continue;

        for (i = rv = 0, max_i = (uint32_t)-1; i < nv; i++)
        {
            if(av[i].del) continue;
            if(max_i == (uint32_t)-1)
            {
                max_i = i;
                max_w = aw[i];
            }
            else if(max_w < aw[i])
            {
                max_i = i;
                max_w = aw[i];
            }
            rv++;
        }

        if(max_i == (uint32_t)-1) continue;
        ///if(max_w <= max_w_cutoff) continue; //must be <=
        if(a_occ[max_i] <= max_w_occ) continue; //must be <=
        if(rv < 2) continue;

        for (i = 0; i < nv; i++)
        {
            if(av[i].del) continue;
            if(i == max_i) continue;
            ///if((av[i].v>>1) == (v>>1) && aw[i] <= max_w_cutoff) continue; ///might be not reasonable
            if((av[i].v>>1) == (v>>1) && a_occ[i] <= max_w_occ) continue; ///might be not reasonable
            if(aw[i]*cutoff < max_w && double_check_bub_branch(&av[i], bs_ug, e_w, e_occ, cutoff, max_w_occ))
            {
                av[i].del = 1; asg_arc_del(bs_ug->g, (av[i].v)^1, (av[i].ul>>32)^1, 1);
            }
        }
    }

    uint32_t rId_0, ori_0, rId_1, ori_1, root_0, root_1, new_bub;
    if(bub->num.n > 0) bub->num.n--;
    new_bub = bub->b_g->n_seq;

    for (v = 0; v < n_vx; v++)
    {
        av = asg_arc_a(bs_ug->g, v);
        nv = asg_arc_n(bs_ug->g, v);
        rv = get_real_length(bs_ug->g, v, NULL);
        if(nv == rv) continue;///no edge drop
        if(rv != 1 || nv <= 1) continue;
        get_real_length(bs_ug->g, v, &u);
        u ^= 1;
        if(get_real_length(bs_ug->g, u, NULL) != 1) continue;
        drop_g_edges_by_utg(bub, bub->b_g, bs_ug, NULL, v, u);
        if(is_used[v] || is_used[u]) continue;

        is_used[v] = is_used[u] = 1;
        root = get_utg_end_from_btg(bub, bs_ug, v);
        rId_0 = root>>1;
        ori_0 = root&1;
        get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);

        root = get_utg_end_from_btg(bub, bs_ug, u);
        rId_1 = root>>1;
        ori_1 = root&1;
        get_bubbles(bub, rId_1, ori_1 == 1?&root_1:NULL, ori_1 == 0?&root_1:NULL, NULL, NULL, NULL);

        res_utg.a.n = 0;
        set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, v^1, vis, flag_pri, NULL);
        get_chain_weight_hic(bub, back_bs_ug, &b, u^1, v, ta, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, &res_utg, NULL);
        set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, v^1, vis, flag_pri, NULL);
        for (i = 0; i < res_utg.a.n; i++) dedup[res_utg.a.a[i]>>1] |= 1;

        set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, u^1, vis, flag_pri, NULL);
        get_chain_weight_hic(bub, back_bs_ug, &b, v^1, u, ta, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, &res_utg, NULL);
        set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, u^1, vis, flag_pri, NULL);
        for (; i < res_utg.a.n; i++) dedup[res_utg.a.a[i]>>1] |= 2;

        for (i = m = 0; i < res_utg.a.n; i++)
        {
            if(dedup[res_utg.a.a[i]>>1] == 3)
            {
                res_utg.a.a[m] = res_utg.a.a[i];
                m++;
            }
            dedup[res_utg.a.a[i]>>1] = 0;
        }
        res_utg.a.n = m;

        if(!IF_HOM(root_0>>1, *bub)) kv_push(uint32_t, res_utg.a, root_0);
        if(!IF_HOM(root_1>>1, *bub)) kv_push(uint32_t, res_utg.a, root_1);

        update_bubble_graph(&res_utg, root_0^1, rId_0, root_1^1, rId_1, bub, &edges, bub->b_g, NULL, NULL, ug, NULL, 0);

        ///fprintf(stderr, "\n******src-btg%.6ul------>dest-btg%.6ul\n", (v>>1)+1, (u>>1)+1);
    }

    kv_push(uint32_t, bub->num, bub->list.n);
    new_bub = bub->b_g->n_seq - new_bub;
    bub->cross_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);
    
    ///debug_tangle_bubble(bub, bub->b_g->n_seq - bub->cross_bub, bub->b_g->n_seq - 1, "Cross-tangle");
    update_bsg(bub->b_g, &edges);

    ma_ug_destroy(bs_ug);
    bs_ug = ma_ug_gen(bub->b_g);
    bub->b_ug = bs_ug;
    kv_destroy(bub->chain_weight);
    ma_utg_t *u_x = NULL;
    bs_ug = bub->b_ug;
    kv_malloc(bub->chain_weight, bs_ug->u.n); bub->chain_weight.n = bs_ug->u.n;
    for (i = 0; i < bs_ug->u.n; i++)
    {
        u_x = &(bs_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_x, bub, ug, &(bub->chain_weight.a[i]));
        }
    }
    qsort(bub->chain_weight.a, bub->chain_weight.n, sizeof(chain_w_type), cmp_chain_weight);

    
    
    free(vis); free(is_vis); free(is_used); free(dedup); free(b.b.a); free(e_w); free(e_occ);
    kv_destroy(stack.a); kv_destroy(result.a); kv_destroy(res_utg.a); kv_destroy(edges.a);
    ma_ug_destroy(back_bs_ug);
    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
movq %rdx, %r14
movq %rsi, 0xa0(%rsp)
movq %rdi, %rbx
callq 0x1303c7
movsd %xmm0, 0xb8(%rsp)
movq %r14, %rbp
movq 0xc0(%r14), %r13
movq 0x18(%r13), %rax
movl 0x14(%rax), %r15d
addl %r15d, %r15d
movq %rbx, 0x48(%rsp)
movq 0x18(%rbx), %rax
movl 0x14(%rax), %eax
addl %eax, %eax
movslq %eax, %r14
pushq $0x1
popq %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x2120
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2120
movq %rax, 0x70(%rsp)
movq %r15, 0xb0(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2120
movq %rax, 0x80(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2120
movq %rax, 0x78(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x150(%rsp)
movapd %xmm0, 0x140(%rsp)
movapd %xmm0, 0x130(%rsp)
movapd %xmm0, 0x120(%rsp)
movapd %xmm0, 0x110(%rsp)
movapd %xmm0, 0x100(%rsp)
andq $0x0, 0x160(%rsp)
movapd %xmm0, 0xe0(%rsp)
andq $0x0, 0xf0(%rsp)
movapd %xmm0, 0xc0(%rsp)
andq $0x0, 0xd0(%rsp)
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq 0x18(%r13), %rax
movl 0x4(%rax), %r14d
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andq %rbx, %r14
leaq (,%r14,8), %rdi
callq 0x2280
movq %rax, %r15
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x2120
movq %rax, 0x50(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x170(%rsp)
andq $0x0, 0x180(%rsp)
movq %r13, %rdi
callq 0xc815c
movq %r13, %r10
movq %rax, 0x40(%rsp)
movq 0x18(%r13), %rax
movl 0x4(%rax), %eax
andq %rbx, %rax
je 0x1995f
xorl %ecx, %ecx
movabsq $-0x4010000000000000, %rdx # imm = 0xBFF0000000000000
movq %rdx, (%r15,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x19953
movq %r15, 0x58(%rsp)
movq 0x18(%r10), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
movq 0x10(%rsp), %r15
movq %r10, 0x8(%rsp)
movq %rbp, %r12
je 0x199c0
xorl %r14d, %r14d
pushq $0x2
popq %r13
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
xorl %ebp, %ebp
movq %r12, %rdi
leaq 0x100(%rsp), %rsi
movl %r14d, %edx
movq %r15, %rcx
movl %r13d, %r8d
xorl %r9d, %r9d
callq 0x146be0
movq 0x8(%rsp), %r10
incl %ebp
movq 0x18(%r10), %rax
movl 0x14(%rax), %eax
andl %ebx, %eax
addl $0x2, %r14d
cmpl %eax, %ebp
jb 0x1998c
movq 0xb0(%rsp), %rax
movl %eax, %ebx
testl %eax, %eax
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %r9
movq %rbx, 0x98(%rsp)
movq %r12, (%rsp)
je 0x19d9f
xorl %r14d, %r14d
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
pushq $0x1
popq %r13
movq 0x18(%r10), %rax
movq 0x28(%rax), %rcx
movq (%rcx,%r14,8), %r12
cmpl $0x2, %r12d
jb 0x19b65
movq %r12, %rcx
andq %r8, %rcx
je 0x19b65
movq 0x8(%rax), %rax
movq %r12, %rsi
shrq $0x20, %rsi
leaq (%rdx,%rsi,8), %r15
leaq (%r9,%rsi,4), %rbx
imulq $0x18, %rsi, %rsi
leaq (%rax,%rsi), %rbp
addq $0xc, %rbp
imulq $0x18, %rcx, %rax
xorl %ecx, %ecx
xorl %edi, %edi
movl (%rbp,%rcx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %edi
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x19a3e
cmpl $0x2, %edi
jl 0x19b65
movl %r14d, %ecx
xorl $0x1, %ecx
subq $0x8, %rsp
movq 0x8(%rsp), %rdi
movq %r10, %rsi
leaq 0x108(%rsp), %rdx
movl %ecx, 0x20(%rsp)
movq 0x18(%rsp), %r8
movl %r13d, %r9d
pushq $0x0
callq 0x149b3f
addq $0x10, %rsp
cmpl $0x1, %r12d
adcl $0x0, %r12d
xorl %r13d, %r13d
cmpl $0x0, (%rbp)
js 0x19b0e
movl -0x4(%rbp), %ecx
subq $0x8, %rsp
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x108(%rsp), %rdx
movl %r14d, %r8d
movq 0xa8(%rsp), %r9
leaq 0xb4(%rsp), %rax
pushq %rax
pushq $0x0
pushq $0x4
pushq $0x1
leaq 0xe8(%rsp), %rax
pushq %rax
leaq 0x110(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq 0xb0(%rsp)
pushq 0x58(%rsp)
callq 0x1522b6
addq $0x50, %rsp
movsd %xmm0, (%r15,%r13,8)
movl 0xac(%rsp), %eax
movl %eax, (%rbx,%r13,4)
incq %r13
addq $0x18, %rbp
cmpq %r13, %r12
jne 0x19a97
subq $0x8, %rsp
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
leaq 0x108(%rsp), %rdx
movl 0x20(%rsp), %ecx
movq 0x18(%rsp), %r8
pushq $0x1
popq %r13
movl %r13d, %r9d
pushq $0x0
callq 0x149b3f
movq %rbx, %r10
addq $0x10, %rsp
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %r9
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
incq %r14
movq 0x98(%rsp), %rbx
cmpq %rbx, %r14
jne 0x199f5
xorpd %xmm1, %xmm1
xorl %r13d, %r13d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
pushq $-0x1
popq %rbp
movq (%rsp), %r12
movq 0x18(%r10), %rax
movq 0x28(%rax), %rcx
movq (%rcx,%r13,8), %r14
cmpl $0x2, %r14d
jb 0x19d93
movq %r14, %rcx
andq %r11, %rcx
je 0x19d93
movq 0x8(%rax), %rax
movq %r14, %rdi
shrq $0x20, %rdi
imulq $0x18, %rdi, %rsi
leaq (%rax,%rsi), %r8
movq %r8, 0x60(%rsp)
leaq (%rdx,%rdi,8), %r15
leaq (%r9,%rdi,4), %rdi
movq %rdi, 0x68(%rsp)
addq %rsi, %rax
addq $0xc, %rax
imulq $0x18, %rcx, %rcx
xorl %r8d, %r8d
xorl %esi, %esi
movl (%rax,%r8), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %r8
cmpq %r8, %rcx
jne 0x19be4
cmpl $0x2, %esi
jl 0x19d93
cmpl $0x1, %r14d
adcl $0x0, %r14d
xorl %edi, %edi
movl %ebp, %esi
xorl %ecx, %ecx
cmpl $0x0, (%rax)
js 0x19c2d
movsd (%r15,%rdi,8), %xmm0
cmpl $-0x1, %esi
je 0x19c25
ucomisd %xmm1, %xmm0
jbe 0x19c2b
movapd %xmm0, %xmm1
movl %edi, %esi
incl %ecx
incq %rdi
addq $0x18, %rax
cmpq %rdi, %r14
jne 0x19c0f
cmpl $-0x1, %esi
je 0x19d93
movl %esi, %esi
movq 0x68(%rsp), %rax
movq %rsi, 0x18(%rsp)
cmpl $0x5, (%rax,%rsi,4)
setb %al
cmpl $0x2, %ecx
setb %cl
orb %al, %cl
jne 0x19d93
movq %r15, 0x90(%rsp)
xorl %ebp, %ebp
movq 0x60(%rsp), %r11
movsd %xmm1, 0x88(%rsp)
imulq $0x18, %rbp, %r12
movl 0xc(%r11,%r12), %r15d
testl %r15d, %r15d
js 0x19d72
cmpq 0x18(%rsp), %rbp
je 0x19d72
addq %r11, %r12
movl 0x8(%r12), %ebx
movl %ebx, %eax
xorl %r13d, %eax
cmpl $0x1, %eax
ja 0x19cb9
movq 0x68(%rsp), %rax
cmpl $0x5, (%rax,%rbp,4)
jb 0x19d72
movq 0x90(%rsp), %rax
movsd (%rax,%rbp,8), %xmm0
addsd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jbe 0x19d72
movq %r12, %rdi
movq %r10, %rsi
movq %r9, %rcx
movsd 0x21532b(%rip), %xmm0   # 0x22f010
pushq $0x4
popq %r8
callq 0x14a8c0
movq 0x60(%rsp), %r11
movsd 0x88(%rsp), %xmm1
movq 0x8(%rsp), %r10
movq 0x50(%rsp), %r9
movq 0x58(%rsp), %rdx
testl %eax, %eax
je 0x19d72
orl $0x80000000, %r15d      # imm = 0x80000000
movl %r15d, 0xc(%r12)
movq 0x18(%r10), %rcx
xorq $0x1, %rbx
movq 0x28(%rcx), %rax
movq (%rax,%rbx,8), %r8
movq %r8, %rsi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rsi
je 0x19d72
movl 0x4(%r12), %eax
movq 0x8(%rcx), %rdi
shrq $0x20, %r8
imulq $0x18, %rsi, %rcx
imulq $0x18, %r8, %rsi
leaq (%rdi,%rsi), %r8
addq $0xc, %r8
xorl %esi, %esi
movl -0x4(%r8,%rsi), %edi
xorl %eax, %edi
cmpl $0x1, %edi
jne 0x19d69
orb $-0x80, 0x3(%r8,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x19d57
incq %rbp
cmpq %r14, %rbp
jne 0x19c7b
movq (%rsp), %r12
movq 0x98(%rsp), %rbx
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
pushq $-0x1
popq %rbp
incq %r13
cmpq %rbx, %r13
jne 0x19b8d
movq 0x30(%r12), %rax
testq %rax, %rax
je 0x19db1
decq %rax
movq %rax, 0x30(%r12)
movq 0xb8(%r12), %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x14(%rax), %ecx
movl %ecx, 0xa8(%rsp)
cmpl $0x0, 0xb0(%rsp)
movq 0x80(%rsp), %r15
movq 0x78(%rsp), %rbp
jne 0x19ff9
movq (%rsp), %r15
movq 0x38(%r15), %rax
cmpq %rax, 0x30(%r15)
jne 0x19e14
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x38(%r15)
movq 0x40(%r15), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x40(%r15)
movl 0x18(%r15), %eax
movq 0x40(%r15), %rcx
movq 0x30(%r15), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x30(%r15)
movl %eax, (%rcx,%rdx,4)
movq 0xb8(%r15), %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x14(%rax), %ecx
movl %ecx, %eax
movl 0xa8(%rsp), %edx
subl %edx, %eax
addq %rax, 0xa0(%r15)
cmpl %edx, %ecx
movq 0x10(%rsp), %r12
je 0x19e5d
movq %r15, %rdi
callq 0x1394bc
movq 0xb8(%r15), %rdi
leaq 0x170(%rsp), %rsi
callq 0x1481b6
movq 0x8(%rsp), %rdi
callq 0xa0004
movq 0xb8(%r15), %rdi
callq 0xb0285
movq %rax, 0xc0(%r15)
movq 0xd8(%r15), %rdi
callq 0x2220
movq 0xc0(%r15), %rbx
andq $0x0, 0xc8(%r15)
movq (%rbx), %r14
movq %r14, 0xd0(%r15)
movq %r14, %rdi
shlq $0x5, %rdi
callq 0x2280
movq %rax, 0xd8(%r15)
movq %r14, 0xc8(%r15)
cmpq $0x0, (%rbx)
movq 0x48(%rsp), %r14
je 0x19f15
pushq $0x1
popq %rbp
xorl %eax, %eax
imulq $0x28, %rax, %rdi
addq 0x10(%rbx), %rdi
movq 0xd8(%r15), %rdx
movq %rax, %rsi
shlq $0x5, %rsi
leaq (%rdx,%rsi), %rcx
movq %rax, 0x10(%rdx,%rsi)
movb $0x0, 0x18(%rdx,%rsi)
movq %r15, %rsi
movq %r14, %rdx
callq 0x14655c
movl %ebp, %eax
incl %ebp
cmpq %rax, (%rbx)
ja 0x19edd
movq 0xc8(%r15), %rsi
movq 0xd8(%r15), %rdi
leaq 0x12c794(%rip), %rcx    # 0x1466be
pushq $0x20
popq %rdx
callq 0x23f0
movq %r12, %rdi
callq 0x2220
movq 0x70(%rsp), %rdi
callq 0x2220
movq 0x80(%rsp), %rdi
callq 0x2220
movq 0x78(%rsp), %rdi
callq 0x2220
movq 0x148(%rsp), %rdi
callq 0x2220
movq 0x58(%rsp), %rdi
callq 0x2220
movq 0x50(%rsp), %rdi
callq 0x2220
movq 0xf0(%rsp), %rdi
callq 0x2220
movq 0xd0(%rsp), %rdi
callq 0x2220
movq 0x30(%rsp), %rdi
callq 0x2220
movq 0x180(%rsp), %rdi
callq 0x2220
movq 0x40(%rsp), %rdi
callq 0xa0004
movq 0x270022(%rip), %rax    # 0x289fe0
movq (%rax), %rbx
callq 0x1303c7
subsd 0xb8(%rsp), %xmm0
leaq 0x2159c5(%rip), %rsi    # 0x22f99b
leaq 0x216048(%rip), %rdx    # 0x230025
movq %rbx, %rdi
movb $0x1, %al
callq 0x22b0
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
movq 0x18(%r10), %rax
movq 0x28(%rax), %rcx
movq (%rcx,%r12,8), %rdx
movq %rdx, %rsi
movl $0x0, %edi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0x1a051
movq 0x8(%rax), %rdi
movq %rdx, %r8
shrq $0x20, %r8
imulq $0x18, %r8, %r8
addq %rdi, %r8
addq $0xc, %r8
imulq $0x18, %rsi, %r9
xorl %r10d, %r10d
xorl %edi, %edi
movl (%r8,%r10), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %edi
addq $0x18, %r10
cmpq %r10, %r9
jne 0x1a03a
cmpl %edx, %edi
jne 0x1a06d
movl %r14d, %r13d
movq 0x8(%rsp), %r10
incq %r12
movl %r13d, %r14d
cmpq %rbx, %r12
jne 0x19ffc
jmp 0x19de3
cmpl $0x2, %edx
jb 0x1a055
cmpl $0x1, %edi
jne 0x1a055
testq %rsi, %rsi
movq 0x8(%rsp), %r10
je 0x1a0ae
movq 0x8(%rax), %rdi
shrq $0x20, %rdx
imulq $0x18, %rsi, %rsi
imulq $0x18, %rdx, %rdx
addq %rdi, %rdx
addq $0xc, %rdx
xorl %edi, %edi
cmpl $0x0, (%rdx,%rdi)
js 0x1a0a5
movl -0x4(%rdx,%rdi), %r14d
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0x1a09a
movl %r14d, %r13d
xorq $0x1, %r13
movq (%rcx,%r13,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0x1a05d
movq 0x8(%rax), %rax
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
addq $0xc, %rax
imulq $0x18, %rcx, %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x1a0e1
cmpl $0x1, %esi
jne 0x1a05d
movq (%rsp), %rax
movq 0xb8(%rax), %rsi
movq %r10, %rdx
xorl %ecx, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
callq 0x147dea
cmpb $0x0, (%r15,%r12)
jne 0x1a058
cmpb $0x0, (%r15,%r13)
jne 0x1a058
movb $0x1, %al
movb %al, (%r15,%r13)
movb %al, (%r15,%r12)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %r12d, %ecx
shrl %ecx
imulq $0x28, %rcx, %rdx
movq 0x18(%rax,%rdx), %rcx
testb $0x1, %r12b
jne 0x1a163
addq %rax, %rdx
movl 0x10(%rdx), %edx
decl %edx
movl 0x4(%rcx,%rdx,8), %ecx
jmp 0x1a169
movl 0x4(%rcx), %ecx
xorl $0x1, %ecx
movq (%rsp), %r15
movl %ecx, %edx
shrl %edx
testb $0x1, %cl
movq %rdx, 0x68(%rsp)
jne 0x1a186
movq 0x40(%r15), %rcx
movl (%rcx,%rdx,4), %ecx
incl %ecx
jmp 0x1a18d
movq 0x40(%r15), %rcx
movl (%rcx,%rdx,4), %ecx
movl %r14d, %edx
shrl %edx
imulq $0x28, %rdx, %rsi
movq 0x18(%rax,%rsi), %rdx
testb $0x1, %r14b
jne 0x1a1a9
movl 0x4(%rdx), %eax
xorl $0x1, %eax
jmp 0x1a1b5
addq %rsi, %rax
movl 0x10(%rax), %eax
decl %eax
movl 0x4(%rdx,%rax,8), %eax
movl %eax, %edx
shrl %edx
testb $0x1, %al
movq %rdx, 0x60(%rsp)
jne 0x1a1cd
movq 0x40(%r15), %rax
movl (%rax,%rdx,4), %eax
incl %eax
jmp 0x1a1d4
movq 0x40(%r15), %rax
movl (%rax,%rdx,4), %eax
movq 0x28(%r15), %rdx
movl %ecx, %ecx
movl (%rdx,%rcx,4), %ecx
movq %rcx, 0x90(%rsp)
movq 0x28(%r15), %rcx
movl %eax, %eax
movl (%rcx,%rax,4), %eax
movq %rax, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movl %r12d, %ebx
xorl $0x1, %ebx
subq $0x8, %rsp
movq %r15, %rdi
movq 0x48(%rsp), %rsi
leaq 0x108(%rsp), %rdx
movl %ebx, %ecx
movq 0x18(%rsp), %r8
pushq $0x1
popq %r9
pushq $0x0
callq 0x149b3f
popq %rax
popq %rcx
subq $0x8, %rsp
movq %r15, %rdi
movq 0x48(%rsp), %rsi
leaq 0x108(%rsp), %rdx
movl %r14d, %ecx
movl %r12d, %r8d
movq 0xa8(%rsp), %r9
pushq $0x0
leaq 0x30(%rsp), %rax
pushq %rax
pushq $0x4
pushq $0x1
leaq 0xe8(%rsp), %rax
pushq %rax
leaq 0x110(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq 0xb0(%rsp)
movq 0x58(%rsp), %r15
pushq %r15
callq 0x1522b6
addq $0x48, %rsp
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %rsi
leaq 0x108(%rsp), %rdx
movl %ebx, 0x90(%rsp)
movl %ebx, %ecx
movq %r15, %r8
pushq $0x1
popq %r9
pushq $0x0
callq 0x149b3f
addq $0x10, %rsp
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x1a2d9
movq 0x30(%rsp), %rcx
xorl %ebx, %ebx
movl (%rcx,%rbx,4), %edx
shrl %edx
orb $0x1, (%rbp,%rdx)
incq %rbx
movl %ebx, %edx
cmpq %rdx, %rax
ja 0x1a2c3
jmp 0x1a2db
xorl %ebx, %ebx
movq (%rsp), %r15
subq $0x8, %rsp
movq %r15, %rdi
movq 0x48(%rsp), %rbp
movq %rbp, %rsi
leaq 0x108(%rsp), %rdx
movl %r14d, %ecx
movq 0x18(%rsp), %r8
pushq $0x1
popq %r9
pushq $0x0
callq 0x149b3f
popq %rax
popq %rcx
subq $0x8, %rsp
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x108(%rsp), %rdx
movl 0x90(%rsp), %ecx
movl %r13d, %r8d
movq 0xa8(%rsp), %r9
pushq $0x0
leaq 0x30(%rsp), %rax
pushq %rax
pushq $0x4
pushq $0x1
leaq 0xe8(%rsp), %rax
pushq %rax
leaq 0x110(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq 0xb0(%rsp)
movq 0x58(%rsp), %rbp
pushq %rbp
callq 0x1522b6
addq $0x48, %rsp
movq %r15, %rdi
movq 0x48(%rsp), %rsi
leaq 0x108(%rsp), %rdx
movl %r14d, %ecx
movq %rbp, %r8
pushq $0x1
popq %r9
pushq $0x0
callq 0x149b3f
popq %rax
popq %rcx
movq 0x20(%rsp), %rax
movl %ebx, %ecx
cmpq %rcx, %rax
movq 0x78(%rsp), %rbp
jbe 0x1a3b9
movq 0x30(%rsp), %rdx
leal 0x1(%rcx), %esi
movl (%rdx,%rcx,4), %ecx
shrl %ecx
orb $0x2, (%rbp,%rcx)
movl %esi, %ecx
incl %esi
cmpq %rcx, %rax
ja 0x1a3a6
testq %rax, %rax
movq 0x48(%rsp), %rbx
movq 0x80(%rsp), %r15
movq 0x90(%rsp), %r14
je 0x1a40e
xorl %ecx, %ecx
movq 0x30(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rcx,4), %edi
movl %edi, %r8d
shrl %r8d
cmpb $0x3, (%rbp,%r8)
jne 0x1a3f6
movl %esi, %r8d
movl %edi, (%rdx,%r8,4)
incl %esi
movl (%rdx,%rcx,4), %edi
shrl %edi
movb $0x0, (%rbp,%rdi)
incq %rcx
movl %ecx, %edi
cmpq %rdi, %rax
ja 0x1a3dc
movl %esi, %eax
jmp 0x1a410
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movl %r14d, %ecx
shrl %ecx
movq (%rsp), %rsi
movq (%rsi), %rdx
movq 0x80(%rsi), %rsi
movl (%rdx,%rcx,4), %ecx
incq %rsi
cmpq %rcx, %rsi
movq 0x18(%rsp), %rcx
jb 0x1a484
movq 0x28(%rsp), %rdx
cmpq %rax, %rdx
jne 0x1a46d
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x18(%rsp), %rcx
movq %rax, 0x30(%rsp)
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rsi
leaq 0x1(%rax), %rdx
movq %rdx, 0x20(%rsp)
movl %r14d, (%rsi,%rax,4)
movl %ecx, %eax
shrl %eax
movq (%rsp), %rdx
movq (%rdx), %rsi
movq 0x80(%rdx), %rdx
movl (%rsi,%rax,4), %eax
incq %rdx
cmpq %rax, %rdx
jb 0x1a4ee
movq 0x28(%rsp), %rax
cmpq %rax, 0x20(%rsp)
jne 0x1a4d8
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x18(%rsp), %rcx
movq %rax, 0x30(%rsp)
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rsi
leaq 0x1(%rax), %rdx
movq %rdx, 0x20(%rsp)
movl %ecx, (%rsi,%rax,4)
xorl $0x1, %r14d
xorl $0x1, %ecx
movq (%rsp), %r9
movq 0xb8(%r9), %rax
subq $0x40, %rsp
xorpd %xmm0, %xmm0
movupd %xmm0, 0x28(%rsp)
movq %rbx, 0x20(%rsp)
movupd %xmm0, 0x10(%rsp)
movq %rax, 0x8(%rsp)
leaq 0x1b0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x60(%rsp), %rdi
movl %r14d, %esi
movq 0xa8(%rsp), %rdx
movq 0xa0(%rsp), %r8
callq 0x145cd9
addq $0x40, %rsp
movq 0x8(%rsp), %r10
movq 0x98(%rsp), %rbx
jmp 0x1a05d