// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rax
shll %cl, %eax
movl %edx, 0x4(%rsp)
cmpl $0x8, %edx
jg 0x7e16
movslq %eax, %r14
decl %eax
movq %r14, %rcx
shlq $0x4, %rcx
leaq (%rsp,%rcx), %rdx
addq $0x10, %rdx
movq %rdx, 0x8(%rsp)
leaq 0x10(%rsp), %r8
testq %rcx, %rcx
je 0x7c82
movq %rdi, 0x8(%r8)
movq %rdi, (%r8)
addq $0x10, %r8
addq $-0x10, %rcx
jmp 0x7c6c
movq %rdi, %r8
cmpq %rsi, %r8
je 0x7ca9
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
jmp 0x7c85
leaq 0x20(%rsp), %rsi
shlq $0x4, %r14
leaq -0x10(%r14), %rcx
movq %rsi, %r8
testq %rcx, %rcx
je 0x7cd9
movq -0x8(%r8), %r9
movq %r9, %r10
subq %rdi, %r10
addq %r10, 0x8(%r8)
movq %r9, (%r8)
addq $0x10, %r8
addq $-0x10, %rcx
jmp 0x7cb9
leaq 0x10(%rsp), %r8
cmpq 0x8(%rsp), %r8
je 0x7d95
movq (%r8), %r10
cmpq 0x8(%r8), %r10
je 0x7d8c
movl 0x4(%r10), %r9d
movl %r9d, %r11d
movl %ebx, %ecx
sarl %cl, %r11d
andl %eax, %r11d
movslq %r11d, %rcx
shlq $0x4, %rcx
addq %rsp, %rcx
addq $0x10, %rcx
cmpq %r8, %rcx
je 0x7d80
movl (%r10), %r11d
movq 0x8(%r10), %r10
movl %r11d, %r15d
movl %r9d, %r12d
movq %r10, %r13
movq (%rcx), %rbp
movl (%rbp), %r11d
movl 0x4(%rbp), %r9d
movq 0x8(%rbp), %r10
leaq 0x10(%rbp), %rdx
movq %rdx, (%rcx)
movl %r15d, (%rbp)
movl %r12d, 0x4(%rbp)
movq %r13, 0x8(%rbp)
movl %r9d, %edx
movl %ebx, %ecx
sarl %cl, %edx
andl %eax, %edx
movslq %edx, %rcx
shlq $0x4, %rcx
addq %rsp, %rcx
addq $0x10, %rcx
cmpq %r8, %rcx
jne 0x7d1f
movq (%r8), %rcx
leaq 0x10(%rcx), %rdx
movq %rdx, (%r8)
movl %r11d, (%rcx)
movl %r9d, 0x4(%rcx)
movq %r10, 0x8(%rcx)
jmp 0x7cde
addq $0x10, %r10
movq %r10, (%r8)
jmp 0x7cde
addq $0x10, %r8
jmp 0x7cde
movq %rdi, 0x10(%rsp)
leaq -0x10(%r14), %rax
testq %rax, %rax
je 0x7db4
movq -0x8(%rsi), %rcx
movq %rcx, (%rsi)
addq $0x10, %rsi
addq $-0x10, %rax
jmp 0x7d9e
testl %ebx, %ebx
je 0x7e04
xorl %eax, %eax
subl 0x4(%rsp), %ebx
cmovlel %eax, %ebx
leaq 0x10(%rsp), %r15
testq %r14, %r14
je 0x7e04
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movq %rsi, %rax
subq %rdi, %rax
sarq $0x4, %rax
cmpq $0x41, %rax
jl 0x7def
movl 0x4(%rsp), %edx
movl %ebx, %ecx
callq 0x7c27
jmp 0x7dfa
cmpq $0x2, %rax
jl 0x7dfa
callq 0x7bdd
addq $0x10, %r15
addq $-0x10, %r14
jmp 0x7dc6
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1fc4c(%rip), %rdi     # 0x27a69
leaq 0x20495(%rip), %rsi     # 0x282b9
leaq 0x205e3(%rip), %rcx     # 0x2840e
movl $0x2a8, %edx            # imm = 0x2A8
callq 0x21a0