// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: ma_ug_gen_primary(asg_t*, unsigned char)
ma_ug_t *ma_ug_gen_primary(asg_t *g, uint8_t flag)
{
    asg_cleanup(g);
	int32_t *mark;
	uint32_t i, v, n_vtx = g->n_seq * 2;
	///is a queue
	kdq_t(uint64_t) *q;
	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);

    ///for each untig, all node have the same direction
    ///and all node except the last one just have one edge
    ///the last one may have multiple edges
	q = kdq_init(uint64_t);
	for (v = 0; v < n_vtx; ++v) {
		uint32_t w, x, l, start, end, len;
		ma_utg_t *p;
        ///what's the usage of mark array
        ///mark array is used to mark if this node has already been included in a contig
        /****************************may have hap bugs********************************/
		///if (g->seq[v>>1].del || arc_cnt(g, v) == 0 || mark[v] || g->seq[v>>1].c != flag) continue;
        ///if (g->seq[v>>1].del || arc_cnt(g, v) == 0 || mark[v] || (g->seq[v>>1].c & flag) == 0) continue;
        ///if (g->seq[v>>1].del || arc_cnt(g, v) == 0 || mark[v]) continue;
        if (g->seq[v>>1].del || mark[v]) continue;
        if (arc_cnt(g, v) == 0 && arc_cnt(g, (v^1)) != 0) continue;
        if(flag == PRIMARY_LABLE && g->seq[v>>1].c == ALTER_LABLE) continue;
        if(flag == ALTER_LABLE && g->seq[v>>1].c != ALTER_LABLE) continue;
        /****************************may have hap bugs********************************/
		mark[v] = 1;
		q->count = 0, start = v, end = v^1, len = 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);
			end = x^1, len += l;
			w = x;
			if (x == v) break;
		}
        ///kdq_size(q) == 0 means there is just one read
		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);
			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);
			start = w, len += l;
			x = w;
		}
