// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %r8, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
callq 0x11941
movq 0x20(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %r13, %rdi
callq 0x32d0
movq %rax, %rbx
incl %eax
movslq %eax, %rdi
callq 0x31d0
movq %rax, %r12
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
andq %rbx, %r14
je 0x11ff1
xorl %ebx, %ebx
xorl %ebp, %ebp
movsbq (%r13,%rbx), %r15
cmpq $0x2c, %r15
je 0x11fc4
callq 0x3310
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r15,2)
jne 0x11fc4
movslq %ebp, %rax
incl %ebp
movb %r15b, (%r12,%rax)
incq %rbx
cmpq %rbx, %r14
jne 0x11f9f
movslq %ebp, %rax
movb $0x0, (%r12,%rax)
movb $0x1, %dl
testl %eax, %eax
je 0x11ff8
movl %ebp, %ecx
xorl %eax, %eax
cmpb $0x3a, (%r12,%rax)
je 0x11ffe
incq %rax
cmpq %rax, %rcx
jne 0x11fde
movl %ecx, %eax
jmp 0x12000
movb $0x0, (%r12)
movb $0x1, %dl
xorl %ebp, %ebp
xorl %eax, %eax
jmp 0x12000
xorl %edx, %edx
movl %edx, 0x20(%rsp)
movl %eax, %eax
movq %rax, 0x40(%rsp)
movb $0x0, (%r12,%rax)
movq 0x10(%rsp), %rax
movl (%rax), %r14d
testl %r14d, %r14d
movq %r12, 0x8(%rsp)
movl %ebp, 0x1c(%rsp)
je 0x1205d
movsbl (%r12), %esi
xorl %edi, %edi
movl $0x0, %ecx
testl %esi, %esi
je 0x12067
movb 0x1(%r12), %al
testb %al, %al
je 0x12065
leaq 0x2(%r12), %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 0x12046
jmp 0x12067
xorl %r15d, %r15d
jmp 0x120f3
movl %esi, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r14d
movl %edx, %r12d
leal -0x1(%r14), %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
incl %edx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r13
movl %r12d, %r15d
movl %edx, 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 0x120e7
testb $0x1, %al
jne 0x120d1
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rsi
callq 0x34e0
movl 0x24(%rsp), %edx
xorl %edi, %edi
testl %eax, %eax
je 0x120e7
addl %edx, %r15d
cmpl %r14d, %r15d
movl %r14d, %eax
cmovbl %edi, %eax
subl %eax, %r15d
cmpl %r12d, %r15d
jne 0x1208d
jmp 0x120f8
movl %ebx, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel %r14d, %r15d
cmpl %r14d, %r15d
jne 0x12105
movq 0x38(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0x12138
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movl %r15d, %ecx
movl (%rax,%rcx,4), %eax
movq 0x38(%rsp), %rcx
movl %eax, (%rcx)
cmpb $0x0, 0x20(%rsp)
je 0x12156
movq 0x28(%rsp), %rax
movl $0x0, (%rax)
movq 0x30(%rsp), %rax
movl $0x20000000, (%rax)     # imm = 0x20000000
movq 0x8(%rsp), %rdi
callq 0x32c0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %r15
movq 0x40(%rsp), %r12
leaq (%r15,%r12), %rdi
incq %rdi
movl 0x1c(%rsp), %ebp
cmpl %ebp, %r12d
movq 0x28(%rsp), %r14
je 0x12186
movl %ebp, %eax
cmpb $0x2d, (%r15,%r12)
je 0x121bd
incq %r12
cmpq %r12, %rax
jne 0x12177
callq 0x3410
movl %eax, (%r14)
movl $0x20000000, %ebx       # imm = 0x20000000
movq 0x30(%rsp), %rax
movl %ebx, (%rax)
movl (%r14), %ebp
testl %ebp, %ebp
jle 0x121a8
decl %ebp
movl %ebp, (%r14)
movl (%rax), %ebx
movq %r15, %rdi
callq 0x32c0
xorl %eax, %eax
cmpl %ebx, %ebp
jle 0x12147
callq 0x3dea
jmp 0x12142
callq 0x3410
movl %eax, (%r14)
movl $0x20000000, %ebx       # imm = 0x20000000
cmpl %r12d, %ebp
jle 0x12193
movl %r12d, %eax
leaq (%r15,%rax), %rdi
incq %rdi
callq 0x3410
movl %eax, %ebx
jmp 0x12193