// File: /workspace/github_c_makefile_star2_O1/lh3[P]fermi-lite/misc.c
// Function: fml_mag2utg
fml_utg_t *fml_mag2utg(struct mag_t *g, int *n)
{
	size_t i, j;
	fml_utg_t *utg;
	khash_t(64) *h;
	khint_t k;

	h = kh_init(64);
	for (i = j = 0; i < g->v.n; ++i) {
		int absent;
		magv_t *p = &g->v.a[i];
		if (p->len < 0) continue;
		k = kh_put(64, h, p->k[0], &absent);
		kh_val(h, k) = j<<1 | 0;
		k = kh_put(64, h, p->k[1], &absent);
		kh_val(h, k) = j<<1 | 1;
		++j;
	}
	*n = j;
	kh_destroy(64, g->h);

	utg = (fml_utg_t*)calloc(*n, sizeof(fml_utg_t));
	for (i = j = 0; i < g->v.n; ++i) {
		magv_t *p = &g->v.a[i];
		fml_utg_t *q;
		int from, a, b;
		if (p->len < 0) continue;
		q = &utg[j++];
		q->len = p->len, q->nsr = p->nsr;
		q->seq = p->seq, q->cov = p->cov;
		for (a = 0; a < q->len; ++a)
			q->seq[a] = "$ACGTN"[(int)q->seq[a]];
		q->seq[q->len] = q->cov[q->len] = 0;
		for (from = 0; from < 2; ++from) {
			ku128_v *r = &p->nei[from];
			for (b = q->n_ovlp[from] = 0; b < r->n; ++b)
				if (!edge_is_del(r->a[b])) ++q->n_ovlp[from];
		}
		q->ovlp = (fml_ovlp_t*)calloc(q->n_ovlp[0] + q->n_ovlp[1], sizeof(fml_ovlp_t));
		for (from = a = 0; from < 2; ++from) {
			ku128_v *r = &p->nei[from];
			for (b = 0; b < r->n; ++b) {
				ku128_t *s = &r->a[b];
				fml_ovlp_t *t;
				if (edge_is_del(*s)) continue;
				t = &q->ovlp[a++];
				k = kh_get(64, h, s->x);
				assert(k != kh_end(h));
				t->id = kh_val(h, k) >> 1;
				t->to = kh_val(h, k) & 1;
				t->len = s->y;
				t->from = from;
			}
			free(p->nei[from].a);
		}
	}
	kh_destroy(64, h);
	free(g->v.a);
	free(g);
	return utg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %rbx
callq 0xc85c
cmpq $0x0, (%rbx)
movq %rbx, 0x8(%rsp)
movq %rax, (%rsp)
je 0x2d62
movq %rbx, %rsi
movq %rax, %rdi
movl $0x18, %r14d
xorl %r13d, %r13d
leaq 0x44(%rsp), %r12
xorl %ebx, %ebx
movq 0x10(%rsi), %rbp
cmpl $0x0, -0x18(%rbp,%r14)
js 0x2d54
movq -0x8(%rbp,%r14), %rsi
movq %r12, %rdx
callq 0xcba8
leaq (%rbx,%rbx), %rcx
movq (%rsp), %rdx
movq 0x20(%rdx), %rdx
movl %eax, %eax
movq %rcx, (%rdx,%rax,8)
movq (%rbp,%r14), %rsi
movq (%rsp), %rdi
movq %r12, %rdx
callq 0xcba8
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq 0x1(,%rbx,2), %rcx
movq 0x20(%rdi), %rdx
movl %eax, %eax
movq %rcx, (%rdx,%rax,8)
incq %rbx
incq %r13
addq $0x68, %r14
cmpq (%rsi), %r13
jb 0x2cfa
jmp 0x2d64
xorl %ebx, %ebx
movl %ebx, (%r15)
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0xc86b
movslq (%r15), %rdi
movl $0x28, %esi
callq 0x2130
movq 0x8(%rsp), %rbx
movq %rax, %r14
cmpq $0x0, (%rbx)
movq (%rsp), %rdi
je 0x2fb1
leaq 0x14619(%rip), %r9      # 0x173b8
xorl %edx, %edx
xorl %r10d, %r10d
movq %r14, 0x10(%rsp)
movq 0x10(%rbx), %r13
imulq $0x68, %rdx, %rcx
movslq (%r13,%rcx), %rax
testq %rax, %rax
js 0x2fa5
movq %rdx, 0x20(%rsp)
addq %rcx, %r13
leaq (%r10,%r10,4), %rcx
movl %eax, (%r14,%rcx,8)
movl 0x4(%r13), %edx
movl %edx, 0x4(%r14,%rcx,8)
movq 0x50(%r13), %rdx
movq %rdx, 0x8(%r14,%rcx,8)
movq 0x58(%r13), %rsi
movq %rsi, 0x10(%r14,%rcx,8)
testl %eax, %eax
je 0x2e05
xorl %edi, %edi
movsbq (%rdx,%rdi), %r8
movb (%r8,%r9), %r8b
movb %r8b, (%rdx,%rdi)
incq %rdi
cmpq %rdi, %rax
jne 0x2df0
incq %r10
leaq (%r14,%rcx,8), %rbx
xorl %ecx, %ecx
movb %cl, (%rsi,%rax)
movb %cl, (%rdx,%rax)
addq $0x20, %r13
xorl %eax, %eax
leaq (%rax,%rax,2), %rdx
movl $0x0, 0x18(%rbx,%rax,4)
movq (%r13,%rdx,8), %rcx
testq %rcx, %rcx
je 0x2e5d
leaq (,%rdx,8), %rdx
addq %r13, %rdx
movq 0x10(%rdx), %rdx
addq $0x8, %rdx
cmpq $-0x2, -0x8(%rdx)
je 0x2e54
cmpq $0x0, (%rdx)
je 0x2e54
incl 0x18(%rbx,%rax,4)
addq $0x10, %rdx
decq %rcx
jne 0x2e43
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0x2e1a
movq %r10, 0x18(%rsp)
movslq 0x18(%rbx), %rax
movslq 0x1c(%rbx), %rdi
addq %rax, %rdi
movl $0x8, %esi
callq 0x2130
movq %rax, %r12
movq %rax, 0x20(%rbx)
xorl %ecx, %ecx
xorl %r15d, %r15d
movq %r13, 0x28(%rsp)
leaq (%rcx,%rcx,2), %rax
leaq (,%rax,8), %rbp
addq %r13, %rbp
cmpq $0x0, (%rbp)
movq %rcx, 0x30(%rsp)
je 0x2f63
shlq $0x1f, %rcx
movq %rcx, 0x38(%rsp)
movl $0x8, %ebx
xorl %r14d, %r14d
movq (%rsp), %rdi
movq 0x10(%rbp), %r13
movq -0x8(%r13,%rbx), %rsi
cmpq $-0x2, %rsi
je 0x2f52
cmpq $0x0, (%r13,%rbx)
je 0x2f52
callq 0xc8d4
movq (%rsp), %rdi
cmpl (%rdi), %eax
je 0x2fd9
movslq %r15d, %rcx
leal 0x1(%rcx), %r15d
movq 0x20(%rdi), %rdx
movl %eax, %esi
movq (%rdx,%rsi,8), %rax
andl $-0x2, %eax
shlq $0x1f, %rax
movq (%r12,%rcx,8), %rdx
movabsq $-0x7fffffff00000001, %r8 # imm = 0x80000000FFFFFFFF
andq %r8, %rdx
orq %rax, %rdx
movq %rdx, (%r12,%rcx,8)
movq 0x20(%rdi), %r8
movq (%r8,%rsi,8), %rsi
shlq $0x3f, %rsi
btrq $0x3f, %rdx
orq %rsi, %rdx
movq %rdx, (%r12,%rcx,8)
movq (%r13,%rbx), %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orq 0x38(%rsp), %rdx
orq %rsi, %rdx
orq %rax, %rdx
movq %rdx, (%r12,%rcx,8)
incq %r14
addq $0x10, %rbx
cmpq %r14, (%rbp)
ja 0x2ec8
movq 0x10(%rbp), %rdi
callq 0x2040
movq 0x30(%rsp), %rcx
leaq 0x1(%rcx), %rax
testq %rcx, %rcx
movq %rax, %rcx
movq 0x28(%rsp), %r13
je 0x2e94
movq 0x8(%rsp), %rbx
movq (%rsp), %rdi
movq 0x10(%rsp), %r14
leaq 0x1441d(%rip), %r9      # 0x173b8
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %r10
incq %rdx
cmpq (%rbx), %rdx
jb 0x2da9
callq 0xc86b
movq 0x10(%rbx), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x2040
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x143df(%rip), %rdi     # 0x173bf
leaq 0x143e7(%rip), %rsi     # 0x173ce
leaq 0x143e7(%rip), %rcx     # 0x173d5
movl $0xc8, %edx
callq 0x20e0