add_unitig:
		if (start != UINT32_MAX) mark[start] = mark[end] = 1;
		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);
	}
	kdq_destroy(uint64_t, q);

	// 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
    ///note ug->u.a[i].start == ug->u.a[i].a[0]
    ///but ug->u.a[i].end = ug->u.a[i].a[ug->u.a[i].n-1]^1
    ///ug->u.a[i].start has the same direction as other non-end node
    ///while ug->u.a[i].end is the only one with reverse direction
	for (i = 0; i < ug->u.n; ++i) {
		if (ug->u.a[i].circ) continue;
        ///i is the untig id
		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;
		/**
	p->ul: |____________31__________|__________1___________|______________32_____________|
	                    qns            direction of overlap       length of this node (not overlap length)
						                 (based on query)
	p->v : |___________31___________|__________1___________|
				        tns             reverse direction of overlap
						                  (based on target)
	p->ol: overlap length
	**/
		///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
        /**for one untig,
          start                end
         ----->              <------
         so if we want to find the edge between two untigs, their start and end look like: 

         start                end
         ----->              <------
         ---------------------------

                                    start                end
                                    ----->              <------
                                    ---------------------------
        p->ul>>32^1 is the end of the first untig,
        p->v is the start of the second untig
        **/
		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
movq %rsp, %rbp
subq $0x80, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rdi
callq 0xcdd10
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x24(%rbp)
movl $0x1, %edi
movl $0x38, %esi
callq 0x2140
movq %rax, -0x38(%rbp)
callq 0xcd150
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x24(%rbp), %eax
movl %eax, %edi
movl $0x4, %esi
callq 0x2140
movq %rax, -0x18(%rbp)
callq 0xe6120
movq %rax, -0x30(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0xe80a9
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xe7b88
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0xe7b8d
jmp 0xe809b
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
jne 0xe7bbf
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x20(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
je 0xe7bbf
jmp 0xe809b
movzbl -0x9(%rbp), %eax
cmpl $0x0, %eax
jne 0xe7be6
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0xe7be6
jmp 0xe809b
movzbl -0x9(%rbp), %eax
cmpl $0x1, %eax
jne 0xe7c0d
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
je 0xe7c0d
jmp 0xe809b
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
movl $0x1, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
movq $0x0, 0x8(%rax)
movl -0x20(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x20(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x1, %eax
je 0xe7c5c
jmp 0xe7d2a
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x40(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x1, %eax
je 0xe7ca2
jmp 0xe7d2a
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movl $0x1, (%rax,%rcx,4)
movq -0x18(%rbp), %rax
movl -0x40(%rbp), %ecx
movl $0x1, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
shlq $0x20, %rsi
movl -0x44(%rbp), %eax
orq %rax, %rsi
callq 0xe61c0
movl -0x40(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x44(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0xe7d25
jmp 0xe7d2a
jmp 0xe7c43
movl -0x48(%rbp), %eax
movl -0x4c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0xe7d42
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xe7d84
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rdi
movl -0x4c(%rbp), %eax
xorl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
shlq $0x20, %rsi
movl -0x44(%rbp), %eax
orq %rax, %rsi
callq 0xe61c0
movl -0x44(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0xe7d97
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
jmp 0xe7e7e
movl -0x20(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x40(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x1, %eax
je 0xe7dbb
jmp 0xe7e7c
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x40(%rbp), %edx
xorl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x1, %eax
je 0xe7e01
jmp 0xe7e7c
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movl $0x1, (%rax,%rcx,4)
movq -0x18(%rbp), %rax
movl -0x40(%rbp), %ecx
movl $0x1, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
shlq $0x20, %rsi
movl -0x44(%rbp), %eax
orq %rax, %rsi
callq 0xe6260
movl -0x3c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0xe7d9d
jmp 0xe7e7e
cmpl $-0x1, -0x48(%rbp)
je 0xe7ea0
movq -0x18(%rbp), %rax
movl -0x4c(%rbp), %ecx
movl $0x1, (%rax,%rcx,4)
movq -0x18(%rbp), %rax
movl -0x48(%rbp), %ecx
movl $0x1, (%rax,%rcx,4)
jmp 0xe7ea2
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0xe7f07
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xe7ecf
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0xe7eda
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0xe7eda
movq -0x78(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
imulq $0x28, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq $0x0, 0x20(%rax)
movl -0x48(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x4c(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x50(%rbp), %edx
movq -0x58(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x10(%rax)
cmpl $-0x1, -0x48(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %edx
movq -0x58(%rbp), %rax
movl (%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x58(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
shrl %ecx
movq -0x58(%rbp), %rax
orl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
shrl $0x2, %ecx
movq -0x58(%rbp), %rax
orl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
shrl $0x4, %ecx
movq -0x58(%rbp), %rax
orl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
shrl $0x8, %ecx
movq -0x58(%rbp), %rax
orl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
shrl $0x10, %ecx
movq -0x58(%rbp), %rax
orl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x2270
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0xe8099
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdx
movabsq $0x3ffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFF
andq (%rdx), %rcx
movl -0x1c(%rbp), %edx
addq %rdx, %rcx
movq -0x30(%rbp), %rdx
andq 0x10(%rdx), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x1c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xe8047
jmp 0xe809b
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xe7b55
movq -0x30(%rbp), %rdi
callq 0xe6290
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0xe80da
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xe80b9
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xe815e
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xe810b
jmp 0xe8153
movl -0x1c(%rbp), %edx
shll %edx
orl $0x0, %edx
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x1c(%rbp), %esi
imulq $0x28, %rsi, %rsi
addq %rsi, %rcx
movl 0x4(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %edx
shll %edx
orl $0x1, %edx
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x1c(%rbp), %esi
imulq $0x28, %rsi, %rsi
addq %rsi, %rcx
movl 0x8(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xe80e1
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xe82d9
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xe81a7
jmp 0xe82cb
movq -0x18(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
xorq $0x1, %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0xe82c9
movq -0x18(%rbp), %rax
movq -0x60(%rbp), %rcx
movl 0x8(%rcx), %ecx
cmpl $0x0, (%rax,%rcx,4)
jl 0xe82c9
movq -0x18(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,4), %eax
xorl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x60(%rbp), %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
subl %ecx, %eax
movl %eax, -0x70(%rbp)
cmpl $0x0, -0x70(%rbp)
jge 0xe8231
movl $0x1, -0x70(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xd4050
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq -0x68(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0xc(%rax)
movq -0x68(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movl -0x6c(%rbp), %eax
movl %eax, %ecx
shlq $0x20, %rcx
movslq -0x70(%rbp), %rax
orq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq -0x60(%rbp), %rcx
movl 0x8(%rcx), %ecx
movl (%rax,%rcx,4), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x68(%rbp), %rax
movw 0x10(%rax), %cx
andw $0xc000, %cx            # imm = 0xC000
orw $0x0, %cx
movw %cx, 0x10(%rax)
movq -0x60(%rbp), %rax
movb 0x12(%rax), %cl
movq -0x68(%rbp), %rax
movb %cl, 0x12(%rax)
jmp 0xe82cb
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xe8165
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xe8323
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x1c(%rbp), %esi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
callq 0xcd8f0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xe82e0
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xcdd10
movq -0x18(%rbp), %rdi
callq 0x2210
movq -0x38(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)