// File: /workspace/github_c_makefile_star2_O3/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, %r14d
movq %rdi, %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testq %rsi, %rsi
je 0xd0bf
cmpb $0x2d, (%rsi)
jne 0xd0ab
cmpb $0x0, 0x1(%rsi)
je 0xd0bf
leaq 0x761c(%rip), %rax      # 0x146ce
movq %rsi, %rdi
movq %rax, %rsi
callq 0x2260
jmp 0xd0cd
leaq 0x7608(%rip), %rsi      # 0x146ce
xorl %edi, %edi
callq 0x20d0
movq %rax, %rbx
testq %rax, %rax
je 0xd3ee
cmpl $0x3f, %r14d
movl $0x3f, %eax
cmovll %r14d, %eax
movl %eax, 0xc(%rsp)
movq %rbp, %rdi
callq 0xcb7f
movslq (%rbp), %rsi
addq %rsi, %rsi
movl $0x10, %edx
xorl %edi, %edi
callq 0x8344
movq %rax, 0x40(%rbp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x21a0
movq %rax, %r14
movq %rbx, 0x30(%rsp)
movq %rbx, 0x10(%rax)
movl $0x10000, 0x8(%rax)     # imm = 0x10000
movl $0x4000, %edi           # imm = 0x4000
callq 0x2220
movq %rax, 0x18(%r14)
leaq 0x40(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
movq %r14, 0x28(%rsp)
movq %r14, %rdi
movl $0x2, %esi
xorl %r8d, %r8d
callq 0xbc31
movl $0x0, %ecx
movq %rcx, 0x10(%rsp)
testl %eax, %eax
js 0xd366
movl 0xc(%rsp), %eax
negl %eax
movl %eax, 0x18(%rsp)
leaq 0x7c25(%rip), %r12      # 0x14da0
movq $0x0, 0x10(%rsp)
movq %rbp, 0x20(%rsp)
movq 0x50(%rsp), %rdi
leaq 0x1(%rdi), %r13
movq $-0x1, %rdx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
xorl %r14d, %r14d
movl $0x0, 0x8(%rsp)
movzbl -0x1(%r13), %ebp
cmpl $0x9, %ebp
je 0xd1ba
testl %ebp, %ebp
jne 0xd217
movb $0x0, -0x1(%r13)
cmpl $0x4, %r14d
ja 0xd20c
movl %r14d, %eax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq %rdi, %r15
jmp 0xd20c
xorl %eax, %eax
cmpb $0x2b, (%rdi)
sete %al
leal -0x1(,%rax,2), %eax
movl %eax, 0x8(%rsp)
jmp 0xd20c
movb (%rdi), %al
xorl %ecx, %ecx
cmpb $0x41, %al
sete %cl
cmpb $0x44, %al
leal -0x1(%rcx,%rcx), %ebx
movl $0x0, %eax
cmovel %eax, %ebx
jmp 0xd20c
callq 0x2270
movq %rax, %rdx
testb %bpl, %bpl
je 0xd21c
incl %r14d
movq %r13, %rdi
incq %r13
jmp 0xd1ac
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x4, %r14d
movq 0x20(%rsp), %rbp
jge 0xd245
jmp 0xd342
movq %rdx, %r14
callq 0x22c0
movq %r14, %rdx
movl %eax, %r13d
movq 0x20(%rsp), %rbp
movq %rdx, %r14
movl 0xc(%rsp), %eax
cmpl %eax, %r13d
cmovgel %eax, %r13d
movl 0x18(%rsp), %eax
cmpl %eax, %r13d
cmovlel %eax, %r13d
movq %rbp, %rdi
movq %r15, %rsi
callq 0xcf93
testl %eax, %eax
js 0xd342
testl %ebx, %ebx
js 0xd342
cmpl $0x0, 0x8(%rsp)
je 0xd342
testq %r14, %r14
js 0xd342
movl %eax, %r15d
movq %r14, %rsi
movq 0x40(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x8(%rsp)
setle %al
leal (%rax,%r15,2), %eax
movslq %eax, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rdi
movl (%rcx,%rdx), %eax
cmpl 0x4(%rcx,%rdx), %eax
jb 0xd2e7
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, 0x38(%rsp)
xorl %edi, %edi
callq 0x85ad
movq 0x38(%rsp), %rdi
movq %r14, %rsi
movq %rax, 0x8(%rdi)
movl %r15d, %eax
cmpl $0x0, 0x8(%rsp)
jns 0xd304
movq 0x28(%rbp), %rcx
leaq (%rax,%rax,2), %rdx
movq 0x8(%rcx,%rdx,8), %rcx
subq %rsi, %rcx
movq %rcx, %rsi
testq %rsi, %rsi
jle 0xd342
movq 0x28(%rbp), %rcx
leaq (%rax,%rax,2), %rax
cmpq 0x8(%rcx,%rax,8), %rsi
jge 0xd342
shlq $0x8, %rsi
leal 0x80(,%r13,2), %eax
cltq
movl %ebx, %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)
movq 0x28(%rsp), %rdi
movl $0x2, %esi
leaq 0x40(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
xorl %r8d, %r8d
callq 0xbc31
testl %eax, %eax
jns 0xd189
movq 0x28(%rsp), %rdi
callq 0xbc15
movq 0x30(%rsp), %rdi
callq 0x2040
movl (%rbp), %eax
testl %eax, %eax
jle 0xd3b8
movl $0x8, %ebx
xorl %r14d, %r14d
movq 0x40(%rbp), %rcx
movl -0x8(%rcx,%rbx), %edx
testq %rdx, %rdx
je 0xd3a6
movq (%rcx,%rbx), %rdi
leaq (%rdi,%rdx,8), %rsi
callq 0x4a34
movl (%rbp), %eax
incq %r14
leal (%rax,%rax), %ecx
movslq %ecx, %rcx
addq $0x10, %rbx
cmpq %rcx, %r14
jl 0xd389
leaq 0xc021(%rip), %rax      # 0x193e0
xorl %ebx, %ebx
cmpl $0x3, (%rax)
jl 0xd3f3
movq 0xbc23(%rip), %rax      # 0x18ff0
movq (%rax), %rdi
leaq 0x7aac(%rip), %rsi      # 0x14e83
leaq 0x7ac5(%rip), %rdx      # 0x14ea3
xorl %ebx, %ebx
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x21d0
jmp 0xd3f3
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq