// File: /workspace/github_cpp_makefile_star2_O2/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, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, %rbx
movq 0x1c0(%rsp), %rbp
movq %rbp, %rdi
callq 0x19c326
callq 0x68f5d
movq %rax, %r15
leaq 0x1b262e(%rip), %rax    # 0x253758
movq 0x270(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x278(%rax), %rax
movq %rax, 0x30(%rsp)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x38(%rsp)
andq $0x0, 0x180(%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0x160(%rsp)
movaps %xmm0, 0x170(%rsp)
andq $0x0, 0x140(%rsp)
movaps %xmm0, 0x150(%rsp)
andq $0x0, 0x120(%rsp)
movaps %xmm0, 0x130(%rsp)
movaps %xmm0, 0x110(%rsp)
movq %rbx, 0xa8(%rsp)
movq (%rbx), %r14
leaq (%r14,%r14), %r13
pushq $0x1
popq %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2120
movq %rax, 0x18(%rsp)
movq %r13, %rdi
movq %r12, %r13
movq %rbp, %r12
movq %rbx, %rsi
callq 0x2120
movq %rax, 0xa0(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2120
movq %rax, 0x28(%rsp)
xorl %ebx, %ebx
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq 0x18(%r12), %rax
cmpq %rax, %r14
jae 0xa1245
movq (%r13), %rax
cmpq %rax, %r14
jae 0xa120a
imulq $0x28, %r14, %rax
addq 0x10(%r13), %rax
jmp 0xa121a
imulq $-0x28, %rax, %rax
movq 0x8(%rsp), %rcx
addq 0x10(%rcx), %rax
addq %rbx, %rax
movl (%rax), %edx
andl %ebp, %edx
movq %r15, %rdi
movl %r14d, %esi
xorl %ecx, %ecx
callq 0x69316
cmpq (%r13), %r14
movb $0x2, %al
sbbb $0x0, %al
movq 0x20(%r15), %rcx
movb %al, 0x4(%rcx,%r14,8)
incq %r14
addq $0x28, %rbx
jmp 0xa11ed
movq 0x30(%rsp), %rcx
negq %rcx
movq %rcx, 0xb8(%rsp)
xorl %edx, %edx
movq %r15, 0x78(%rsp)
movq %r13, 0x10(%rsp)
movq 0x58(%rsp), %rbp
cmpq %rax, %rdx
jae 0xa1730
movq 0x28(%r12), %rcx
movq %rdx, 0x70(%rsp)
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
cmpq $0x2, %rdx
jb 0xa171b
movq 0x10(%r12), %rbx
shrq $0x20, %rcx
imulq $0x30, %rcx, %r14
leaq (%rbx,%r14), %rcx
leaq (%rbx,%r14), %rsi
addq $0x28, %rsi
xorl %r12d, %r12d
cmpq %r12, %rdx
je 0xa12b8
cmpb $0x0, (%rsi)
js 0xa12bb
incq %r12
addq $0x30, %rsi
jmp 0xa12a5
movq %rdx, %r12
imulq $0x30, %r12, %rsi
cmpq %rdx, %r12
movq %rdx, %r8
cmovaq %r12, %r8
leaq (%rcx,%rsi), %rdi
movq %rdi, 0xc8(%rsp)
addq %r14, %rsi
addq %rbx, %rsi
movq %r12, %rdi
cmpq %rdx, %rdi
jae 0xa12f4
cmpl $-0x1, (%rsi)
je 0xa12f1
incq %rdi
addq $0x30, %rsi
jmp 0xa12de
movq %rdi, %r8
cmpq $0x2, %r12
jb 0xa171b
subq %r12, %r8
xorl %eax, %eax
cmpq %rax, %r12
je 0xa1331
testb $0x3f, 0x28(%rcx)
jne 0xa132c
movl 0x4(%rcx), %edx
subl (%rcx), %edx
cmpq %rdx, %rbp
ja 0xa1323
movl 0x10(%rcx), %edx
subl 0xc(%rcx), %edx
cmpq %rdx, %rbp
jbe 0xa132c
incq %rax
addq $0x30, %rcx
jmp 0xa1303
movq %rax, %rsi
jmp 0xa1337
movq %r12, %rax
pushq $-0x1
popq %rsi
imulq $0x30, %rax, %rcx
addq %r14, %rcx
addq %rbx, %rcx
movq %rsi, %rdi
cmpq %r12, %rax
jae 0xa1372
testb $0x3f, 0x28(%rcx)
je 0xa1354
movq %rax, %rdi
jmp 0xa1369
movl 0x4(%rcx), %edx
subl (%rcx), %edx
cmpq %rdx, %rbp
ja 0xa1369
movl 0x10(%rcx), %edx
subl 0xc(%rcx), %edx
cmpq %rdx, %rbp
jbe 0xa134f
incq %rax
addq $0x30, %rcx
jmp 0xa1344
movq 0x70(%rsp), %rdx
movq %rdx, %rax
subq (%r13), %rax
movq %r8, 0xc0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdi, 0xd0(%rsp)
jae 0xa13b2
imulq $0x28, %rdx, %rax
addq 0x10(%r13), %rax
movq %rax, 0x98(%rsp)
movq 0x60(%rsp), %rcx
movq %rdx, %rax
jmp 0xa13cc
imulq $0x28, %rax, %rdx
movq 0x8(%rsp), %rcx
addq 0x10(%rcx), %rdx
movq %rdx, 0x98(%rsp)
movq 0x68(%rsp), %rcx
imulq $0x58, %rax, %rdx
addq (%rcx), %rdx
movq 0x28(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0xa10a1
leaq (%rbx,%r14), %rbp
addq $0x30, %rbp
pushq $0x1
popq %rbx
movq %r12, 0xe0(%rsp)
cmpq %r12, %rbx
jae 0xa16d9
movl -0x1c(%rbp), %ecx
movq (%r13), %rax
movq %rcx, %rdx
subq %rax, %rdx
jae 0xa1415
imulq $0x28, %rcx, %rdx
addq 0x10(%r13), %rdx
jmp 0xa1422
imulq $0x28, %rdx, %rdx
movq 0x8(%rsp), %rsi
addq 0x10(%rsi), %rdx
cmpl $0x0, (%rdx)
js 0xa16cd
movl 0x14(%rbp), %edx
movq %rdx, %rsi
subq %rax, %rsi
jae 0xa1440
imulq $0x28, %rdx, %rsi
addq 0x10(%r13), %rsi
jmp 0xa144d
imulq $0x28, %rsi, %rsi
movq 0x8(%rsp), %rdi
addq 0x10(%rdi), %rsi
cmpl $0x0, (%rsi)
js 0xa16cd
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
cmpq %rax, %rcx
setae %sil
movl 0x38(%rsp,%rsi,4), %ecx
movl -0x28(%rbp), %esi
xorl %r8d, %r8d
cmpq %rsi, %rax
setbe %r8b
cmpl 0x38(%rsp,%r8,4), %ecx
movq %rbx, 0x20(%rsp)
je 0xa149e
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 0xa14a9
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0xa1620
leaq -0x1(%rbx), %rax
movq 0xd8(%rsp), %rdx
cmpq %rdx, %rax
setb %cl
movq 0xd0(%rsp), %rsi
cmpq %rsi, %rax
seta %al
cmpq %rdx, %rbx
setb %dl
orb %cl, %dl
orb %al, %dl
cmpq %rsi, %rbx
seta %al
orb %dl, %al
je 0xa14e7
xorl %eax, %eax
xorl %r13d, %r13d
jmp 0xa1580
movq %rdi, %r14
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, %r13
subq %rsi, %r13
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 0x14201a(%rip), %xmm0   # 0x1e3548
movq 0xc8(%rsp), %r8
movq 0xc0(%rsp), %r9
callq 0x9ebe6
testq %rax, %rax
je 0xa1552
xorl %eax, %eax
xorl %r13d, %r13d
movq %r14, %rdi
jmp 0xa1580
testb $0x3f, -0x8(%rbp)
movq %r14, %rdi
je 0xa156b
testb $0x3f, 0x28(%rbp)
je 0xa156b
cmpq 0x30(%rsp), %r13
setle %al
jmp 0xa1580
cmpq 0xb8(%rsp), %r13
setge %cl
cmpq 0x30(%rsp), %r13
setle %al
andb %cl, %al
movzbl %al, %r15d
andq $0x0, 0xb0(%rsp)
movq %rdi, %r14
movq %rbp, %rsi
movq 0xa8(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x60(%rsp), %r9
leaq 0xb0(%rsp), %rax
pushq %rax
pushq $0x4c4b40               # imm = 0x4C4B40
pushq 0x38(%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 0xb0(%rsp)
callq 0xa0b9b
addq $0x50, %rsp
cmpq $-0x1, %rax
je 0xa161d
leaq 0x1b2155(%rip), %rcx    # 0x253758
cmpq 0x278(%rcx), %rax
jg 0xa161d
cmpq $0x0, 0xb0(%rsp)
cmoveq %rax, %r13
pushq $0x1
popq %r15
movq %r14, %rdi
movq 0x1c8(%rsp), %rax
cmpq %rax, %r13
cmovleq %rax, %r13
testq %r15, %r15
setne %al
cmpq 0x30(%rsp), %r13
setle %cl
andb %al, %cl
movzbl %cl, %r14d
movq %rbp, %rsi
xorl %edx, %edx
movq %r14, %rcx
movq %rdi, %r12
movq %r13, %r8
leaq 0xf8(%rsp), %rbx
movq %rbx, %r9
callq 0xa1c6e
movq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0x6c45d
movups 0xf8(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x108(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
movq %r13, %r8
movq %rbx, %r9
callq 0xa1c6e
movq %r15, %rdi
callq 0x6c45d
movups 0xf8(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x108(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rsp), %r13
movq 0x20(%rsp), %rbx
movq 0xe0(%rsp), %r12
incq %rbx
addq $0x30, %rbp
jmp 0xa13f3
movq 0x70(%rsp), %rcx
movq %rcx, %rax
subq (%r13), %rax
jae 0xa16f2
imulq $0x58, %rcx, %rdx
movq 0x60(%rsp), %rax
jmp 0xa16fb
imulq $0x58, %rax, %rdx
movq 0x68(%rsp), %rax
addq (%rax), %rdx
movq 0x1c0(%rsp), %rbx
movq 0x58(%rsp), %rbp
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0xa10a1
movq 0x18(%rbx), %rax
movq 0x70(%rsp), %rdx
incq %rdx
movq 0x1c0(%rsp), %r12
jmp 0xa1266
movq %r15, %rdi
callq 0x694eb
movq %r15, %rdi
callq 0x69638
movl 0x14(%r15), %eax
addl %eax, %eax
cltq
xorl %ebx, %ebx
pushq $0x1
popq %rbp
movq %rax, 0x8(%rsp)
cmpq %rax, %rbx
je 0xa17d3
movq 0x20(%r15), %rax
movq %rbx, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0xa1778
movq 0x28(%r15), %rax
movq (%rax,%rbx,8), %rax
movl %eax, %ecx
cmpq $0x2, %rcx
jae 0xa1782
incq %rbx
movq 0x8(%rsp), %rax
jmp 0xa1752
movq 0x8(%r15), %rdx
shrq $0x20, %rax
imulq $0x18, %rcx, %r14
imulq $0x18, %rax, %rax
leaq (%rdx,%rax), %r12
addq $0xc, %r12
xorl %r13d, %r13d
cmpq %r13, %r14
je 0xa1778
movl (%r12,%r13), %eax
testl %eax, %eax
js 0xa17cd
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, (%r12,%r13)
movl -0x8(%r12,%r13), %edx
movl -0x4(%r12,%r13), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %r15, %rdi
movl %ebp, %ecx
callq 0x6db50
addq $0x18, %r13
jmp 0xa179d
pushq $0xc
popq %rax
xorl %ecx, %ecx
movq 0x18(%rsp), %rbx
movl 0x4(%r15), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rcx
jae 0xa1805
movq 0x8(%r15), %rdx
cmpb $0x0, 0x6(%rdx,%rax)
jne 0xa17fc
orb $-0x80, 0x3(%rdx,%rax)
incq %rcx
addq $0x18, %rax
jmp 0xa17dd
movq %r15, %rdi
callq 0x694eb
movq 0xa8(%rsp), %rax
movq (%rax), %rax
addq %rax, %rax
movl 0x14(%r15), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
cmpq %r14, %rax
jae 0xa1839
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2370
movq %rax, %rbx
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x20e0
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
pushq $0x1
popq %r14
pushq $0x20
popq %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x2120
movq %rax, 0x20(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2120
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
movq %rbx, 0x18(%rsp)
movq 0x8(%rsp), %rsi
cmpq %rsi, %rbp
je 0xa19e0
movq 0x28(%r15), %rax
testl $0xfffffffe, (%rax,%rbp,8) # imm = 0xFFFFFFFE
jne 0xa1bd3
movq %rbp, %rcx
shrq %rcx
cmpb $0x0, (%rbx,%rcx)
jne 0xa19d8
movq %rbp, %rcx
xorq $0x1, %rcx
cmpl $0x0, (%rax,%rcx,8)
jne 0xa19d8
andq $0x0, 0x80(%rsp)
movq %r15, %rdi
movl %ebp, %esi
leaq 0x80(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
leaq 0xe8(%rsp), %r8
callq 0xa0d1f
cmpl $0x5, %eax
jne 0xa1c4f
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x80(%rsp), %r14
movq 0x90(%rsp), %r13
xorl %eax, %eax
cmpq %rax, %r14
je 0xa1945
movl (%r13,%rax,8), %ecx
shrl %ecx
movb $0x1, (%rbx,%rcx)
movq 0x20(%r15), %rdx
movl (%rdx,%rcx,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movzbl 0x4(%rdx,%rcx,8), %ecx
addq %rsi, 0x38(%rsp,%rcx,8)
incq %rax
jmp 0xa1919
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
movq 0x20(%rsp), %rbx
cmovbq 0x10(%rsp), %rbx
movq (%rbx), %r12
movq 0x8(%rbx), %r15
cmpq 0x10(%rbx), %r15
jne 0xa198f
leaq (%r15,%r15), %rsi
testq %r15, %r15
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x10(%rbx)
shlq $0x5, %rsi
movq %r12, %rdi
callq 0x2370
movq %rax, %r12
movq %rax, (%rbx)
movq 0x8(%rbx), %r15
leaq 0x1(%r15), %rax
movq %rax, 0x8(%rbx)
shlq $0x5, %r15
andq $0x0, 0x10(%r12,%r15)
movq %r14, (%r12,%r15)
movq %r14, 0x8(%r12,%r15)
shlq $0x3, %r14
movq %r14, %rdi
callq 0x2280
movq %rax, 0x18(%r12,%r15)
movq %rax, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2160
movq 0x78(%rsp), %r15
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %rsi
incq %rbp
jmp 0xa1890
xorl %ebp, %ebp
cmpq %rsi, %rbp
je 0xa1b3e
movq 0x28(%r15), %rax
movl (%rax,%rbp,8), %ecx
cmpq $0x2, %rcx
jae 0xa1bf2
movq %rbp, %rdx
shrq %rdx
cmpb $0x0, (%rbx,%rdx)
jne 0xa1b36
cmpl $0x1, %ecx
jne 0xa1c11
movq %rbp, %rcx
xorq $0x1, %rcx
cmpl $0x1, (%rax,%rcx,8)
jne 0xa1c11
andq $0x0, 0x80(%rsp)
movq %r15, %rdi
movl %ebp, %esi
leaq 0x80(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
leaq 0xe8(%rsp), %r8
callq 0xa0d1f
cmpl $0x7, %eax
jne 0xa1c30
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x80(%rsp), %r14
movq 0x90(%rsp), %r13
xorl %eax, %eax
cmpq %rax, %r14
je 0xa1aa0
movl (%r13,%rax,8), %ecx
shrl %ecx
movb $0x1, (%rbx,%rcx)
movq 0x20(%r15), %rdx
movl (%rdx,%rcx,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movzbl 0x4(%rdx,%rcx,8), %ecx
addq %rsi, 0x38(%rsp,%rcx,8)
incq %rax
jmp 0xa1a74
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
movq 0x20(%rsp), %rbx
cmovbq 0x10(%rsp), %rbx
movq (%rbx), %r12
movq 0x8(%rbx), %r15
cmpq 0x10(%rbx), %r15
jne 0xa1aea
leaq (%r15,%r15), %rsi
testq %r15, %r15
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x10(%rbx)
shlq $0x5, %rsi
movq %r12, %rdi
callq 0x2370
movq %rax, %r12
movq %rax, (%rbx)
movq 0x8(%rbx), %r15
leaq 0x1(%r15), %rax
movq %rax, 0x8(%rbx)
shlq $0x5, %r15
movq $0x1, 0x10(%r12,%r15)
movq %r14, (%r12,%r15)
movq %r14, 0x8(%r12,%r15)
shlq $0x3, %r14
movq %r14, %rdi
callq 0x2280
movq %rax, 0x18(%r12,%r15)
movq %rax, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2160
movq 0x78(%rsp), %r15
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %rsi
incq %rbp
jmp 0xa19e2
movq %r13, %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 %rbx, %rdi
callq 0x2220
movq 0xa0(%rsp), %rdi
callq 0x2220
movq 0x28(%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x68f68
movq 0x1d0(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
movq 0x1d8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x147ec0(%rip), %rdi    # 0x1e9a9a
leaq 0x1461b0(%rip), %rsi    # 0x1e7d91
leaq 0x147eba(%rip), %rcx    # 0x1e9aa2
movl $0x5913, %edx           # imm = 0x5913
callq 0x2110
leaq 0x147ea1(%rip), %rdi    # 0x1e9a9a
leaq 0x146191(%rip), %rsi    # 0x1e7d91
leaq 0x147e9b(%rip), %rcx    # 0x1e9aa2
movl $0x5925, %edx           # imm = 0x5925
callq 0x2110
leaq 0x147f35(%rip), %rdi    # 0x1e9b4d
leaq 0x146172(%rip), %rsi    # 0x1e7d91
leaq 0x147e7c(%rip), %rcx    # 0x1e9aa2
movl $0x5927, %edx           # imm = 0x5927
callq 0x2110
leaq 0x147f3e(%rip), %rdi    # 0x1e9b75
leaq 0x146153(%rip), %rsi    # 0x1e7d91
leaq 0x147e5d(%rip), %rcx    # 0x1e9aa2
movl $0x5929, %edx           # imm = 0x5929
callq 0x2110
leaq 0x147ee8(%rip), %rdi    # 0x1e9b3e
leaq 0x146134(%rip), %rsi    # 0x1e7d91
leaq 0x147e3e(%rip), %rcx    # 0x1e9aa2
movl $0x5917, %edx           # imm = 0x5917
callq 0x2110