// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: ma_ug_gen_phase(asg_t*, unsigned int, double)
ma_ug_t *ma_ug_gen_phase(asg_t *g, uint32_t min_occ, double cutoff)
{
    // fprintf(stderr, "\n-0-[M::%s] min_occ::%u, cutoff::%f\n", __func__, min_occ, cutoff);
    asg_cleanup(g);
	int32_t *mark; 
	uint32_t i, v, n_vtx = g->n_seq * 2, fn, mn, fn0, mn0, fn1, mn1, n1, cn, k, st, pt, ct, sz, ez;
    uint64_t z;
	///is a queue
	kdq_t(uint64_t) *q;
    asg64_v uidx; kv_init(uidx); 
    
	ma_ug_t *ug;

	ug = (ma_ug_t*)calloc(1, sizeof(ma_ug_t));
	ug->g = asg_init();
    ///each node has two directions
	mark = (int32_t*)calloc(n_vtx, 4);

	q = kdq_init(uint64_t);
	for (v = 0; v < n_vtx; ++v) {
		uint32_t w, x, l, start, end, len;
		ma_utg_t *p;
        if (g->seq[v>>1].del || mark[v]) continue;
        if (arc_cnt(g, v) == 0 && arc_cnt(g, (v^1)) != 0) continue;
		mark[v] = 1;
		q->count = 0, start = v, end = v^1, len = 0; fn = mn = 0;
		// forward
		w = v; 
		while (1) {
			/**
			 * w----->x
			 * w<-----x
			 * that means the only suffix of w is x, and the only prefix of x is w
			 **/
			if (arc_cnt(g, w) != 1) break;
			x = arc_first(g, w).v; // w->x
			if (arc_cnt(g, x^1) != 1) break;
			/**
			 * another direction of w would be marked as used (since w has been used)
			**/
			mark[x] = mark[w^1] = 1;
			///l is the edge length, instead of overlap length
            ///note: edge length is different with overlap length
			l = asg_arc_len(arc_first(g, w));
			kdq_push(uint64_t, q, (uint64_t)w<<32 | l);
            if(R_INF.trio_flag[w>>1] == FATHER) fn++;
            if(R_INF.trio_flag[w>>1] == MOTHER) mn++;
			end = x^1, len += l;
			w = x;
			if (x == v) break;
		}
		if (start != (end^1) || kdq_size(q) == 0) { // linear unitig
			///length of seq, instead of edge
			l = g->seq[end>>1].len;
			kdq_push(uint64_t, q, (uint64_t)(end^1)<<32 | l);
            if(R_INF.trio_flag[end>>1] == FATHER) fn++;
            if(R_INF.trio_flag[end>>1] == MOTHER) mn++;
			len += l;
		} else { // circular unitig
			start = end = UINT32_MAX;
			goto add_unitig; // then it is not necessary to do the backward
		}
		// backward
		x = v;
		while (1) { // similar to forward but not the same
			if (arc_cnt(g, x^1) != 1) break;
			w = arc_first(g, x^1).v ^ 1; // w->x
			if (arc_cnt(g, w) != 1) break;
			mark[x] = mark[w^1] = 1;
			l = asg_arc_len(arc_first(g, w));
			///w is the seq id + direction, l is the length of edge
			///push element to the front of a queue
			kdq_unshift(uint64_t, q, (uint64_t)w<<32 | l);
            if(R_INF.trio_flag[w>>1] == FATHER) fn++;
            if(R_INF.trio_flag[w>>1] == MOTHER) mn++;
            // fprintf(stderr, "uId: %u, >%.*s (%u)\n", 
            // ug->u.n, (int)Get_NAME_LENGTH((R_INF), w>>1), Get_NAME((R_INF), w>>1), w>>1);

			start = w, len += l;
			x = w;
		}
add_unitig:
		if (start != UINT32_MAX) mark[start] = mark[end] = 1;
        // fprintf(stderr, "\n-0-[M::%s] fn::%u, mn::%u\n", __func__, fn, mn);
        cn = MIN(fn, mn);
        // if((cn > min_occ) && (cn > ((fn+mn)*cutoff)))
        if((cn <= ((fn+mn)*cutoff)) || (cn <= min_occ)) {
            kv_pushp(ma_utg_t, ug->u, &p);
            p->s = 0, p->start = start, p->end = end, p->len = len, p->n = kdq_size(q), p->circ = (start == UINT32_MAX);
            p->m = p->n;
            kv_roundup32(p->m);
            p->a = (uint64_t*)malloc(8 * p->m);
            //all elements are saved here
            for (i = 0; i < kdq_size(q); ++i) p->a[i] = kdq_at(q, i);
        } else if(kdq_size(q)) {
            ct = R_INF.trio_flag[kdq_at(q, 0)>>33]; 
            if((ct != FATHER) && (ct != MOTHER)) ct = AMBIGU; 
            pt = ct;
            fn0 = fn; mn0 = mn; uidx.n = fn = mn = 0; 
            if(ct == FATHER) fn++; if(ct == MOTHER) mn++;
            for (k = 1, l = 0; k <= kdq_size(q); k++) {
                st = 0; ct = AMBIGU;
                if(k == kdq_size(q)) {
                    st = 1;
                } else {
                    ct = R_INF.trio_flag[kdq_at(q, k)>>33];
                    if((ct != FATHER) && (ct != MOTHER)) ct = AMBIGU; 
                    if((ct != AMBIGU) && (pt != AMBIGU) && (ct != pt)) {
                        st = 1;
                    }
                }
                if(st) {
                    // fprintf(stderr, "-1-[M::%s] l::%u, k::%u, kdq_size(q)::%u, fn::%u, mn::%u, ct::%u, pt::%u\n", 
                    // __func__, l, k, (uint32_t)kdq_size(q), fn, mn, ct, pt);
                    if(k < kdq_size(q)) {
                        assert(fn || mn); assert((!fn) || (!mn));
                    }
                    z = l<<1; z |= (((uint64_t)MAX(fn, mn))<<32);
                    if(mn) z |= 1;
                    kv_push(uint64_t, uidx, z);
                    fn = mn = 0; l = k;
                }
                if(ct != AMBIGU) pt = ct;
                if(ct == FATHER) fn++; if(ct == MOTHER) mn++;
            }


            fn = mn = 0; fn1 = mn1 = n1 = 0;
            if(uidx.a[0]&1) mn += uidx.a[0]>>32;
            else fn += uidx.a[0]>>32;
            for (k = 1, l = 0; k <= uidx.n; k++) {
                st = 0;
                if(k == uidx.n) {
                    st = 1;
                } else {
                    if(uidx.a[k]&1) mn += uidx.a[k]>>32;
                    else fn += uidx.a[k]>>32;
                    cn = MIN(fn, mn);
                    if((cn > min_occ) && (cn > ((fn+mn)*cutoff))) st = 1;
                    // fprintf(stderr, "-2-[M::%s] fn::%u, mn::%u, cn::%u, ((fn+mn)*cutoff)::%u, st::%u\n", 
                    // __func__, fn, mn, cn, (uint32_t)(((fn+mn)*cutoff)), st);
                }
                if(st) {
                    // fprintf(stderr, "-3-[M::%s] fn::%u, mn::%u\n", __func__, fn, mn);
                    sz = ((uint32_t)uidx.a[l])>>1;
                    ez = ((k<uidx.n)?(((uint32_t)uidx.a[k])>>1):(kdq_size(q)));
                    assert(ez > sz); n1 += ez - sz;
                    kv_pushp(ma_utg_t, ug->u, &p);
                    if ((start == UINT32_MAX) && (sz == 0) && (ez == kdq_size(q))) {///circle
                        p->s = 0, p->start = start, p->end = end, p->len = len, p->n = kdq_size(q), p->circ = (start == UINT32_MAX);
                        p->m = p->n;
                        kv_roundup32(p->m);
                        p->a = (uint64_t*)malloc(8 * p->m);
                        //all elements are saved here
                        for (i = 0; i < kdq_size(q); ++i) {
                            p->a[i] = kdq_at(q, i);
                            ct = R_INF.trio_flag[p->a[i]>>33];
                            if((ct != FATHER) && (ct != MOTHER)) ct = AMBIGU; 
                            if(ct == FATHER) fn1++; if(ct == MOTHER) mn1++;
                        }
                    } else {
                        p->s = 0; p->len = 0; p->circ = 0;
                        p->start = kdq_at(q, sz)>>32;
                        p->end = (kdq_at(q, (ez-1))>>32)^1;
                        p->m = p->n = ez - sz; kv_roundup32(p->m);
                        p->a = (uint64_t*)malloc(8 * p->m);

                        for (i = sz, z = 0; i+1 < ez; i++, z++) {
                            p->a[z] = kdq_at(q, i); p->len += (uint32_t)p->a[z];
                            ct = R_INF.trio_flag[p->a[z]>>33];
                            if((ct != FATHER) && (ct != MOTHER)) ct = AMBIGU; 
                            if(ct == FATHER) fn1++; if(ct == MOTHER) mn1++;
                        }
                        p->a[z] = kdq_at(q, i); p->a[z] >>= 32; p->a[z] <<= 32; 
                        p->a[z] |= g->seq[p->a[z]>>33].len; p->len += (uint32_t)p->a[z];
                        ct = R_INF.trio_flag[p->a[z]>>33];
                        if((ct != FATHER) && (ct != MOTHER)) ct = AMBIGU; 
                        if(ct == FATHER) fn1++; if(ct == MOTHER) mn1++;
                    }
                    fn = mn = 0; l = k;
                    if(k < uidx.n) {
                        if(uidx.a[k]&1) mn += uidx.a[k]>>32;
                        else fn += uidx.a[k]>>32;
                    }
                }
            }
            assert(n1 == kdq_size(q));
            assert(fn1 == fn0); assert(mn1 == mn0);
        }
	}
	kdq_destroy(uint64_t, q); kv_destroy(uidx); 

	// add arcs between unitigs; reusing mark for a different purpose
	//ug saves all unitigs
	for (v = 0; v < n_vtx; ++v) mark[v] = -1;

    //mark all start nodes and end nodes of all unitigs
	for (i = 0; i < ug->u.n; ++i) {
		if (ug->u.a[i].circ) continue;
		mark[ug->u.a[i].start] = i<<1 | 0;
		mark[ug->u.a[i].end] = i<<1 | 1;
	}

	//scan all edges
	for (i = 0; i < g->n_arc; ++i) {
		asg_arc_t *p = &g->arc[i];
		if (p->del) continue;
		///to connect two unitigs, we need to connect the end of unitig x to the start of unitig y
		///so we need to ^1 to get the reverse direction of (x's end)?
        ///>=0 means this node is a start/end node of an unitig
        ///means this node is a intersaction node
		if (mark[p->ul>>32^1] >= 0 && mark[p->v] >= 0) {
			asg_arc_t *q;
			uint32_t u = mark[p->ul>>32^1]^1;
			int l = ug->u.a[u>>1].len - p->ol;
			if (l < 0) l = 1;
			q = asg_arc_pushp(ug->g);
			q->ol = p->ol, q->del = 0;
			q->ul = (uint64_t)u<<32 | l;
			q->v = mark[p->v]; q->ou = 0;
            q->el = p->el;
		}
	}
	for (i = 0; i < ug->u.n; ++i)
		asg_seq_set(ug->g, i, ug->u.a[i].len, 0);
	asg_cleanup(ug->g);
	free(mark);
	return ug;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %xmm0, 0xa8(%rsp)
movl %esi, 0x7c(%rsp)
movq %rdi, %r13
movabsq $0x3ffffffffffffff, %r14 # imm = 0x3FFFFFFFFFFFFFF
callq 0x694eb
movl 0x14(%r13), %ebx
addl %ebx, %ebx
pushq $0x1
popq %rdi
pushq $0x38
popq %rsi
callq 0x2120
movq %rax, %rbp
callq 0x68f5d
movq %rax, 0x18(%rbp)
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x2120
movq %rax, %r12
callq 0x77275
movq %r14, %r9
movq %rbx, %rdx
movq %rax, %rdi
leaq 0x1dcdfd(%rip), %r11    # 0x254230
xorl %esi, %esi
movq $0x0, 0x48(%rsp)
movq $0x0, 0xa0(%rsp)
movq %rbp, 0x40(%rsp)
movq %r12, 0x68(%rsp)
movq %r13, 0x88(%rsp)
movq %rbx, 0x50(%rsp)
movq %rax, 0x10(%rsp)
cmpq %rdx, %rsi
je 0x77f96
movq 0x20(%r13), %rax
movl %esi, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x77484
cmpl $0x0, (%r12,%rsi,4)
je 0x77489
incq %rsi
jmp 0x77466
movq 0x28(%r13), %rcx
movl %esi, %eax
xorl $0x1, %eax
cmpl $0x0, (%rcx,%rsi,8)
je 0x77741
andq $0x0, 0x8(%rdi)
movl $0x1, (%r12,%rsi,4)
pxor %xmm0, %xmm0
movl $0x0, 0x8(%rsp)
movq %rsi, 0x38(%rsp)
movl %esi, %ebp
movq 0x28(%r13), %rdx
movl %ebp, %r14d
movq (%rdx,%r14,8), %rsi
cmpl $0x1, %esi
jne 0x77589
movq 0x8(%r13), %rcx
shrq $0x20, %rsi
imulq $0x18, %rsi, %rsi
movl 0x8(%rcx,%rsi), %ebp
movq %rbp, %rbx
xorq $0x1, %rbx
cmpl $0x1, (%rdx,%rbx,8)
jne 0x77589
movl %r14d, %eax
pushq $0x1
popq %rdx
xorl %edx, %eax
movl %edx, (%r12,%rax,4)
movl %edx, (%r12,%rbp,4)
movq (%rcx,%rsi), %r15
movl %r15d, %eax
movq %r14, %rsi
shlq $0x20, %rsi
orq %rax, %rsi
movq 0x10(%rsp), %rdi
movdqa %xmm0, 0x20(%rsp)
callq 0x772b6
leaq 0x1dcd07(%rip), %r11    # 0x254230
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
movq 0x28(%r11), %rax
shrl %r14d
movzbl (%rax,%r14), %eax
movd %eax, %xmm0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pcmpeqb 0x170671(%rip), %xmm0   # 0x1e7bc0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
punpcklwd %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3]
pand 0x16b671(%rip), %xmm0   # 0x1e2bd0
movdqa 0x20(%rsp), %xmm1
paddd %xmm0, %xmm1
movdqa %xmm1, 0x20(%rsp)
movdqa 0x20(%rsp), %xmm0
addl %r15d, 0x8(%rsp)
movl %ebx, %eax
cmpq %rbp, 0x38(%rsp)
jne 0x774bc
jmp 0x7758b
movl %eax, %ebx
movl %ebx, %esi
xorl $0x1, %esi
cmpq %rsi, 0x38(%rsp)
movq 0x10(%rsp), %rdi
movq 0x40(%rsp), %rbp
jne 0x775bd
movb $0x1, %al
movl %eax, 0x1c(%rsp)
cmpq $0x0, 0x8(%rdi)
je 0x775bd
pushq $-0x1
popq %rbx
movl %ebx, %ecx
movq 0x50(%rsp), %rdx
jmp 0x7773a
movq 0x20(%r13), %rax
movq %rbx, 0x80(%rsp)
movl %ebx, %r14d
shrl %r14d
movl (%rax,%r14,8), %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
shlq $0x20, %rsi
orq %rbx, %rsi
movdqa %xmm0, 0x20(%rsp)
callq 0x772b6
leaq 0x1dcc3e(%rip), %r11    # 0x254230
movq 0x28(%r11), %rax
movzbl (%rax,%r14), %eax
movd %eax, %xmm0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pcmpeqb 0x1705b5(%rip), %xmm0   # 0x1e7bc0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
punpcklwd %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3]
pand 0x16b5b5(%rip), %xmm0   # 0x1e2bd0
movdqa 0x20(%rsp), %xmm1
paddd %xmm0, %xmm1
movdqa %xmm1, 0x20(%rsp)
movdqa 0x20(%rsp), %xmm0
addl %ebx, 0x8(%rsp)
movq 0x38(%rsp), %rax
movl %eax, %ebx
movq 0x28(%r13), %rdx
movl %ebx, %eax
xorl $0x1, %eax
movq (%rdx,%rax,8), %rsi
movl %ebx, %eax
cmpl $0x1, %esi
jne 0x77701
movq 0x8(%r13), %rcx
shrq $0x20, %rsi
imulq $0x18, %rsi, %rsi
movl 0x8(%rcx,%rsi), %r15d
movq %r15, %r14
xorq $0x1, %r14
movq (%rdx,%r14,8), %rdx
cmpl $0x1, %edx
jne 0x77701
pushq $0x1
popq %rsi
movl %esi, (%r12,%r15,4)
movl %esi, (%r12,%rax,4)
shrq $0x20, %rdx
imulq $0x18, %rdx, %rax
movq (%rcx,%rax), %rbx
movl %ebx, %eax
movq %r14, %rsi
shlq $0x20, %rsi
orq %rax, %rsi
movq 0x10(%rsp), %rdi
movdqa %xmm0, 0x20(%rsp)
callq 0x77318
leaq 0x1dcb7d(%rip), %r11    # 0x254230
movq 0x28(%r11), %rax
shrl %r15d
movzbl (%rax,%r15), %eax
movd %eax, %xmm0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pcmpeqb 0x1704f1(%rip), %xmm0   # 0x1e7bc0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
punpcklwd %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3]
pand 0x16b4f1(%rip), %xmm0   # 0x1e2bd0
movdqa 0x20(%rsp), %xmm1
paddd %xmm0, %xmm1
movdqa %xmm1, 0x20(%rsp)
movdqa 0x20(%rsp), %xmm0
addl %ebx, 0x8(%rsp)
movl %r14d, %ebx
jmp 0x7763c
cmpl $-0x1, %ebx
movq 0x10(%rsp), %rdi
je 0x77757
movq 0x80(%rsp), %rsi
movl %esi, %ecx
pushq $0x1
popq %rdx
movl %edx, (%r12,%rcx,4)
movq %rsi, %rcx
movl %edx, (%r12,%rax,4)
movl $0x0, 0x1c(%rsp)
movq 0x50(%rsp), %rdx
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
movq 0x38(%rsp), %rsi
jmp 0x7777c
movl %eax, %edx
cmpl $0x0, (%rcx,%rdx,8)
je 0x7749c
movq 0x50(%rsp), %rdx
jmp 0x77484
movb $0x1, %al
movl %eax, 0x1c(%rsp)
pushq $-0x1
popq %rbx
movq 0x50(%rsp), %rdx
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
movq 0x38(%rsp), %rsi
movq 0x80(%rsp), %rcx
movd %xmm0, %r8d
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %r10d
cmpl %r8d, %r10d
movl %r8d, %eax
cmovbl %r10d, %eax
cmpl 0x7c(%rsp), %eax
jbe 0x779a6
cvtsi2sd %rax, %xmm0
leal (%r8,%r10), %eax
cvtsi2sd %rax, %xmm1
mulsd 0xa8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x779a6
movq %r8, 0xc0(%rsp)
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x77484
movq %rax, 0x58(%rsp)
movq %rcx, 0x80(%rsp)
movq 0x28(%r11), %rax
movq 0x18(%rdi), %rcx
movq (%rdi), %rdx
andq %r9, %rdx
andq 0x10(%rdi), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %eax
leal -0x3(%rax), %ecx
xorl %edx, %edx
cmpb $-0x2, %cl
movl $0x0, %ecx
movq %rcx, 0x70(%rsp)
cmovbl %edx, %eax
movzbl %al, %ecx
xorl %r15d, %r15d
cmpb $0x1, %cl
sete %r15b
xorl %eax, %eax
cmpb $0x2, %cl
sete %al
pushq $0x1
popq %rbp
xorl %ebx, %ebx
movq 0x48(%rsp), %rdx
movq 0xa0(%rsp), %r12
movq %r10, 0xb8(%rsp)
movl %ecx, %r10d
movl %ebp, %ecx
movq 0x58(%rsp), %r8
cmpq %rcx, %r8
movq %rdx, 0x48(%rsp)
jb 0x77aaf
xorl %r14d, %r14d
cmpq %rcx, %r8
je 0x778b8
movq 0x28(%r11), %rdx
movq 0x18(%rdi), %rsi
movq (%rdi), %r8
andq %r9, %r8
addq %rcx, %r8
andq 0x10(%rdi), %r8
movq (%rsi,%r8,8), %rsi
shrq $0x21, %rsi
movzbl (%rdx,%rsi), %edx
leal -0x3(%rdx), %esi
cmpb $-0x2, %sil
movl $0x0, %esi
cmovbl %esi, %edx
movzbl %dl, %r14d
testb %r14b, %r14b
je 0x7799f
testl %r10d, %r10d
movq 0x48(%rsp), %rdx
je 0x7797a
cmpl %r14d, %r10d
je 0x7797a
cmpq %rcx, 0x58(%rsp)
jbe 0x778d7
movl %r15d, %ecx
orl %eax, %ecx
je 0x78160
testl %r15d, %r15d
je 0x778d7
testl %eax, %eax
jne 0x78157
cmpl %eax, %r15d
cmovbel %eax, %r15d
xorl %r13d, %r13d
testl %eax, %eax
setne %al
cmpq %r12, 0x70(%rsp)
jne 0x77942
movb %al, 0x58(%rsp)
movq %r12, %rax
addq %r12, %r12
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r12
leaq (,%r12,8), %rsi
movq %rdx, %rdi
movq %rbx, 0x20(%rsp)
movl %ebp, %ebx
movl %r10d, %ebp
callq 0x2370
movl %ebp, %r10d
movl %ebx, %ebp
movq 0x20(%rsp), %rbx
leaq 0x1dc904(%rip), %r11    # 0x254230
movq 0x10(%rsp), %rdi
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
movq %rax, %rdx
movb 0x58(%rsp), %al
addl %ebx, %ebx
shlq $0x20, %r15
orq %rbx, %r15
movb %al, %r13b
orq %r15, %r13
movq 0x70(%rsp), %rax
movq %r13, (%rdx,%rax,8)
incq %rax
movq %rax, 0x70(%rsp)
movq 0x8(%rdi), %rax
movq %rax, 0x58(%rsp)
xorl %eax, %eax
movl %ebp, %ebx
xorl %r15d, %r15d
movq 0x88(%rsp), %r13
testl %r14d, %r14d
cmovnel %r14d, %r10d
xorl %ecx, %ecx
cmpl $0x1, %r14d
sete %cl
addl %ecx, %r15d
xorl %ecx, %ecx
cmpl $0x2, %r14d
sete %cl
addl %ecx, %eax
incl %ebp
jmp 0x77847
movq 0x48(%rsp), %rdx
jmp 0x7797a
movq (%rbp), %r14
movq 0x10(%rbp), %r12
cmpq 0x8(%rbp), %r14
jne 0x779e4
leaq (%r14,%r14), %rax
testq %r14, %r14
movq %rcx, %r15
pushq $0x2
popq %rcx
cmoveq %rcx, %rax
movq %rax, 0x8(%rbp)
imulq $0x28, %rax, %rsi
movq %r12, %rdi
callq 0x2370
movq %r15, %rcx
movq 0x10(%rsp), %rdi
movq %rax, %r12
movq %rax, 0x10(%rbp)
leaq 0x1(%r14), %rax
movq %rax, (%rbp)
imulq $0x28, %r14, %r14
andq $0x0, 0x20(%r12,%r14)
movl %ebx, 0x4(%r12,%r14)
movl %ecx, 0x8(%r12,%r14)
movl 0x8(%rsp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x8(%rdi), %rbx
movl %ebx, 0x10(%r12,%r14)
movzbl 0x1c(%rsp), %eax
shll $0x1f, %eax
orl %ecx, %eax
movl %eax, (%r12,%r14)
leal -0x1(%rbx), %eax
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
leal 0x1(%rcx), %eax
movl %eax, 0xc(%r12,%r14)
leal 0x8(,%rcx,8), %edi
callq 0x2280
movq 0x10(%rsp), %rdi
movq %rax, 0x18(%r12,%r14)
xorl %ecx, %ecx
movq 0x68(%rsp), %r12
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
leaq 0x1dc7b4(%rip), %r11    # 0x254230
movl %ecx, %ecx
cmpq %rcx, %rbx
jbe 0x77aa0
movq (%rdi), %rdx
andq %r9, %rdx
addq %rcx, %rdx
andq 0x10(%rdi), %rdx
movq 0x18(%rdi), %rsi
movq (%rsi,%rdx,8), %rdx
movq %rdx, (%rax,%rcx,8)
incl %ecx
jmp 0x77a7c
movq 0x50(%rsp), %rdx
movq 0x38(%rsp), %rsi
jmp 0x77484
movq %r12, 0xa0(%rsp)
movq (%rdx), %rax
movq %rax, %rcx
shrq $0x20, %rcx
xorl %edx, %edx
testb $0x1, %al
movl %ecx, %r10d
cmovel %edx, %r10d
movl $0x0, 0xc(%rsp)
cmovnel %edx, %ecx
orl $0x80000000, 0x8(%rsp)  # imm = 0x80000000
leal -0x1(%r8), %eax
movl %eax, %edx
shrl %edx
orl %eax, %edx
movl %edx, %eax
shrl $0x2, %eax
orl %edx, %eax
movl %eax, %edx
shrl $0x4, %edx
orl %eax, %edx
movl %edx, %eax
shrl $0x8, %eax
orl %edx, %eax
movl %eax, %edx
shrl $0x10, %edx
orl %eax, %edx
leal 0x8(,%rdx,8), %eax
movq %rax, 0xc8(%rsp)
movl %edx, %eax
incl %eax
movl %eax, 0x9c(%rsp)
pushq $0x1
popq %rdx
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %eax, %eax
movq 0x40(%rsp), %rbp
movq 0x70(%rsp), %r14
movq %r8, %r15
movl %edx, 0x64(%rsp)
movl %edx, %edx
cmpq %rdx, %r14
jb 0x77f50
movq %rdx, 0x90(%rsp)
jne 0x77ce0
movq %r15, %rsi
movq 0x90(%rsp), %rdx
cmpq %rdx, %r14
movq 0x48(%rsp), %rcx
jbe 0x77b6d
movl (%rcx,%rdx,8), %esi
shrl %esi
movl %eax, %eax
movq (%rcx,%rax,8), %r14
movl %r14d, %r13d
shrl %r13d
movl %esi, %r8d
subl %r13d, %r8d
jbe 0x78138
movq (%rbp), %r15
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %r15
movq %rsi, 0xb0(%rsp)
jne 0x77bdf
leaq (%r15,%r15), %rcx
testq %r15, %r15
pushq $0x2
popq %rdx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%rbp)
imulq $0x28, %rcx, %rsi
movq %rax, %rdi
movq %r8, %rbp
callq 0x2370
movq 0xb0(%rsp), %rsi
movq %rbp, %r8
movq 0x40(%rsp), %rbp
movq 0x10(%rsp), %rdi
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
movq %rax, 0x10(%rbp)
leaq 0x1(%r15), %rcx
movq %rcx, (%rbp)
imulq $0x28, %r15, %rcx
leaq (%rax,%rcx), %rbp
cmpl $0x2, %r14d
setb %dl
andb 0x1c(%rsp), %dl
andq $0x0, 0x20(%rax,%rcx)
cmpb $0x1, %dl
movq 0x58(%rsp), %r15
movq %r8, 0xd0(%rsp)
jne 0x77d4f
movl %esi, %eax
cmpq %r15, %rax
jne 0x77d4f
orl $-0x1, 0x4(%rbp)
movq 0x80(%rsp), %rax
movl %eax, 0x8(%rbp)
movl %r15d, 0x10(%rbp)
movl 0x8(%rsp), %eax
movl %eax, (%rbp)
movl 0x9c(%rsp), %eax
movl %eax, 0xc(%rbp)
movq 0xc8(%rsp), %rdi
callq 0x2280
movq 0x10(%rsp), %rdi
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
movq %rax, 0x18(%rbp)
leaq 0x1dc5c4(%rip), %r11    # 0x254230
movq 0x28(%r11), %rcx
xorl %edx, %edx
movq 0x40(%rsp), %rbp
movq 0x88(%rsp), %r13
movq 0x70(%rsp), %r14
movl %edx, %edx
cmpq %rdx, %r15
jbe 0x77ef6
movq (%rdi), %rsi
andq %r9, %rsi
addq %rdx, %rsi
andq 0x10(%rdi), %rsi
movq 0x18(%rdi), %r8
movq (%r8,%rsi,8), %rsi
movq %rsi, (%rax,%rdx,8)
shrq $0x21, %rsi
movzbl (%rcx,%rsi), %r10d
leal -0x3(%r10), %r8d
xorl %esi, %esi
cmpb $-0x2, %r8b
jb 0x77cc0
movl %r10d, %esi
xorl %r8d, %r8d
cmpb $0x1, %sil
sete %r8b
addl %r8d, %r12d
xorl %r8d, %r8d
cmpb $0x2, %sil
sete %r8b
addl %r8d, %ebx
incl %edx
jmp 0x77c84
movq 0x48(%rsp), %rdx
movq 0x90(%rsp), %rsi
movq (%rdx,%rsi,8), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
testb $0x1, %dl
movl %esi, %edx
movl $0x0, %r8d
cmovel %r8d, %edx
cmovnel %r8d, %esi
addl %r10d, %edx
addl %ecx, %esi
cmpl %edx, %esi
movl %edx, %ecx
cmovbl %esi, %ecx
cmpl 0x7c(%rsp), %ecx
jbe 0x77d3f
movl %ecx, %ecx
cvtsi2sd %rcx, %xmm0
leal (%rsi,%rdx), %ecx
cvtsi2sd %rcx, %xmm1
mulsd 0xa8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x77b53
movl 0xc(%rsp), %ecx
movl %ecx, %r8d
movl 0x64(%rsp), %ecx
jmp 0x77f3d
andl $0x0, (%rbp)
movq 0x10(%rdi), %rdx
movq 0x18(%rdi), %rcx
movq (%rdi), %r15
andq %r9, %r15
movl %r13d, %eax
addq %r15, %rax
andq %rdx, %rax
movl 0x4(%rcx,%rax,8), %eax
movl %eax, 0x4(%rbp)
leal -0x1(%rsi), %eax
addq %r15, %rax
movq %rdx, 0x20(%rsp)
andq %rdx, %rax
movq %rcx, %r13
movl 0x4(%rcx,%rax,8), %eax
xorl $0x1, %eax
movl %eax, 0x8(%rbp)
movl %r8d, 0x10(%rbp)
leal -0x1(%r8), %eax
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
leal 0x1(%rcx), %eax
movl %eax, 0xc(%rbp)
leal 0x8(,%rcx,8), %edi
callq 0x2280
movq %rax, 0x18(%rbp)
shrl %r14d
movl 0xb0(%rsp), %ecx
movq 0x88(%rsp), %r9
leaq 0x1dc44b(%rip), %r11    # 0x254230
leaq 0x1(%r14), %rdx
cmpq %rcx, %rdx
jae 0x77e53
addq %r15, %r14
andq 0x20(%rsp), %r14
movq (%r13,%r14,8), %rsi
movq %rsi, (%rax)
movl (%rbp), %edi
addl %edi, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edi       # imm = 0x80000000
orl %esi, %edi
movl %edi, (%rbp)
movq 0x28(%r11), %rsi
movq (%rax), %rdi
shrq $0x21, %rdi
movzbl (%rsi,%rdi), %edi
leal -0x3(%rdi), %r8d
xorl %esi, %esi
cmpb $-0x2, %r8b
jb 0x77e31
movl %edi, %esi
xorl %edi, %edi
cmpb $0x1, %sil
sete %dil
addl %edi, %r12d
xorl %edi, %edi
cmpb $0x2, %sil
sete %dil
addl %edi, %ebx
addq $0x8, %rax
movq %rdx, %r14
jmp 0x77de5
movl %r14d, %ecx
addq %rcx, %r15
andq 0x20(%rsp), %r15
movq (%r13,%r15,8), %rcx
movq %rcx, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
andq %rsi, %rdx
movq %rdx, (%rax)
movq %r9, %r13
movq 0x20(%r9), %rsi
shrq $0x21, %rcx
movl (%rsi,%rcx,8), %ecx
movl %ecx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orq %rdx, %rsi
movq %rsi, (%rax)
movl (%rbp), %edx
addl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %ecx, %edx
movl %edx, (%rbp)
movq 0x28(%r11), %rcx
movq (%rax), %rax
shrq $0x21, %rax
movzbl (%rcx,%rax), %eax
leal -0x3(%rax), %ecx
cmpb $-0x2, %cl
movl $0x0, %ecx
cmovbl %ecx, %eax
xorl %ecx, %ecx
cmpb $0x1, %al
sete %cl
addl %ecx, %r12d
xorl %ecx, %ecx
cmpb $0x2, %al
sete %cl
addl %ecx, %ebx
movq 0x40(%rsp), %rbp
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
movq 0x10(%rsp), %rdi
movq 0x70(%rsp), %r14
movq 0x58(%rsp), %r15
movq 0xd0(%rsp), %r8
addl 0xc(%rsp), %r8d
xorl %edx, %edx
movq 0x90(%rsp), %rsi
cmpq %rsi, %r14
movl 0x64(%rsp), %ecx
jbe 0x77f39
movq 0x48(%rsp), %rax
movq (%rax,%rsi,8), %rax
movq %rax, %rsi
shrq $0x20, %rsi
testb $0x1, %al
movl %esi, %edx
movl $0x0, %eax
cmovel %eax, %edx
cmovnel %eax, %esi
movl %ecx, %eax
jmp 0x77f3d
movl %ecx, %eax
xorl %esi, %esi
incl %ecx
movl %r8d, 0xc(%rsp)
movl %edx, %r10d
movl %ecx, %edx
movl %esi, %ecx
jmp 0x77b36
movl 0xc(%rsp), %eax
cmpq %rax, %r15
jne 0x7817f
cmpl 0xb8(%rsp), %r12d
movq 0x50(%rsp), %rdx
movq 0x38(%rsp), %rsi
movq 0xc0(%rsp), %rax
jne 0x7819e
cmpl %eax, %ebx
movq 0x68(%rsp), %r12
je 0x77484
leaq 0x1702ab(%rip), %rdi    # 0x1e823c
jmp 0x781a5
callq 0x773a7
movq 0x48(%rsp), %rdi
callq 0x2220
movq 0x50(%rsp), %rcx
xorl %eax, %eax
cmpq %rax, %rcx
je 0x77fbb
orl $-0x1, (%r12,%rax,4)
incq %rax
jmp 0x77fac
movq (%rbp), %r9
xorl %eax, %eax
pushq $0x1
popq %rcx
movl %eax, %eax
cmpq %rax, %r9
jbe 0x77ff7
movq 0x10(%rbp), %rdx
imulq $0x28, %rax, %rsi
cmpl $0x0, (%rdx,%rsi)
js 0x77ff0
leaq (%rdx,%rsi), %rdi
leal -0x1(%rcx), %r8d
movl 0x4(%rdi), %edi
movl %r8d, (%r12,%rdi,4)
movl 0x8(%rdx,%rsi), %edx
movl %ecx, (%r12,%rdx,4)
incl %eax
addl $0x2, %ecx
jmp 0x77fc4
movq %r9, 0x20(%rsp)
pushq $0x12
popq %r14
xorl %r15d, %r15d
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl 0x4(%r13), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r15
jae 0x780d1
movq 0x8(%r13), %r13
movl -0x6(%r13,%r14), %eax
testl %eax, %eax
js 0x780bd
movl -0xe(%r13,%r14), %ecx
shlq $0x2, %rcx
xorq $0x4, %rcx
movq 0x68(%rsp), %rdx
movl (%rdx,%rcx), %r12d
testl %r12d, %r12d
js 0x780bd
movl -0xa(%r13,%r14), %ecx
movq 0x68(%rsp), %rdx
cmpl $0x0, (%rdx,%rcx,4)
js 0x780bd
movl %r12d, %ecx
shrl %ecx
imulq $0x28, %rcx, %rcx
movq 0x10(%rbp), %rdx
movl (%rdx,%rcx), %ecx
andl %esi, %ecx
subl %eax, %ecx
pushq $0x1
popq %rbx
js 0x78071
movl %ecx, %ebx
xorl $0x1, %r12d
movq 0x40(%rsp), %rbp
movq 0x18(%rbp), %rdi
callq 0x6c45d
movl -0x6(%r13,%r14), %ecx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %ecx
movl %ecx, 0xc(%rax)
shlq $0x20, %r12
movslq %ebx, %rcx
orq %r12, %rcx
movq %rcx, (%rax)
movl -0xa(%r13,%r14), %ecx
movq 0x68(%rsp), %rdx
movl (%rdx,%rcx,4), %ecx
movl %ecx, 0x8(%rax)
andw $0xc000, 0x10(%rax)     # imm = 0xC000
movb (%r13,%r14), %cl
movb %cl, 0x12(%rax)
incq %r15
addq $0x18, %r14
movq 0x88(%rsp), %r13
jmp 0x78008
movq 0x18(%rbp), %r15
xorl %eax, %eax
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq 0x20(%rsp), %rbx
movl %eax, %r12d
cmpq %r12, %rbx
jbe 0x7810f
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
imulq $0x28, %r12, %rcx
movl (%rax,%rcx), %edx
andl %ebp, %edx
movq %r15, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x69316
leal 0x1(%r12), %eax
jmp 0x780e1
movq %r15, %rdi
callq 0x694eb
movq 0x68(%rsp), %rdi
callq 0x2220
movq 0x40(%rsp), %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1700d8(%rip), %rdi    # 0x1e8217
leaq 0x16fc4b(%rip), %rsi    # 0x1e7d91
leaq 0x170087(%rip), %rcx    # 0x1e81d4
movl $0x2338, %edx           # imm = 0x2338
callq 0x2110
leaq 0x1700aa(%rip), %rdi    # 0x1e8208
jmp 0x78167
leaq 0x170064(%rip), %rdi    # 0x1e81cb
leaq 0x16fc23(%rip), %rsi    # 0x1e7d91
leaq 0x17005f(%rip), %rcx    # 0x1e81d4
movl $0x2319, %edx           # imm = 0x2319
callq 0x2110
leaq 0x170099(%rip), %rdi    # 0x1e821f
leaq 0x16fc04(%rip), %rsi    # 0x1e7d91
leaq 0x170040(%rip), %rcx    # 0x1e81d4
movl $0x2360, %edx           # imm = 0x2360
callq 0x2110
leaq 0x17008c(%rip), %rdi    # 0x1e8231
leaq 0x16fbe5(%rip), %rsi    # 0x1e7d91
leaq 0x170021(%rip), %rcx    # 0x1e81d4
movl $0x2361, %edx           # imm = 0x2361
callq 0x2110