// File: /workspace/github_c_makefile_star2_O3/lh3[P]miniprot/ntseq.c
// Function: mp_ntseq_read
mp_ntdb_t *mp_ntseq_read(const char *fn)
{
	gzFile fp;
	kseq_t *ks;
	mp_ntdb_t *d = 0;
	int64_t off = 0;

	fp = gzopen(fn, "r");
	if (fp == 0) return 0;
	ks = kseq_init(fp);

	d = Kcalloc(0, mp_ntdb_t, 1);
	while (kseq_read(ks) >= 0) {
		int64_t i, ltmp;
		mp_ctg_t *c;

		// update mp_ntdb_t::ctg
		if (d->n_ctg == d->m_ctg) {
			d->m_ctg += (d->m_ctg>>1) + 16;
			d->ctg = Krealloc(0, mp_ctg_t, d->ctg, d->m_ctg);
		}
		c = &d->ctg[d->n_ctg++];
		c->name = mp_strdup(ks->name.s);
		c->off = off;
		c->len = ks->seq.l;

		// update mp_ntdb_t::seq
		ltmp = (d->l_seq + ks->seq.l + 1) >> 1 << 1;
		if (ltmp > d->m_seq) {
			int64_t oldm = d->m_seq;
			d->m_seq = ltmp;
			kroundup64(d->m_seq);
			d->seq = Krealloc(0, uint8_t, d->seq, d->m_seq >> 1);
			memset(&d->seq[oldm>>1], 0, (d->m_seq - oldm) >> 1);
		}
		for (i = 0; i < ks->seq.l; ++i, ++off) {
			uint8_t b = ns_tab_nt4[(uint8_t)ks->seq.s[i]];
			d->seq[off >> 1] |= b << (off&1) * 4;
		}
		d->l_seq += ks->seq.l;
	}

	kseq_destroy(ks);
	gzclose(fp);
	mp_ntseq_merge_name(d);
	if (mp_verbose >= 3)
		fprintf(stderr, "[M::%s@%.3f*%.2f] read %ld bases in %d contigs\n", __func__, mp_realtime(), mp_percent_cpu(), (long)d->l_seq, d->n_ctg);
	return d;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x70e0(%rip), %rsi      # 0x133e0
callq 0x2260
testq %rax, %rax
je 0xc571
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0xbeee
movq %rax, %r14
movl $0x1, %esi
movl $0x48, %edx
xorl %edi, %edi
callq 0x8344
movq %rax, %rbx
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0xbf80
testq %rax, %rax
js 0xc496
xorl %r13d, %r13d
leaq 0xd0ae(%rip), %rbp      # 0x19400
movl (%rbx), %eax
movq 0x28(%rbx), %r12
cmpl 0x4(%rbx), %eax
jne 0xc386
movl %eax, %ecx
sarl %ecx
addl %ecx, %eax
addl $0x10, %eax
movl %eax, 0x4(%rbx)
cltq
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdx
xorl %edi, %edi
movq %r12, %rsi
callq 0x85ad
movq %rax, %r12
movq %rax, 0x28(%rbx)
movl (%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, (%rbx)
cltq
leaq (%rax,%rax,2), %r15
movq 0x8(%rsp), %r14
movq 0x10(%r14), %rdi
callq 0x4cdb
movq %rax, 0x10(%r12,%r15,8)
movq %r13, (%r12,%r15,8)
movq 0x30(%r14), %r14
movq %r14, 0x8(%r12,%r15,8)
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %r12
addq %r14, %rax
incq %rax
andq $-0x2, %rax
cmpq %r12, %rax
jle 0xc439
decq %rax
movq %rax, %rcx
sarq %rcx
orq %rax, %rcx
movq %rcx, %rax
sarq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
sarq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
sarq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
sarq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %rdx
sarq $0x20, %rdx
orq %rcx, %rdx
incq %rdx
movq %rdx, 0x18(%rbx)
movq 0x20(%rbx), %rsi
sarq %rdx
xorl %edi, %edi
callq 0x85ad
movq %rax, 0x20(%rbx)
movq %r12, %rdi
sarq %rdi
addq %rax, %rdi
movq 0x18(%rbx), %rdx
subq %r12, %rdx
sarq %rdx
xorl %esi, %esi
callq 0x2160
testq %r14, %r14
je 0xc47f
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rax
leal (,%r13,4), %edx
xorl %esi, %esi
leaq (%rsi,%r13), %rdi
movzbl (%rax,%rsi), %ecx
movb (%rbp,%rcx), %r8b
movl %edx, %ecx
andb $0x4, %cl
shlb %cl, %r8b
movq 0x20(%rbx), %rcx
sarq %rdi
orb %r8b, (%rcx,%rdi)
incq %rsi
addb $0x4, %dl
cmpq %r14, %rsi
jb 0xc451
addq %rsi, %r13
addq %r14, 0x10(%rbx)
movq 0x8(%rsp), %rdi
callq 0xbf80
testq %rax, %rax
jns 0xc352
movq 0x8(%rsp), %rdi
callq 0xbf40
movq 0x10(%rsp), %rdi
callq 0x2040
movl $0x0, 0x8(%rbx)
movslq (%rbx), %rax
xorl %r14d, %r14d
testq %rax, %rax
jle 0xc4eb
movq 0x28(%rbx), %r15
shlq $0x3, %rax
leaq (%rax,%rax,2), %r12
xorl %r13d, %r13d
movq 0x10(%r15,%r13), %rdi
callq 0x2100
addl %eax, %r14d
incl %r14d
movl %r14d, 0x8(%rbx)
addq $0x18, %r13
cmpq %r13, %r12
jne 0xc4cb
movslq %r14d, %r14
xorl %edi, %edi
movq %r14, %rsi
callq 0x84a5
movq %rax, 0x30(%rbx)
cmpl $0x0, (%rbx)
jle 0xc55b
movq %rax, %r14
movq 0x28(%rbx), %r15
movl $0x10, %r12d
xorl %r13d, %r13d
movq (%r15,%r12), %r15
movq %r15, %rdi
callq 0x2100
leaq 0x1(%rax), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x21e0
movq 0x28(%rbx), %rax
movq (%rax,%r12), %rdi
callq 0x2050
movq 0x28(%rbx), %r15
movq %r14, (%r15,%r12)
movq %r14, %rdi
callq 0x2100
addq %rax, %r14
incq %r14
incq %r13
movslq (%rbx), %rax
addq $0x18, %r12
cmpq %rax, %r13
jl 0xc50e
leaq 0xce7e(%rip), %rax      # 0x193e0
cmpl $0x3, (%rax)
jl 0xc573
movq %rbx, %rdi
callq 0x2c6f
jmp 0xc573
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq