// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/path.c
// Function: slim_graph
static void slim_graph(asg_t *asg, og_component_v *sequence_og, og_component_t *component_g, clust_dp_t *comp_dps, OG_TYPE_t og_target, 
        OG_TYPE_t *og_seeds, double c_mean, int max_r_len, og_component_v *components, int verbose)
{
    uint32_t i, j, k, l, v, w, r, nv, na, len, gen, cov, gid, n_vtx, imax, smax, *comp_v;
    uint8_t *dels, *visited;
    double score[4];
    asmg_t *asmg;
    asmg_arc_t *av;
    og_component_t *component_s, *component;

    asmg = asg_make_asmg_copy(component_g->asmg, 0);
    n_vtx = asmg->n_vtx;
    comp_v = component_g->v;
    nv = component_g->nv;

    // do graph slimming
    if (verbose > 1) {
        fprintf(stderr, "[M::%s] subgraph slimming for organelle [%s] with average sequence coverage %.3f\n", 
                __func__, OG_TYPES[og_target], c_mean);
        if (verbose > 2) {
            asmg_t *g = asg->asmg;
            asg->asmg = asmg;
            asg_print(asg, stderr, 1);
            asg->asmg = g;
        }
    }

    // find sequences to remove
    MYCALLOC(dels, n_vtx);
    for (i = 0; i < nv; ++i)
        if (og_seeds[i] != og_target)
            dels[comp_v[i]] = 1;

    // bring back the sequence if in a critical path
    // TODO improve the recalling strategy
    // currently bring repeat sequences back if attached to any non-deleted
    /***
    while (1) {
        int recall = 0;
        for (i = 0; i < nv; ++i) {
            v = comp_v[i];
            if (!dels[v] || asmg->vtx[v].len > max_r_len)
                continue; // not a repeat
            // check incoming and outgoing arcs to see if any non-deleted
            int done = 0;
            for (j = 0; j < 2 && !done; ++j) {
                av = asmg_arc_a(asmg, v<<1 | j);
                na = asmg_arc_n(asmg, v<<1 | j);
                for (k = 0; k < na; ++k) {
                    if (!av[k].del && !dels[av[k].w>>1]) {
                        dels[v] = 0;
                        ++recall;
                        done = 1;
                        break;
                    }
                }
            }
        }
        if (!recall) break;
    }
    **/
    
    // here is an improved strategy
    // bring a repeat sequence back if both ends connect to a sequence
    // through a path of all repeats
    // and the distance is no greater than max_r_len
    // repeat this process until no sequence is added
    int recall, max_r, *dist, *flag;
    kdq_u64_t *q;

    MYMALLOC(dist, n_vtx << 1);
    MYMALLOC(flag, n_vtx << 1);
    q = kdq_init(uint64_t, 0);
    while (1) {
        MYBZERO(dist, n_vtx << 1);
        for (i = 0; i < nv; ++i) {
            if (dels[comp_v[i]])
                // skip dels
                continue;
            // the maximum distance to radiate
            max_r = asmg->vtx[comp_v[i]].len;
            if (max_r > max_r_len)
                max_r = max_r_len;
            for (k = 0; k < 2; ++k) {
                uint64_t source = comp_v[i] << 1 | k;
                // find all reachable repeats from 'source'
                MYBZERO(flag, n_vtx << 1);
                kdq_push(uint64_t, q, source << 32 | 0);
                while (kdq_size(q) > 0) {
                    uint64_t x = *kdq_shift(uint64_t, q);
                    v = x >> 32;
                    r = (uint32_t) x;
                    flag[v] = 1;
                    dist[v] = source << 1 | 1;
                    av = asmg_arc_a(asmg, v);
                    na = asmg_arc_n(asmg, v);
                    for (j = 0; j < na; ++j) {
                        if (av[j].del)
                            continue;
                        w = av[j].w;
                        if (!flag[w] &&
                                r <= av[j].ls + max_r &&
                                asmg->vtx[w>>1].len <= max_r)
                            // add non-visited repeats
                            kdq_push(uint64_t, q, (uint64_t) w << 32 | (r + asmg->vtx[w>>1].len - av[j].ls));
                    }
                }
            }
        }

        recall = 0;
        for (i = 0; i < nv; ++i) {
            v = comp_v[i];
            if (dels[v] &&
                    asmg->vtx[v].len <= max_r_len &&
                    dist[v<<1] &&
                    dist[v<<1 | 1]) {
                dels[v] = 0;
                ++recall;
                if (verbose > 2)
                    fprintf(stderr, "[M::%s] recall repeat %s: %s%c <-> %s%c\n", __func__,
                            asg->seg[v].name,
                            asg->seg[dist[v<<1]>>2].name, "+-"[(dist[v<<1]>>1)&1],
                            asg->seg[dist[v<<1|1]>>2].name, "+-"[(dist[v<<1|1]>>1)&1]);
            }
        }
        if (!recall) break;
    }
    free(dist);
    free(flag);
    kdq_destroy(uint64_t, q);

    for (i = 0; i < nv; ++i) {
        v = comp_v[i];
        if (dels[v])
            asmg_vtx_del(asmg, v, 1);
    }

    if (verbose > 2) {
        asmg_t *g = asg->asmg;
        asg->asmg = asmg;
        asg_print(asg, stderr, 1);
        asg->asmg = g;
    }

    uint64_t cleaned = 1;
    while (cleaned) {
        // simple clean
        cleaned = 0;
        cleaned += asmg_pop_bubble(asmg, max_r_len, 0, 0, 1, 0, verbose);
        cleaned += asmg_remove_weak_crosslink(asmg, 0.3, 10, 0, verbose);
        cleaned += asmg_drop_tip(asmg, INT32_MAX, max_r_len, 1, 0, verbose);
    }
    // add cleaned vtx to dels for integrity
    for (i = 0; i < nv; ++i) {
        v = comp_v[i];
        if (asmg->vtx[v].del)
            dels[v] = 1;
    }

    if (verbose > 2) {
        asmg_t *g = asg->asmg;
        asg->asmg = asmg;
        asg_print(asg, stderr, 1);
        asg->asmg = g;
    }

    // minimum subgraph size to keep
    // set as 10% of the total sequence
    double m_size = 0;
    for (i = 0; i < nv; ++i) {
        v = comp_v[i];
        if (!asmg->vtx[v].del)
            m_size += asmg->vtx[v].len;
    }
    m_size *= 0.1;

    // now process each subgraph
    MYCALLOC(visited, n_vtx);
    for (i = 0; i < nv; ++i) {
        v = comp_v[i];
        if (visited[v] || asmg->vtx[v].del)
            continue;
        
        asmg_t *g = asg_make_asmg_copy(asmg, 0);
        asmg_subgraph(g, &v, 1, 0, 0, 0, 1);

        kvec_t(uint32_t) comp_s;
        kv_init(comp_s);
        len = gen = 0;
        for (j = 0; j < nv; ++j) {
            w = comp_v[j];
            if (g->vtx[w].del)
                continue;
            kv_push(uint32_t, comp_s, w);
            len += g->vtx[w].len;
            gen += comp_dps[j].gene_num[og_target];
            visited[w] = 1;
        }
        if (len < m_size || gen == 0) {
            // not a good subgraph
            asmg_destroy(g);
            kv_destroy(comp_s);
            continue;
        }
        
        // add subgraph component
        // adjust repeat sequence coverage if necessary
        // also fix the arc coverage
        for (j = 0; j < nv; ++j) {
            w = comp_v[j];
            if (g->vtx[w].del ||
                    og_seeds[j] == og_target ||
                    g->vtx[w].len >= max_r_len ||
                    g->vtx[w].cov < c_mean * 3.5)
                continue;
            int n_del, n_arc;
            n_del = n_arc = 0;
            for (k = 0; k < 2; ++k) {
                av = asmg_arc_a(asmg, w << 1 | k);
                na = asmg_arc_n(asmg, w << 1 | k);
                for (l = 0; l < na; ++l) {
                    if (dels[av[l].w>>1])
                        ++n_del;
                    if (!av[l].del)
                        ++n_arc;
                }
            }
            if (!n_del) continue;
            cov = g->vtx[w].cov;
            g->vtx[w].cov = c_mean * n_arc / 2.0;
            // fix arc coverage
            for (k = 0; k < 2; ++k) {
                av = asmg_arc_a(asmg, w << 1 | k);
                na = asmg_arc_n(asmg, w << 1 | k);
                for (l = 0; l < na; ++l) {
                    if (av[l].del) continue;
                    if (av[l].cov > cov)
                        av[l].cov = cov;
                }
            }
            if (verbose > 2)
                fprintf(stderr, "[M::%s] sequence %s coverage adjusted: %u -> %u\n", 
                        __func__, asg->seg[w].name, cov, g->vtx[w].cov);
        }

        // make seg list
        MYREALLOC(comp_s.a, comp_s.n);

        // make gene list
        kvec_t(uint64_t) comp_g;
        kv_init(comp_g);
        // collect genes from sequences in the subgraph
        for (j = 0; j < nv; ++j) {
            w = comp_v[j];
            if (g->vtx[w].del)
                continue;
            component_s = &sequence_og->a[w];
            kv_pushn(uint64_t, comp_g, component_s->g, component_s->ng);
        }
        // sort by gid and then score - descending order
        qsort(comp_g.a, comp_g.n, sizeof(uint64_t), u64_cmpfunc_r);
        // keep only the best hit for each gene
        k = 0;
        gid = UINT32_MAX;
        for (j = 0; j < comp_g.n; ++j) {
            if (comp_g.a[j] >> 32 != gid) {
                comp_g.a[k++] = comp_g.a[j];
                gid = comp_g.a[j] >> 32;
            }
        }
        comp_g.n = k;
        MYREALLOC(comp_g.a, k);

        // calculate subgraph annotation scores
        uint64_t *a_s = comp_g.a;
        MYBZERO(score, 4);
        for (j = 0, k = comp_g.n; j < k; ++j)
            score[(a_s[j] >> 32) & 0x3] += (uint32_t) a_s[j];
        imax = max2(score, 4, &smax);

        // update component vector
        kv_pushp(og_component_t, *components, &component);
        component->type = (uint32_t) og_target;
        component->score = score[imax];
        component->sscore = score[smax];
        component->len = len;
        component->nv = comp_s.n;
        component->v = comp_s.a;
        component->ng = comp_g.n;
        component->g = comp_g.a;
        component->asmg = g;

        if (verbose > 0)
            fprintf(stderr, "[M::%s] subgraph seeding from %s: segs, %lu; size, %d; mito score, %.3f; pltd score, %.3f; mini score, %.3f; classification, %d\n",
                    __func__, asg->seg[v].name, comp_s.n, len, score[OG_MITO], score[OG_PLTD], score[OG_MINI], og_target);

    }

    free(dels);
    free(visited);
    asmg_destroy(asmg);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movsd %xmm0, 0x88(%rsp)
movq %r9, 0xa8(%rsp)
movl %r8d, %ebp
movq %rcx, 0x78(%rsp)
movq %rdx, %rbx
movq %rsi, 0xe0(%rsp)
movq %rdi, 0x60(%rsp)
movq 0x38(%rdx), %rdi
xorl %esi, %esi
callq 0x9778
movq %rax, 0x10(%rsp)
movq (%rax), %r12
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movl 0x1c(%rbx), %eax
movq %rax, 0x28(%rsp)
movl %ebp, 0x1c(%rsp)
movl %ebp, %eax
movq %rax, 0x68(%rsp)
cmpl $0x2, 0x130(%rsp)
jge 0xea40
movl %r12d, %edi
pushq $0x1
popq %rsi
movq %rdi, 0x90(%rsp)
callq 0x3240
movq %rax, 0x38(%rsp)
xorl %eax, %eax
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rsi
cmpq %rax, 0x28(%rsp)
je 0xde3f
movq 0xa8(%rsp), %rcx
cmpl %edx, (%rcx,%rax,4)
je 0xde3a
movq 0x20(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movb $0x1, (%rsi,%rcx)
incq %rax
jmp 0xde1a
movabsq $0x3ffffffffffffff, %rbx # imm = 0x3FFFFFFFFFFFFFF
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
shlq $0x3, %r12
movq %r12, %rdi
callq 0x32f0
movq %rax, 0x30(%rsp)
movq %r12, %rdi
callq 0x32f0
movq %rax, %r14
pushq $0x1
popq %rsi
pushq $0x28
popq %rdx
xorl %edi, %edi
callq 0x145b8
movq %rax, %r15
movq (%rax), %rax
andq %rbx, %rax
btsq $0x3b, %rax
movq %rax, (%r15)
movq $0x3, 0x10(%r15)
pushq $0x20
popq %rsi
xorl %edi, %edi
callq 0x14734
movq %rax, 0x18(%r15)
movq %r15, 0x48(%rsp)
andq $0x0, 0x20(%r15)
movslq 0x120(%rsp), %rax
movq %rax, 0x80(%rsp)
movq %r12, 0x98(%rsp)
movq 0x30(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x31b0
xorl %edx, %edx
movq 0x10(%rsp), %r8
cmpq 0x28(%rsp), %rdx
je 0xe075
movq 0x20(%rsp), %rax
movl (%rax,%rdx,4), %eax
movq 0x38(%rsp), %rcx
cmpb $0x0, (%rcx,%rax)
je 0xdefb
incq %rdx
jmp 0xded8
movq 0x10(%r8), %rcx
imulq $0x28, %rax, %rax
movl 0x18(%rcx,%rax), %eax
movl 0x120(%rsp), %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
movslq %eax, %r13
xorl %ecx, %ecx
movq %rdx, 0x50(%rsp)
cmpl $0x2, %ecx
je 0xdef6
movq 0x20(%rsp), %rax
movl (%rax,%rdx,4), %eax
movq %rcx, 0x40(%rsp)
leal (%rcx,%rax,2), %ebx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x31b0
movq %rbx, %rsi
shlq $0x20, %rsi
movq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0xf88c
movq %r15, %r10
movq 0x10(%rsp), %r8
leal 0x1(,%rbx,2), %eax
movl %eax, 0x58(%rsp)
movq 0x8(%r10), %rax
testq %rax, %rax
je 0xe05c
movq (%r10), %rcx
movq 0x18(%r10), %rdx
movq %rcx, %rsi
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
andq %r9, %rsi
leaq 0x1(%rcx), %rdi
andq %r9, %rdi
movabsq $-0x400000000000000, %r9 # imm = 0xFC00000000000000
andq %r9, %rcx
andq 0x10(%r10), %rdi
orq %rcx, %rdi
movq %rdi, (%r10)
decq %rax
movq %rax, 0x8(%r10)
movq (%rdx,%rsi,8), %rax
movl %eax, %ebx
shrq $0x20, %rax
movl %eax, 0x18(%rsp)
movl $0x1, (%r14,%rax,4)
movq 0x30(%rsp), %rcx
movl 0x58(%rsp), %edx
movl %edx, (%rcx,%rax,4)
movq 0x28(%r8), %rcx
movq 0x30(%r8), %rdx
movq 0x38(%r8), %rsi
movl (%rsi,%rax,8), %esi
imulq $0x30, %rsi, %r15
imulq $0x30, (%rdx,%rax,8), %rax
leaq (%rcx,%rax), %r12
addq $0x20, %r12
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0xdf66
testb $0x40, 0x3(%r12,%rbp)
jne 0xe056
movq -0x18(%r12,%rbp), %rdx
movl %edx, %eax
cmpl $0x0, (%r14,%rax,4)
jne 0xe056
movq -0x8(%r12,%rbp), %rcx
leaq (%rcx,%r13), %rsi
cmpq %rsi, %rbx
ja 0xe056
movq 0x10(%r8), %rsi
shrl %edx
imulq $0x28, %rdx, %rdx
movq 0x18(%rsi,%rdx), %rdx
cmpq %r13, %rdx
ja 0xe056
shlq $0x20, %rax
movq %rbx, %rsi
subq %rcx, %rsi
addq %rdx, %rsi
orq %rax, %rsi
movq %r10, %rdi
callq 0xf88c
movq 0x48(%rsp), %r10
movq 0x10(%rsp), %r8
addq $0x30, %rbp
jmp 0xdff3
movq 0x40(%rsp), %rcx
incl %ecx
movq 0x98(%rsp), %r12
movq 0x50(%rsp), %rdx
jmp 0xdf1d
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x80(%rsp), %rdi
cmpq %r13, 0x28(%rsp)
je 0xe175
movq 0x20(%rsp), %rax
movl (%rax,%r13,4), %eax
movl %eax, 0x18(%rsp)
movq 0x38(%rsp), %rcx
cmpb $0x0, (%rcx,%rax)
je 0xe0e4
movq 0x10(%r8), %rcx
imulq $0x28, %rax, %rdx
cmpq %rdi, 0x18(%rcx,%rdx)
ja 0xe0e4
leal (%rax,%rax), %ecx
movq 0x30(%rsp), %rdx
movl (%rdx,%rcx,4), %esi
testq %rsi, %rsi
je 0xe0e4
movl %ecx, %ecx
movl 0x4(%rdx,%rcx,4), %edx
testq %rdx, %rdx
je 0xe0e4
incl %ebx
movq 0x38(%rsp), %rcx
movb $0x0, (%rcx,%rax)
cmpl $0x3, 0x130(%rsp)
jge 0xe0e9
incq %r13
jmp 0xe082
movq 0xef08(%rip), %rcx      # 0x1cff8
movq (%rcx), %rdi
movq 0x60(%rsp), %rcx
movq 0x10(%rcx), %r10
imulq $0x18, %rax, %rax
movq (%r10,%rax), %rcx
movl %esi, %eax
sarl $0x2, %eax
cltq
imulq $0x18, %rax, %rax
btl $0x1, %esi
leaq 0x8752(%rip), %r11      # 0x1686c
movq %r11, %rsi
adcq $0x0, %rsi
movq (%r10,%rax), %r8
movsbl (%rsi), %r9d
movl %edx, %eax
sarl $0x2, %eax
cltq
imulq $0x18, %rax, %rax
movq (%r10,%rax), %rax
btl $0x1, %edx
movq %r11, %rdx
adcq $0x0, %rdx
movsbl (%rdx), %edx
movl %edx, 0x8(%rsp)
movq %rax, (%rsp)
leaq 0x956a(%rip), %rsi      # 0x176bf
leaq 0x9558(%rip), %rdx      # 0x176b4
xorl %eax, %eax
callq 0x3290
movq 0x80(%rsp), %rdi
movq 0x10(%rsp), %r8
jmp 0xe0e4
testl %ebx, %ebx
jne 0xdec2
movq 0x30(%rsp), %rdi
callq 0x3060
movq %r14, %rdi
callq 0x3060
movq 0x48(%rsp), %rbx
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdi
callq 0x1463f
movq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0x1463f
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
cmpq %rbx, 0x28(%rsp)
je 0xe1e1
movq 0x20(%rsp), %rax
movl (%rax,%rbx,4), %esi
movl %esi, 0x18(%rsp)
movq 0x38(%rsp), %rax
cmpb $0x0, (%rax,%rsi)
je 0xe1dc
callq 0x5fc7
movq 0x10(%rsp), %rdi
incq %rbx
jmp 0xe1b4
cmpl $0x3, 0x130(%rsp)
jl 0xe216
movq 0x60(%rsp), %r14
movq 0x20(%r14), %rbx
movq %rdi, 0x20(%r14)
movq 0xedf9(%rip), %rax      # 0x1cff8
movq (%rax), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x9c19
movq 0x10(%rsp), %rdi
movq %rbx, 0x20(%r14)
pushq $0x1
popq %rbx
pushq $0x1
popq %rax
movq 0x80(%rsp), %r15
testq %rax, %rax
je 0xe290
movl 0x130(%rsp), %ebp
movl %ebp, (%rsp)
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movl %ebx, %r8d
xorl %r9d, %r9d
callq 0x10ce0
movq %rax, %r14
movq 0x10(%rsp), %rdi
movsd 0x8263(%rip), %xmm0     # 0x164b8
movsd 0x830b(%rip), %xmm1     # 0x16568
xorl %esi, %esi
movl %ebp, %edx
callq 0x10a91
movq %rax, %r13
movq 0x10(%rsp), %rdi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %r15, %rdx
movl %ebx, %ecx
xorl %r8d, %r8d
movl %ebp, %r9d
callq 0x10677
movq 0x10(%rsp), %rdi
addq %r14, %rax
addq %r13, %rax
jmp 0xe224
xorl %eax, %eax
cmpq %rax, 0x28(%rsp)
je 0xe2c2
movq 0x20(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x18(%rsp)
movq 0x10(%rdi), %rdx
imulq $0x28, %rcx, %rsi
testb $0x40, 0x23(%rdx,%rsi)
je 0xe2bd
movq 0x38(%rsp), %rdx
movb $0x1, (%rdx,%rcx)
incq %rax
jmp 0xe292
cmpl $0x3, 0x130(%rsp)
jl 0xe2f7
movq 0x60(%rsp), %r14
movq 0x20(%r14), %rbx
movq %rdi, 0x20(%r14)
movq 0xed18(%rip), %rax      # 0x1cff8
movq (%rax), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x9c19
movq 0x10(%rsp), %rdi
movq %rbx, 0x20(%r14)
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
xorl %eax, %eax
movsd 0x8286(%rip), %xmm0     # 0x16590
movapd 0x828e(%rip), %xmm1     # 0x165a0
cmpq %rax, 0x28(%rsp)
je 0xe364
movq 0x20(%rsp), %rcx
movl (%rcx,%rax,4), %edx
movl %edx, 0x18(%rsp)
movq 0x10(%rdi), %rcx
imulq $0x28, %rdx, %rdx
testb $0x40, 0x23(%rcx,%rdx)
jne 0xe35f
addq %rdx, %rcx
movsd 0x18(%rcx), %xmm2
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
subpd %xmm1, %xmm2
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
movsd 0x50(%rsp), %xmm2
addsd %xmm3, %xmm2
movsd %xmm2, 0x50(%rsp)
incq %rax
jmp 0xe312
movsd 0x50(%rsp), %xmm0
mulsd 0x81fe(%rip), %xmm0     # 0x16570
movsd %xmm0, 0x50(%rsp)
pushq $0x1
popq %rsi
movq 0x90(%rsp), %rdi
callq 0x3240
movq 0x10(%rsp), %r10
movq %rax, %rdi
movsd 0x81e0(%rip), %xmm0     # 0x16578
mulsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
movq 0x78(%rsp), %rax
movq 0x68(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
addq $0x18, %rax
movq %rax, 0xd0(%rsp)
xorl %ebx, %ebx
movq %rdi, 0x40(%rsp)
cmpq 0x28(%rsp), %rbx
je 0xea0e
movq 0x20(%rsp), %rax
movl (%rax,%rbx,4), %eax
movl %eax, 0x18(%rsp)
cmpb $0x0, (%rdi,%rax)
jne 0xe9a8
movq 0x10(%r10), %rcx
imulq $0x28, %rax, %rax
testb $0x40, 0x23(%rcx,%rax)
jne 0xe9a8
movq %rbx, 0x68(%rsp)
xorl %r12d, %r12d
movq %r10, %rdi
xorl %esi, %esi
callq 0x9778
movq %rax, %rbp
movl $0x1, (%rsp)
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x12281
movq 0x40(%rsp), %rdx
movq 0xd0(%rsp), %r14
xorl %esi, %esi
xorl %r8d, %r8d
xorl %edi, %edi
xorl %eax, %eax
xorl %r9d, %r9d
movq %rbp, 0x48(%rsp)
cmpq %r12, 0x28(%rsp)
je 0xe4e0
movq 0x20(%rsp), %rcx
movl (%rcx,%r12,4), %ebx
movq 0x10(%rbp), %rcx
imulq $0x28, %rbx, %r15
testb $0x40, 0x23(%rcx,%r15)
jne 0xe4d4
cmpq %rax, %r9
jne 0xe4c1
leaq (%rax,%rax), %r13
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r13
movl %esi, 0x30(%rsp)
leaq (,%r13,4), %rsi
movl %r8d, %ebp
movq %r9, 0x58(%rsp)
callq 0x3330
movl 0x30(%rsp), %esi
movq 0x58(%rsp), %r9
movl %ebp, %r8d
movq 0x48(%rsp), %rbp
movq 0x40(%rsp), %rdx
movq %rax, %rdi
movq 0x10(%rbp), %rcx
movq %r13, %rax
movl %ebx, (%rdi,%r9,4)
addl 0x18(%rcx,%r15), %r8d
incq %r9
addl (%r14), %esi
movb $0x1, (%rdx,%rbx)
incq %r12
addq $0x30, %r14
jmp 0xe451
movq %rdi, 0x78(%rsp)
movl %r8d, %eax
cvtsi2sd %rax, %xmm0
movsd 0x50(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0xe728
testl %esi, %esi
je 0xe728
movq %r9, 0x58(%rsp)
movl %r8d, 0x74(%rsp)
xorl %r12d, %r12d
movl 0x1c(%rsp), %r11d
cmpq 0x28(%rsp), %r12
je 0xe74e
movq 0x20(%rsp), %rax
movl (%rax,%r12,4), %ecx
movq 0x10(%rbp), %rsi
movq %rcx, 0x30(%rsp)
imulq $0x28, %rcx, %rdx
movl 0x20(%rsi,%rdx), %edi
btl $0x1e, %edi
jb 0xe6d6
movq 0xa8(%rsp), %rax
cmpl %r11d, (%rax,%r12,4)
je 0xe6d6
leaq (%rsi,%rdx), %rcx
movq 0x80(%rsp), %rax
cmpq %rax, 0x18(%rcx)
jae 0xe6d6
movl %edi, %r8d
andl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
cvtsi2sd %r8d, %xmm0
movsd 0x98(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0xe6d6
movq %rsi, 0xd8(%rsp)
movq %rdx, 0x90(%rsp)
movq 0x10(%rsp), %rax
movq 0x28(%rax), %r9
movq 0x30(%rax), %r10
movq 0x30(%rsp), %rcx
leal (%rcx,%rcx), %edx
movq 0x38(%rax), %r11
addq $0x20, %r9
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %ebx, %ebx
cmpq $0x2, %r14
je 0xe612
movq %r14, %rcx
orq %rdx, %rcx
movl (%r11,%rcx,8), %r15d
imulq $0x30, %r15, %r15
imulq $0x30, (%r10,%rcx,8), %r13
addq %r9, %r13
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0xe60d
movq -0x18(%r13,%rcx), %rax
shrq %rax
movq 0x38(%rsp), %rsi
cmpb $0x1, (%rsi,%rax)
sbbl $-0x1, %ebp
movb 0x3(%r13,%rcx), %al
andb $0x40, %al
cmpb $0x1, %al
adcl $0x0, %ebx
addq $0x30, %rcx
jmp 0xe5e2
incq %r14
jmp 0xe5c4
testl %ebp, %ebp
movl 0x1c(%rsp), %r11d
movq 0x48(%rsp), %rbp
movq 0x90(%rsp), %r14
movq 0xd8(%rsp), %rcx
je 0xe6d6
cvtsi2sd %ebx, %xmm0
mulsd 0x88(%rsp), %xmm0
mulsd 0x7ea7(%rip), %xmm0     # 0x164f0
cvttsd2si %xmm0, %rax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
andl $0x80000000, %edi       # imm = 0x80000000
orl %eax, %edi
movl %edi, 0x20(%rcx,%r14)
xorl %esi, %esi
cmpq $0x2, %rsi
je 0xe6cc
movq 0x10(%rsp), %rdi
movq 0x28(%rdi), %rax
movq 0x30(%rdi), %rcx
movq %rsi, %r9
orq %rdx, %r9
movq 0x38(%rdi), %rdi
movl (%rdi,%r9,8), %edi
imulq $0x30, %rdi, %rdi
imulq $0x30, (%rcx,%r9,8), %rcx
leaq (%rax,%rcx), %r9
addq $0x20, %r9
xorl %ecx, %ecx
cmpq %rcx, %rdi
je 0xe6c7
movl (%r9,%rcx), %r10d
btl $0x1e, %r10d
jb 0xe6c1
movl %r10d, %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpl %r8d, %eax
jbe 0xe6c1
andl $0x80000000, %r10d      # imm = 0x80000000
orl %r8d, %r10d
movl %r10d, (%r9,%rcx)
addq $0x30, %rcx
jmp 0xe696
incq %rsi
jmp 0xe662
cmpl $0x3, 0x130(%rsp)
jge 0xe6de
incq %r12
jmp 0xe517
movq 0xe913(%rip), %rax      # 0x1cff8
movq (%rax), %rdi
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rax
imulq $0x18, 0x30(%rsp), %rcx
movq (%rax,%rcx), %rcx
movq 0x10(%rbp), %rax
movl 0x20(%rax,%r14), %r9d
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
andl %eax, %r9d
leaq 0x8fd5(%rip), %rsi      # 0x176e8
leaq 0x8f9a(%rip), %rdx      # 0x176b4
xorl %eax, %eax
callq 0x3290
movl 0x1c(%rsp), %r11d
jmp 0xe6d6
movq %rbp, %rdi
callq 0xf9e0
movq 0x78(%rsp), %rdi
callq 0x3060
movq 0x10(%rsp), %r10
movq 0x40(%rsp), %rdi
movq 0x68(%rsp), %rbx
jmp 0xe9a8
movq 0x58(%rsp), %rax
leaq (,%rax,4), %rsi
movq 0x78(%rsp), %rdi
callq 0x3330
movq %rax, %r15
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %ebp, %ebp
cmpq %r12, 0x28(%rsp)
je 0xe82d
movq 0x20(%rsp), %rax
movl (%rax,%r12,4), %eax
movq 0x48(%rsp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rax, %rdx
testb $0x40, 0x23(%rcx,%rdx)
jne 0xe825
movq 0xe0(%rsp), %rcx
movq 0x10(%rcx), %rcx
shlq $0x6, %rax
leaq (%rcx,%rax), %r13
movl 0x28(%rcx,%rax), %edx
leaq (%rdx,%rbp), %rax
cmpq %rbx, %rax
jbe 0xe80d
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rbx
shrq $0x10, %rbx
orq %rax, %rbx
leaq 0x8(,%rbx,8), %rsi
incq %rbx
movq %r14, %rdi
callq 0x3330
movq %rax, %r14
movl 0x28(%r13), %edx
leaq (%r14,%rbp,8), %rdi
movq 0x30(%r13), %rsi
shlq $0x3, %rdx
callq 0x32c0
movl 0x28(%r13), %eax
addq %rax, %rbp
incq %r12
jmp 0xe772
movq %r14, %rdi
movq %rbp, %rsi
pushq $0x8
popq %rdx
leaq -0x2fd9(%rip), %rcx     # 0xb864
callq 0x30c0
xorl %r12d, %r12d
pushq $-0x1
popq %rcx
xorl %eax, %eax
movl %eax, %eax
movl %r12d, %ebx
cmpq %rax, %rbp
jbe 0xe873
movq (%r14,%rax,8), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
cmpl %ecx, %esi
je 0xe86f
incl %r12d
movq %rdx, (%r14,%rbx,8)
movl 0x4(%r14,%rax,8), %ecx
incl %eax
jmp 0xe84a
leaq (,%rbx,8), %rsi
movq %r14, %rdi
callq 0x3330
movq %rax, %r14
xorpd %xmm0, %xmm0
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xc0(%rsp)
xorl %eax, %eax
cmpq %rax, %rbx
je 0xe8cc
movq (%r14,%rax,8), %rcx
movl %ecx, %edx
cvtsi2sd %rdx, %xmm0
shrq $0x20, %rcx
andl $0x3, %ecx
addsd 0xb0(%rsp,%rcx,8), %xmm0
movsd %xmm0, 0xb0(%rsp,%rcx,8)
incq %rax
jmp 0xe89e
leaq 0xb0(%rsp), %rdi
leaq 0xa4(%rsp), %rsi
callq 0xb7ff
movl %eax, %ebp
movq 0x128(%rsp), %rdx
movq (%rdx), %rcx
movq 0x10(%rdx), %rax
cmpq 0x8(%rdx), %rcx
jne 0xe926
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x6, %rsi
movq %rax, %rdi
movq %rdx, %rbx
callq 0x3330
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movl 0x1c(%rsp), %esi
jmp 0xe92d
movl 0x1c(%rsp), %esi
movq %rdx, %rbx
movq 0x10(%rsp), %r10
movq 0x40(%rsp), %rdi
movl 0x74(%rsp), %r9d
movq 0x58(%rsp), %r8
leaq 0x1(%rcx), %rdx
shlq $0x6, %rcx
movq %rdx, (%rbx)
movl %esi, (%rax,%rcx)
movl %ebp, %edx
movsd 0xb0(%rsp,%rdx,8), %xmm0
movsd %xmm0, 0x8(%rax,%rcx)
movl 0xa4(%rsp), %edx
movsd 0xb0(%rsp,%rdx,8), %xmm0
movsd %xmm0, 0x10(%rax,%rcx)
movl %r9d, 0x18(%rax,%rcx)
movl %r8d, 0x1c(%rax,%rcx)
movq %r15, 0x20(%rax,%rcx)
movl %r12d, 0x28(%rax,%rcx)
movq %r14, 0x30(%rax,%rcx)
movq 0x48(%rsp), %rdx
movq %rdx, 0x38(%rax,%rcx)
cmpl $0x0, 0x130(%rsp)
movq 0x68(%rsp), %rbx
jg 0xe9b0
incq %rbx
jmp 0xe3cb
movq 0xe641(%rip), %rax      # 0x1cff8
movq (%rax), %rdi
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x18(%rsp), %ecx
imulq $0x18, %rcx, %rcx
movq (%rax,%rcx), %rcx
movsd 0xb8(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm1
movsd 0xc8(%rsp), %xmm2
movl %esi, (%rsp)
leaq 0x8d25(%rip), %rsi      # 0x17719
leaq 0x8cb9(%rip), %rdx      # 0x176b4
movb $0x3, %al
callq 0x3290
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %r10
jmp 0xe9a8
movq %rdi, %r14
movq 0x38(%rsp), %rdi
movq %r10, %rbx
callq 0x3060
movq %r14, %rdi
callq 0x3060
movq %rbx, %rdi
callq 0xf9e0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xe5b1(%rip), %rbx      # 0x1cff8
movq (%rbx), %rdi
leaq 0xe0ef(%rip), %rax      # 0x1cb40
movq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x8c01(%rip), %rsi      # 0x17662
leaq 0x8c4c(%rip), %rdx      # 0x176b4
movsd 0x88(%rsp), %xmm0
movb $0x1, %al
callq 0x3290
cmpl $0x2, 0x130(%rsp)
je 0xddf7
movq 0x60(%rsp), %r15
movq 0x20(%r15), %r14
movq 0x10(%rsp), %rax
movq %rax, 0x20(%r15)
movq (%rbx), %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x9c19
movq %r14, 0x20(%r15)
jmp 0xddf7