// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_double_scaffold_gfa(ma_ug_t*, ma_ug_t*, ma_ug_t*, scaf_res_t*, scaf_res_t*, asg_t*, kv_u_trans_t*, long, kvect_sec_t**, kvect_sec_t**)
void gen_double_scaffold_gfa(ma_ug_t *ref, ma_ug_t *hu1, ma_ug_t *hu2, scaf_res_t *cp1, scaf_res_t *cp2, asg_t *sg, kv_u_trans_t *os, int64_t minNs, kvect_sec_t **sc1, kvect_sec_t **sc2)
{
    order_contig_trans(os);
    asg_t *g = asg_init(); uint64_t k, s, e, z, rn, pn, dn, rthres = asm_opt.self_scaf_reliable_min, el, glen; ma_utg_t *u, *ut; u_trans_t *p, *d, *r; 
    asg_arc_t t, *c; int64_t zs, ze, gl, gmin = -asm_opt.self_scaf_gap_max, gmax = asm_opt.self_scaf_gap_max; uint64_t mf, blen, bf, is_dip; uint32_t sce[2]; sce[0] = 0; sce[1] = 1;
    asg32_v b0, b1, b2, b3; kv_init(b0); kv_init(b1); kv_init(b2); kv_init(b3); uint8_t *f, *fs, *fsk; CALLOC(f, (ref->u.n<<1)); CALLOC(fs, (ref->u.n<<1)); CALLOC(fsk, ref->u.n);

    // fprintf(stderr, "[M::%s::] SSS\n", __func__); 
    for (k = 0; k < os->idx.n; ++k) {
        u = ((k<hu1->u.n)?&(hu1->u.a[k]):&(hu2->u.a[k-hu1->u.n]));
        asg_seq_set(g, k, u->len, 0); g->seq[k].c = (k<hu1->u.n?1:2);
    }

    // fprintf(stderr, "[M::%s::] MMM\n", __func__); 
    for (k = 0; k < os->idx.n; ++k) {
        
        r = u_trans_a(*os, k); rn = u_trans_n(*os, k); p = d = NULL; pn = dn = 0;
        // fprintf(stderr, "[M::%s::] # k:%lu, rn::%lu\n", __func__, k, rn); 
        if(rn <= 1) continue;
        for (z = 0, p = r; (z < rn) && (!(r[z].del)); z++); pn = z;
        for (d = r + z; (z < rn) && (r[z].qs != ((uint32_t)-1)); z++); dn = z - pn;
        // fprintf(stderr, "[M::%s::] # k:%lu, pn::%lu, dn::%lu\n", __func__, k, pn, dn); 
        if(pn <= 1) continue;///no scaf
        s = e = (uint64_t)-1;
        for (z = 0; z < pn; z++) {
            if((p[z].f) || (((p[z].qe-p[z].qs) >= rthres) && ((p[z].te-p[z].ts) >= rthres))) {
                s = e = z; break;
            }
        }
        for (; z < pn; z++) {
            if((p[z].f) || (((p[z].qe-p[z].qs) >= rthres) && ((p[z].te-p[z].ts) >= rthres))) e = z;
        }
        // fprintf(stderr, "[M::%s::] # k:%lu, s::%lu, e::%lu\n", __func__, k, s, e); 
        ///[s, e]
        u = ((k<hu1->u.n)?&(hu1->u.a[k]):&(hu2->u.a[k-hu1->u.n]));
        set_fsk(fsk, 1, ((k<hu1->u.n)?&(cp1->a[k]):&(cp2->a[k-hu1->u.n])));
        for (z = 1; z < pn; z++) {
            ///cannot scaffold circles
            ut = ((p[z-1].tn<hu1->u.n)?&(hu1->u.a[p[z-1].tn]):&(hu2->u.a[p[z-1].tn-hu1->u.n])); if(ut->circ) continue;
            ut = ((p[z].tn<hu1->u.n)?&(hu1->u.a[p[z].tn]):&(hu2->u.a[p[z].tn-hu1->u.n])); if(ut->circ) continue;
            // fprintf(stderr, "[M::%s::] # k:%lu, z::%lu, p[z-1].tn::%u, p[z].tn::%u, hu1->u.n::%u, hu2->u.n::%u\n", __func__, k, z, p[z-1].tn, p[z].tn, (uint32_t)hu1->u.n, (uint32_t)hu2->u.n); 
            
            el = 0; gl = 0;
            if((sce[(p[z-1].tn<hu1->u.n)?0:1] != sce[(p[z-1].qn<hu1->u.n)?0:1]) && (sce[(p[z].tn<hu1->u.n)?0:1] != sce[(p[z].qn<hu1->u.n)?0:1])) {///tn and qn come from different haplotypes
                if((((z-1)>=s)&&((z-1)<=e))&&(((z)>=s)&&((z)<=e))) el = 1;
                // fprintf(stderr, "-0-[M::%s::] # k::%lu, z::%lu, el::%lu\n", __func__, k, z, el); 
                if(el) {
                    zs = MAX(p[z-1].qs, p[z].qs); 
                    ze = MIN(p[z-1].qe, p[z].qe);
                    if(is_noisy_ov(MIN(zs, ze), MAX(zs, ze), u->len, 2500000, 0.5, d, dn)) el = 0;
                    // fprintf(stderr, "-1-[M::%s::] # k::%lu, z::%lu, el::%lu, zs::%ld, ze::%ld\n", __func__, k, z, el, zs, ze); 
                    if(el) {
                        gl = zs - ze;
                        if((!(p[z-1].f)) || (!(p[z].f))) {
                            if(gl >= gmin && gl <= gmax) el = 1;
                            else el = 0;///gap is too long
                        } else if(p[z-1].f && p[z].f) {
                            if(gl <= gmax) el = 1; ///p[z-1] and p[z] are too far away is bad; p[z-1] and p[z] are overlapped is fine
                            else el = 0;
                        }
                    }
                    // fprintf(stderr, "-2-[M::%s::] # k::%lu, z::%lu, el::%lu, zs::%ld, ze::%ld, p[z-1].f::%u, p[z].f::%u, gmin::%ld, gmax::%ld\n", __func__, k, z, el, zs, ze, p[z-1].f, p[z].f, gmin, gmax); 
                }
                ///final try in graph
                // fprintf(stderr, "[M::%s::] # k::%lu, z::%lu, el::%lu, gl::%ld\n", __func__, k, z, el, gl); 
                is_dip = 0;

                glen = is_small_tangle(&(p[z-1]), &(p[z]), ref, hu1, hu2, cp1, cp2, &b0, &b1, &b2, &b3, f, fs, fsk, 5000000, &is_dip);
                // fprintf(stderr, "[M::%s::] # k::%lu, z::%lu, el::%lu, glen::%lu, gl::%ld\n", __func__, k, z, el, glen, gl); 
                if((glen != (uint64_t)-1) && (((int64_t)glen) <= asm_opt.self_scaf_gap_max)) {
                    el = 1; if(!is_dip) gl = glen;
                }
            }
            if(gl < minNs) gl = minNs;
            if(el) {
                ///in anyway the gap cannot be too large
                if(gl <= gmax) el = 1; ///p[z-1] and p[z] are too far away is bad; p[z-1] and p[z] are overlapped is fine
                else el = 0;
            }
            
            scaf_hit2arc(&(p[z-1]), &(p[z]), 0, el, gl, &t);
            c = asg_arc_pushp(g); *c = t;
            scaf_hit2arc(&(p[z]), &(p[z-1]), 1, el, gl, &t);
            c = asg_arc_pushp(g); *c = t;
        }
        set_fsk(fsk, 0, ((k<hu1->u.n)?&(cp1->a[k]):&(cp2->a[k-hu1->u.n])));  
    }
    asg_cleanup(g); asg_symm(g);
    // fprintf(stderr, "[M::%s::] EEE\n", __func__); 

    uint64_t v, n_vtx = g->n_seq<<1, nv; asg_arc_t *av;
    for (v = 0; v < n_vtx; ++v) {
        if (g->seq[v>>1].del) continue;
        nv = asg_arc_n(g, v);
        if(nv <= 1) continue;
        av = asg_arc_a(g, v);
        for(k = 0; k < nv; k++) {
            if(av[k].del) continue;
            av[k].del = 1;
            asg_arc_del(g, av[k].v^1, (av[k].ul>>32)^1, 1);
        }
    }
    for (k = 0; k < g->n_arc; k++) {
        if(!(g->arc[k].el)) g->arc[k].del = 1;
    }
    asg_cleanup(g);

    if((ref->u.n<<1) < g->n_seq) REALLOC(f, g->n_seq);
    memset(f, 0, sizeof((*f))*g->n_seq);
    asg64_v b64; kv_init(b64); kvect_sec_t *i1 = NULL, *i2 = NULL, *im = NULL; uint64_t len[2];///, mmip;
    sec_t *mmi; CALLOC(i1, 1); CALLOC(i2, 1); ///i1->ctg = hu1; i2->ctg = hu2; 

    b0.n = 0; ///mmip = hu1->u.n; mmip <<= 1;
    for (v = 0; v < n_vtx; ++v) {
        nv = asg_arc_n(g, v); assert(nv <= 1);
        if(f[v>>1]) continue;
        if(asg_arc_n(g, (v^1)) != 0) continue;
        b64.n = 0; mf = gen_scaf_path_lst(g, v, &b64, &blen, &bf);
        assert(mf == END_TIPS);
        // rn = prt_gen_scaf_path_lst(b64.a, b64.n, (mf==LOOP)?1:0, hu1, hu2); kv_push(uint32_t, b0, rn);
        for (k = len[0] = len[1] = 0; k < b64.n; k++) {
            f[((uint32_t)b64.a[k])>>1] = 1;
            len[g->seq[((uint32_t)b64.a[k])>>1].c-1] += g->seq[((uint32_t)b64.a[k])>>1].len;
        }
        im = ((len[0] >= len[1])?i1:i2); kv_pushp(sec_t, (*im), &mmi); memset(mmi, 0, sizeof((*mmi)));
        mmi->is_c = 0; mmi->n = mmi->m = b64.n; MALLOC(mmi->a, mmi->n); memcpy(mmi->a, b64.a, sizeof((*(mmi->a)))*mmi->n);
        // for (k = 0; k < mmi->n; k++) { ///scaffold bug
        //     if((((uint32_t)mmi->a[k])>>1) >= hu1->u.n) mmi->a[k] -= mmip;
        // }
    }

    for (v = 0; v < n_vtx; ++v) {
        nv = asg_arc_n(g, v); assert(nv <= 1);
        if(f[v>>1]) continue;
        assert((nv == 1) && (asg_arc_n(g, (v^1)) == 1));
        b64.n = 0; mf = gen_scaf_path_lst(g, v, &b64, &blen, &bf);
        assert(mf == LOOP);
        // rn = prt_gen_scaf_path_lst(b64.a, b64.n, (mf==LOOP)?1:0, hu1, hu2); kv_push(uint32_t, b0, rn);
        for (k = len[0] = len[1] = 0; k < b64.n; k++) {
            f[((uint32_t)b64.a[k])>>1] = 1;
            len[g->seq[((uint32_t)b64.a[k])>>1].c-1] += g->seq[((uint32_t)b64.a[k])>>1].len;
        }
        im = ((len[0] >= len[1])?i1:i2);
        im = ((len[0] >= len[1])?i1:i2); kv_pushp(sec_t, (*im), &mmi); memset(mmi, 0, sizeof((*mmi)));
        mmi->is_c = 1; mmi->n = mmi->m = b64.n; MALLOC(mmi->a, mmi->n); memcpy(mmi->a, b64.a, sizeof((*(mmi->a)))*mmi->n);
        // for (k = 0; k < mmi->n; k++) { ///scaffold bug
        //     if((((uint32_t)mmi->a[k])>>1) >= hu1->u.n) mmi->a[k] -= mmip;
        // }
    }
    kv_destroy(b64);
    // cal_arr_N50(b0.a, b0.n, "Scf");

    // b1.n = 0;
    // for(k = 0; k < hu1->u.n; k++) kv_push(uint32_t, b1, hu1->u.a[k].len);
    // for(k = 0; k < hu2->u.n; k++) kv_push(uint32_t, b1, hu2->u.a[k].len);
    // cal_arr_N50(b1.a, b1.n, "Ctg");

    kv_destroy(b0); kv_destroy(b1); kv_destroy(b2); kv_destroy(b3); free(f); free(fs); free(fsk); asg_destroy(g); 
    (*sc1) = i1; (*sc2) = i2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %r8, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movq %rdx, %r13
movq %rsi, (%rsp)
movq %rdi, %r14
movq 0x1c0(%rsp), %r15
movq %r15, %rdi
callq 0x281af
movl $0x1, %edi
movl $0x48, %esi
callq 0x2120
movq %rax, 0x8(%rsp)
leaq 0x1b6fe9(%rip), %rax    # 0x295758
movq 0x270(%rax), %rcx
movq %rcx, 0xc8(%rsp)
movq 0x278(%rax), %rax
movq %rax, 0x10(%rsp)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x170(%rsp)
xorl %ebx, %ebx
movq %rbx, 0x180(%rsp)
movaps %xmm0, 0x150(%rsp)
movq %rbx, 0x160(%rsp)
movaps %xmm0, 0x130(%rsp)
movq %rbx, 0x140(%rsp)
movaps %xmm0, 0x110(%rsp)
movq %rbx, 0x120(%rsp)
movq %r14, 0xa8(%rsp)
movq (%r14), %r14
leaq (%r14,%r14), %rbp
movl $0x1, %esi
movq %rbp, %rdi
callq 0x2120
movq %rax, 0x18(%rsp)
movl $0x1, %esi
movq %rbp, %rdi
callq 0x2120
movq %rax, 0xa0(%rsp)
movl $0x1, %esi
movq %r14, %rdi
callq 0x2120
movq %rax, 0x30(%rsp)
cmpq %rbx, 0x18(%r15)
je 0xdef5e
movq 0x10(%rsp), %rax
negq %rax
movq %rax, 0xc0(%rsp)
movq (%rsp), %r12
movq (%r12), %rax
xorl %ebx, %ebx
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq 0x8(%rsp), %r15
movq %r14, %rcx
subq %rax, %rcx
jae 0xde869
movq 0x10(%r12), %rax
addq %rbx, %rax
jmp 0xde875
leaq (%rcx,%rcx,4), %rax
shlq $0x3, %rax
addq 0x10(%r13), %rax
movl (%rax), %edx
andl %ebp, %edx
movq %r15, %rdi
movl %r14d, %esi
xorl %ecx, %ecx
callq 0xa0887
movq (%r12), %rax
cmpq %rax, %r14
movb $0x2, %cl
sbbb $0x0, %cl
movq 0x20(%r15), %rdx
movb %cl, 0x4(%rdx,%r14,8)
incq %r14
movq 0x1c0(%rsp), %r8
movq 0x18(%r8), %rcx
addq $0x28, %rbx
cmpq %rcx, %r14
jb 0xde857
testq %rcx, %rcx
je 0xdef5e
xorl %ebx, %ebx
movq 0x1c8(%rsp), %rax
testq %rax, %rax
movl $0x0, %edx
cmovgq %rax, %rdx
movq %rdx, 0xb0(%rsp)
movq %r13, 0xf8(%rsp)
movq 0x28(%r8), %rax
movq (%rax,%rbx,8), %rsi
movl %esi, %edx
cmpq $0x2, %rdx
jb 0xdef52
movq 0x10(%r8), %r15
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
addq %r15, %rax
shlq $0x4, %rsi
leaq (%rsi,%rsi,2), %r12
leaq (%r15,%r12), %rdi
addq $0x28, %rdi
movq %rax, %rsi
xorl %r9d, %r9d
cmpb $0x0, (%rdi)
js 0xde939
incq %r9
addq $0x30, %rdi
addq $0x30, %rsi
cmpq %r9, %rdx
jne 0xde91f
movq %rdx, %r9
jmp 0xde952
movq %r9, %rdi
cmpq %rdx, %r9
jae 0xde955
cmpl $-0x1, (%rsi)
je 0xde955
incq %rdi
addq $0x30, %rsi
cmpq %rdi, %rdx
jne 0xde941
movq %rdx, %rdi
cmpq $0x2, %r9
jb 0xdef52
leaq (%r9,%r9,2), %rcx
shlq $0x4, %rcx
addq %rax, %rcx
movq %rcx, 0xd8(%rsp)
subq %r9, %rdi
xorl %r8d, %r8d
movq 0xc8(%rsp), %rsi
testb $0x3f, 0x28(%rax)
jne 0xde9b7
movl 0x4(%rax), %ecx
subl (%rax), %ecx
cmpq %rcx, %rsi
ja 0xde99b
movl 0x10(%rax), %ecx
subl 0xc(%rax), %ecx
cmpq %rcx, %rsi
jbe 0xde9b7
incq %r8
addq $0x30, %rax
cmpq %r8, %r9
jne 0xde980
movq $-0x1, %r8
movq $-0x1, %r10
jmp 0xde9ee
movq %r8, %r10
cmpq %r9, %r8
jae 0xde9ee
movq %r8, %rcx
testb $0x3f, 0x28(%rax)
je 0xde9cd
movq %rcx, %r10
jmp 0xde9e2
movl 0x4(%rax), %edx
subl (%rax), %edx
cmpq %rdx, %rsi
ja 0xde9e2
movl 0x10(%rax), %edx
subl 0xc(%rax), %edx
cmpq %rdx, %rsi
jbe 0xde9c8
incq %rcx
addq $0x30, %rax
cmpq %rcx, %r9
jne 0xde9c2
movq %r10, 0xe8(%rsp)
movq %r8, 0xf0(%rsp)
movq %rbx, %rax
movq (%rsp), %rcx
subq (%rcx), %rax
movq %r9, 0x20(%rsp)
movq %rbx, 0xd0(%rsp)
movq %rdi, 0xe0(%rsp)
jae 0xdea3d
leaq (%rbx,%rbx,4), %rax
shlq $0x3, %rax
addq 0x10(%rcx), %rax
movq %rax, 0x98(%rsp)
movq 0x70(%rsp), %rcx
movq %rbx, %rax
jmp 0xdea56
leaq (%rax,%rax,4), %rcx
shlq $0x3, %rcx
addq 0x10(%r13), %rcx
movq %rcx, 0x98(%rsp)
movq 0x78(%rsp), %rcx
imulq $0x58, %rax, %rdx
addq (%rcx), %rdx
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0xde6c4
leaq (%r15,%r12), %rbp
addq $0x30, %rbp
movl $0x1, %r8d
movq (%rsp), %r14
movq 0x20(%rsp), %r9
movl -0x1c(%rbp), %ecx
movq (%r14), %rax
movq %rcx, %rdx
subq %rax, %rdx
jae 0xdea9f
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%r14), %rdx
jmp 0xdeaab
leaq (%rdx,%rdx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%r13), %rdx
cmpl $0x0, (%rdx)
js 0xded57
movl 0x14(%rbp), %edx
movq %rdx, %rsi
subq %rax, %rsi
jae 0xdeacd
leaq (%rdx,%rdx,4), %rsi
shlq $0x3, %rsi
addq 0x10(%r14), %rsi
jmp 0xdead9
leaq (%rsi,%rsi,4), %rsi
shlq $0x3, %rsi
addq 0x10(%r13), %rsi
cmpl $0x0, (%rsi)
js 0xded57
xorl %esi, %esi
cmpq %rax, %rcx
setae %sil
movl 0x38(%rsp,%rsi,4), %ecx
movl -0x28(%rbp), %esi
xorl %edi, %edi
cmpq %rsi, %rax
setbe %dil
cmpl 0x38(%rsp,%rdi,4), %ecx
movq %r8, 0x28(%rsp)
je 0xdeb28
xorl %ecx, %ecx
cmpq %rax, %rdx
setae %cl
movl 0x38(%rsp,%rcx,4), %ecx
movl 0x8(%rbp), %edx
xorl %esi, %esi
cmpq %rdx, %rax
setbe %sil
cmpl 0x38(%rsp,%rsi,4), %ecx
jne 0xded6c
xorl %r10d, %r10d
movq 0xb0(%rsp), %rbx
movl -0x1c(%rbp), %esi
movl -0x8(%rbp), %r15d
movl 0x14(%rbp), %edi
movl 0x28(%rbp), %r14d
xorl %r11d, %r11d
testq %rbx, %rbx
setns %r8b
movq %rbx, %r13
negq %r13
cmovsq %rbx, %r13
movq 0x8(%rsp), %r12
movl 0x4(%r12), %edx
movl %edx, %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
cmpl (%r12), %ecx
jne 0xdebde
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%r12)
movq %rdi, 0x88(%rsp)
movq 0x8(%r12), %rdi
shlq $0x3, %rax
movq %rsi, 0x80(%rsp)
leaq (%rax,%rax,2), %rsi
movq %r10, %rbx
movb %r8b, 0x90(%rsp)
callq 0x2370
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdi
movb 0x90(%rsp), %r8b
xorl %r11d, %r11d
movq %rbx, %r10
movq %rax, 0x8(%r12)
movl 0x4(%r12), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0xdebe3
movq 0x8(%r12), %rax
shrl $0x6, %r15d
andl $0x1, %r15d
leal (%r15,%rsi,2), %esi
shrl $0x6, %r14d
andl $0x1, %r14d
leal (%r14,%rdi,2), %edi
shlq $0x20, %rsi
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl %r9d, %r13d
movb %r8b, %r11b
shll $0xe, %r11d
leal 0x1(%rdx), %r8d
andl %r9d, %r8d
andl $0x80000000, %edx       # imm = 0x80000000
orl %r8d, %edx
movl %edx, 0x4(%r12)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq %rsi, (%rax,%rcx,8)
movl %edi, 0x8(%rax,%rcx,8)
movl %r13d, 0xc(%rax,%rcx,8)
movw %r11w, 0x10(%rax,%rcx,8)
movb %r10b, 0x12(%rax,%rcx,8)
movl $0x0, 0x13(%rax,%rcx,8)
movb $0x0, 0x17(%rax,%rcx,8)
movl 0x14(%rbp), %esi
movl 0x28(%rbp), %ebx
movl -0x1c(%rbp), %edi
movl -0x8(%rbp), %r14d
movl 0x4(%r12), %edx
movl %edx, %ecx
andl %r9d, %ecx
cmpl (%r12), %ecx
jne 0xdecd9
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%r12)
movq %rdi, 0x88(%rsp)
movq 0x8(%r12), %rdi
shlq $0x3, %rax
movq %rsi, 0x80(%rsp)
leaq (%rax,%rax,2), %rsi
movq %r10, 0x90(%rsp)
movl %r11d, %r15d
callq 0x2370
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdi
movl %r15d, %r11d
movq 0x90(%rsp), %r10
movq %rax, 0x8(%r12)
movl 0x4(%r12), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0xdecde
movq 0x8(%r12), %rax
movq 0x20(%rsp), %r9
shrl $0x6, %ebx
andl $0x1, %ebx
leal (%rbx,%rsi,2), %esi
xorl $0x1, %esi
shrl $0x6, %r14d
andl $0x1, %r14d
leal (%r14,%rdi,2), %edi
shlq $0x20, %rsi
xorl $0x1, %edi
leal 0x1(%rdx), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %r8d, %edx
movl %edx, 0x4(%r12)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq %rsi, (%rax,%rcx,8)
movl %edi, 0x8(%rax,%rcx,8)
movl %r13d, 0xc(%rax,%rcx,8)
movw %r11w, 0x10(%rax,%rcx,8)
movb %r10b, 0x12(%rax,%rcx,8)
movl $0x0, 0x13(%rax,%rcx,8)
movb $0x0, 0x17(%rax,%rcx,8)
movq 0xf8(%rsp), %r13
movq (%rsp), %r14
movq 0x28(%rsp), %r8
incq %r8
addq $0x30, %rbp
cmpq %r8, %r9
jne 0xdea83
jmp 0xdef13
leaq -0x1(%r8), %rax
movq 0xf0(%rsp), %rdx
cmpq %rdx, %rax
setb %cl
movq 0xe8(%rsp), %rsi
cmpq %rsi, %rax
seta %al
cmpq %rdx, %r8
setb %dl
orb %cl, %dl
orb %al, %dl
cmpq %rsi, %r8
seta %al
orb %dl, %al
jne 0xdee02
movl (%rbp), %eax
movl -0x30(%rbp), %ecx
cmpl %eax, %ecx
cmoval %ecx, %eax
movl -0x2c(%rbp), %ecx
movl 0x4(%rbp), %esi
cmpl %esi, %ecx
cmovbl %ecx, %esi
movq %rax, %rbx
subq %rsi, %rbx
movq %rsi, %rdi
cmovaq %rax, %rsi
cmovbq %rax, %rdi
movq 0x98(%rsp), %rax
movl (%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x2625a0, %ecx         # imm = 0x2625A0
movsd 0x15280c(%rip), %xmm0   # 0x2315f0
movq 0xd8(%rsp), %r8
movq 0xe0(%rsp), %r9
callq 0xdc2b9
testq %rax, %rax
je 0xdeedd
xorl %r15d, %r15d
xorl %ebx, %ebx
leaq -0x30(%rbp), %rdi
movq $0x0, 0xb8(%rsp)
movq %rbp, %rsi
movq 0xa8(%rsp), %rdx
movq %r14, %rcx
movq 0x70(%rsp), %r9
leaq 0xb8(%rsp), %rax
pushq %rax
pushq $0x4c4b40               # imm = 0x4C4B40
pushq 0x40(%rsp)
pushq 0xb8(%rsp)
pushq 0x38(%rsp)
leaq 0x138(%rsp), %rax
pushq %rax
leaq 0x160(%rsp), %rax
pushq %rax
leaq 0x188(%rsp), %rax
pushq %rax
leaq 0x1b0(%rsp), %rax
pushq %rax
pushq 0xc0(%rsp)
callq 0xde30d
addq $0x50, %rsp
cmpq $-0x1, %rax
je 0xdeebb
leaq 0x1b68d0(%rip), %rcx    # 0x295758
cmpq 0x278(%rcx), %rax
jg 0xdeebb
cmpq $0x0, 0xb8(%rsp)
cmoveq %rax, %rbx
movq 0x1c8(%rsp), %rax
cmpq %rax, %rbx
cmovleq %rax, %rbx
cmpq 0x10(%rsp), %rbx
setle %r10b
jmp 0xdeb33
movq 0x1c8(%rsp), %rax
cmpq %rax, %rbx
cmovleq %rax, %rbx
cmpq 0x10(%rsp), %rbx
setle %al
movq %r15, %r10
andb %al, %r10b
jmp 0xdeb33
testb $0x3f, -0x8(%rbp)
je 0xdeef7
testb $0x3f, 0x28(%rbp)
je 0xdeef7
cmpq 0x10(%rsp), %rbx
setle %r15b
jmp 0xdee07
cmpq 0xc0(%rsp), %rbx
setge %al
cmpq 0x10(%rsp), %rbx
setle %r15b
andb %al, %r15b
jmp 0xdee07
movq 0xd0(%rsp), %rbx
movq %rbx, %rax
subq (%r14), %rax
jae 0xdef2e
imulq $0x58, %rbx, %rdx
movq 0x70(%rsp), %rax
jmp 0xdef37
imulq $0x58, %rax, %rdx
movq 0x78(%rsp), %rax
addq (%rax), %rdx
movq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0xde6c4
movq 0x1c0(%rsp), %r8
movq 0x18(%r8), %rcx
incq %rbx
cmpq %rcx, %rbx
jb 0xde8e2
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xa0a7d
movq %r14, %rdi
callq 0xa0ab6
movq %r14, %rdi
callq 0xa0b79
movl 0x14(%r14), %ebp
movl %ebp, %eax
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, 0x14(%r14)
addl %ebp, %ebp
movslq %ebp, %r15
testl %r15d, %r15d
je 0xdf062
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x20(%r14), %rdx
movq %rax, %rsi
andq $-0x2, %rsi
cmpl $0x0, (%rdx,%rsi,4)
js 0xdf056
movq 0x28(%r14), %rdx
movq (%rdx,%rax,8), %rsi
movl %esi, %edx
cmpq $0x2, %rdx
jb 0xdf056
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r14), %rsi
xorl %edi, %edi
leaq (%rdi,%rdi,2), %r8
movl 0xc(%rsi,%r8,8), %r9d
testl %r9d, %r9d
js 0xdf04e
leaq (%rsi,%r8,8), %r8
orl $0x80000000, %r9d       # imm = 0x80000000
movl %r9d, 0xc(%r8)
movl 0x8(%r8), %r9d
xorq $0x1, %r9
movq 0x28(%r14), %r10
movq (%r10,%r9,8), %r10
movq %r10, %r9
andq %rcx, %r9
je 0xdf04e
movl 0x4(%r8), %r8d
movq 0x8(%r14), %r11
shrq $0x20, %r10
shlq $0x3, %r9
leaq (%r9,%r9,2), %r9
leaq (%r10,%r10,2), %r10
leaq (%r11,%r10,8), %r10
addq $0xc, %r10
xorl %r11d, %r11d
movl -0x4(%r10,%r11), %ebx
xorl %r8d, %ebx
cmpl $0x1, %ebx
jne 0xdf045
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xdf032
incq %rdi
cmpq %rdx, %rdi
jne 0xdefda
incq %rax
cmpq %r15, %rax
jne 0xdef9f
movl 0x4(%r14), %eax
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rbx
je 0xdf0a1
movl $0xc, %ecx
xorl %edx, %edx
movq 0x8(%r14), %rsi
cmpb $0x0, 0x6(%rsi,%rcx)
jne 0xdf08d
orb $-0x80, 0x3(%rsi,%rcx)
movl 0x4(%r14), %eax
incq %rdx
movl %eax, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq $0x18, %rcx
cmpq %rsi, %rdx
jb 0xdf079
movq %r14, %rdi
callq 0xa0a7d
movq 0xa8(%rsp), %rax
movq (%rax), %rax
addq %rax, %rax
movl 0x14(%r14), %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
cmpq %r12, %rax
jae 0xdf0d5
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2370
movq %rax, %rbx
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x20e0
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, 0x28(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, (%rsp)
testl %ebp, %ebp
je 0xdf3f9
movl %ebp, 0x20(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x8(%rsp), %r12
movq %rbx, 0x18(%rsp)
movq 0x28(%r12), %rax
testl $0xfffffffe, (%rax,%rbp,8) # imm = 0xFFFFFFFE
jne 0xdf495
movq %rbp, %rcx
shrq %rcx
cmpb $0x0, (%rbx,%rcx)
jne 0xdf27f
movq %rbp, %rcx
xorq $0x1, %rcx
cmpl $0x0, (%rax,%rcx,8)
jne 0xdf27f
movq $0x0, 0x50(%rsp)
movq %r12, %rdi
movl %ebp, %esi
leaq 0x50(%rsp), %rdx
leaq 0x108(%rsp), %rcx
leaq 0x100(%rsp), %r8
callq 0xde492
cmpl $0x5, %eax
jne 0xdf511
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x50(%rsp), %r13
testq %r13, %r13
je 0xdf1ea
movq 0x60(%rsp), %rax
movq 0x20(%r12), %rcx
xorl %edx, %edx
movl (%rax,%rdx,8), %esi
shrl %esi
movb $0x1, (%rbx,%rsi)
movl (%rcx,%rsi,8), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movzbl 0x4(%rcx,%rsi,8), %esi
addq %rdi, 0x38(%rsp,%rsi,8)
incq %rdx
cmpq %rdx, %r13
jne 0xdf1ba
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
jmp 0xdf1ee
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, %rcx
movq 0x28(%rsp), %rbx
cmovbq (%rsp), %rbx
movq (%rbx), %r14
movq 0x8(%rbx), %r12
cmpq 0x10(%rbx), %r12
jne 0xdf232
leaq (%r12,%r12), %rsi
testq %r12, %r12
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%rbx)
shlq $0x5, %rsi
movq %r14, %rdi
callq 0x2370
movq %rax, %r14
movq %rax, (%rbx)
movq 0x8(%rbx), %r12
leaq 0x1(%r12), %rax
movq %rax, 0x8(%rbx)
shlq $0x5, %r12
movq $0x0, 0x10(%r14,%r12)
movq %r13, (%r14,%r12)
movq %r13, 0x8(%r14,%r12)
shlq $0x3, %r13
movq %r13, %rdi
callq 0x2280
movq %rax, 0x18(%r14,%r12)
movq 0x60(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2160
movq 0x8(%rsp), %r12
movq 0x18(%rsp), %rbx
incq %rbp
cmpq %r15, %rbp
jne 0xdf138
cmpl $0x0, 0x20(%rsp)
je 0xdf3fe
xorl %r13d, %r13d
movq 0x28(%r12), %rax
movl (%rax,%r13,8), %ecx
cmpq $0x2, %rcx
jae 0xdf4b4
movq %r13, %rdx
shrq %rdx
cmpb $0x0, (%rbx,%rdx)
jne 0xdf3eb
cmpl $0x1, %ecx
jne 0xdf4d3
movq %r13, %rcx
xorq $0x1, %rcx
cmpl $0x1, (%rax,%rcx,8)
jne 0xdf4d3
movq $0x0, 0x50(%rsp)
movq %r12, %rdi
movl %r13d, %esi
leaq 0x50(%rsp), %rdx
leaq 0x108(%rsp), %rcx
leaq 0x100(%rsp), %r8
callq 0xde492
cmpl $0x7, %eax
jne 0xdf4f2
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x50(%rsp), %rbp
testq %rbp, %rbp
je 0xdf356
movq 0x60(%rsp), %rax
movq 0x20(%r12), %rcx
xorl %edx, %edx
movl (%rax,%rdx,8), %esi
shrl %esi
movb $0x1, (%rbx,%rsi)
movl (%rcx,%rsi,8), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movzbl 0x4(%rcx,%rsi,8), %esi
addq %rdi, 0x38(%rsp,%rsi,8)
incq %rdx
cmpq %rdx, %rbp
jne 0xdf326
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
jmp 0xdf35a
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, %rcx
movq 0x28(%rsp), %rbx
cmovbq (%rsp), %rbx
movq (%rbx), %r14
movq 0x8(%rbx), %r12
cmpq 0x10(%rbx), %r12
jne 0xdf39e
leaq (%r12,%r12), %rsi
testq %r12, %r12
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%rbx)
shlq $0x5, %rsi
movq %r14, %rdi
callq 0x2370
movq %rax, %r14
movq %rax, (%rbx)
movq 0x8(%rbx), %r12
leaq 0x1(%r12), %rax
movq %rax, 0x8(%rbx)
shlq $0x5, %r12
movq $0x1, 0x10(%r14,%r12)
movq %rbp, (%r14,%r12)
movq %rbp, 0x8(%r14,%r12)
shlq $0x3, %rbp
movq %rbp, %rdi
callq 0x2280
movq %rax, 0x18(%r14,%r12)
movq 0x60(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2160
movq 0x8(%rsp), %r12
movq 0x18(%rsp), %rbx
incq %r13
cmpq %r15, %r13
jne 0xdf299
jmp 0xdf3fe
movq 0x8(%rsp), %r12
movq %rbx, %r13
movq 0x1d8(%rsp), %rbx
movq 0x1d0(%rsp), %r15
movq %r14, %rdi
callq 0x2220
movq 0x180(%rsp), %rdi
callq 0x2220
movq 0x160(%rsp), %rdi
callq 0x2220
movq 0x140(%rsp), %rdi
callq 0x2220
movq 0x120(%rsp), %rdi
callq 0x2220
movq %r13, %rdi
callq 0x2220
movq 0xa0(%rsp), %rdi
callq 0x2220
movq 0x30(%rsp), %rdi
callq 0x2220
movq %r12, %rdi
callq 0xa0494
movq 0x28(%rsp), %rax
movq %rax, (%r15)
movq (%rsp), %rax
movq %rax, (%rbx)
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1586fe(%rip), %rdi    # 0x237b9a
leaq 0x1569ee(%rip), %rsi    # 0x235e91
leaq 0x1586f8(%rip), %rcx    # 0x237ba2
movl $0x5913, %edx           # imm = 0x5913
callq 0x2110
leaq 0x1586df(%rip), %rdi    # 0x237b9a
leaq 0x1569cf(%rip), %rsi    # 0x235e91
leaq 0x1586d9(%rip), %rcx    # 0x237ba2
movl $0x5925, %edx           # imm = 0x5925
callq 0x2110
leaq 0x158773(%rip), %rdi    # 0x237c4d
leaq 0x1569b0(%rip), %rsi    # 0x235e91
leaq 0x1586ba(%rip), %rcx    # 0x237ba2
movl $0x5927, %edx           # imm = 0x5927
callq 0x2110
leaq 0x15877c(%rip), %rdi    # 0x237c75
leaq 0x156991(%rip), %rsi    # 0x235e91
leaq 0x15869b(%rip), %rcx    # 0x237ba2
movl $0x5929, %edx           # imm = 0x5929
callq 0x2110
leaq 0x158726(%rip), %rdi    # 0x237c3e
leaq 0x156972(%rip), %rsi    # 0x235e91
leaq 0x15867c(%rip), %rcx    # 0x237ba2
movl $0x5917, %edx           # imm = 0x5917
callq 0x2110