// File: /workspace/github_c_makefile_star2_O2/lh3[P]fermi2/mag.c
// Function: mag_g_read
mag_t *mag_g_read(const char *fn, const magopt_t *opt)
{
	gzFile fp;
	kseq_t *seq;
	ku128_v nei;
	mag_t *g;
	int is_mod = 0;
	double t;

	t = cputime();
	fp = strcmp(fn, "-")? gzopen(fn, "r") : gzdopen(fileno(stdin), "r");
	if (fp == 0) return 0;
	kv_init(nei);
	g = calloc(1, sizeof(mag_t));
	seq = kseq_init(fp);
	while (kseq_read(seq) >= 0) {
		int i, j;
		char *q;
		magv_t *p;
		kv_pushp(magv_t, g->v, &p);
		memset(p, 0, sizeof(magv_t));
		p->len = -1;
		// parse ->k[2]
		p->k[0] = strtol(seq->name.s, &q, 10); ++q;
		p->k[1] = strtol(q, &q, 10);
		// parse ->nsr
		p->nsr = strtol(seq->comment.s, &q, 10); ++q;
		// parse ->nei[2]
		for (j = 0; j < 2; ++j) {
			int max, max2;
			max = max2 = 0; // largest and 2nd largest overlaps
			nei.n = 0;
			if (*q == '.') {
				q += 2; // skip "." and "\t" (and perhaps "\0", but does not matter)
				continue;
			}
			while (isdigit(*q) || *q == '-') { // parse the neighbors
				ku128_t *r;
				kv_pushp(ku128_t, nei, &r);
				r->x = strtol(q, &q, 10); ++q;
				r->y = strtol(q, &q, 10); ++q;
				g->min_ovlp = g->min_ovlp < r->y? g->min_ovlp : r->y;
				if (max < r->y) max2 = max, max = r->y;
				else if (max2 < r->y) max2 = r->y;
			}
			++q; // skip the tailing blank
			if (!(opt->flag & MAG_F_READ_ORI)) {
				double thres = (int)(max2 * opt->min_dratio0 + .499);
				for (i = 0; i < nei.n; ++i)
					if (nei.a[i].y < thres) is_mod = 1, nei.a[i].y = 0; // to be deleted in rmdup_128v()
				v128_rmdup(&nei);
				if (nei.n > opt->max_arc) {
					is_mod = 1;
					v128_cap(&nei, opt->max_arc);
				}
			}
			kv_copy(ku128_t, p->nei[j], nei);
		}
		// test if to cut a tip
		p->len = seq->seq.l;
		if (!(opt->flag & MAG_F_READ_ORI) && (p->nei[0].n == 0 || p->nei[1].n == 0) && p->len < opt->min_elen && p->nsr == 1) {
			free(p->nei[0].a); free(p->nei[1].a); // only ->nei[2] have been allocated so far
			--g->v.n;
			is_mod = 1;
			continue;
		}
		// set ->{seq,cov,max_len}
		p->max_len = p->len + 1;
		kroundup32(p->max_len);
		p->seq = malloc(p->max_len);
		for (i = 0; i < p->len; ++i) p->seq[i] = seq_nt6_table[(int)seq->seq.s[i]];
		p->cov = malloc(p->max_len);
		if (seq->qual.l == 0)
			for (i = 0; i < seq->seq.l; ++i)
				p->cov[i] = 34;
		else strcpy(p->cov, seq->qual.s);
	}
	// free and finalize the graph
	kseq_destroy(seq);
	gzclose(fp);
	free(nei.a);
	// finalize
	mag_g_build_hash(g);
	if (fm_verbose >= 3)
		fprintf(stderr, "[M::%s] read the graph and constructed the dictionary in %.3f sec\n", __func__, cputime() - t);
	if (is_mod && fm_verbose >= 3)
		fprintf(stderr, "[M::%s] the graph is modified during reading.\n", __func__);
	if (is_mod || !(opt->flag & MAG_F_NO_AMEND)) {
		t = cputime();
		mag_amend(g);
		fprintf(stderr, "[M::%s] amended the graph in %.3f sec.\n", __func__, cputime() - t);
	}
	g->rdist = mag_cal_rdist(g);
	if (opt->flag & MAG_F_READnMERGE) mag_g_merge(g, 1, opt->min_merge_len);
	return g;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x3b2e
movsd %xmm0, 0x70(%rsp)
cmpb $0x2d, (%rbx)
jne 0xf21c
cmpb $0x0, 0x1(%rbx)
je 0xf83f
leaq 0xa181(%rip), %rsi      # 0x193a4
movq %rbx, %rdi
callq 0x22b0
testq %rax, %rax
je 0xf82b
movq %r14, 0x20(%rsp)
movq $0x0, 0x60(%rsp)
movq %rax, %rbx
pushq $0x1
popq %rdi
pushq $0x28
popq %rsi
callq 0x2190
movq %rax, 0x10(%rsp)
xorpd %xmm0, %xmm0
leaq 0x40(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %rbx, 0x78(%rsp)
movq %rbx, %rdi
callq 0xc26c
movq %rax, %rdx
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %rax, 0x8(%rsp)
movq %rdx, %rdi
callq 0xc2d8
testl %eax, %eax
js 0xf7aa
movq 0x10(%rsp), %rbx
movq (%rbx), %r14
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %r14
jne 0xf2c6
leaq (%r14,%r14), %rcx
testq %r14, %r14
pushq $0x2
popq %rdx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%rbx)
imulq $0x68, %rcx, %rsi
movq %rax, %rdi
callq 0x2260
movq %rax, 0x10(%rbx)
movq 0x8(%rsp), %rdx
leaq 0x1(%r14), %rcx
movq %rcx, (%rbx)
movq %r14, 0x80(%rsp)
imulq $0x68, %r14, %rcx
leaq (%rax,%rcx), %rsi
movq %rsi, 0x88(%rsp)
leaq (%rax,%rcx), %rbp
addq $0x20, %rbp
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rbp)
movups %xmm0, 0x30(%rbp)
movups %xmm0, 0x20(%rbp)
movups %xmm0, 0x10(%rbp)
movups %xmm0, (%rbp)
movups %xmm0, -0x10(%rbp)
andq $0x0, 0x40(%rbp)
orl $-0x1, -0x20(%rbp)
movq %rdx, %rbx
movq 0x8(%rdx), %rdi
movq %rsp, %r14
movq %r14, %rsi
pushq $0xa
popq %r15
movl %r15d, %edx
callq 0x21e0
movq %rax, -0x10(%rbp)
movq (%rsp), %rdi
incq %rdi
movq %rdi, (%rsp)
movq %r14, %rsi
movl %r15d, %edx
callq 0x21e0
movq %rax, -0x8(%rbp)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x21e0
movq %rbp, 0x58(%rsp)
movl %eax, -0x1c(%rbp)
movq (%rsp), %rax
incq %rax
movq %rax, (%rsp)
xorl %r14d, %r14d
cmpq $0x2, %r14
je 0xf694
andq $0x0, 0x40(%rsp)
movb (%rax), %r15b
cmpb $0x2e, %r15b
jne 0xf398
addq $0x2, %rax
movq %rax, (%rsp)
jmp 0xf68c
movq %r14, 0x30(%rsp)
movq %r13, %rbp
movl %r12d, 0x2c(%rsp)
movq %rax, %rbx
callq 0x2360
movq %rbx, %r8
movq %rax, 0x90(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x48(%rsp), %rsi
pushq $0x8
popq %r12
xorl %edx, %edx
xorl %r14d, %r14d
movq 0x60(%rsp), %rdi
cmpb $0x2d, %r15b
je 0xf3f8
movq 0x90(%rsp), %rax
movq (%rax), %rax
movsbq %r15b, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
je 0xf4d5
movl %edx, 0x3c(%rsp)
movq 0x18(%rsp), %rcx
cmpq %rsi, %rcx
jne 0xf441
leaq (%rsi,%rsi), %r15
testq %rsi, %rsi
pushq $0x2
popq %rax
cmoveq %rax, %r15
movq %r15, %rsi
shlq $0x4, %rsi
movq %rbp, %rdi
movq %r8, %rbx
callq 0x2260
movq 0x18(%rsp), %rcx
movq %rbx, %r8
movq %rax, %rbx
movq 0x10(%rsp), %rax
movl 0x1c(%rax), %r13d
movq %r15, 0x68(%rsp)
jmp 0xf44c
movq %rsi, 0x68(%rsp)
movq %rdi, %r13
movq %rbp, %rbx
incq %rcx
movq %rcx, 0x18(%rsp)
movq %r8, %rdi
movq %rsp, %r15
movq %r15, %rsi
pushq $0xa
popq %rbp
movl %ebp, %edx
callq 0x21e0
movq %rax, -0x8(%rbx,%r12)
movq (%rsp), %rdi
incq %rdi
movq %rdi, (%rsp)
movq %r15, %rsi
movl %ebp, %edx
callq 0x21e0
movq %rbx, %rbp
movq %rax, (%rbx,%r12)
movslq %r13d, %r13
cmpq %r13, %rax
cmovbel %eax, %r13d
movq (%rsp), %rcx
leaq 0x1(%rcx), %r8
movslq 0x3c(%rsp), %rdx
movslq %r14d, %rsi
cmpq %rsi, %rax
cmoval %eax, %r14d
cmpq %rdx, %rax
cmoval %edx, %r14d
cmoval %eax, %edx
movq %r8, (%rsp)
movq 0x10(%rsp), %rax
movl %r13d, 0x1c(%rax)
movb 0x1(%rcx), %r15b
addq $0x10, %r12
movq %r13, %rdi
movq 0x68(%rsp), %rsi
jmp 0xf3d4
movq 0x18(%rsp), %rdx
movq %rdx, 0x40(%rsp)
movq %rsi, 0x48(%rsp)
movq %rbp, 0x50(%rsp)
incq %r8
movq %r8, (%rsp)
movq 0x20(%rsp), %r15
testb $0x1, (%r15)
jne 0xf560
cvtsi2ss %r14d, %xmm0
mulss 0x2c(%r15), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0xa03e(%rip), %xmm0     # 0x19550
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
addq $0x8, %rbp
pushq $0x1
popq %rax
movl 0x2c(%rsp), %r12d
subq $0x1, %rdx
jb 0xf56f
movsd (%rbp), %xmm1
unpcklps 0x9f88(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x9f90(%rip), %xmm1     # 0x194d0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0xf55a
andq $0x0, (%rbp)
movl %eax, %r12d
addq $0x10, %rbp
jmp 0xf526
movl 0x2c(%rsp), %r12d
movq 0x30(%rsp), %r14
jmp 0xf5fd
movq %r8, %r13
movq %rdi, %r14
leaq 0x40(%rsp), %rdi
callq 0xec3a
movq 0x40(%rsp), %rdx
movslq 0x4(%r15), %rbx
cmpq %rbx, %rdx
jbe 0xf5e1
movq 0x50(%rsp), %r12
movq %rdx, %rdi
movq %r12, %rsi
movq %rdx, %rbp
callq 0xdd8d
movq %rbp, %r9
shlq $0x4, %rbx
movslq 0x8(%r12,%rbx), %rax
addq $0x8, %r12
movq %rbp, %rdx
negq %rdx
pushq $-0x1
popq %rcx
movq %r14, %rdi
movq 0x30(%rsp), %r14
movq %r13, %r8
leaq (%rdx,%rcx), %rsi
cmpq $-0x1, %rsi
je 0xf5ee
incq %rcx
leaq 0x10(%r12), %rsi
cmpq %rax, (%r12)
movq %rsi, %r12
jne 0xf5c4
jmp 0xf5f1
movq %r14, %rdi
movq 0x30(%rsp), %r14
movq %r13, %r8
jmp 0xf5fd
movq %r9, %rcx
movq %rcx, 0x40(%rsp)
movq %rcx, %rdx
pushq $0x1
popq %r12
movq %r8, %rbp
movq %rdi, 0x60(%rsp)
imulq $0x18, %r14, %rax
movq 0x58(%rsp), %rcx
leaq (%rcx,%rax), %rbx
cmpq %rdx, 0x8(%rcx,%rax)
jae 0xf671
leaq -0x1(%rdx), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rsi
movq %rdx, %r15
callq 0x2260
movq %r15, %rdx
movq %rax, %rdi
movq %rax, 0x10(%rbx)
jmp 0xf675
movq 0x10(%rbx), %rdi
movq %rdx, (%rbx)
movq 0x50(%rsp), %r13
shlq $0x4, %rdx
movq %r13, %rsi
callq 0x21f0
movq %rbp, %rax
incq %r14
jmp 0xf372
movq 0x8(%rsp), %rax
movl 0x20(%rax), %ebx
movq 0x88(%rsp), %r14
movl %ebx, (%r14)
movq 0x20(%rsp), %rax
testb $0x1, (%rax)
jne 0xf6ff
movq 0x58(%rsp), %rax
cmpq $0x0, (%rax)
je 0xf6c3
cmpq $0x0, 0x38(%r14)
jne 0xf6ff
movq 0x20(%rsp), %rax
cmpl 0xc(%rax), %ebx
jge 0xf6ff
cmpl $0x1, 0x4(%r14)
jne 0xf6ff
movq 0x30(%r14), %rdi
callq 0x2040
movq 0x48(%r14), %rdi
callq 0x2040
movq 0x10(%rsp), %rax
movq 0x80(%rsp), %rcx
movq %rcx, (%rax)
pushq $0x1
popq %r12
jmp 0xf785
movl %ebx, %eax
shrl %eax
orl %ebx, %eax
movl %eax, %ecx
shrl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %edi
shrl $0x10, %edi
orl %ecx, %edi
incl %edi
movl %edi, 0x8(%r14)
callq 0x2220
movq %rax, 0x50(%r14)
xorl %eax, %eax
movq 0x8(%rsp), %rsi
leaq 0x12aa2(%rip), %rdi     # 0x221e0
movslq %ebx, %rcx
cmpq %rcx, %rax
jge 0xf761
movq 0x28(%rsi), %rcx
movsbq (%rcx,%rax), %rcx
movb (%rdi,%rcx), %cl
movq 0x50(%r14), %rdx
movb %cl, (%rdx,%rax)
incq %rax
movl (%r14), %ebx
jmp 0xf73e
movl 0x8(%r14), %edi
callq 0x2220
movq 0x8(%rsp), %rdx
movq %rax, 0x58(%r14)
cmpl $0x0, 0x30(%rdx)
je 0xf78f
movq 0x38(%rdx), %rsi
movq %rax, %rdi
callq 0x2070
movq 0x8(%rsp), %rdx
jmp 0xf282
xorl %eax, %eax
movl 0x20(%rdx), %ecx
cmpq %rcx, %rax
jae 0xf282
movq 0x58(%r14), %rcx
movb $0x22, (%rcx,%rax)
incq %rax
jmp 0xf791
movq 0x8(%rsp), %rdi
callq 0xc298
movq 0x78(%rsp), %rdi
callq 0x2030
movq %r13, %rdi
callq 0x2040
movq 0x10(%rsp), %rdi
callq 0xe9e4
leaq 0x12a89(%rip), %r14     # 0x22260
cmpl $0x2, (%r14)
jg 0xf861
testl %r12d, %r12d
movq 0x20(%rsp), %r13
jne 0xf8c1
testb $0x40, (%r13)
je 0xf8c1
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0xf908
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18(%rbx)
testb $0x4, (%r13)
je 0xf826
movl 0x20(%r13), %edx
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xfae0
movq %rbx, %rax
jmp 0xf82d
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x12782(%rip), %rax     # 0x21fc8
movq (%rax), %rdi
callq 0x2200
leaq 0x9b4f(%rip), %rsi      # 0x193a4
movl %eax, %edi
callq 0x20c0
jmp 0xf22b
movq 0x12790(%rip), %r15     # 0x21ff8
movq (%r15), %rbx
callq 0x3b2e
subsd 0x70(%rsp), %xmm0
leaq 0xa881(%rip), %rsi      # 0x1a0fe
leaq 0xa8bd(%rip), %rdx      # 0x1a141
movq %rbx, %rdi
movb $0x1, %al
callq 0x21c0
testl %r12d, %r12d
movq 0x20(%rsp), %r13
je 0xf89e
cmpl $0x3, (%r14)
jge 0xf8a9
testl %r12d, %r12d
je 0xf7ef
jmp 0xf8c1
movq (%r15), %rdi
leaq 0xa899(%rip), %rsi      # 0x1a14c
leaq 0xa887(%rip), %rdx      # 0x1a141
xorl %eax, %eax
callq 0x21c0
callq 0x3b2e
movsd %xmm0, 0x18(%rsp)
movq 0x10(%rsp), %rdi
callq 0xeb00
movq 0x1271b(%rip), %rax     # 0x21ff8
movq (%rax), %rbx
callq 0x3b2e
subsd 0x18(%rsp), %xmm0
leaq 0xa889(%rip), %rsi      # 0x1a17b
leaq 0xa848(%rip), %rdx      # 0x1a141
movq %rbx, %rdi
movb $0x1, %al
callq 0x21c0
jmp 0xf7fa