// File: /workspace/github_c_makefile_star2_O3/rikuu[P]kermit/miniasm/asm.c
// Function: ma_ug_gen
ma_ug_t *ma_ug_gen(asg_t *g)
{
	int32_t *mark;
	uint32_t i, v, n_vtx = g->n_seq * 2;
	kdq_t(uint64_t) *q;
	ma_ug_t *ug;

	ug = (ma_ug_t*)calloc(1, sizeof(ma_ug_t));
	ug->g = asg_init();
	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 || arc_cnt(g, v) == 0 || mark[v]) continue;
		mark[v] = 1;
		q->count = 0, start = v, end = v^1, len = 0;
		// forward
		w = v;
		while (1) {
			if (arc_cnt(g, w) != 1) break;
			x = arc_first(g, w).v; // w->x
			if (arc_cnt(g, x^1) != 1) break;
			mark[x] = mark[w^1] = 1;
			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;
		}
		if (start != (end^1) || kdq_size(q) == 0) { // linear unitig
			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));
			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);
		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
	for (v = 0; v < n_vtx; ++v) mark[v] = -1;
	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;
	}
	for (i = 0; i < g->n_arc; ++i) {
		asg_arc_t *p = &g->arc[i];
		if (p->del) continue;
		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];
		}
	}
	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 $0x58, %rsp
