// File: /workspace/github_c_makefile_star2_O1/lh3[P]bgt/bedidx.c
// Function: bed_read
void *bed_read(const char *fn)
{
	reghash_t *h = kh_init(reg);
	gzFile fp;
	kstream_t *ks;
	int dret;
	kstring_t *str;
	// read the list
	fp = strcmp(fn, "-")? gzopen(fn, "r") : gzdopen(fileno(stdin), "r");
	if (fp == 0) return 0;
	str = (kstring_t*)calloc(1, sizeof(kstring_t));
	ks = ks_init(fp);
	while (ks_getuntil(ks, 0, str, &dret) >= 0) { // read the chr name
		int beg = -1, end = -1;
		bed_reglist_t *p;
		khint_t k = kh_get(reg, h, str->s);
		if (k == kh_end(h)) { // absent from the hash table
			int ret;
			char *s = strdup(str->s);
			k = kh_put(reg, h, s, &ret);
			memset(&kh_val(h, k), 0, sizeof(bed_reglist_t));
		}
		p = &kh_val(h, k);
		if (dret != '\n') { // if the lines has other characters
			if (ks_getuntil(ks, 0, str, &dret) > 0 && isdigit(str->s[0])) {
				beg = atoi(str->s); // begin
				if (dret != '\n') {
					if (ks_getuntil(ks, 0, str, &dret) > 0 && isdigit(str->s[0])) {
						end = atoi(str->s); // end
						if (end < beg) end = -1;
					}
				}
			}
		}
		if (dret != '\n') while ((dret = ks_getc(ks)) > 0 && dret != '\n'); // skip the rest of the line
		if (end < 0 && beg > 0) end = beg, beg = beg - 1; // if there is only one column
		if (beg >= 0 && end > beg) {
			if (p->n == p->m) {
				p->m = p->m? p->m<<1 : 4;
				p->a = (uint64_t*)realloc(p->a, p->m * 8);
			}
			p->a[p->n++] = (uint64_t)beg<<32 | end;
		}
	}
	ks_destroy(ks);
	gzclose(fp);
	free(str->s); free(str);
	bed_index(h);
	return h;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
movl $0x1, %edi
movl $0x28, %esi
callq 0x2220
movq %rax, %r12
leaq 0xa57e(%rip), %rsi      # 0x1e4b4
movq %r14, %rdi
callq 0x2230
testl %eax, %eax
je 0x13f53
leaq 0xb2f2(%rip), %rsi      # 0x1f23b
movq %r14, %rdi
callq 0x2370
jmp 0x13f70
movq 0x1202e(%rip), %rax     # 0x25f88
movq (%rax), %rdi
callq 0x22a0
leaq 0xb2d2(%rip), %rsi      # 0x1f23b
movl %eax, %edi
callq 0x2140
movq %rax, %rbx
testq %rax, %rax
je 0x144dc
movl $0x1, %edi
movl $0x18, %esi
callq 0x2220
movq %rax, %r14
movl $0x1, %edi
movl $0x20, %esi
callq 0x2220
movq %rax, %r13
movq %rbx, 0x40(%rsp)
movq %rbx, 0x10(%rax)
movq %r14, %rbx
movl 0x8(%rax), %eax
andl $0x3, %eax
orl $0x8000, %eax           # imm = 0x8000
movl %eax, 0x8(%r13)
movl $0x2000, %edi           # imm = 0x2000
callq 0x22e0
movq %rax, 0x18(%r13)
leaq 0x4(%rsp), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x144f1
testl %eax, %eax
js 0x144a1
movq %rbx, 0x18(%rsp)
movq %r13, 0x8(%rsp)
movq %r12, 0x38(%rsp)
movq 0x10(%rbx), %rsi
movl (%r12), %ebp
movl $0x0, %r15d
testl %ebp, %ebp
je 0x140d5
movsbl (%rsi), %ebx
testl %ebx, %ebx
je 0x1402f
movb 0x1(%rsi), %al
testb %al, %al
je 0x14031
leaq 0x2(%rsi), %rcx
movl %ebx, %edx
shll $0x5, %edx
subl %ebx, %edx
movsbl %al, %ebx
addl %edx, %ebx
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x14018
jmp 0x14031
xorl %ebx, %ebx
movq %rbp, 0x20(%rsp)
leal -0x1(%rbp), %edx
movl %ebx, %edi
andl %edx, %edi
movl %ebx, %eax
shrl $0x3, %eax
shll $0x3, %ebx
xorl %eax, %ebx
orl $0x1, %ebx
andl %edx, %ebx
movq 0x10(%r12), %r14
movl %edi, %r15d
movl %edi, 0x10(%rsp)
movl %edx, 0x30(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%r14,%rax,4), %r13d
leal (%r15,%r15), %ebp
andl $0x1e, %ebp
movl %r13d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x140b9
testb $0x1, %al
jne 0x140a4
movq 0x18(%r12), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rsi, %r12
callq 0x2230
movl 0x10(%rsp), %edi
movl 0x30(%rsp), %edx
movq %r12, %rsi
movq 0x38(%rsp), %r12
testl %eax, %eax
je 0x140b9
addl %ebx, %r15d
andl %edx, %r15d
cmpl %edi, %r15d
jne 0x1405c
movq 0x20(%rsp), %rbp
movl %ebp, %r15d
jmp 0x140cb
movl %ebp, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
movq 0x20(%rsp), %rbp
cmovnel %ebp, %r15d
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r13
cmpl %ebp, %r15d
jne 0x142c7
movq %rsi, %rdi
callq 0x2420
movq %rax, %r14
movl 0x8(%r12), %eax
cmpl 0xc(%r12), %eax
jb 0x14112
movl 0x4(%r12), %eax
addl %eax, %eax
cmpl %ebp, %eax
movl $0x0, %esi
sbbl %esi, %esi
orl $0x1, %esi
addl %ebp, %esi
movq %r12, %rdi
callq 0x14758
movl (%r12), %esi
movsbl (%r14), %ebp
testl %ebp, %ebp
je 0x14144
movb 0x1(%r14), %al
testb %al, %al
je 0x14146
movq %r14, %rcx
addq $0x2, %rcx
movl %ebp, %edx
shll $0x5, %edx
subl %ebp, %edx
movsbl %al, %ebp
addl %edx, %ebp
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x1412d
jmp 0x14146
xorl %ebp, %ebp
leal -0x1(%rsi), %edx
movl %ebp, %r15d
andl %edx, %r15d
movq 0x10(%r12), %r8
movl %r15d, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %eax
leal (%r15,%r15), %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x14235
movq %r14, 0x10(%rsp)
movl %ebp, %eax
shrl $0x3, %eax
shll $0x3, %ebp
xorl %eax, %ebp
orl $0x1, %ebp
andl %edx, %ebp
movq %rsi, 0x28(%rsp)
movl %esi, %ebx
movl %r15d, %r13d
movq %r8, 0x30(%rsp)
movl %edx, 0x20(%rsp)
movl %r13d, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %r12d
leal (,%r13,2), %r14d
andl $0x1e, %r14d
movl %r12d, %eax
movl %r14d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x141f7
testb $0x1, %al
jne 0x141e0
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x10(%rsp), %rsi
callq 0x2230
movl 0x20(%rsp), %edx
movq 0x30(%rsp), %r8
testl %eax, %eax
je 0x141f7
btl %r14d, %r12d
cmovbl %r13d, %ebx
addl %ebp, %r13d
andl %edx, %r13d
movl %ebx, %eax
cmpl %r15d, %r13d
jne 0x14193
jmp 0x141fc
movq 0x28(%rsp), %rax
movl %eax, %r15d
movq 0x28(%rsp), %rdx
cmpl %edx, %eax
movq 0x38(%rsp), %r12
movq 0x10(%rsp), %r14
jne 0x14235
movl %r13d, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %eax
leal (,%r13,2), %ecx
shrl %cl, %eax
cmpl %edx, %ebx
cmovel %r13d, %ebx
testb $0x2, %al
cmovel %r13d, %ebx
movl %ebx, %r15d
movl %r15d, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %edx
leal (%r15,%r15), %ecx
andl $0x1e, %ecx
movl %edx, %edi
shrl %cl, %edi
movl %r15d, %esi
testb $0x2, %dil
jne 0x14282
testb $0x1, %dil
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r13
je 0x142ae
movl $0x3, %edi
shll %cl, %edi
movq 0x18(%r12), %rcx
movq %r14, (%rcx,%rsi,8)
notl %edi
andl %edi, %edx
movl %edx, (%r8,%rax,4)
incl 0x4(%r12)
jmp 0x142ae
movl $0x3, %edi
shll %cl, %edi
movq 0x18(%r12), %rcx
movq %r14, (%rcx,%rsi,8)
notl %edi
andl %edi, %edx
movl %edx, (%r8,%rax,4)
incl 0x4(%r12)
incl 0x8(%r12)
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r13
movq 0x20(%r12), %rax
leaq (%rsi,%rsi,2), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%rax,%rcx,8)
movq $0x0, 0x10(%rax,%rcx,8)
movl %r15d, %eax
leaq (%rax,%rax,2), %r15
shlq $0x3, %r15
addq 0x20(%r12), %r15
cmpl $0xa, 0x4(%rsp)
je 0x1431c
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x4(%rsp), %rdx
callq 0x144f1
testl %eax, %eax
jle 0x1431c
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
callq 0x2460
movq %rax, %r13
movq (%rax), %rax
movq 0x10(%rbx), %rdi
movsbq (%rdi), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x1432c
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x1437a
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x1437f
callq 0x23e0
movl %eax, %r14d
cmpl $0xa, 0x4(%rsp)
je 0x1437a
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
leaq 0x4(%rsp), %rdx
callq 0x144f1
testl %eax, %eax
jle 0x1437a
movq (%r13), %rax
movq 0x10(%rbx), %rdi
movsbq (%rdi), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x1437a
callq 0x23e0
movl %eax, %ecx
cmpl %r14d, %eax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovll %eax, %ecx
movl %ecx, 0x10(%rsp)
movq 0x8(%rsp), %r13
cmpl $0xa, 0x4(%rsp)
je 0x1441e
movl 0x8(%r13), %ebx
testb $0x3, %bl
je 0x143a2
movl (%r13), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0x4(%r13), %ecx
jge 0x143ff
movl (%r13), %eax
cmpl 0x4(%r13), %eax
jl 0x143ec
movq %r12, %rbp
movl $0x0, (%r13)
movq 0x10(%r13), %rdi
movq 0x18(%r13), %rsi
movq %r13, %r12
movl %ebx, %r13d
sarl $0x2, %r13d
movl %r13d, %edx
callq 0x2240
movl %eax, 0x4(%r12)
cmpl %r13d, %eax
jge 0x143e0
andl $-0x4, %ebx
incl %ebx
testl %eax, %eax
movq 0x8(%rsp), %r13
movq %rbp, %r12
je 0x1440e
movq 0x18(%r13), %rax
movslq (%r13), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%r13)
movzbl (%rax,%rcx), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
jle 0x14415
cmpl $0xa, %eax
jne 0x1438e
jmp 0x14415
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x143ff
movl %ebx, 0x8(%r13)
movq 0x18(%rsp), %rbx
movl 0x10(%rsp), %ebp
testl %ebp, %ebp
sets %al
testl %r14d, %r14d
setg %cl
andb %al, %cl
movzbl %cl, %eax
testb %al, %al
cmovnel %r14d, %ebp
subl %eax, %r14d
js 0x14489
cmpl %r14d, %ebp
jle 0x14489
movl 0x4(%r15), %eax
cmpl %eax, (%r15)
jne 0x1446f
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x4, %eax
cmovel %eax, %ecx
movl %ecx, 0x4(%r15)
movq 0x8(%r15), %rdi
shll $0x3, %ecx
movslq %ecx, %rsi
callq 0x2330
movq %rax, 0x8(%r15)
shlq $0x20, %r14
movl %ebp, %eax
orq %r14, %rax
movq 0x8(%r15), %rcx
movslq (%r15), %rdx
leal 0x1(%rdx), %esi
movl %esi, (%r15)
movq %rax, (%rcx,%rdx,8)
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x4(%rsp), %rdx
callq 0x144f1
testl %eax, %eax
jns 0x13ff0
testq %r13, %r13
je 0x144b7
movq 0x18(%r13), %rdi
callq 0x2050
movq %r13, %rdi
callq 0x2050
movq 0x40(%rsp), %rdi
callq 0x2040
movq 0x10(%rbx), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2050
movq %r12, %rdi
callq 0x13cb0
jmp 0x144df
xorl %r12d, %r12d
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq