// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
pushq $0x18
popq %r14
xorl %ebx, %ebx
callq 0xafb0
movq %rax, %rdi
leaq 0x44(%rsp), %r12
xorl %r13d, %r13d
movq %rax, (%rsp)
movq 0x10(%rsp), %rbp
cmpq (%rbp), %r13
jae 0x2b97
movq 0x10(%rbp), %rbp
cmpl $0x0, -0x18(%rbp,%r14)
js 0x2b8e
movq -0x8(%rbp,%r14), %rsi
movq %r12, %rdx
callq 0xb2d5
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 0xb2d5
movq (%rsp), %rdi
leaq 0x1(,%rbx,2), %rcx
movq 0x20(%rdi), %rdx
movl %eax, %eax
movq %rcx, (%rdx,%rax,8)
incq %rbx
incq %r13
addq $0x68, %r14
jmp 0x2b2e
movl %ebx, (%r15)
movq 0x20(%rbp), %rdi
callq 0xafbb
movslq (%r15), %rdi
pushq $0x28
popq %rsi
callq 0x2130
movq (%rsp), %rdi
movq %rax, 0x8(%rsp)
pushq $0x8
popq %r14
leaq 0x117f6(%rip), %r8      # 0x143b8
xorl %r9d, %r9d
xorl %r10d, %r10d
movq %rbp, %rbx
cmpq (%rbx), %r10
jae 0x2db8
movq 0x10(%rbx), %r12
imulq $0x68, %r10, %rcx
movslq (%r12,%rcx), %rax
testq %rax, %rax
js 0x2db0
addq %rcx, %r12
imulq $0x28, %r9, %rsi
movq 0x8(%rsp), %rdi
leaq (%rdi,%rsi), %rbx
movl %eax, (%rdi,%rsi)
movl 0x4(%r12), %ecx
movl %ecx, 0x4(%rdi,%rsi)
movq 0x50(%r12), %rcx
movq %rcx, 0x8(%rdi,%rsi)
movq 0x58(%r12), %rdx
movq %rdx, 0x10(%rdi,%rsi)
xorl %esi, %esi
cmpq %rsi, %rax
je 0x2c32
movsbq (%rcx,%rsi), %rdi
movb (%rdi,%r8), %dil
movb %dil, (%rcx,%rsi)
incq %rsi
jmp 0x2c1b
xorl %esi, %esi
movb %sil, (%rdx,%rax)
movb %sil, (%rcx,%rax)
addq $0x20, %r12
xorl %eax, %eax
cmpq $0x2, %rax
je 0x2c88
imulq $0x18, %rax, %rdx
andl $0x0, 0x18(%rbx,%rax,4)
leaq (%r12,%rdx), %rcx
movq (%r12,%rdx), %rdx
xorl %esi, %esi
movq %r14, %rdi
subq $0x1, %rdx
jb 0x2c83
movq 0x10(%rcx), %r8
cmpq $-0x2, -0x8(%r8,%rdi)
je 0x2c7d
cmpq $0x0, (%r8,%rdi)
je 0x2c7d
incl %esi
movl %esi, 0x18(%rbx,%rax,4)
addq $0x10, %rdi
jmp 0x2c5e
incq %rax
jmp 0x2c42
movq %r10, 0x18(%rsp)
incq %r9
movq %r9, 0x20(%rsp)
movslq 0x18(%rbx), %rax
movslq 0x1c(%rbx), %rdi
addq %rax, %rdi
movq %r14, %rsi
callq 0x2130
movq %rax, %r13
movq %rax, 0x20(%rbx)
xorl %eax, %eax
xorl %ebx, %ebx
movq %r12, 0x28(%rsp)
cmpq $0x2, %rax
movq (%rsp), %rdi
je 0x2d9a
imulq $0x18, %rax, %r15
addq %r12, %r15
movq %rax, 0x30(%rsp)
shlq $0x1f, %rax
movq %rax, 0x38(%rsp)
xorl %r12d, %r12d
movq 0x10(%r15), %rbp
cmpq %r12, (%r15)
jbe 0x2d7c
movq -0x8(%rbp,%r14), %rsi
cmpq $-0x2, %rsi
je 0x2d70
cmpq $0x0, (%rbp,%r14)
je 0x2d70
callq 0xb01f
movq (%rsp), %rdi
cmpl (%rdi), %eax
je 0x2de2
movslq %ebx, %rcx
leal 0x1(%rcx), %ebx
movq 0x20(%rdi), %rdx
movl %eax, %esi
movq (%rdx,%rsi,8), %rax
andl $-0x2, %eax
shlq $0x1f, %rax
movq (%r13,%rcx,8), %r8
movabsq $-0x7fffffff00000001, %r9 # imm = 0x80000000FFFFFFFF
andq %r9, %r8
orq %rax, %r8
movq %r8, (%r13,%rcx,8)
movq (%rdx,%rsi,8), %rdx
shlq $0x3f, %rdx
btrq $0x3f, %r8
orq %rdx, %r8
movq %r8, (%r13,%rcx,8)
movq (%rbp,%r14), %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orq 0x38(%rsp), %rsi
orq %rdx, %rsi
orq %rax, %rsi
movq %rsi, (%r13,%rcx,8)
incq %r12
addq $0x10, %r14
jmp 0x2cde
movq %rbp, %rdi
callq 0x2040
movq 0x30(%rsp), %rax
incq %rax
pushq $0x8
popq %r14
movq 0x28(%rsp), %r12
jmp 0x2cb8
movq 0x10(%rsp), %rbx
leaq 0x11612(%rip), %r8      # 0x143b8
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
incq %r10
jmp 0x2bcb
callq 0xafbb
movq 0x10(%rbx), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x2040
movq 0x8(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x115d6(%rip), %rdi     # 0x143bf
leaq 0x115de(%rip), %rsi     # 0x143ce
leaq 0x115de(%rip), %rcx     # 0x143d5
movl $0xc8, %edx
callq 0x20e0