// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
callq 0x19d00
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xe134(%rip), %rsi      # 0x274b4
callq 0x2240
cmpl $0x0, %eax
je 0x193a0
movq -0x10(%rbp), %rdi
leaq 0xed49(%rip), %rsi      # 0x280de
callq 0x2380
movq %rax, -0x60(%rbp)
jmp 0x193c1
movq 0x14be1(%rip), %rax     # 0x2df88
movq (%rax), %rdi
callq 0x22b0
movl %eax, %edi
leaq 0xed26(%rip), %rsi      # 0x280de
callq 0x2140
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x193dd
movq $0x0, -0x8(%rbp)
jmp 0x19693
movl $0x1, %edi
movl $0x18, %esi
callq 0x2230
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x196a0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rdx
xorl %esi, %esi
leaq -0x2c(%rbp), %rcx
callq 0x19700
cmpl $0x0, %eax
jl 0x1965a
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x19200
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x19489
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2440
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x19740
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x4c(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x21e0
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
cmpl $0xa, -0x2c(%rbp)
je 0x19562
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rdx
xorl %esi, %esi
leaq -0x2c(%rbp), %rcx
callq 0x19700
cmpl $0x0, %eax
jle 0x19560
callq 0x2480
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x19560
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x23f0
movl %eax, -0x3c(%rbp)
cmpl $0xa, -0x2c(%rbp)
je 0x1955e
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rdx
xorl %esi, %esi
leaq -0x2c(%rbp), %rcx
callq 0x19700
cmpl $0x0, %eax
jle 0x1955c
callq 0x2480
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x1955c
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x23f0
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x1955a
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
jmp 0x1955c
jmp 0x1955e
jmp 0x19560
jmp 0x19562
cmpl $0xa, -0x2c(%rbp)
je 0x19599
jmp 0x1956a
movq -0x28(%rbp), %rdi
callq 0x19a70
movl %eax, %ecx
movl %ecx, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x61(%rbp)
jle 0x1958c
cmpl $0xa, -0x2c(%rbp)
setne %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x19595
jmp 0x19597
jmp 0x1956a
jmp 0x19599
cmpl $0x0, -0x40(%rbp)
jge 0x195b4
cmpl $0x0, -0x3c(%rbp)
jle 0x195b4
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x19655
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x19655
movq -0x48(%rbp), %rax
movl (%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x1962a
movq -0x48(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x195f1
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
shll %eax
movl %eax, -0x68(%rbp)
jmp 0x195fb
movl $0x4, %eax
movl %eax, -0x68(%rbp)
jmp 0x195fb
movl -0x68(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0x2340
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movslq -0x3c(%rbp), %rdx
shlq $0x20, %rdx
movslq -0x40(%rbp), %rax
orq %rax, %rdx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x193fd
movq -0x28(%rbp), %rdi
callq 0x19b50
movq -0x20(%rbp), %rdi
callq 0x2030
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2040
movq -0x38(%rbp), %rdi
callq 0x2040
movq -0x18(%rbp), %rdi
callq 0x18f50
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)