// File: /workspace/github_c_makefile_star2_O2/lh3[P]miniprot/ntseq.c
// Function: mp_ntseq_read_spsc
int32_t mp_ntseq_read_spsc(mp_ntdb_t *nt, const char *fn, int32_t max_sc)
{
	gzFile fp;
	kstring_t str = {0,0,0};
	kstream_t *ks;
	int32_t dret, j;
	int64_t n_read = 0;

	fp = fn && strcmp(fn, "-") != 0? gzopen(fn, "rb") : gzdopen(0, "rb");
	if (fp == 0) return -1;
	if (max_sc > 63) max_sc = 63;
	mp_ntseq_index_name(nt);
	nt->spsc = Kcalloc(0, mp_spsc_t, nt->n_ctg * 2);
	ks = ks_init(fp);
	while (ks_getuntil(ks, KS_SEP_LINE, &str, &dret) >= 0) {
		mp_spsc_t *s;
		char *p, *q, *name = 0;
		int32_t i, type = -1, strand = 0, cid = -1, score = -1;
		int64_t pos = -1;
		for (i = 0, p = q = str.s;; ++p) {
			if (*p == '\t' || *p == 0) {
				int c = *p;
				*p = 0;
				if (i == 0) {
					name = q;
				} else if (i == 1) {
					pos = atol(q);
				} else if (i == 2) {
					strand = *q == '+'? 1 : '-'? -1 : 0;
				} else if (i == 3) {
					type = *q == 'D'? 0 : *q == 'A'? 1 : -1;
				} else if (i == 4) {
					score = atoi(q);
					break;
				}
				if (c == 0) break;
				q = p + 1, ++i;
			}
		}
		if (i < 4) continue; // not enough fields
		if (score > max_sc) score = max_sc;
		if (score < -max_sc) score = -max_sc;
		cid = mp_ntseq_name2id(nt, name);
		if (cid < 0 || type < 0 || strand == 0 || pos < 0) continue; // FIXME: give a warning!
		s = &nt->spsc[cid << 1 | (strand > 0? 0 : 1)];
		Kgrow(0, uint64_t, s->a, s->n, s->m);
		if (strand < 0) pos = nt->ctg[cid].len - pos;
		if (pos > 0 && pos < nt->ctg[cid].len) { // ignore scores at the ends
			s->a[s->n++] = (uint64_t)pos << 8 | (score + NS_SPSC_OFFSET) << 1 | type;
			++n_read;
		}
	}
	ks_destroy(ks);
	gzclose(fp);
	for (j = 0; j < nt->n_ctg * 2; ++j) {
		mp_spsc_t *s = &nt->spsc[j];
		if (s->n > 0)
			radix_sort_mp64(s->a, s->a + s->n);
	}
	if (mp_verbose >= 3)
		fprintf(stderr, "[M::%s] read %ld splice scores\n", __func__, (long)n_read);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %ebp
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
testq %rsi, %rsi
je 0xb849
cmpb $0x2d, (%rsi)
jne 0xb835
cmpb $0x0, 0x1(%rsi)
je 0xb849
leaq 0x6e92(%rip), %rax      # 0x126ce
movq %rsi, %rdi
movq %rax, %rsi
callq 0x2280
jmp 0xb857
leaq 0x6e7e(%rip), %rsi      # 0x126ce
xorl %edi, %edi
callq 0x20d0
movq %rax, %rbx
testq %rax, %rax
je 0xbb21
cmpl $0x3f, %ebp
pushq $0x3f
popq %r14
cmovll %ebp, %r14d
movq %r15, %rdi
callq 0xb34e
movslq (%r15), %rsi
addq %rsi, %rsi
pushq $0x10
popq %rdx
xorl %edi, %edi
callq 0x72e4
movq %rax, 0x40(%r15)
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
callq 0xa518
movq %rax, 0x28(%rsp)
movl %r14d, 0xc(%rsp)
negl %r14d
movl %r14d, 0x8(%rsp)
leaq 0x74f0(%rip), %r12      # 0x12da0
movq $0x0, 0x10(%rsp)
movq %r15, 0x20(%rsp)
movq 0x28(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0x40(%rsp), %rdx
leaq 0x3c(%rsp), %rcx
callq 0xaae3
testl %eax, %eax
js 0xbaa3
movq 0x50(%rsp), %rdi
leaq 0x1(%rdi), %r14
xorl %ebp, %ebp
xorl %r15d, %r15d
pushq $-0x1
popq %r13
movl $0x0, 0x4(%rsp)
pushq $-0x1
popq %rdx
movzbl -0x1(%r14), %ebx
cmpl $0x9, %ebx
je 0xb908
testl %ebx, %ebx
jne 0xb966
movb $0x0, -0x1(%r14)
cmpl $0x4, %r15d
ja 0xb95c
movl %r15d, %eax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq %rdi, %rbp
jmp 0xb95c
xorl %eax, %eax
cmpb $0x2b, (%rdi)
sete %al
leal -0x1(,%rax,2), %eax
movl %eax, 0x4(%rsp)
jmp 0xb95c
movb (%rdi), %al
xorl %ecx, %ecx
cmpb $0x41, %al
sete %cl
cmpb $0x44, %al
leal -0x1(%rcx,%rcx), %r13d
movl $0x0, %eax
cmovel %eax, %r13d
jmp 0xb95c
callq 0x2290
movq %rax, %rdx
testb %bl, %bl
je 0xb96b
incl %r15d
movq %r14, %rdi
incq %r14
jmp 0xb8fa
pushq $-0x1
popq %rax
movq %rax, 0x18(%rsp)
cmpl $0x4, %r15d
movq 0x20(%rsp), %r15
jl 0xb8be
jmp 0xb999
movq %rdx, %rbx
callq 0x22e0
movq %rbx, %rdx
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rdx, %rbx
movq %rbp, %rsi
callq 0xb74d
testl %eax, %eax
js 0xb8be
testl %r13d, %r13d
js 0xb8be
cmpl $0x0, 0x4(%rsp)
je 0xb8be
movq %rbx, %rsi
testq %rbx, %rbx
js 0xb8be
movl %eax, %ebp
movq 0x40(%r15), %rcx
xorl %eax, %eax
cmpl $0x0, 0x4(%rsp)
setle %al
leal (%rax,%rbp,2), %eax
movslq %eax, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rdi
movl (%rcx,%rdx), %eax
cmpl 0x4(%rcx,%rdx), %eax
jb 0xba20
leal 0x1(%rax), %ecx
shrl %ecx
leal (%rax,%rcx), %edx
addl $0x11, %edx
movl %edx, 0x4(%rdi)
movq 0x8(%rdi), %rsi
shlq $0x3, %rdx
movq %rdi, %r14
xorl %edi, %edi
callq 0x7568
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, 0x8(%r14)
movl %ebp, %eax
cmpl $0x0, 0x4(%rsp)
jns 0xba3c
movq 0x28(%r15), %rcx
imulq $0x18, %rax, %rdx
movq 0x8(%rcx,%rdx), %rcx
subq %rsi, %rcx
movq %rcx, %rsi
testq %rsi, %rsi
jle 0xb8be
movq 0x28(%r15), %rcx
imulq $0x18, %rax, %rax
cmpq 0x8(%rcx,%rax), %rsi
jge 0xb8be
movl 0xc(%rsp), %eax
movq 0x18(%rsp), %r14
cmpl %eax, %r14d
cmovgel %eax, %r14d
movl 0x8(%rsp), %eax
cmpl %eax, %r14d
cmovlel %eax, %r14d
shlq $0x8, %rsi
leal 0x80(,%r14,2), %eax
cltq
movl %r13d, %ecx
orq %rsi, %rcx
orq %rax, %rcx
movq 0x8(%rdi), %rax
movl (%rdi), %edx
leal 0x1(%rdx), %esi
movl %esi, (%rdi)
movq %rcx, (%rax,%rdx,8)
incq 0x10(%rsp)
jmp 0xb8be
movq 0x28(%rsp), %rdi
callq 0xa551
movq 0x30(%rsp), %rdi
callq 0x2040
pushq $0x8
popq %rbx
xorl %r14d, %r14d
movslq (%r15), %rax
addq %rax, %rax
cmpq %rax, %r14
jge 0xbaeb
movq 0x40(%r15), %rax
movl -0x8(%rax,%rbx), %ecx
testq %rcx, %rcx
je 0xbae2
movq (%rax,%rbx), %rdi
leaq (%rdi,%rcx,8), %rsi
callq 0x3a66
incq %r14
addq $0x10, %rbx
jmp 0xbabd
leaq 0xc8fe(%rip), %rax      # 0x183f0
xorl %ebx, %ebx
cmpl $0x3, (%rax)
jl 0xbb24
movq 0xc4f0(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x7379(%rip), %rsi      # 0x12e83
leaq 0x7392(%rip), %rdx      # 0x12ea3
xorl %ebx, %ebx
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x21e0
jmp 0xbb24
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq