// File: /workspace/github_c_makefile_star2_O1/lh3[P]minimap2/index.c
// Function: rs_sort_end
static mm_idx_intv_t *mm_idx_bed_read_core(const mm_idx_t *mi, const char *fn, int read_junc, int min_sc)
{
	gzFile fp;
	kstream_t *ks;
	kstring_t str = {0,0,0};
	mm_idx_intv_t *I;

	fp = fn && strcmp(fn, "-")? gzopen(fn, "r") : gzdopen(fileno(stdin), "r");
	if (fp == 0) return 0;
	I = CALLOC(mm_idx_intv_t, mi->n_seq);
	ks = ks_init(fp);
	while (ks_getuntil(ks, KS_SEP_LINE, &str, 0) >= 0) {
		mm_idx_intv_t *r;
		mm_idx_intv1_t t = {-1,-1,-1,-1,0};
		char *p, *q, *bl, *bs;
		int32_t i, id = -1, n_blk = 0;
		for (p = q = str.s, i = 0;; ++p) {
			if (*p == 0 || *p == '\t') {
				int32_t c = *p;
				*p = 0;
				if (i == 0) { // chr
					id = mm_idx_name2id(mi, q);
					if (id < 0) break; // unknown name; TODO: throw a warning
				} else if (i == 1) { // start
					t.st = atol(q); // TODO: watch out integer overflow!
					if (t.st < 0) break;
				} else if (i == 2) { // end
					t.en = atol(q);
					if (t.en < 0) break;
				} else if (i == 4) { // BED score
					t.score = *q >= '0' && *q <= '9'? atol(q) : -1;
				} else if (i == 5) { // strand
					t.strand = *q == '+'? 1 : *q == '-'? -1 : 0;
				} else if (i == 9) {
					if (!isdigit(*q)) break;
					n_blk = atol(q);
				} else if (i == 10) {
					bl = q;
				} else if (i == 11) {
					bs = q;
					break;
				}
				if (c == 0) break;
				++i, q = p + 1;
			}
		}
		if (id < 0 || t.st < 0 || t.st >= t.en) continue; // contig ID not found, or other problems
		if (min_sc > 0 && t.score < min_sc) continue;
		r = &I[id];
		if (i >= 11 && read_junc) { // BED12
			int32_t st, sz, en;
			st = strtol(bs, &bs, 10); ++bs;
			sz = strtol(bl, &bl, 10); ++bl;
			en = t.st + st + sz;
			for (i = 1; i < n_blk; ++i) {
				mm_idx_intv1_t s = t;
				if (r->n == r->m) {
					r->m = r->m? r->m + (r->m>>1) : 16;
					r->a = (mm_idx_intv1_t*)realloc(r->a, sizeof(*r->a) * r->m);
				}
				st = strtol(bs, &bs, 10); ++bs;
				sz = strtol(bl, &bl, 10); ++bl;
				s.st = en, s.en = t.st + st;
				en = t.st + st + sz;
				if (s.en > s.st) r->a[r->n++] = s;
			}
		} else {
			if (r->n == r->m) {
				r->m = r->m? r->m + (r->m>>1) : 16;
				r->a = (mm_idx_intv1_t*)realloc(r->a, sizeof(*r->a) * r->m);
			}
			r->a[r->n++] = t;
		}
	}
	free(str.s);
	ks_destroy(ks);
	gzclose(fp);
	return I;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movl %ecx, %ebx
movl %edx, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %edx, 0xc(%rsp)
cmpl $0x8, %edx
jg 0x8f8c
movslq %eax, %r14
decl %eax
shlq $0x4, %r14
leaq (%rsp,%r14), %rdx
addq $0x10, %rdx
xorl %ecx, %ecx
movq %rdi, 0x18(%rsp,%rcx)
movq %rdi, 0x10(%rsp,%rcx)
addq $0x10, %rcx
cmpq %rcx, %r14
jne 0x8df4
cmpq %rsi, %rdi
je 0x8e31
movq %rdi, %r8
movl 0x4(%r8), %r9d
movl %ebx, %ecx
sarl %cl, %r9d
andl %eax, %r9d
movslq %r9d, %rcx
shlq $0x4, %rcx
addq $0x10, 0x18(%rsp,%rcx)
addq $0x10, %r8
cmpq %rsi, %r8
jne 0x8e0f
cmpl $0x0, 0xc(%rsp)
je 0x8e5b
movl $0x10, %ecx
movq 0x8(%rsp,%rcx), %rsi
movq %rsi, %r8
subq %rdi, %r8
addq %r8, 0x18(%rsp,%rcx)
movq %rsi, 0x10(%rsp,%rcx)
addq $0x10, %rcx
cmpq %rcx, %r14
jne 0x8e3d
leaq 0x10(%rsp), %rsi
movq (%rsi), %r9
cmpq 0x8(%rsi), %r9
je 0x8ef6
movl 0x4(%r9), %r8d
movl %r8d, %r10d
movl %ebx, %ecx
sarl %cl, %r10d
andl %eax, %r10d
movslq %r10d, %rcx
shlq $0x4, %rcx
addq %rsp, %rcx
addq $0x10, %rcx
cmpq %rsi, %rcx
je 0x8efc
movl (%r9), %r10d
movq 0x8(%r9), %r9
movl %r10d, %r11d
movl %r8d, %r15d
movq %r9, %r12
movq (%rcx), %r13
movl (%r13), %r10d
movl 0x4(%r13), %r8d
movq 0x8(%r13), %r9
leaq 0x10(%r13), %rbp
movq %rbp, (%rcx)
movl %r11d, (%r13)
movl %r15d, 0x4(%r13)
movq %r12, 0x8(%r13)
movl %r8d, %r11d
movl %ebx, %ecx
sarl %cl, %r11d
andl %eax, %r11d
movslq %r11d, %rcx
shlq $0x4, %rcx
addq %rsp, %rcx
addq $0x10, %rcx
cmpq %rsi, %rcx
jne 0x8e96
movq (%rsi), %rcx
leaq 0x10(%rcx), %r11
movq %r11, (%rsi)
movl %r10d, (%rcx)
movl %r8d, 0x4(%rcx)
movq %r9, 0x8(%rcx)
jmp 0x8f03
addq $0x10, %rsi
jmp 0x8f03
addq $0x10, %r9
movq %r9, (%rsi)
cmpq %rdx, %rsi
jne 0x8e60
movq %rdi, 0x10(%rsp)
cmpl $0x0, 0xc(%rsp)
je 0x8f30
movl $0x10, %eax
movq 0x8(%rsp,%rax), %rcx
movq %rcx, 0x10(%rsp,%rax)
addq $0x10, %rax
cmpq %rax, %r14
jne 0x8f1d
testl %ebx, %ebx
je 0x8f7a
xorl %r15d, %r15d
subl 0xc(%rsp), %ebx
cmovlel %r15d, %ebx
movq 0x10(%rsp,%r15), %rdi
movq 0x18(%rsp,%r15), %rsi
movq %rsi, %rax
subq %rdi, %rax
sarq $0x4, %rax
cmpq $0x41, %rax
jl 0x8f66
movl 0xc(%rsp), %edx
movl %ebx, %ecx
callq 0x8db8
jmp 0x8f71
cmpq $0x2, %rax
jl 0x8f71
callq 0x8d56
addq $0x10, %r15
cmpq %r15, %r14
jne 0x8f3f
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x22ad6(%rip), %rdi     # 0x2ba69
leaq 0x232fb(%rip), %rsi     # 0x2c295
leaq 0x23449(%rip), %rcx     # 0x2c3ea
movl $0x2a8, %edx            # imm = 0x2A8
callq 0x21a0