movabsq $0x800000000000000, %r13 # imm = 0x800000000000000
movq %rdi, 0x10(%rsp)
movl 0x14(%rdi), %r14d
addl %r14d, %r14d
movl $0x1, %edi
movl $0x20, %esi
callq 0x10f0
movq %rax, %rbx
callq 0x3e60
movq %rbx, 0x20(%rsp)
movq %rax, 0x48(%rsp)
movq %rax, 0x18(%rbx)
movl $0x4, %esi
movq %r14, %rdi
callq 0x10f0
movq %rax, 0x8(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x10f0
movq %rax, %rbx
movq %r13, (%rax)
movq $0x3, 0x10(%rax)
movl $0x20, %edi
callq 0x1160
movq %rbx, %r11
movq %rax, %r9
movq %rax, 0x18(%rbx)
testl %r14d, %r14d
je 0x7180
movq $0x0, 0x18(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movq $0x0, 0x38(%rsp)
xorl %ebp, %ebp
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r10
movq %r14, 0x40(%rsp)
movq %r11, 0x30(%rsp)
movq 0x18(%r10), %rax
movl %ebp, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,4)
js 0x715b
movq 0x20(%r10), %rax
movq (%rax,%rbp,8), %rcx
movq %rcx, %rdx
andq %rsi, %rdx
je 0x715b
cmpl $0x0, (%r8,%rbp,4)
jne 0x715b
movl $0x1, (%r8,%rbp,4)
movq $0x0, 0x8(%r11)
movl %ebp, %r15d
xorl $0x1, %r15d
cmpl $0x1, %edx
movq %r12, 0x50(%rsp)
jne 0x6dc1
movq %r10, %rdx
movq %r8, %r10
movq 0x8(%rdx), %rdx
shrq $0x20, %rcx
movq %rcx, %rsi
shlq $0x4, %rsi
movl 0x8(%rdx,%rsi), %esi
movq %rsi, %rdi
xorq $0x1, %rdi
cmpl $0x1, (%rax,%rdi,8)
movl %r15d, 0x28(%rsp)
jne 0x6dcd
xorl %r12d, %r12d
movl %ebp, %r8d
movq %rbp, %r14
xorl %eax, %eax
movl $0x1, %ebx
xorl %ebx, %r8d
movl %ebx, (%r10,%r8,4)
movl %edi, 0x4(%rsp)
movl %esi, 0x18(%rsp)
movl %esi, %r15d
movl %ebx, (%r10,%r15,4)
shlq $0x4, %rcx
movq (%rdx,%rcx), %rbx
movq %r13, %rcx
shrq $0x3a, %rcx
movl $0x1, %edx
shlq %cl, %rdx
cmpq %rdx, %rax
movq %r9, %rdi
jne 0x6d4a
incl %ecx
movq %r11, %rdi
movl %ecx, %esi
callq 0x7a99
movq 0x30(%rsp), %r11
movq 0x8(%rsp), %r10
movq (%r11), %r13
movq 0x8(%r11), %rax
movq 0x18(%r11), %rdi
movl %ebx, %ecx
shlq $0x20, %r14
movq %r13, %rdx
movabsq $0x3ffffffffffffff, %rsi # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rdx
addq %rax, %rdx
incq %rax
movq %rax, 0x8(%r11)
andq 0x10(%r11), %rdx
orq %rcx, %r14
movq %rdi, %r9
movq %r14, (%rdi,%rdx,8)
addl %ebx, %r12d
cmpq %r15, %rbp
je 0x6dd7
movq 0x10(%rsp), %rdx
movq 0x20(%rdx), %r8
movq (%r8,%r15,8), %rcx
cmpl $0x1, %ecx
jne 0x6dd7
movq 0x8(%rdx), %rdx
shrq $0x20, %rcx
movq %rcx, %rsi
shlq $0x4, %rsi
movl 0x8(%rdx,%rsi), %esi
movq %rsi, %rdi
xorq $0x1, %rdi
cmpl $0x1, (%r8,%rdi,8)
movq %r15, %r14
movl 0x18(%rsp), %r8d
je 0x6cef
jmp 0x6dd7
movl %ebp, %ebx
xorl %r12d, %r12d
movl %r15d, %edx
xorl %eax, %eax
jmp 0x6e13
xorl %eax, %eax
movl %r15d, 0x4(%rsp)
xorl %r12d, %r12d
movl 0x4(%rsp), %edx
movl %edx, %ebx
xorl $0x1, %ebx
cmpq %rbx, %rbp
jne 0x6dff
testq %rax, %rax
je 0x6e04
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x80000000, %r8d       # imm = 0x80000000
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0x6fda
movq %r10, %r8
jmp 0x6e09
movq %r10, %r8
xorl %eax, %eax
movq 0x10(%rsp), %r10
movl 0x28(%rsp), %r15d
movq 0x18(%r10), %rcx
movl %edx, 0x4(%rsp)
shrl %edx
movl (%rcx,%rdx,4), %r14d
movq %r13, %rcx
shrq $0x3a, %rcx
movl $0x1, %edx
shlq %cl, %rdx
cmpq %rdx, %rax
jne 0x6e5b
incl %ecx
movq %r11, %rdi
movl %ecx, %esi
callq 0x7a99
movq 0x30(%rsp), %r11
movq 0x10(%rsp), %r10
movq 0x8(%rsp), %r8
movq (%r11), %r13
movq 0x8(%r11), %rax
movq 0x18(%r11), %r9
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
shlq $0x20, %rbx
orq %r14, %rbx
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r11)
movq %r13, %rcx
movabsq $0x3ffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFF
andq %rdx, %rcx
addq %rax, %rcx
andq 0x10(%r11), %rcx
movq %rbx, (%r9,%rcx,8)
addl %r14d, %r12d
movq 0x20(%r10), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdx
cmpl $0x1, %edx
jne 0x6fbb
movq 0x8(%r10), %rcx
shrq $0x1c, %rdx
andq $-0x10, %rdx
movl 0x8(%rcx,%rdx), %edx
movq %rdx, %rbx
xorq $0x1, %rbx
movq (%rax,%rbx,8), %rsi
cmpl $0x1, %esi
jne 0x6fbb
movl %ebp, %edi
movl %edi, %edi
movl %ebx, 0x18(%rsp)
movl %edx, %r14d
movl $0x1, %edx
movl %edx, (%r8,%r14,4)
movl %edx, (%r8,%rdi,4)
shrq $0x1c, %rsi
andq $-0x10, %rsi
movq (%rcx,%rsi), %r15
movq 0x8(%r11), %rdx
movq %r13, %rcx
shrq $0x3a, %rcx
movl $0x1, %esi
shlq %cl, %rsi
cmpq %rsi, %rdx
jne 0x6f34
incl %ecx
movq %r11, %rdi
movl %ecx, %esi
callq 0x7a99
movq 0x30(%rsp), %r11
movq 0x10(%rsp), %r10
movq 0x8(%rsp), %r8
movq (%r11), %r13
movq 0x8(%r11), %rdx
movq %r13, %rcx
shrq $0x3a, %rcx
movq 0x18(%r11), %r9
movq 0x20(%r10), %rax
movl %r15d, %esi
shlq $0x20, %rbx
orq %rsi, %rbx
incq %rdx
movq %rdx, 0x8(%r11)
movabsq $0x3ffffffffffffff, %rdi # imm = 0x3FFFFFFFFFFFFFF
leaq (%rdi,%r13), %rdx
movq $-0x1, %rsi
shlq %cl, %rsi
testq %rdi, %r13
notq %rsi
cmovneq %rdx, %rsi
andq %rdi, %rsi
movabsq $-0x400000000000000, %rcx # imm = 0xFC00000000000000
andq %rcx, %r13
orq %rsi, %r13
movq %r13, (%r11)
movq %rbx, (%r9,%rsi,8)
addl %r15d, %r12d
movq (%rax,%r14,8), %rdx
cmpl $0x1, %edx
jne 0x7169
movq 0x8(%r10), %rcx
shrq $0x1c, %rdx
andq $-0x10, %rdx
movl 0x8(%rcx,%rdx), %edx
movq %rdx, %rbx
xorq $0x1, %rbx
movq (%rax,%rbx,8), %rsi
cmpl $0x1, %esi
movl 0x18(%rsp), %edi
je 0x6ec9
jmp 0x6fbd
movl %ebp, %edi
cmpl $-0x1, %edi
je 0x6fe1
movl 0x4(%rsp), %esi
movl %esi, %eax
movl $0x1, %ecx
movl %ecx, (%r8,%rax,4)
movl %edi, %eax
movl %ecx, (%r8,%rax,4)
xorl %r8d, %r8d
movq 0x20(%rsp), %rcx
jmp 0x6ff5
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x80000000, %r8d       # imm = 0x80000000
movq 0x20(%rsp), %rcx
movl 0x4(%rsp), %esi
movq %r9, 0x28(%rsp)
movq (%rcx), %r14
cmpq 0x8(%rcx), %r14
jne 0x704e
leaq (%r14,%r14), %rax
testq %r14, %r14
movl $0x2, %edx
cmoveq %rdx, %rax
movq %rax, 0x8(%rcx)
shlq $0x3, %rax
movl %esi, 0x4(%rsp)
leaq (%rax,%rax,4), %rsi
movl %edi, %ebx
movq 0x38(%rsp), %rdi
movl %r8d, %r15d
callq 0x1180
movl %r15d, %r8d
movl %ebx, %edi
movl 0x4(%rsp), %esi
movq 0x30(%rsp), %r11
movq 0x20(%rsp), %rcx
movq %rax, 0x50(%rsp)
movq %rax, 0x10(%rcx)
leaq 0x1(%r14), %rdx
movq %rdx, 0x18(%rsp)
movq %rdx, (%rcx)
leaq (%r14,%r14,4), %r15
movq 0x50(%rsp), %rdx
movq $0x0, 0x20(%rdx,%r15,8)
movl %edi, 0x4(%rdx,%r15,8)
movl %esi, 0x8(%rdx,%r15,8)
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl (%rdx,%r15,8), %eax
movl $0x80000000, %ecx       # imm = 0x80000000
andl %ecx, %eax
orl %r12d, %eax
movl %eax, (%rdx,%r15,8)
movq 0x8(%r11), %r14
movl %r14d, 0x10(%rdx,%r15,8)
orl %r8d, %r12d
movl %r12d, (%rdx,%r15,8)
movq %rdx, %r12
leal -0x1(%r14), %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(%rdx,%r15,8)
leal 0x8(,%rcx,8), %edi
movq %r11, %rbx
callq 0x1160
movq %rax, 0x18(%r12,%r15,8)
testq %r14, %r14
je 0x713a
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %r9
movq %r13, %rdx
movabsq $0x3ffffffffffffff, %rsi # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rdx
xorl %esi, %esi
movq 0x10(%rsp), %r10
movq %rbx, %r11
leaq (%rdx,%rsi), %rdi
andq %rcx, %rdi
movq (%r9,%rdi,8), %rdi
movq %rdi, (%rax,%rsi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %r14
ja 0x710b
movq %r12, 0x38(%rsp)
movq 0x8(%rsp), %r8
movq 0x40(%rsp), %r14
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
jmp 0x715b
movq %r12, 0x38(%rsp)
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r10
movq 0x40(%rsp), %r14
movq %rbx, %r11
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq 0x28(%rsp), %r9
incq %rbp
cmpq %r14, %rbp
jne 0x6c5f
jmp 0x7172
movl 0x18(%rsp), %edi
jmp 0x6fbd
movq 0x18(%r11), %r9
movq %r11, %rbx
movq 0x18(%rsp), %r15
jmp 0x7186
xorl %r15d, %r15d
movq %r11, %rbx
movq %r9, %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x1040
testq %r14, %r14
je 0x71b2
leaq (,%r14,4), %rdx
movq 0x8(%rsp), %rdi
movl $0xff, %esi
callq 0x10d0
testq %r15, %r15
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r9
je 0x71fe
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
addq $0x8, %rax
movl $0x1, %ecx
movl $0x1, %edx
cmpl $0x0, -0x8(%rax)
js 0x71ee
leal -0x1(%rcx), %esi
movl -0x4(%rax), %edi
movl %esi, (%r8,%rdi,4)
movl (%rax), %esi
movl %ecx, (%r8,%rsi,4)
movl %edx, %esi
addq $0x28, %rax
incl %edx
addl $0x2, %ecx
cmpq %rsi, %r15
ja 0x71d8
movq %r15, 0x18(%rsp)
movl 0x4(%r9), %eax
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x732a
movl $0xc, %ebx
xorl %r14d, %r14d
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq 0x48(%rsp), %rbp
movq 0x8(%r9), %r12
movl (%r12,%rbx), %ecx
testl %ecx, %ecx
js 0x7312
movl -0x8(%r12,%rbx), %edx
shlq $0x2, %rdx
xorq $0x4, %rdx
movl (%r8,%rdx), %r13d
testl %r13d, %r13d
js 0x7312
movl -0x4(%r12,%rbx), %edx
cmpl $0x0, (%r8,%rdx,4)
js 0x7312
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl %r13d, %edx
shrl %edx
leaq (%rdx,%rdx,4), %rdx
movl (%rax,%rdx,8), %eax
andl %edi, %eax
subl %ecx, %eax
movl $0x1, %r15d
js 0x7282
movl %eax, %r15d
movl 0x4(%rbp), %edx
movl %edx, %ecx
andl %edi, %ecx
cmpl (%rbp), %ecx
jne 0x72cb
leal (%rcx,%rcx), %esi
testl %ecx, %ecx
movl $0x10, %eax
cmovel %eax, %esi
movl %esi, (%rbp)
movq 0x8(%rbp), %rdi
shlq $0x4, %rsi
callq 0x1180
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r8
movq %rax, 0x8(%rbp)
movl 0x4(%rbp), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x72cf
movq 0x8(%rbp), %rax
xorl $0x1, %r13d
leal 0x1(%rdx), %esi
andl %edi, %esi
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%rbp)
movl %ecx, %ecx
shlq $0x4, %rcx
movl (%r12,%rbx), %edx
andl %edi, %edx
movl %edx, 0xc(%rax,%rcx)
shlq $0x20, %r13
movslq %r15d, %rdx
orq %r13, %rdx
movq %rdx, (%rax,%rcx)
movl -0x4(%r12,%rbx), %edx
movl (%r8,%rdx,4), %edx
movl %edx, 0x8(%rax,%rcx)
movl 0x4(%r9), %eax
incq %r14
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq $0x10, %rbx
cmpq %rcx, %r14
jb 0x7224
movq 0x18(%rsp), %r12
testq %r12, %r12
movq 0x48(%rsp), %r15
je 0x7366
movq 0x20(%rsp), %rax
movq 0x10(%rax), %r14
xorl %ebx, %ebx
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
leaq (%rbx,%rbx,4), %rax
movl (%r14,%rax,8), %edx
andl %ebp, %edx
movq %r15, %rdi
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x3f77
incl %ebx
cmpq %rbx, %r12
ja 0x7349
movq %r15, %rdi
callq 0x40c7
movq 0x8(%rsp), %rdi
callq 0x1040
movq 0x20(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq