// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x5117
movsd %xmm0, 0x38(%rsp)
leaq 0xba86(%rip), %rsi      # 0x1cb8d
movq %rbx, %rdi
callq 0x21a0
testl %eax, %eax
je 0x11124
leaq 0xb26a(%rip), %rsi      # 0x1c384
movq %rbx, %rdi
callq 0x22b0
jmp 0x11141
movq 0x12e9d(%rip), %rax     # 0x23fc8
movq (%rax), %rdi
callq 0x2200
leaq 0xb24a(%rip), %rsi      # 0x1c384
movl %eax, %edi
callq 0x20c0
testq %rax, %rax
je 0x1175d
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x2190
movq %rax, 0x10(%rsp)
movq %rbx, 0x40(%rsp)
movq %rbx, %rdi
callq 0xd8f7
movq %rax, 0x18(%rsp)
movq %rax, %rdi
callq 0xd991
xorl %ebp, %ebp
testl %eax, %eax
js 0x11768
movq $0x0, 0x30(%rsp)
xorl %ebx, %ebx
movq %r14, 0x50(%rsp)
movq %r14, %r15
movq %rbx, %r14
movq 0x10(%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %rax
cmpq %rax, %rbx
jne 0x111d9
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq 0x10(%rsp), %r12
movq %rcx, 0x8(%r12)
movq 0x10(%r12), %rdi
imulq $0x68, %rcx, %rsi
callq 0x2260
movq %rax, 0x10(%r12)
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rax
leaq 0x1(%rbx), %rcx
movq %rcx, (%rdx)
imulq $0x68, %rbx, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x48(%rsp)
leaq (%rax,%rcx), %r13
addq $0x20, %r13
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%r13)
movups %xmm0, 0x30(%r13)
movups %xmm0, 0x20(%r13)
movups %xmm0, 0x10(%r13)
movups %xmm0, (%r13)
movups %xmm0, -0x10(%r13)
movq $0x0, 0x40(%r13)
movl $0xffffffff, -0x20(%r13) # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rbx
movq 0x8(%rbx), %rdi
leaq 0x8(%rsp), %r12
movq %r12, %rsi
movl $0xa, %edx
callq 0x21e0
movq %rax, -0x10(%r13)
movq 0x8(%rsp), %rdi
incq %rdi
movq %rdi, 0x8(%rsp)
movq %r12, %rsi
movl $0xa, %edx
callq 0x21e0
movq %rax, -0x8(%r13)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x21e0
movl %eax, -0x1c(%r13)
incq 0x8(%rsp)
xorl %r12d, %r12d
movq %r14, %rbx
movq %r15, %r14
movq %r13, 0x28(%rsp)
movq 0x8(%rsp), %rax
cmpb $0x2e, (%rax)
jne 0x112ac
addq $0x2, %rax
movq %rax, 0x8(%rsp)
jmp 0x11639
callq 0x2360
movq 0x8(%rsp), %rsi
movsbq (%rsi), %rcx
cmpq $0x2d, %rcx
je 0x112da
movq (%rax), %rdx
movzwl (%rdx,%rcx,2), %ecx
andl $0x800, %ecx            # imm = 0x800
jne 0x112da
xorps %xmm0, %xmm0
xorl %r15d, %r15d
jmp 0x113df
movq %rax, 0x20(%rsp)
movq %r12, 0x58(%rsp)
movq %rbp, 0x60(%rsp)
xorl %r12d, %r12d
movl $0x8, %r14d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x30(%rsp), %rax
cmpq %rax, %r15
jne 0x11328
leaq (%rax,%rax), %r13
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r13
movq %r13, %rsi
shlq $0x4, %rsi
movq %rbx, %rdi
callq 0x2260
movq %rax, %rbx
movq %r13, 0x30(%rsp)
incq %r15
movq 0x8(%rsp), %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
movl $0xa, %edx
callq 0x21e0
movq %rax, -0x8(%rbx,%r14)
movq 0x8(%rsp), %rdi
incq %rdi
movq %rdi, 0x8(%rsp)
movq %r13, %rsi
movl $0xa, %edx
callq 0x21e0
movq %rax, (%rbx,%r14)
incq 0x8(%rsp)
movq 0x10(%rsp), %rsi
movslq 0x1c(%rsi), %rcx
cmpq %rcx, %rax
movl %eax, %edx
cmoval %ecx, %edx
movl %edx, 0x1c(%rsi)
movslq %ebp, %rcx
movslq %r12d, %r12
cmpq %r12, %rax
cmoval %eax, %r12d
cmpq %rcx, %rax
cmoval %ecx, %r12d
movl %ecx, %ebp
cmoval %eax, %ebp
movq 0x8(%rsp), %rsi
movsbq (%rsi), %rcx
addq $0x10, %r14
cmpq $0x2d, %rcx
je 0x112f7
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movzwl (%rdx,%rcx,2), %ecx
andl $0x800, %ecx            # imm = 0x800
jne 0x112f7
cvtsi2ss %r12d, %xmm0
movq 0x50(%rsp), %r14
movq 0x60(%rsp), %rbp
movq 0x28(%rsp), %r13
movq 0x58(%rsp), %r12
incq %rsi
movq %rsi, 0x8(%rsp)
testb $0x1, (%r14)
movq %rbx, 0x20(%rsp)
jne 0x115bc
mulss 0x2c(%r14), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0xb088(%rip), %xmm0     # 0x1c490
testq %r15, %r15
movsd 0xafbd(%rip), %xmm3     # 0x1c3d0
movapd 0xafc5(%rip), %xmm4     # 0x1c3e0
je 0x1145e
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
leaq 0x8(%rbx), %rax
movq %r15, %rcx
movsd (%rax), %xmm1
unpcklps %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x11455
movq $0x0, (%rax)
movl $0x1, %ebp
addq $0x10, %rax
decq %rcx
jne 0x1142c
cmpq $0x2, %r15
jb 0x1146f
movq %r15, %rdi
movq %rbx, %rsi
callq 0xedd3
testq %r15, %r15
je 0x1149b
leaq 0x8(%rbx), %rcx
xorl %eax, %eax
cmpq $-0x2, -0x8(%rcx)
je 0x11487
cmpq $0x0, (%rcx)
jne 0x11496
incq %rax
addq $0x10, %rcx
cmpq %rax, %r15
jne 0x1147a
movq %r15, %rax
leal 0x1(%rax), %esi
jmp 0x114a2
xorl %eax, %eax
movl $0x1, %esi
cmpq %rax, %r15
jne 0x114ae
xorl %ebx, %ebx
jmp 0x11559
movq %r15, %rcx
subq %rsi, %rcx
jbe 0x11500
movq %rax, %rdx
shlq $0x4, %rdx
movq (%rbx,%rdx), %rdx
shlq $0x4, %rsi
addq %rbx, %rsi
addq $0x8, %rsi
movq -0x8(%rsi), %rdi
cmpq $-0x2, %rdi
jne 0x114e9
movq $-0x2, -0x8(%rsi)
movq $0x0, (%rsi)
incl %eax
jmp 0x114f7
cmpq $0x0, (%rsi)
je 0x114d6
cmpq %rdx, %rdi
je 0x114d6
movq %rdi, %rdx
addq $0x10, %rsi
decq %rcx
jne 0x114cc
testl %eax, %eax
movl $0x0, %ebx
cmoveq %r15, %rbx
testq %r15, %r15
je 0x11559
testl %eax, %eax
je 0x11559
xorl %eax, %eax
movq 0x20(%rsp), %r8
movq %r8, %rcx
xorl %edx, %edx
cmpq $-0x2, (%rcx)
je 0x1154a
cmpq $0x0, 0x8(%rcx)
je 0x1154a
movl %edx, %edi
leal 0x1(%rdx), %esi
cmpq %rdi, %rax
je 0x11548
movslq %edx, %rdx
shlq $0x4, %rdx
movupd (%rcx), %xmm0
movupd %xmm0, (%r8,%rdx)
movl %esi, %edx
incq %rax
addq $0x10, %rcx
cmpq %rax, %r15
jne 0x11520
movslq %edx, %rbx
movq %r12, %r13
movq %r14, %r12
movslq 0x4(%r14), %r14
cmpq %r14, %rbx
jbe 0x115ae
movq %rbx, %rdi
movq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0xf872
shlq $0x4, %r14
movslq 0x8(%r15,%r14), %rax
leaq 0x8(%r15), %rcx
xorl %r15d, %r15d
movq %r12, %r14
movq %r13, %r12
movq 0x28(%rsp), %r13
movl $0x1, %ebp
cmpq %rax, (%rcx)
je 0x115bc
incq %r15
addq $0x10, %rcx
cmpq %r15, %rbx
jne 0x11593
movq %rbx, %r15
jmp 0x115bc
movq %rbx, %r15
movq %r12, %r14
movq %r13, %r12
movq 0x28(%rsp), %r13
leaq (%r12,%r12,2), %rax
leaq (,%rax,8), %rbx
addq %r13, %rbx
cmpq %r15, 0x8(%rbx)
jae 0x1161e
leaq -0x1(%r15), %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
callq 0x2260
movq %rax, 0x10(%rbx)
movq %r15, (%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %r15
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
callq 0x21f0
leaq 0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
je 0x11294
movq 0x18(%rsp), %rax
movl 0x20(%rax), %eax
movq 0x48(%rsp), %r15
movl %eax, (%r15)
testb $0x1, (%r14)
jne 0x1169f
cmpq $0x0, 0x20(%r15)
je 0x1166e
cmpq $0x0, 0x38(%r15)
jne 0x1169f
cmpl 0xc(%r14), %eax
jge 0x1169f
cmpl $0x1, 0x4(%r15)
jne 0x1169f
movq 0x30(%r15), %rdi
callq 0x2040
movq 0x48(%r15), %rdi
callq 0x2040
movq 0x10(%rsp), %rax
decq (%rax)
movl $0x1, %ebp
jmp 0x11726
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, %edi
shrl $0x10, %edi
orl %eax, %edi
incl %edi
movl %edi, 0x8(%r15)
callq 0x2220
movq %rax, 0x50(%r15)
cmpl $0x0, (%r15)
movq 0x18(%rsp), %rsi
leaq 0x12b00(%rip), %rdi     # 0x241e0
jle 0x11702
xorl %eax, %eax
movq 0x28(%rsi), %rcx
movsbq (%rcx,%rax), %rcx
movb (%rdi,%rcx), %cl
movq 0x50(%r15), %rdx
movb %cl, (%rdx,%rax)
incq %rax
movslq (%r15), %rcx
cmpq %rcx, %rax
jl 0x116e4
movl 0x8(%r15), %edi
callq 0x2220
movq 0x18(%rsp), %rdi
movq %rax, 0x58(%r15)
cmpl $0x0, 0x30(%rdi)
je 0x1172d
movq 0x38(%rdi), %rsi
movq %rax, %rdi
callq 0x2070
movq 0x18(%rsp), %rdi
jmp 0x11748
cmpl $0x0, 0x20(%rdi)
je 0x11748
xorl %eax, %eax
movq 0x58(%r15), %rcx
movb $0x22, (%rcx,%rax)
incq %rax
movl 0x20(%rdi), %ecx
cmpq %rcx, %rax
jb 0x11735
callq 0xd991
testl %eax, %eax
jns 0x11195
testl %ebp, %ebp
setne %bpl
jmp 0x1176a
movq $0x0, 0x10(%rsp)
jmp 0x117e3
xorl %ebx, %ebx
movq 0x18(%rsp), %rdi
callq 0xd951
movq 0x40(%rsp), %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x2040
movq 0x10(%rsp), %rdi
callq 0x10589
leaq 0x12ac9(%rip), %rbx     # 0x24260
cmpl $0x3, (%rbx)
jge 0x11803
cmpl $0x3, (%rbx)
setge %al
andb %bpl, %al
cmpb $0x1, %al
je 0x11810
testb %bpl, %bpl
jne 0x117f7
testb $0x40, (%r14)
je 0x117f7
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x11817
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18(%rbx)
testb $0x4, (%r14)
je 0x117e3
movl 0x20(%r14), %edx
movq 0x10(%rsp), %rdi
movl $0x1, %esi
callq 0x119be
movq 0x10(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
callq 0x2d8a
jmp 0x117b4
movsd 0x38(%rsp), %xmm0
callq 0x2d2e
jmp 0x1179c
callq 0x2d6b
jmp 0x117a9