// File: /workspace/github_c_makefile_star2_O3/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 0xcd98
movq %rax, %rdi
movq (%rbx), %rax
testq %rax, %rax
movq %rbx, 0x8(%rsp)
movq %rdi, (%rsp)
je 0x2d57
movq %rbx, %rsi
movl $0x18, %r14d
xorl %r13d, %r13d
leaq 0x44(%rsp), %r12
xorl %ebx, %ebx
movq 0x10(%rsi), %rbp
cmpl $0x0, -0x18(%rbp,%r14)
js 0x2d49
movq -0x8(%rbp,%r14), %rsi
movq %r12, %rdx
callq 0xd0dd
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 0xd0dd
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
movq (%rsi), %rax
incq %r13
addq $0x68, %r14
cmpq %rax, %r13
jb 0x2cec
jmp 0x2d59
xorl %ebx, %ebx
movl %ebx, (%r15)
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0xcda7
movslq (%r15), %rdi
movl $0x28, %esi
callq 0x2130
movq 0x8(%rsp), %rbx
movq %rax, %r14
movq (%rbx), %rcx
testq %rcx, %rcx
movq (%rsp), %rdi
je 0x2fae
xorl %esi, %esi
xorl %r10d, %r10d
movq %r14, 0x20(%rsp)
movq 0x10(%rbx), %r15
imulq $0x68, %rsi, %rdx
movslq (%r15,%rdx), %rax
testq %rax, %rax
js 0x2fa2
movq %rsi, 0x30(%rsp)
addq %rdx, %r15
leaq (%r10,%r10,4), %rcx
movl %eax, (%r14,%rcx,8)
movl 0x4(%r15), %edx
movl %edx, 0x4(%r14,%rcx,8)
movq 0x50(%r15), %rdx
movq %rdx, 0x8(%r14,%rcx,8)
movq 0x58(%r15), %rsi
movq %rsi, 0x10(%r14,%rcx,8)
testl %eax, %eax
je 0x2dfd
xorl %edi, %edi
leaq 0x145d2(%rip), %r9      # 0x173b8
movsbq (%rdx,%rdi), %r8
movb (%r8,%r9), %r8b
movb %r8b, (%rdx,%rdi)
incq %rdi
cmpq %rdi, %rax
jne 0x2de6
jmp 0x2dff
xorl %eax, %eax
incq %r10
leaq (%r14,%rcx,8), %rbx
xorl %ecx, %ecx
movb %cl, (%rsi,%rax)
movb %cl, (%rdx,%rax)
addq $0x20, %r15
movb $0x1, %al
xorl %ecx, %ecx
leaq (%rcx,%rcx,2), %rsi
movl $0x0, 0x18(%rbx,%rcx,4)
movq (%r15,%rsi,8), %rdx
testq %rdx, %rdx
je 0x2e55
leaq (%r15,%rsi,8), %rsi
movq 0x10(%rsi), %rsi
addq $0x8, %rsi
xorl %edi, %edi
cmpq $-0x2, -0x8(%rsi)
je 0x2e4c
cmpq $0x0, (%rsi)
je 0x2e4c
incl %edi
movl %edi, 0x18(%rbx,%rcx,4)
addq $0x10, %rsi
decq %rdx
jne 0x2e39
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0x2e16
movq $0x0, 0x18(%rsp)
movq %r10, 0x28(%rsp)
movslq 0x18(%rbx), %rax
movslq 0x1c(%rbx), %rdi
addq %rax, %rdi
movl $0x8, %esi
callq 0x2130
movq %rax, %r12
movq %rax, 0x20(%rbx)
movb $0x1, %cl
xorl %r13d, %r13d
movq %r15, 0x38(%rsp)
leaq (,%r13,2), %rax
addq %r13, %rax
leaq (%r15,%rax,8), %r15
movq (%r15), %rax
testq %rax, %rax
movl %ecx, 0x14(%rsp)
je 0x2f63
shlq $0x1f, %r13
movl $0x8, %ebx
xorl %r14d, %r14d
movq (%rsp), %rdi
movq 0x10(%r15), %rbp
movq -0x8(%rbp,%rbx), %rsi
cmpq $-0x2, %rsi
je 0x2f53
cmpq $0x0, (%rbp,%rbx)
je 0x2f53
callq 0xce10
movq (%rsp), %rdi
cmpl (%rdi), %eax
je 0x2fd6
movslq 0x18(%rsp), %rcx
leal 0x1(%rcx), %edx
movq %rdx, 0x18(%rsp)
movq 0x20(%rdi), %rdx
movl %eax, %eax
movq (%rdx,%rax,8), %rsi
andl $-0x2, %esi
shlq $0x1f, %rsi
movq (%r12,%rcx,8), %r8
movabsq $-0x7fffffff00000001, %r9 # imm = 0x80000000FFFFFFFF
andq %r9, %r8
orq %rsi, %r8
movq %r8, (%r12,%rcx,8)
movq (%rdx,%rax,8), %rax
shlq $0x3f, %rax
btrq $0x3f, %r8
orq %rax, %r8
movq %r8, (%r12,%rcx,8)
movq (%rbp,%rbx), %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orq %r13, %rdx
orq %rsi, %rdx
orq %rax, %rdx
movq %rdx, (%r12,%rcx,8)
movq (%r15), %rax
incq %r14
addq $0x10, %rbx
cmpq %r14, %rax
ja 0x2ec6
movq 0x10(%r15), %rdi
callq 0x2040
movl $0x1, %r13d
testb $0x1, 0x14(%rsp)
movl $0x0, %ecx
movq 0x38(%rsp), %r15
jne 0x2e97
movq 0x8(%rsp), %rbx
movq (%rbx), %rcx
movq (%rsp), %rdi
movq 0x20(%rsp), %r14
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %r10
incq %rsi
cmpq %rcx, %rsi
jb 0x2d99
callq 0xcda7
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 0x143e2(%rip), %rdi     # 0x173bf
leaq 0x143ea(%rip), %rsi     # 0x173ce
leaq 0x143ea(%rip), %rcx     # 0x173d5
movl $0xc8, %edx
callq 0x20e0