// File: /workspace/github_cpp_makefile_star2_O1/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam_aux.c
// Function: bam_parse_region
int bam_parse_region(bam_header_t *header, const char *str, int *ref_id, int *begin, int *end)
{
	char *s, *p;
	int i, l, k;
	khiter_t iter;
	khash_t(s) *h;

	bam_init_header_hash(header);
	h = (khash_t(s)*)header->hash;

	l = strlen(str);
	p = s = (char*)malloc(l+1);
	/* squeeze out "," */
	for (i = k = 0; i != l; ++i)
		if (str[i] != ',' && !isspace(str[i])) s[k++] = str[i];
	s[k] = 0;
	for (i = 0; i != k; ++i) if (s[i] == ':') break;
	s[i] = 0;
	iter = kh_get(s, h, s); /* get the ref_id */
	if (iter == kh_end(h)) { // name not found
		*ref_id = -1; free(s);
		return -1;
	}
	*ref_id = kh_value(h, iter);
	if (i == k) { /* dump the whole sequence */
		*begin = 0; *end = 1<<29; free(s);
		return -1;
	}
	for (p = s + i + 1; i != k; ++i) if (s[i] == '-') break;
	*begin = atoi(p);
	if (i < k) {
		p = s + i + 1;
		*end = atoi(p);
	} else *end = 1<<29;
	if (*begin > 0) --*begin;
	free(s);
	if (*begin > *end) {
		fprintf(stderr, "[bam_parse_region] invalid region.\n");
		return -1;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r12
movq %rcx, 0x30(%rsp)
movq %rdx, 0x40(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
callq 0x112f2
movq 0x20(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %r13, %rdi
callq 0x32d0
movq %rax, %rbx
incl %eax
movslq %eax, %rdi
callq 0x31d0
movq %rax, 0x10(%rsp)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x0, %ebp
andq %rbx, %r14
je 0x116f7
xorl %ebx, %ebx
xorl %ebp, %ebp
movsbq (%r13,%rbx), %r15
cmpq $0x2c, %r15
je 0x116ef
callq 0x3310
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r15,2)
jne 0x116ef
movslq %ebp, %rax
incl %ebp
movq 0x10(%rsp), %rcx
movb %r15b, (%rcx,%rax)
incq %rbx
cmpq %rbx, %r14
jne 0x116c5
movl %ebp, %edi
movslq %ebp, %rax
movq 0x10(%rsp), %r13
movb $0x0, (%r13,%rax)
testl %eax, %eax
sete %dl
je 0x11739
cmpb $0x3a, (%r13)
movl $0x0, %ebp
je 0x1173f
leaq -0x1(%rdi), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
sete %dl
je 0x1173d
leaq 0x1(%rcx), %rbp
cmpb $0x3a, 0x1(%r13,%rcx)
movq %rbp, %rcx
jne 0x11720
jmp 0x1173f
xorl %ebp, %ebp
jmp 0x1173f
movl %edi, %ebp
movq %r12, 0x38(%rsp)
movl %ebp, %eax
movq %rax, 0x48(%rsp)
movb $0x0, (%r13,%rax)
movq 0x18(%rsp), %rax
movl (%rax), %r14d
testl %r14d, %r14d
movq %rdi, 0x50(%rsp)
je 0x1179d
movb %dl, 0xf(%rsp)
movsbl (%r13), %esi
xorl %r8d, %r8d
movl $0x0, %ecx
testl %esi, %esi
je 0x117a7
movb 0x1(%r13), %al
testb %al, %al
je 0x117a5
leaq 0x2(%r13), %rdx
movl %esi, %ecx
movl %ecx, %esi
shll $0x5, %esi
subl %ecx, %esi
movsbl %al, %ecx
addl %esi, %ecx
movb (%rdx), %al
incq %rdx
testb %al, %al
jne 0x11786
jmp 0x117a7
xorl %r15d, %r15d
jmp 0x1184e
movl %esi, %ecx
movq %rbp, 0x28(%rsp)
movl %ecx, %eax
xorl %edx, %edx
divl %r14d
movl %edx, %edi
leal -0x1(%r14), %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %edx, %r12d
incl %r12d
movq 0x18(%rsp), %rax
movq 0x10(%rax), %r13
movl %edi, %r15d
movl %edi, 0x24(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%r13,%rax,4), %ebp
leal (%r15,%r15), %ebx
andl $0x1e, %ebx
movl %ebp, %eax
movl %ebx, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x11834
testb $0x1, %al
jne 0x1181a
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x10(%rsp), %rsi
callq 0x34e0
movl 0x24(%rsp), %edi
xorl %r8d, %r8d
testl %eax, %eax
je 0x11834
addl %r12d, %r15d
cmpl %r14d, %r15d
movl %r14d, %eax
cmovbl %r8d, %eax
subl %eax, %r15d
cmpl %edi, %r15d
jne 0x117d5
movl %r14d, %r15d
jmp 0x11840
movl %ebx, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel %r14d, %r15d
movq 0x10(%rsp), %r13
movq 0x28(%rsp), %rbp
movb 0xf(%rsp), %dl
cmpl %r14d, %r15d
jne 0x11860
movq 0x40(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0x11890
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movl %r15d, %ecx
movl (%rax,%rcx,4), %eax
movq 0x40(%rsp), %rcx
movl %eax, (%rcx)
testb %dl, %dl
je 0x1189f
movq 0x30(%rsp), %rax
movl $0x0, (%rax)
movq 0x38(%rsp), %rax
movl $0x20000000, (%rax)     # imm = 0x20000000
movq %r13, %rdi
callq 0x32c0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x11915
movq 0x48(%rsp), %rax
leaq (%rax,%r13), %rdi
incq %rdi
movq 0x50(%rsp), %r15
cmpl %r15d, %ebp
movq 0x38(%rsp), %rbx
movq 0x30(%rsp), %r14
je 0x118d6
cmpb $0x2d, (%r13,%rax)
je 0x118d4
incq %rax
cmpq %rax, %r15
jne 0x118bf
movl %r15d, %ebp
jmp 0x118d6
movl %eax, %ebp
callq 0x3410
movl %eax, (%r14)
movl $0x20000000, %eax       # imm = 0x20000000
cmpl %r15d, %ebp
jge 0x118f6
movl %ebp, %eax
leaq (%rax,%r13), %rdi
incq %rdi
callq 0x3410
movl %eax, (%rbx)
movl (%r14), %eax
testl %eax, %eax
jle 0x11904
decl %eax
movl %eax, (%r14)
movq %r13, %rdi
callq 0x32c0
movl (%r14), %ecx
xorl %eax, %eax
cmpl (%rbx), %ecx
jg 0x11924
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3dea
jmp 0x11898