// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movl %edx, %ebp
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
testq %rsi, %rsi
je 0xce34
movq %rsi, %r14
leaq 0x68fe(%rip), %rsi      # 0x13715
movq %r14, %rdi
callq 0x21b0
testl %eax, %eax
je 0xce34
leaq 0x6854(%rip), %rsi      # 0x1367e
movq %r14, %rdi
callq 0x2260
jmp 0xce42
leaq 0x6843(%rip), %rsi      # 0x1367e
xorl %edi, %edi
callq 0x20d0
movq %rax, %rbx
testq %rax, %rax
je 0xd19a
cmpl $0x3f, %ebp
movl $0x3f, %eax
cmovll %ebp, %eax
movl %eax, 0xc(%rsp)
movq %r15, %rdi
callq 0xc904
movslq (%r15), %rsi
addq %rsi, %rsi
movl $0x10, %edx
xorl %edi, %edi
callq 0x7f34
movq %rax, 0x40(%r15)
movl $0x1, %edi
movl $0x20, %esi
callq 0x21a0
movq %rax, %r14
movq %rbx, 0x48(%rsp)
movq %rbx, 0x10(%rax)
movl 0x8(%rax), %eax
andl $0x3, %eax
orl $0x10000, %eax          # imm = 0x10000
movl %eax, 0x8(%r14)
movl $0x4000, %edi           # imm = 0x4000
callq 0x2220
movq %rax, 0x18(%r14)
leaq 0x50(%rsp), %rdx
leaq 0x24(%rsp), %rcx
movq %r14, 0x30(%rsp)
movq %r14, %rdi
movl $0x2, %esi
xorl %r8d, %r8d
callq 0xb9a5
movl $0x0, %ecx
movq %rcx, 0x18(%rsp)
testl %eax, %eax
js 0xd116
movl 0xc(%rsp), %eax
negl %eax
movl %eax, 0x20(%rsp)
leaq 0x6e5b(%rip), %rbx      # 0x13d50
movq $0x0, 0x18(%rsp)
movq %r15, 0x28(%rsp)
movq 0x60(%rsp), %rbp
leaq 0x1(%rbp), %r13
movq $-0x1, 0x38(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq $0x0, 0x40(%rsp)
xorl %r15d, %r15d
movl $0x0, 0x8(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x10(%rsp)
movzbl -0x1(%r13), %r14d
cmpl $0x9, %r14d
je 0xcf4d
testl %r14d, %r14d
jne 0xcfd4
movb $0x0, -0x1(%r13)
cmpl $0x4, %r15d
ja 0xcfbf
movl %r15d, %eax
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
movq %rbp, 0x40(%rsp)
jmp 0xcfbf
movq %rbp, %rdi
callq 0x22c0
movq %rax, 0x10(%rsp)
movl $0x4, %r15d
jmp 0xcfce
xorl %eax, %eax
cmpb $0x2b, (%rbp)
sete %al
leal -0x1(,%rax,2), %eax
movl %eax, 0x8(%rsp)
jmp 0xcfbf
movb (%rbp), %al
xorl %ecx, %ecx
cmpb $0x41, %al
sete %cl
cmpb $0x44, %al
leal -0x1(%rcx,%rcx), %r12d
movl $0x0, %eax
cmovel %eax, %r12d
jmp 0xcfbf
movq %rbp, %rdi
callq 0x2270
movq %rax, 0x38(%rsp)
testb %r14b, %r14b
je 0xcfce
incl %r15d
movb $0x1, %al
movq %r13, %rbp
jmp 0xcfd0
xorl %eax, %eax
testb %al, %al
je 0xcfdc
incq %r13
jmp 0xcf39
cmpl $0x4, %r15d
jge 0xd010
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %rdi
movl $0x2, %esi
leaq 0x50(%rsp), %rdx
leaq 0x24(%rsp), %rcx
xorl %r8d, %r8d
callq 0xb9a5
testl %eax, %eax
jns 0xcf03
jmp 0xd116
movl 0xc(%rsp), %eax
movq 0x10(%rsp), %r14
cmpl %eax, %r14d
cmovgel %eax, %r14d
movl 0x20(%rsp), %eax
cmpl %eax, %r14d
cmovlel %eax, %r14d
movq 0x28(%rsp), %r15
movq %r15, %rdi
movq 0x40(%rsp), %rsi
callq 0xcce0
testl %eax, %eax
js 0xcfe7
testl %r12d, %r12d
js 0xcfe7
cmpl $0x0, 0x8(%rsp)
je 0xcfe7
movq %r14, 0x10(%rsp)
movq 0x38(%rsp), %rbp
testq %rbp, %rbp
js 0xcfe7
movl %eax, %r13d
movq 0x40(%r15), %rcx
xorl %eax, %eax
cmpl $0x0, 0x8(%rsp)
setle %al
leal (%rax,%r13,2), %eax
movslq %eax, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %r14
movl (%rcx,%rdx), %eax
cmpl 0x4(%rcx,%rdx), %eax
jb 0xd0a7
leal 0x1(%rax), %ecx
shrl %ecx
leal (%rax,%rcx), %edx
addl $0x11, %edx
movl %edx, 0x4(%r14)
movq 0x8(%r14), %rsi
shlq $0x3, %rdx
xorl %edi, %edi
callq 0x81a4
movq %rax, 0x8(%r14)
movl %r13d, %eax
cmpl $0x0, 0x8(%rsp)
jns 0xd0c4
movq 0x28(%r15), %rcx
leaq (%rax,%rax,2), %rdx
movq 0x8(%rcx,%rdx,8), %rcx
subq %rbp, %rcx
movq %rcx, %rbp
testq %rbp, %rbp
jle 0xcfe7
movq 0x28(%r15), %rcx
leaq (%rax,%rax,2), %rax
cmpq 0x8(%rcx,%rax,8), %rbp
jge 0xcfe7
shlq $0x8, %rbp
movq 0x10(%rsp), %rax
leal 0x80(,%rax,2), %eax
cltq
movl %r12d, %ecx
orq %rbp, %rcx
orq %rax, %rcx
movq 0x8(%r14), %rax
movl (%r14), %edx
leal 0x1(%rdx), %esi
movl %esi, (%r14)
movq %rcx, (%rax,%rdx,8)
incq 0x18(%rsp)
jmp 0xcfe7
movq 0x30(%rsp), %rdi
callq 0xb989
movq 0x48(%rsp), %rdi
callq 0x2040
cmpl $0x0, (%r15)
jle 0xd164
movl $0x8, %ebx
xorl %r14d, %r14d
movq 0x40(%r15), %rax
movl -0x8(%rax,%rbx), %ecx
testq %rcx, %rcx
je 0xd152
movq (%rax,%rbx), %rdi
leaq (%rdi,%rcx,8), %rsi
callq 0x46b4
incq %r14
movslq (%r15), %rax
addq %rax, %rax
addq $0x10, %rbx
cmpq %rax, %r14
jl 0xd138
leaq 0xb275(%rip), %rax      # 0x183e0
xorl %ebx, %ebx
cmpl $0x3, (%rax)
jl 0xd19f
movq 0xae77(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x6cb0(%rip), %rsi      # 0x13e33
leaq 0x6cc9(%rip), %rdx      # 0x13e53
xorl %ebx, %ebx
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x21d0
jmp 0xd19f
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq