// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %rbx
movabsq $0x3ffffffffffffff, %r12 # imm = 0x3FFFFFFFFFFFFFF
movl 0x14(%rdi), %r14d
addl %r14d, %r14d
movl $0x1, %edi
movl $0x20, %esi
callq 0x10f0
movq %rax, %r15
callq 0x3f78
movq %rax, 0x30(%rsp)
movq %rax, 0x18(%r15)
movl $0x4, %esi
movq %r14, %rdi
callq 0x10f0
movq %rax, 0x8(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x10f0
movq %rax, %rbp
movq (%rax), %rax
andq %r12, %rax
btsq $0x3b, %rax
movq %rax, (%rbp)
movq $0x3, 0x10(%rbp)
movl $0x20, %edi
callq 0x1160
movq %rbx, %r9
movq %rax, 0x18(%rbp)
movl %r14d, %ebx
movq %r14, 0x38(%rsp)
testl %r14d, %r14d
movq %r15, 0x18(%rsp)
movq %r9, 0x20(%rsp)
je 0x72d9
xorl %r13d, %r13d
movq %rbx, 0x40(%rsp)
movq 0x18(%r9), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,4)
js 0x72cd
movq 0x20(%r9), %rax
cmpl $0x0, (%rax,%r13,8)
je 0x72cd
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax,%r13,4)
jne 0x72cd
movq 0x8(%rsp), %r8
movl $0x1, (%r8,%r13,4)
movq $0x0, 0x8(%rbp)
movl %r13d, %eax
xorl $0x1, %eax
movl %eax, 0x10(%rsp)
movq 0x20(%r9), %rdi
movq (%rdi,%r13,8), %rax
xorl %ebx, %ebx
cmpl $0x1, %eax
jne 0x6fec
movq 0x8(%r9), %rdx
shrq $0x20, %rax
movq %rax, %rcx
shlq $0x4, %rcx
movl 0x8(%rdx,%rcx), %ecx
movq %rcx, %rsi
xorq $0x1, %rsi
cmpl $0x1, (%rdi,%rsi,8)
jne 0x6fec
xorl %ebx, %ebx
movl %r13d, %r11d
movq %r13, %r12
movl %r11d, %edi
movl $0x1, %r10d
xorl %r10d, %edi
movl %r10d, (%r8,%rdi,4)
movl %ecx, %r11d
movl %ecx, %r15d
movl %r10d, (%r8,%r15,4)
shlq $0x4, %rax
movq (%rbp), %rcx
shrq $0x3a, %rcx
movl $0x1, %edi
shlq %cl, %rdi
movq (%rdx,%rax), %r14
movl %esi, 0x10(%rsp)
cmpq %rdi, 0x8(%rbp)
jne 0x6f7a
incl %ecx
movq %rbp, %rdi
movl %ecx, %esi
movl %r11d, 0x2c(%rsp)
callq 0x7bc9
movl 0x2c(%rsp), %r11d
movq 0x20(%rsp), %r9
movq 0x8(%rsp), %r8
movq 0x8(%rbp), %rax
movq 0x18(%rbp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%rbp)
movq (%rbp), %rdx
movabsq $0x3ffffffffffffff, %rsi # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rdx
addq %rax, %rdx
movl %r14d, %eax
shlq $0x20, %r12
andq 0x10(%rbp), %rdx
orq %rax, %r12
movq %r12, (%rcx,%rdx,8)
addl %r14d, %ebx
cmpq %r15, %r13
je 0x6fec
movq 0x20(%r9), %rdi
movq (%rdi,%r15,8), %rax
cmpl $0x1, %eax
jne 0x6fec
movq 0x8(%r9), %rdx
shrq $0x20, %rax
movq %rax, %rcx
shlq $0x4, %rcx
movl 0x8(%rdx,%rcx), %ecx
movq %rcx, %rsi
xorq $0x1, %rsi
cmpl $0x1, (%rdi,%rsi,8)
movq %r15, %r12
je 0x6f1e
movl 0x10(%rsp), %eax
movl %eax, %r15d
xorl $0x1, %r15d
cmpq %r15, %r13
jne 0x7016
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpq $0x0, 0x8(%rbp)
je 0x7016
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
jmp 0x718e
movq 0x18(%r9), %rax
movl 0x10(%rsp), %ecx
movl %ecx, %edx
movq (%rbp), %rcx
shrq $0x3a, %rcx
movl $0x1, %esi
shlq %cl, %rsi
shrl %edx
movl (%rax,%rdx,4), %r14d
cmpq %rsi, 0x8(%rbp)
jne 0x7052
incl %ecx
movq %rbp, %rdi
movl %ecx, %esi
callq 0x7bc9
movq 0x20(%rsp), %r9
movq 0x8(%rsp), %r8
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
shlq $0x20, %r15
movq 0x8(%rbp), %rax
movq 0x18(%rbp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%rbp)
movq (%rbp), %rdx
movabsq $0x3ffffffffffffff, %rsi # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rdx
addq %rax, %rdx
andq 0x10(%rbp), %rdx
orq %r14, %r15
movq %r15, (%rcx,%rdx,8)
addl %r14d, %ebx
movq 0x20(%r9), %rax
movl %r13d, %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rcx
movl %r13d, %r14d
cmpl $0x1, %ecx
jne 0x718e
movq 0x8(%r9), %rdx
shrq $0x1c, %rcx
andq $-0x10, %rcx
movl 0x8(%rdx,%rcx), %r12d
movq %r12, %r15
xorq $0x1, %r15
movq (%rax,%r15,8), %rax
cmpl $0x1, %eax
jne 0x718e
movl $0x1, %esi
movl %esi, (%r8,%r12,4)
movl %r14d, %ecx
movl %esi, (%r8,%rcx,4)
shrq $0x1c, %rax
movq (%rbp), %rcx
shrq $0x3a, %rcx
movl $0x1, %esi
shlq %cl, %rsi
andq $-0x10, %rax
movq (%rdx,%rax), %r14
cmpq %rsi, 0x8(%rbp)
jne 0x7117
incl %ecx
movq %rbp, %rdi
movl %ecx, %esi
callq 0x7bc9
movq 0x20(%rsp), %r9
movq 0x8(%rsp), %r8
movl %r14d, %eax
movq %r15, %rdx
shlq $0x20, %rdx
orq %rax, %rdx
incq 0x8(%rbp)
movq (%rbp), %rax
movq %rax, %rcx
shrq $0x3a, %rcx
movq $-0x1, %rsi
shlq %cl, %rsi
movq 0x18(%rbp), %rcx
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
leaq (%rax,%r10), %rdi
testq %r10, %rax
notq %rsi
cmovneq %rdi, %rsi
andq %r10, %rsi
movabsq $-0x400000000000000, %rdi # imm = 0xFC00000000000000
andq %rdi, %rax
orq %rsi, %rax
movq %rax, (%rbp)
movq %rdx, (%rcx,%rsi,8)
addl %r14d, %ebx
movq 0x20(%r9), %rax
movq (%rax,%r12,8), %rcx
movl %r15d, %r14d
cmpl $0x1, %ecx
je 0x70aa
movl %r15d, %r14d
cmpl $-0x1, %r14d
movq 0x18(%rsp), %r15
je 0x71ad
movl 0x10(%rsp), %eax
movl $0x1, %ecx
movl %ecx, (%r8,%rax,4)
movl %r14d, %eax
movl %ecx, (%r8,%rax,4)
movq (%r15), %r12
movq 0x8(%r15), %rax
cmpq %rax, %r12
jne 0x71e2
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
callq 0x1180
movq %rax, 0x10(%r15)
xorl %eax, %eax
cmpl $-0x1, %r14d
sete %al
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %r15
leaq 0x1(%r12), %rcx
movq 0x18(%rsp), %rdx
movq %rcx, (%rdx)
leaq (%r12,%r12,4), %r12
movq $0x0, 0x20(%r15,%r12,8)
movl %r14d, 0x4(%r15,%r12,8)
movl 0x10(%rsp), %ecx
movl %ecx, 0x8(%r15,%r12,8)
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movl (%r15,%r12,8), %ecx
movl $0x80000000, %edx       # imm = 0x80000000
andl %edx, %ecx
orl %ebx, %ecx
movl %ecx, (%r15,%r12,8)
movq 0x8(%rbp), %r14
movl %r14d, 0x10(%r15,%r12,8)
shll $0x1f, %eax
orl %ebx, %eax
movl %eax, (%r15,%r12,8)
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(%r15,%r12,8)
leal 0x8(,%rcx,8), %edi
callq 0x1160
movq %rax, 0x18(%r15,%r12,8)
movq 0x18(%rsp), %r15
testq %r14, %r14
movq 0x20(%rsp), %r9
movq 0x40(%rsp), %rbx
je 0x72cd
movq 0x10(%rbp), %rcx
movq 0x18(%rbp), %rdx
movq (%rbp), %rsi
movabsq $0x3ffffffffffffff, %rdi # imm = 0x3FFFFFFFFFFFFFF
andq %rdi, %rsi
xorl %edi, %edi
leaq (%rsi,%rdi), %r8
andq %rcx, %r8
movq (%rdx,%r8,8), %r8
movq %r8, (%rax,%rdi,8)
incq %rdi
movl %edi, %r8d
cmpq %r8, %r14
ja 0x72b3
incq %r13
cmpq %rbx, %r13
jne 0x6e8e
movq 0x18(%rbp), %rdi
callq 0x1040
movq %rbp, %rdi
callq 0x1040
cmpl $0x0, 0x38(%rsp)
je 0x7307
shlq $0x2, %rbx
movq 0x8(%rsp), %rdi
movl $0xff, %esi
movq %rbx, %rdx
callq 0x10d0
movq (%r15), %rbx
testq %rbx, %rbx
movq 0x8(%rsp), %r8
movq 0x20(%rsp), %r9
je 0x7351
movq 0x10(%r15), %rax
addq $0x8, %rax
movl $0x1, %ecx
movl $0x1, %edx
cmpl $0x0, -0x8(%rax)
js 0x7341
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, %rbx
ja 0x732b
testl $0x7fffffff, 0x4(%r9)   # imm = 0x7FFFFFFF
je 0x748e
movl $0xc, %r14d
xorl %r13d, %r13d
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq %rbx, 0x10(%rsp)
movq 0x30(%rsp), %r12
movq 0x8(%r9), %rbp
movl (%rbp,%r14), %eax
testl %eax, %eax
js 0x7475
movl -0x8(%rbp,%r14), %ecx
shlq $0x2, %rcx
xorq $0x4, %rcx
movl (%r8,%rcx), %r15d
testl %r15d, %r15d
js 0x7475
movl -0x4(%rbp,%r14), %ecx
cmpl $0x0, (%r8,%rcx,4)
js 0x7475
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rcx
movl %r15d, %edx
shrl %edx
leaq (%rdx,%rdx,4), %rdx
movl (%rcx,%rdx,8), %ecx
andl %edi, %ecx
subl %eax, %ecx
movl $0x1, %r10d
js 0x73d6
movl %ecx, %r10d
movl 0x4(%r12), %ecx
andl %edi, %ecx
movl (%r12), %eax
cmpl %eax, %ecx
jne 0x7423
leal (%rax,%rax), %esi
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %esi
movl %esi, (%r12)
movq 0x8(%r12), %rdi
shlq $0x4, %rsi
movl %r10d, %ebx
callq 0x1180
movl %ebx, %r10d
movq 0x10(%rsp), %rbx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq 0x20(%rsp), %r9
movq 0x8(%rsp), %r8
movq %rax, 0x8(%r12)
xorl $0x1, %r15d
movq 0x8(%r12), %rax
movl 0x4(%r12), %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(%r12)
shlq $0x4, %rdx
movl (%rbp,%r14), %ecx
andl %edi, %ecx
movl %ecx, 0xc(%rax,%rdx)
shlq $0x20, %r15
movslq %r10d, %rcx
orq %r15, %rcx
movq %rcx, (%rax,%rdx)
movl -0x4(%rbp,%r14), %ecx
movl (%r8,%rcx,4), %ecx
movl %ecx, 0x8(%rax,%rdx)
incq %r13
movl 0x4(%r9), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq $0x10, %r14
cmpq %rax, %r13
jb 0x7377
testq %rbx, %rbx
movq 0x18(%rsp), %r15
movq 0x30(%rsp), %r13
je 0x74c8
movq 0x10(%r15), %r14
xorl %r12d, %r12d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
leaq (%r12,%r12,4), %rax
movl (%r14,%rax,8), %edx
andl %ebp, %edx
movq %r13, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x4074
incl %r12d
cmpq %r12, %rbx
ja 0x74a9
movq %r13, %rdi
callq 0x41c9
movq 0x8(%rsp), %rdi
callq 0x1040
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq