// File: /workspace/github_c_makefile_star2_O3/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, %r12
movq %rdi, %rbx
callq 0x4fe7
movsd %xmm0, 0x40(%rsp)
cmpb $0x2d, (%rbx)
jne 0x1179d
cmpb $0x0, 0x1(%rbx)
je 0x11e47
leaq 0xbc18(%rip), %rsi      # 0x1d3bc
movq %rbx, %rdi
callq 0x22b0
testq %rax, %rax
je 0x11dc8
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x2190
movq %rax, %r14
movq %rbx, 0x48(%rsp)
movq %rbx, %rdi
callq 0xde96
movq %rax, %r15
movq %rax, %rdi
callq 0xdf28
xorl %ebp, %ebp
testl %eax, %eax
js 0x11dcd
movq $0x0, 0x38(%rsp)
xorl %r13d, %r13d
movq %r12, 0x58(%rsp)
movq %r14, 0x28(%rsp)
movq %r15, 0x50(%rsp)
movq (%r14), %rbx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rbx
jne 0x11838
leaq (%rbx,%rbx), %rcx
testq %rbx, %rbx
movl $0x2, %edx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%r14)
imulq $0x68, %rcx, %rsi
movq %rax, %rdi
callq 0x2260
movq %rax, 0x10(%r14)
leaq 0x1(%rbx), %rcx
movq %rcx, (%r14)
imulq $0x68, %rbx, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x18(%rsp)
leaq (%rax,%rcx), %r14
addq $0x20, %r14
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%r14)
movups %xmm0, 0x30(%r14)
movups %xmm0, 0x20(%r14)
movups %xmm0, 0x10(%r14)
movups %xmm0, (%r14)
movups %xmm0, -0x10(%r14)
movq $0x0, 0x40(%r14)
movl $0xffffffff, -0x20(%r14) # imm = 0xFFFFFFFF
movq 0x8(%r15), %rdi
movq %rsp, %rbx
movq %rbx, %rsi
movl $0xa, %edx
callq 0x21e0
movq %rax, -0x10(%r14)
movq (%rsp), %rdi
incq %rdi
movq %rdi, (%rsp)
movq %rbx, %rsi
movl $0xa, %edx
callq 0x21e0
movq %rax, -0x8(%r14)
movq 0x18(%r15), %rdi
movq %rbx, %rsi
movl $0xa, %edx
callq 0x21e0
movq %r14, 0x8(%rsp)
movl %eax, -0x1c(%r14)
movq (%rsp), %r15
incq %r15
movq %r15, (%rsp)
movb $0x1, %al
xorl %ecx, %ecx
movsbq (%r15), %rbx
cmpq $0x2e, %rbx
jne 0x118f8
addq $0x2, %r15
movq %r15, (%rsp)
jmp 0x11c7e
movq %rcx, 0x20(%rsp)
movq %r12, %r14
movq %r15, %r12
movl %eax, 0x34(%rsp)
movq %r13, %r15
callq 0x2360
cmpb $0x2d, %bl
je 0x11933
movq (%rax), %rcx
movzwl (%rcx,%rbx,2), %ecx
andl $0x800, %ecx            # imm = 0x800
jne 0x11933
xorps %xmm0, %xmm0
xorl %ebx, %ebx
movq %r12, %r8
movq %r14, %r12
jmp 0x11a2d
movq %rax, 0x10(%rsp)
movq %rbp, 0x60(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %r12, %r8
cmpq 0x38(%rsp), %rbx
jne 0x1197c
testq %rbx, %rbx
movq %rbp, %rsi
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x38(%rsp)
shlq $0x4, %rsi
movq %r15, %rdi
movq %r8, %r15
callq 0x2260
movq %r15, %r8
movq %rax, %r12
jmp 0x1197f
movq %r15, %r12
incq %rbx
movq %r8, %rdi
movq %rsp, %r15
movq %r15, %rsi
movl $0xa, %edx
callq 0x21e0
movq %rax, (%r12,%rbp,8)
movq (%rsp), %rdi
incq %rdi
movq %rdi, (%rsp)
movq %r15, %rsi
movl $0xa, %edx
callq 0x21e0
movq %r12, %r15
movq %rax, 0x8(%r12,%rbp,8)
movq (%rsp), %rcx
movq 0x28(%rsp), %rdi
movslq 0x1c(%rdi), %rdx
cmpq %rdx, %rax
movl %eax, %esi
cmoval %edx, %esi
leaq 0x1(%rcx), %r8
movq %r8, (%rsp)
movslq %r13d, %rdx
movslq %r14d, %r14
cmpq %r14, %rax
cmoval %eax, %r14d
cmpq %rdx, %rax
cmoval %edx, %r14d
movl %edx, %r13d
cmoval %eax, %r13d
movl %esi, 0x1c(%rdi)
movsbq 0x1(%rcx), %rax
addq $0x2, %rbp
cmpq $0x2d, %rax
je 0x1194a
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movzwl (%rcx,%rax,2), %eax
andl $0x800, %eax            # imm = 0x800
jne 0x1194a
cvtsi2ss %r14d, %xmm0
movq 0x58(%rsp), %r12
movq 0x60(%rsp), %rbp
incq %r8
movq %r8, (%rsp)
testb $0x1, (%r12)
movq %r15, %r13
movsd 0xba9c(%rip), %xmm3     # 0x1d4e0
movapd 0xbaa4(%rip), %xmm4     # 0x1d4f0
jne 0x11bed
mulss 0x2c(%r12), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0xbb9b(%rip), %xmm0     # 0x1d600
testq %rbx, %rbx
je 0x11ae5
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
leaq 0x8(%r13), %r14
movq %rbx, %rax
movq %r14, %rcx
movsd (%rcx), %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 0x11aa5
movq $0x0, (%rcx)
movl $0x1, %ebp
addq $0x10, %rcx
decq %rax
jne 0x11a7c
cmpq $0x1, %rbx
je 0x11ac5
movq %rbx, %rdi
movq %r13, %rsi
movq %r8, %r15
callq 0xf3cb
movq %r15, %r8
xorl %eax, %eax
cmpq $-0x2, -0x8(%r14)
je 0x11ad4
cmpq $0x0, (%r14)
jne 0x11ae7
incq %rax
addq $0x10, %r14
cmpq %rax, %rbx
jne 0x11ac7
movq %rbx, %rax
jmp 0x11ae7
xorl %eax, %eax
cmpq %rax, %rbx
jne 0x11b08
movq %r8, %r15
movq 0x20(%rsp), %rdx
leaq (%rdx,%rdx,2), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %r14
xorl %ebx, %ebx
jmp 0x11c5a
leal 0x1(%rax), %esi
movq %rbx, %rcx
subq %rsi, %rcx
jbe 0x11b5e
movq %rax, %rdx
shlq $0x4, %rdx
movq (%r13,%rdx), %rdx
shlq $0x4, %rsi
addq %r13, %rsi
addq $0x8, %rsi
movq -0x8(%rsi), %rdi
cmpq $-0x2, %rdi
jne 0x11b47
movq $-0x2, -0x8(%rsi)
movq $0x0, (%rsi)
incl %eax
jmp 0x11b55
cmpq $0x0, (%rsi)
je 0x11b34
cmpq %rdx, %rdi
je 0x11b34
movq %rdi, %rdx
addq $0x10, %rsi
decq %rcx
jne 0x11b2a
testl %eax, %eax
je 0x11ba8
testq %rbx, %rbx
je 0x11aec
xorl %eax, %eax
movq %r13, %rcx
xorl %edx, %edx
cmpq $-0x2, (%rcx)
je 0x11b99
cmpq $0x0, 0x8(%rcx)
je 0x11b99
movl %edx, %edi
leal 0x1(%rdx), %esi
cmpq %rdi, %rax
je 0x11b97
movslq %edx, %rdx
shlq $0x4, %rdx
movupd (%rcx), %xmm0
movupd %xmm0, (%r13,%rdx)
movl %esi, %edx
incq %rax
addq $0x10, %rcx
cmpq %rax, %rbx
jne 0x11b6e
movslq %edx, %rbx
movslq 0x4(%r12), %r14
cmpq %r14, %rbx
jbe 0x11bed
movq %rbx, %rdi
movq %r13, %rsi
movq %r8, %r15
callq 0xfe80
movq %r15, %r8
shlq $0x4, %r14
movslq 0x8(%r13,%r14), %rax
leaq 0x8(%r13), %rcx
xorl %edx, %edx
movl $0x1, %ebp
cmpq %rax, (%rcx)
je 0x11bea
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %rbx
jne 0x11bd2
jmp 0x11bed
movq %rdx, %rbx
movq %r8, %r15
movq 0x20(%rsp), %rdx
leaq (%rdx,%rdx,2), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %r14
cmpq %rbx, 0x8(%r14)
jae 0x11c5a
leaq -0x1(%rbx), %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(%r14)
movq 0x10(%r14), %rdi
shlq $0x4, %rsi
callq 0x2260
movq 0x20(%rsp), %rdx
movq %rax, 0x10(%r14)
movq %rbx, (%r14)
leaq (%rdx,%rdx,2), %rax
movq 0x8(%rsp), %rcx
movq 0x10(%rcx,%rax,8), %rdi
shlq $0x4, %rbx
movq %r13, %rsi
movq %rbx, %rdx
callq 0x21f0
movl 0x34(%rsp), %eax
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0x118e1
movq %r13, 0x10(%rsp)
movq %rbp, %r13
movq 0x50(%rsp), %r15
movl 0x20(%r15), %ebp
movq 0x18(%rsp), %rdx
movl %ebp, (%rdx)
testb $0x1, (%r12)
jne 0x11cfa
movq 0x8(%rsp), %rax
cmpq $0x0, (%rax)
je 0x11cc1
cmpq $0x0, 0x38(%rdx)
jne 0x11cfa
cmpl 0xc(%r12), %ebp
jge 0x11cfa
cmpl $0x1, 0x4(%rdx)
jne 0x11cfa
movq %rdx, %rbx
movq 0x30(%rdx), %rdi
callq 0x2040
movq 0x48(%rbx), %rdi
callq 0x2040
movq 0x28(%rsp), %r14
decq (%r14)
movl $0x1, %ebp
movq 0x10(%rsp), %r13
jmp 0x11db0
movl %ebp, %eax
shrl %eax
orl %ebp, %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, %ebx
shrl $0x10, %ebx
orl %ecx, %ebx
incl %ebx
movl %ebx, 0x8(%rdx)
movq %rbx, %rdi
callq 0x2220
movq 0x18(%rsp), %rdi
movq %rax, 0x50(%rdi)
testl %ebp, %ebp
movq 0x28(%rsp), %r14
movq %r13, %rbp
movq 0x10(%rsp), %r13
jle 0x11d6d
xorl %eax, %eax
leaq 0x13494(%rip), %rsi     # 0x251e0
movq 0x28(%r15), %rcx
movsbq (%rcx,%rax), %rcx
movb (%rsi,%rcx), %cl
movq 0x50(%rdi), %rdx
movb %cl, (%rdx,%rax)
incq %rax
movslq (%rdi), %rcx
cmpq %rcx, %rax
jl 0x11d4c
movl 0x8(%rdi), %ebx
movq %rbx, %rdi
callq 0x2220
movq 0x18(%rsp), %rdx
movq %rax, 0x58(%rdx)
cmpl $0x0, 0x30(%r15)
je 0x11d93
movq 0x38(%r15), %rsi
movq %rax, %rdi
callq 0x2070
jmp 0x11db0
cmpl $0x0, 0x20(%r15)
je 0x11db0
xorl %eax, %eax
movq 0x58(%rdx), %rcx
movb $0x22, (%rcx,%rax)
incq %rax
movl 0x20(%r15), %ecx
cmpq %rcx, %rax
jb 0x11d9c
movq %r15, %rdi
callq 0xdf28
testl %eax, %eax
jns 0x11807
testl %ebp, %ebp
setne %bpl
jmp 0x11dd0
xorl %r14d, %r14d
jmp 0x11e35
xorl %r13d, %r13d
movq %r15, %rdi
callq 0xdee8
movq 0x48(%rsp), %rdi
callq 0x2030
movq %r13, %rdi
callq 0x2040
movq %r14, %rdi
callq 0x10baf
leaq 0x13467(%rip), %rax     # 0x25260
cmpl $0x3, (%rax)
jge 0x11e69
testb %bpl, %bpl
jne 0x11e7c
testb $0x40, (%r12)
je 0x11e7c
movq %r14, %rdi
callq 0x11e86
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18(%r14)
testb $0x4, (%r12)
je 0x11e35
movl 0x20(%r12), %edx
movq %r14, %rdi
movl $0x1, %esi
callq 0x12031
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1317a(%rip), %rax     # 0x24fc8
movq (%rax), %rdi
callq 0x2200
leaq 0xb55f(%rip), %rsi      # 0x1d3bc
movl %eax, %edi
callq 0x20c0
jmp 0x117ac
movzbl %bpl, %edi
movsd 0x40(%rsp), %xmm0
callq 0x2cd2
testb $0x1, %al
jne 0x11dfe
movq %r14, %rdi
callq 0x2d49
jmp 0x11e0a