// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movsd %xmm0, 0x70(%rsp)
movl %esi, 0x64(%rsp)
movq %rdi, %rbx
movabsq $0x3ffffffffffffff, %r15 # imm = 0x3FFFFFFFFFFFFFF
callq 0xa02fa
movq %rbx, 0x8(%rsp)
movl 0x14(%rbx), %ebx
addl %ebx, %ebx
movl $0x1, %edi
movl $0x38, %esi
callq 0x2120
movq %rax, %r14
movl $0x1, %edi
movl $0x48, %esi
callq 0x2120
movq %rax, 0x18(%r14)
movl $0x4, %esi
movq %rbx, %rdi
callq 0x2120
movq %rax, %rbp
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %r12
movq (%rax), %rax
andq %r15, %rax
btsq $0x3b, %rax
movq %rax, (%r12)
movq $0x3, 0x10(%r12)
movl $0x20, %edi
callq 0x2280
movq %r12, %r10
movq %rax, 0x18(%r12)
movl %ebx, %eax
movq %rax, 0x90(%rsp)
movq %rbx, 0xa8(%rsp)
testl %ebx, %ebx
movq %r14, 0x10(%rsp)
movq %rbp, 0x40(%rsp)
je 0xb17c4
leaq 0x1da79f(%rip), %r11    # 0x28b230
xorl %r13d, %r13d
xorl %edx, %edx
xorl %ebx, %ebx
movq 0x8(%rsp), %r8
movq %r10, 0x30(%rsp)
movq 0x20(%r8), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xb0ab9
cmpl $0x0, (%rbp,%r13,4)
je 0xb0acb
incq %r13
cmpq 0x90(%rsp), %r13
jne 0xb0aa2
jmp 0xb17c6
movq 0x28(%r8), %rax
cmpl $0x0, (%rax,%r13,8)
je 0xb1229
movq %rdx, 0x48(%rsp)
movq %rbx, 0x18(%rsp)
movl $0x1, (%rbp,%r13,4)
movq $0x0, 0x8(%r10)
movl %r13d, %eax
xorl $0x1, %eax
movl %eax, 0x4(%rsp)
movq 0x28(%r8), %rdi
movq (%rdi,%r13,8), %rax
xorl %ebp, %ebp
cmpl $0x1, %eax
movq %r13, 0x88(%rsp)
jne 0xb0c6f
movq 0x8(%r8), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rcx
movl 0x8(%rdx,%rcx,8), %ecx
movq %rcx, %rsi
xorq $0x1, %rsi
cmpl $0x1, (%rdi,%rsi,8)
movl $0x0, %edi
movq %rdi, 0x28(%rsp)
movl $0x0, %edi
movq %rdi, 0x20(%rsp)
jne 0xb0c81
xorl %ebp, %ebp
movl %r13d, %r15d
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq %r13, %r12
movl %ecx, %ebx
movl %r15d, %ecx
movl $0x1, %edi
xorl %edi, %ecx
movq 0x40(%rsp), %r9
movl %edi, (%r9,%rcx,4)
movl %ebx, %r14d
movl %edi, (%r9,%r14,4)
leaq (%rax,%rax,2), %rax
movq (%r10), %rcx
shrq $0x3a, %rcx
movl $0x1, %edi
shlq %cl, %rdi
movq (%rdx,%rax,8), %r13
movl %esi, 0x4(%rsp)
cmpq %rdi, 0x8(%r10)
jne 0xb0bc3
incl %ecx
movq %r10, %rdi
movl %ecx, %esi
callq 0x100f0f
leaq 0x1da677(%rip), %r11    # 0x28b230
movq 0x30(%rsp), %r10
movq 0x8(%rsp), %r8
movl %r13d, %eax
shlq $0x20, %r12
orq %rax, %r12
movq 0x8(%r10), %rax
movq 0x18(%r10), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r10)
movq (%r10), %rdx
movabsq $0x3ffffffffffffff, %rsi # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rdx
addq %rax, %rdx
andq 0x10(%r10), %rdx
movq %r12, (%rcx,%rdx,8)
movq 0x28(%r11), %rax
shrl %r15d
movb (%rax,%r15), %al
xorl %ecx, %ecx
cmpb $0x1, %al
sete %cl
movq 0x20(%rsp), %rdx
addl %ecx, %edx
movq %rdx, 0x20(%rsp)
xorl %ecx, %ecx
cmpb $0x2, %al
sete %cl
movq 0x28(%rsp), %rax
addl %ecx, %eax
movq %rax, 0x28(%rsp)
addl %r13d, %ebp
movq 0x88(%rsp), %r13
cmpq %r14, %r13
je 0xb0c81
movq 0x28(%r8), %rdi
movq (%rdi,%r14,8), %rax
cmpl $0x1, %eax
jne 0xb0c81
movq 0x8(%r8), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rcx
movl 0x8(%rdx,%rcx,8), %ecx
movq %rcx, %rsi
xorq $0x1, %rsi
cmpl $0x1, (%rdi,%rsi,8)
movl %ebx, %r15d
movq %r14, %r12
je 0xb0b69
jmp 0xb0c81
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movl 0x4(%rsp), %eax
movl %eax, %ebx
xorl $0x1, %ebx
cmpq %rbx, %r13
jne 0xb0cb1
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpq $0x0, 0x8(%r10)
je 0xb0cb1
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movl %ebp, %r12d
movq 0x28(%rsp), %rbp
jmp 0xb0e8c
movq 0x20(%r8), %rax
movl 0x4(%rsp), %ecx
movl %ecx, %r15d
movq (%r10), %rcx
shrq $0x3a, %rcx
movl $0x1, %edx
shlq %cl, %rdx
shrl %r15d
movl (%rax,%r15,8), %r14d
cmpq %rdx, 0x8(%r10)
movl %ebp, %r12d
jne 0xb0cf8
incl %ecx
movq %r10, %rdi
movl %ecx, %esi
callq 0x100f0f
leaq 0x1da542(%rip), %r11    # 0x28b230
movq 0x30(%rsp), %r10
movq 0x8(%rsp), %r8
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
shlq $0x20, %rbx
orq %r14, %rbx
movq 0x8(%r10), %rax
movq 0x18(%r10), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r10)
movq (%r10), %rdx
movabsq $0x3ffffffffffffff, %rsi # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rdx
addq %rax, %rdx
andq 0x10(%r10), %rdx
movq %rbx, (%rcx,%rdx,8)
movq 0x28(%r11), %rax
movb (%rax,%r15), %al
xorl %ecx, %ecx
cmpb $0x1, %al
sete %cl
movq 0x20(%rsp), %rdx
addl %ecx, %edx
movq %rdx, 0x20(%rsp)
xorl %ecx, %ecx
cmpb $0x2, %al
sete %cl
movq 0x28(%rsp), %rbp
addl %ecx, %ebp
addl %r14d, %r12d
movq 0x28(%r8), %rax
movl %r13d, %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rcx
movl %r13d, %r15d
cmpl $0x1, %ecx
jne 0xb0e8c
movq 0x8(%r8), %rdx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rdx,%rcx,8), %r14d
movq %r14, %rbx
xorq $0x1, %rbx
movq (%rax,%rbx,8), %rax
cmpl $0x1, %eax
jne 0xb0e8c
movl $0x1, %esi
movq 0x40(%rsp), %rdi
movl %esi, (%rdi,%r14,4)
movl %r15d, %ecx
movl %esi, (%rdi,%rcx,4)
shrq $0x20, %rax
movq (%r10), %rcx
shrq $0x3a, %rcx
movl $0x1, %esi
shlq %cl, %rsi
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %r15
cmpq %rsi, 0x8(%r10)
jne 0xb0def
incl %ecx
movq %r10, %rdi
movl %ecx, %esi
callq 0x100f0f
leaq 0x1da44b(%rip), %r11    # 0x28b230
movq 0x30(%rsp), %r10
movq 0x8(%rsp), %r8
movl %r15d, %eax
movq %rbx, %rdx
shlq $0x20, %rdx
orq %rax, %rdx
incq 0x8(%r10)
movq (%r10), %rax
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
leaq (%rax,%r9), %rsi
movq %rax, %rcx
shrq $0x3a, %rcx
movq $-0x1, %rdi
shlq %cl, %rdi
testq %r9, %rax
notq %rdi
cmovneq %rsi, %rdi
movq 0x18(%r10), %rcx
andq %r9, %rdi
movabsq $-0x400000000000000, %rsi # imm = 0xFC00000000000000
andq %rsi, %rax
orq %rdi, %rax
movq %rax, (%r10)
movq %rdx, (%rcx,%rdi,8)
movq 0x28(%r11), %rax
movl %r14d, %ecx
shrl %ecx
movb (%rax,%rcx), %al
xorl %ecx, %ecx
cmpb $0x1, %al
sete %cl
movq 0x20(%rsp), %rdx
addl %ecx, %edx
movq %rdx, 0x20(%rsp)
xorl %ecx, %ecx
cmpb $0x2, %al
sete %cl
addl %ecx, %ebp
addl %r15d, %r12d
movq 0x28(%r8), %rax
movq (%rax,%r14,8), %rcx
movl %ebx, %r15d
cmpl $0x1, %ecx
je 0xb0d78
movl %ebx, %r15d
cmpl $-0x1, %r15d
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
movq 0x48(%rsp), %rdx
je 0xb0eb8
movl 0x4(%rsp), %eax
movl $0x1, %ecx
movq 0x40(%rsp), %rsi
movl %ecx, (%rsi,%rax,4)
movl %r15d, %eax
movl %ecx, (%rsi,%rax,4)
movq 0x20(%rsp), %rcx
cmpl %ebp, %ecx
movl %ebp, %eax
cmovbl %ecx, %eax
cmpl 0x64(%rsp), %eax
jbe 0xb10f1
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
leal (%rcx,%rbp), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x70(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0xb10f1
cmpq $0x0, 0x8(%r10)
je 0xb1262
movl %r15d, 0x6c(%rsp)
movq %rbp, 0x28(%rsp)
movl %r12d, 0x5c(%rsp)
movq 0x8(%r10), %rsi
testq %rsi, %rsi
je 0xb126c
movq 0x28(%r11), %rax
movq 0x18(%r10), %rcx
movq (%r10), %rdx
movq %rsi, %rdi
movabsq $0x3ffffffffffffff, %rsi # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rdx
movq %rdi, %rsi
andq 0x10(%r10), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x48(%rsp), %rdx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %ecx
leal -0x3(%rcx), %eax
xorl %edi, %edi
cmpb $-0x2, %al
movl $0x0, %eax
movq %rax, 0x38(%rsp)
cmovbl %edi, %ecx
xorl %eax, %eax
cmpb $0x2, %cl
sete %al
xorl %r12d, %r12d
cmpb $0x1, %cl
sete %r12b
movzbl %cl, %r14d
movl $0x1, %r15d
movl $0x1, %ecx
xorl %r9d, %r9d
movq %rdx, %r13
movl $0x0, %edx
movl $0x0, %ebp
cmpq %rcx, %rsi
je 0xb100d
movq 0x28(%r11), %rdx
movq %rbx, 0x18(%rsp)
movq %r8, %rbx
movq %r11, %r8
movq %rsi, %r11
movq 0x18(%r10), %rsi
movq (%r10), %rdi
movq %r9, %rbp
movabsq $0x3ffffffffffffff, %r9 # imm = 0x3FFFFFFFFFFFFFF
andq %r9, %rdi
movq %rbp, %r9
addq %rcx, %rdi
andq 0x10(%r10), %rdi
movq (%rsi,%rdi,8), %rsi
shrq $0x21, %rsi
movzbl (%rdx,%rsi), %edx
leal -0x3(%rdx), %esi
cmpb $-0x2, %sil
movl $0x0, %esi
cmovbl %esi, %edx
movzbl %dl, %ebp
testb %bpl, %bpl
sete %dl
testl %r14d, %r14d
sete %sil
orb %dl, %sil
cmpl %ebp, %r14d
sete %dl
orb %sil, %dl
movq %r11, %rsi
movq %r8, %r11
movq %rbx, %r8
movq 0x18(%rsp), %rbx
testb %dl, %dl
je 0xb1019
movq %r13, %rdx
jmp 0xb10be
cmpq %rcx, %rsi
movq %r13, %rdx
jbe 0xb1039
movl %r12d, %ecx
orl %eax, %ecx
je 0xb1a1d
testl %r12d, %r12d
je 0xb1039
testl %eax, %eax
jne 0xb1a26
cmpl %eax, %r12d
cmovbel %eax, %r12d
xorl %r13d, %r13d
testl %eax, %eax
setne %cl
cmpq %rdx, %r9
jne 0xb1096
movq %rbx, %rdi
leaq (%rdx,%rdx), %rbx
testq %rdx, %rdx
movl $0x2, %eax
cmoveq %rax, %rbx
leaq (,%rbx,8), %rsi
movq %r9, 0x50(%rsp)
movb %cl, 0x18(%rsp)
callq 0x2370
movb 0x18(%rsp), %cl
movq 0x50(%rsp), %r9
leaq 0x1da1aa(%rip), %r11    # 0x28b230
movq 0x30(%rsp), %r10
movq 0x8(%rsp), %r8
movq %rbx, %rdx
movq %rax, %rbx
movq 0x38(%rsp), %rax
addl %eax, %eax
shlq $0x20, %r12
orq %rax, %r12
movb %cl, %r13b
orq %r12, %r13
movq %r13, (%rbx,%r9,8)
incq %r9
xorl %eax, %eax
movl %r15d, %ecx
movq %rcx, 0x38(%rsp)
xorl %r12d, %r12d
testl %ebp, %ebp
cmovnel %ebp, %r14d
xorl %ecx, %ecx
cmpl $0x1, %ebp
sete %cl
addl %ecx, %r12d
xorl %ecx, %ecx
cmpl $0x2, %ebp
sete %cl
addl %ecx, %eax
incl %r15d
movq 0x8(%r10), %rsi
movq %r15, %rcx
cmpq %r15, %rsi
jae 0xb0f83
jmp 0xb126f
movq (%r14), %rbx
movq 0x8(%r14), %rax
cmpq %rax, %rbx
jne 0xb112b
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
callq 0x2370
movq 0x30(%rsp), %r10
movq %rax, 0x10(%r14)
xorl %eax, %eax
cmpl $-0x1, %r15d
sete %al
movq %r14, %rdx
movq 0x10(%r14), %r14
leaq 0x1(%rbx), %rcx
movq %rcx, (%rdx)
movl %r15d, %ecx
leaq (%rbx,%rbx,4), %r15
movq $0x0, 0x20(%r14,%r15,8)
movl %ecx, 0x4(%r14,%r15,8)
movl 0x4(%rsp), %ecx
movl %ecx, 0x8(%r14,%r15,8)
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl (%r14,%r15,8), %ecx
movl $0x80000000, %edx       # imm = 0x80000000
andl %edx, %ecx
orl %r12d, %ecx
movl %ecx, (%r14,%r15,8)
movq 0x8(%r10), %rbx
movl %ebx, 0x10(%r14,%r15,8)
shll $0x1f, %eax
orl %r12d, %eax
movl %eax, (%r14,%r15,8)
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(%r14,%r15,8)
leal 0x8(,%rcx,8), %edi
movq %r10, %r12
callq 0x2280
movq %rax, 0x18(%r14,%r15,8)
testq %rbx, %rbx
movq 0x40(%rsp), %rbp
je 0xb123f
movq 0x10(%r12), %rcx
movq 0x18(%r12), %rdx
movq (%r12), %rsi
movabsq $0x3ffffffffffffff, %rdi # imm = 0x3FFFFFFFFFFFFFF
andq %rdi, %rsi
xorl %edi, %edi
movq %r12, %r10
leaq 0x1da032(%rip), %r11    # 0x28b230
leaq (%rsi,%rdi), %r8
andq %rcx, %r8
movq (%rdx,%r8,8), %r8
movq %r8, (%rax,%rdi,8)
incq %rdi
movl %edi, %r8d
cmpq %r8, %rbx
ja 0xb11fe
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %rbx
jmp 0xb1258
movl %r13d, %ecx
xorq $0x1, %rcx
cmpl $0x0, (%rax,%rcx,8)
jne 0xb0ab9
jmp 0xb0ada
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r8
movq %r12, %r10
movq 0x18(%rsp), %rbx
leaq 0x1d9fd8(%rip), %r11    # 0x28b230
movq 0x48(%rsp), %rdx
jmp 0xb0ab9
movq 0x40(%rsp), %rbp
jmp 0xb0ab9
xorl %r9d, %r9d
testq %r9, %r9
je 0xb1779
movq %rdx, 0x48(%rsp)
movq (%rbx), %rdx
movq %rdx, %rax
shrq $0x20, %rax
xorl %ecx, %ecx
testb $0x1, %dl
movl $0x0, %edx
cmovel %eax, %edx
cmovel %ecx, %eax
orl $0x80000000, 0x5c(%rsp) # imm = 0x80000000
movq %rsi, 0x38(%rsp)
decl %esi
movl %esi, %edi
shrl %edi
orl %esi, %edi
movl %edi, %esi
shrl $0x2, %esi
orl %edi, %esi
movl %esi, %edi
shrl $0x4, %edi
orl %esi, %edi
movl %edi, %esi
shrl $0x8, %esi
orl %edi, %esi
movl %esi, %edi
shrl $0x10, %edi
orl %esi, %edi
leal 0x8(,%rdi,8), %esi
movq %rsi, 0xb0(%rsp)
movl %edi, %esi
incl %esi
movl %esi, 0x68(%rsp)
movl $0x1, %edi
movl $0x1, %esi
xorl %r13d, %r13d
xorl %r15d, %r15d
movl $0x0, 0x60(%rsp)
movq 0x10(%rsp), %r14
movq %r9, 0x50(%rsp)
movq %rbx, 0x18(%rsp)
cmpq %rsi, %r9
jne 0xb1312
movq %rsi, %r12
xorl %esi, %esi
jmp 0xb1376
movq %rdi, %rbp
movq %rsi, %r12
movq (%rbx,%rsi,8), %rsi
movq %rsi, %rdi
shrq $0x20, %rdi
testb $0x1, %sil
movl %edi, %esi
movl $0x0, %r9d
cmovel %r9d, %esi
cmovnel %r9d, %edi
addl %esi, %eax
addl %edi, %edx
cmpl %eax, %edx
movl %eax, %edi
cmovbl %edx, %edi
movb $0x1, %sil
cmpl 0x64(%rsp), %edi
jbe 0xb136e
movl %edi, %edi
xorps %xmm0, %xmm0
cvtsi2sd %rdi, %xmm0
leal (%rdx,%rax), %edi
xorps %xmm1, %xmm1
cvtsi2sd %rdi, %xmm1
mulsd 0x70(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xb136e
xorl %esi, %esi
movq 0x50(%rsp), %r9
movq %rbp, %rdi
testb %sil, %sil
jne 0xb175b
movq 0x38(%rsp), %rdx
movq %rdx, %r8
movq %r12, %rsi
cmpq %r12, %r9
jbe 0xb1396
movl (%rbx,%rsi,8), %r8d
shrl %r8d
movl %ecx, %eax
movq (%rbx,%rax,8), %r12
movl %r12d, %ebp
shrl %ebp
movl %r8d, %eax
subl %ebp, %eax
movq %rax, 0xa0(%rsp)
jbe 0xb19fe
movq %rsi, 0xc0(%rsp)
movq %rdi, 0x98(%rsp)
movq (%r14), %rbx
movq 0x8(%r14), %rax
cmpq %rax, %rbx
jne 0xb1409
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
movq %r8, %r14
callq 0x2370
movq %r14, %r8
movq 0x10(%rsp), %r14
movq 0x38(%rsp), %rdx
movq %rax, 0x10(%r14)
leaq 0x1(%rbx), %rax
movq 0x10(%r14), %rcx
movq %rax, (%r14)
leaq (%rbx,%rbx,4), %rax
leaq (%rcx,%rax,8), %rbx
movq $0x0, 0x20(%rbx)
cmpl $-0x1, 0x6c(%rsp)
jne 0xb1506
cmpl $0x1, %r12d
ja 0xb1506
movl %r8d, %eax
cmpq %rdx, %rax
jne 0xb1506
movl $0xffffffff, 0x4(%rbx)  # imm = 0xFFFFFFFF
movl 0x4(%rsp), %eax
movl %eax, 0x8(%rbx)
movl %edx, 0x10(%rbx)
movl 0x5c(%rsp), %eax
movl %eax, (%rbx)
movl 0x68(%rsp), %eax
movl %eax, 0xc(%rbx)
movq 0xb0(%rsp), %rdi
movq %rdx, %rbp
callq 0x2280
movq %rax, 0x18(%rbx)
testq %rbp, %rbp
je 0xb16f3
movq 0x30(%rsp), %rsi
movq 0x10(%rsi), %rcx
movq 0x18(%rsi), %rdx
movq (%rsi), %rsi
movabsq $0x3ffffffffffffff, %rdi # imm = 0x3FFFFFFFFFFFFFF
andq %rdi, %rsi
leaq 0x1d9d8c(%rip), %rdi    # 0x28b230
movq 0x28(%rdi), %rdi
xorl %r8d, %r8d
movq 0x18(%rsp), %rbx
leaq (%rsi,%r8), %r9
andq %rcx, %r9
movq (%rdx,%r9,8), %r9
movq %r9, (%rax,%r8,8)
shrq $0x21, %r9
movzbl (%rdi,%r9), %r10d
leal -0x3(%r10), %r11d
xorl %r9d, %r9d
cmpb $-0x2, %r11b
jb 0xb14d8
movl %r10d, %r9d
xorl %r10d, %r10d
cmpb $0x1, %r9b
sete %r10b
addl %r10d, %r13d
xorl %r10d, %r10d
cmpb $0x2, %r9b
sete %r10b
addl %r10d, %r15d
incq %r8
movl %r8d, %r9d
cmpq %r9, 0x38(%rsp)
ja 0xb14b0
jmp 0xb16f8
movl $0x0, (%rbx)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdx
movq 0x18(%rax), %rcx
movq (%rax), %r14
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq %rax, %r14
movl %ebp, %eax
addq %r14, %rax
andq %rdx, %rax
movl 0x4(%rcx,%rax,8), %eax
movl %eax, 0x4(%rbx)
movl %r8d, %eax
decl %eax
addq %r14, %rax
movq %rdx, 0x78(%rsp)
andq %rdx, %rax
movq %rcx, 0x80(%rsp)
movl 0x4(%rcx,%rax,8), %eax
xorl $0x1, %eax
movl %eax, 0x8(%rbx)
movq 0xa0(%rsp), %rax
movl %eax, 0x10(%rbx)
decl %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(%rbx)
leal 0x8(,%rcx,8), %edi
movq %r8, 0xb8(%rsp)
callq 0x2280
movq 0xb8(%rsp), %rdx
movq %rax, 0x18(%rbx)
leal 0x1(%rbp), %eax
cmpl %edx, %eax
jae 0xb164b
shrl %r12d
movl %ebp, %ecx
notl %ecx
addl %edx, %ecx
xorl %eax, %eax
movq 0x8(%rsp), %r8
leaq 0x1d9c5f(%rip), %r9     # 0x28b230
movq 0x80(%rsp), %r10
movq 0x78(%rsp), %r11
movl %ebp, %edx
addq %r14, %rdx
andq %r11, %rdx
movq (%r10,%rdx,8), %rdx
movq 0x18(%rbx), %rsi
movq %rdx, (%rsi,%rax,8)
movl (%rbx), %edi
addl %edi, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %edi       # imm = 0x80000000
orl %edx, %edi
movl %edi, (%rbx)
movq 0x28(%r9), %rdx
movq (%rsi,%rax,8), %rsi
shrq $0x21, %rsi
movzbl (%rdx,%rsi), %esi
leal -0x3(%rsi), %edi
xorl %edx, %edx
cmpb $-0x2, %dil
jb 0xb1623
movl %esi, %edx
xorl %esi, %esi
cmpb $0x1, %dl
sete %sil
addl %esi, %r13d
xorl %esi, %esi
cmpb $0x2, %dl
sete %sil
addl %esi, %r15d
incq %rax
incl %r12d
movl %r12d, %ebp
cmpq %rax, %rcx
jne 0xb15de
jmp 0xb1669
xorl %eax, %eax
movl %ebp, %r12d
movq 0x8(%rsp), %r8
leaq 0x1d9bd4(%rip), %r9     # 0x28b230
movq 0x80(%rsp), %r10
movq 0x78(%rsp), %r11
movl %r12d, %ecx
addq %rcx, %r14
andq %r11, %r14
movq (%r10,%r14,8), %rcx
movq 0x18(%rbx), %rdx
movq %rcx, %rsi
movabsq $-0x100000000, %rdi     # imm = 0xFFFFFFFF00000000
andq %rdi, %rsi
movq %rsi, (%rdx,%rax,8)
movq 0x20(%r8), %rdi
shrq $0x21, %rcx
movl (%rdi,%rcx,8), %ecx
movl %ecx, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
orq %rsi, %rdi
movq %rdi, (%rdx,%rax,8)
movl (%rbx), %esi
addl %esi, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %esi       # imm = 0x80000000
orl %ecx, %esi
movl %esi, (%rbx)
movq 0x28(%r9), %rcx
movq (%rdx,%rax,8), %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, %r13d
xorl %ecx, %ecx
cmpb $0x2, %al
sete %cl
addl %ecx, %r15d
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
movq 0xa0(%rsp), %rax
addl %eax, 0x60(%rsp)
xorl %eax, %eax
movq 0x50(%rsp), %r9
movq 0xc0(%rsp), %rcx
cmpq %rcx, %r9
jbe 0xb173e
movq (%rbx,%rcx,8), %rax
movq %rax, %rdx
shrq $0x20, %rdx
testb $0x1, %al
movl %edx, %eax
movl $0x0, %ecx
cmovel %ecx, %eax
cmovnel %ecx, %edx
movq 0x98(%rsp), %rdi
movl %edi, %ecx
jmp 0xb174a
movq 0x98(%rsp), %rdi
movl %edi, %ecx
xorl %edx, %edx
movq 0x8(%rsp), %r8
movq 0x30(%rsp), %r10
leaq 0x1d9ad5(%rip), %r11    # 0x28b230
incl %edi
movq %rdi, %rsi
cmpq %rdi, %r9
jae 0xb1306
movl 0x60(%rsp), %eax
movq 0x48(%rsp), %rdx
movq 0x38(%rsp), %rsi
jmp 0xb1786
xorl %eax, %eax
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x10(%rsp), %r14
movq 0x28(%rsp), %rcx
cmpq %rax, %rsi
movq 0x20(%rsp), %rax
jne 0xb1a45
cmpl %eax, %r13d
jne 0xb1a64
cmpl %ecx, %r15d
movq 0x88(%rsp), %r13
movq 0x40(%rsp), %rbp
je 0xb0ab9
leaq 0x17898d(%rip), %rdi    # 0x22a14c
jmp 0xb1a6b
xorl %ebx, %ebx
testq %r10, %r10
je 0xb17e5
movq 0x18(%r10), %rdi
movq %rbx, %r15
movq %r10, %rbx
callq 0x2220
movq %rbx, %rdi
movq %r15, %rbx
callq 0x2220
movq %rbx, %rdi
callq 0x2220
cmpl $0x0, 0xa8(%rsp)
je 0xb1810
movq 0x90(%rsp), %rdx
shlq $0x2, %rdx
movq %rbp, %rdi
movl $0xff, %esi
callq 0x20e0
movq (%r14), %r9
testq %r9, %r9
movq 0x8(%rsp), %r8
je 0xb1855
movq 0x10(%r14), %rax
addq $0x8, %rax
movl $0x1, %ecx
movl $0x1, %edx
cmpl $0x0, -0x8(%rax)
js 0xb1845
leal -0x1(%rcx), %esi
movl -0x4(%rax), %edi
movl %esi, (%rbp,%rdi,4)
movl (%rax), %esi
movl %ecx, (%rbp,%rsi,4)
movl %edx, %esi
addq $0x28, %rax
incl %edx
addl $0x2, %ecx
cmpq %rsi, %r9
ja 0xb182f
movq %r9, 0x38(%rsp)
testl $0x7fffffff, 0x4(%r8)   # imm = 0x7FFFFFFF
je 0xb1993
movl $0x12, %r14d
xorl %r15d, %r15d
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq 0x8(%r8), %r13
movl -0x6(%r13,%r14), %eax
testl %eax, %eax
js 0xb197a
movl -0xe(%r13,%r14), %ecx
shlq $0x2, %rcx
xorq $0x4, %rcx
movl (%rbp,%rcx), %r12d
testl %r12d, %r12d
js 0xb197a
movl -0xa(%r13,%r14), %ecx
cmpl $0x0, (%rbp,%rcx,4)
js 0xb197a
movl %r12d, %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rdx
movl (%rdx,%rcx,8), %ecx
andl %edi, %ecx
subl %eax, %ecx
movl $0x1, %ebx
js 0xb18d4
movl %ecx, %ebx
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rbp
movl 0x4(%rbp), %ecx
andl %edi, %ecx
movl (%rbp), %eax
cmpl %eax, %ecx
jne 0xb1918
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%rbp)
movq 0x8(%rbp), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r8
movq %rax, 0x8(%rbp)
xorl $0x1, %r12d
movq 0x8(%rbp), %rax
movl 0x4(%rbp), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl %edi, %esi
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbp)
leaq (%rdx,%rdx,2), %rcx
movl -0x6(%r13,%r14), %edx
andl %edi, %edx
movl %edx, 0xc(%rax,%rcx,8)
shlq $0x20, %r12
movslq %ebx, %rdx
orq %r12, %rdx
movq %rdx, (%rax,%rcx,8)
movl -0xa(%r13,%r14), %edx
movq 0x40(%rsp), %rbp
movl (%rbp,%rdx,4), %edx
movl %edx, 0x8(%rax,%rcx,8)
andw $0xc000, 0x10(%rax,%rcx,8) # imm = 0xC000
movb (%r13,%r14), %dl
movb %dl, 0x12(%rax,%rcx,8)
incq %r15
movl 0x4(%r8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq $0x18, %r14
cmpq %rax, %r15
jb 0xb1876
movq 0x38(%rsp), %rbx
testq %rbx, %rbx
je 0xb19d1
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r14
movq 0x18(%rax), %r15
xorl %r12d, %r12d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
leaq (%r12,%r12,4), %rax
movl (%r14,%rax,8), %edx
andl %ebp, %edx
movq %r15, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0xa0115
incl %r12d
cmpq %r12, %rbx
ja 0xb19b2
movq 0x10(%rsp), %rbx
movq 0x18(%rbx), %rdi
callq 0xa02fa
movq 0x40(%rsp), %rdi
callq 0x2220
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x178722(%rip), %rdi    # 0x22a127
leaq 0x178295(%rip), %rsi    # 0x229ca1
leaq 0x1786d1(%rip), %rcx    # 0x22a0e4
movl $0x2338, %edx           # imm = 0x2338
callq 0x2110
leaq 0x1786b7(%rip), %rdi    # 0x22a0db
jmp 0xb1a2d
leaq 0x1786eb(%rip), %rdi    # 0x22a118
leaq 0x17826d(%rip), %rsi    # 0x229ca1
leaq 0x1786a9(%rip), %rcx    # 0x22a0e4
movl $0x2319, %edx           # imm = 0x2319
callq 0x2110
leaq 0x1786e3(%rip), %rdi    # 0x22a12f
leaq 0x17824e(%rip), %rsi    # 0x229ca1
leaq 0x17868a(%rip), %rcx    # 0x22a0e4
movl $0x2360, %edx           # imm = 0x2360
callq 0x2110
leaq 0x1786d6(%rip), %rdi    # 0x22a141
leaq 0x17822f(%rip), %rsi    # 0x229ca1
leaq 0x17866b(%rip), %rcx    # 0x22a0e4
movl $0x2361, %edx           # imm = 0x2361
callq 0x2110