// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam_aux.c
// Function: bam_parse_region
int bam_parse_region(bam_header_t *header, const char *str, int *ref_id, int *beg, int *end)
{
	char *s;
	int i, l, k, name_end;
	khiter_t iter;
	khash_t(s) *h;

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

	*ref_id = *beg = *end = -1;
	name_end = l = strlen(str);
	s = (char*)malloc(l+1);
	// remove space
	for (i = k = 0; i < l; ++i)
		if (!isspace(str[i])) s[k++] = str[i];
	s[k] = 0; l = k;
	// determine the sequence name
	for (i = l - 1; i >= 0; --i) if (s[i] == ':') break; // look for colon from the end
	if (i >= 0) name_end = i;
	if (name_end < l) { // check if this is really the end
		int n_hyphen = 0;
		for (i = name_end + 1; i < l; ++i) {
			if (s[i] == '-') ++n_hyphen;
			else if (!isdigit(s[i]) && s[i] != ',') break;
		}
		if (i < l || n_hyphen > 1) name_end = l; // malformated region string; then take str as the name
		s[name_end] = 0;
		iter = kh_get(s, h, s);
		if (iter == kh_end(h)) { // cannot find the sequence name
			iter = kh_get(s, h, str); // try str as the name
			if (iter == kh_end(h)) {
				if (bam_verbose >= 2) fprintf(stderr, "[%s] fail to determine the sequence name.\n", __func__);
				free(s); return -1;
			} else s[name_end] = ':', name_end = l;
		}
	} else iter = kh_get(s, h, str);
        if (iter == kh_end(h)) {
          free(s); 
          return -1;
        }
	*ref_id = kh_val(h, iter);
	// parse the interval
	if (name_end < l) {
		for (i = k = name_end + 1; i < l; ++i)
			if (s[i] != ',') s[k++] = s[i];
		s[k] = 0;
		*beg = atoi(s + name_end + 1);
		for (i = name_end + 1; i != k; ++i) if (s[i] == '-') break;
		*end = i < k? atoi(s + i + 1) : 1<<29;
		if (*beg > 0) --*beg;
	} else *beg = 0, *end = 1<<29;
	free(s);
	return *beg <= *end? 0 : -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %rbx
callq 0x8e02
movq 0x20(%rbx), %rax
movq %rax, 0x10(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, (%r15)
movl %eax, (%r13)
movq %r14, 0x50(%rsp)
movl %eax, (%r14)
movq %rbp, %rdi
callq 0x31e0
movq %rax, %r14
incl %eax
movslq %eax, %rdi
callq 0x33e0
testl %r14d, %r14d
movq %rax, 0x18(%rsp)
jle 0x94a2
callq 0x35f0
movq 0x18(%rsp), %r9
movq (%rax), %rax
movl %r14d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
xorl %r8d, %r8d
movsbq (%rbp,%rdx), %rsi
testb $0x20, 0x1(%rax,%rsi,2)
jne 0x9498
movslq %r8d, %rdi
incl %r8d
movb %sil, (%r9,%rdi)
incq %rdx
cmpq %rdx, %rcx
jne 0x9481
jmp 0x94a8
movq %rax, %r9
xorl %r8d, %r8d
movq %r15, 0x28(%rsp)
movslq %r8d, %r15
movb $0x0, (%r9,%r15)
movl %r15d, %eax
decq %rax
movl %r8d, %r12d
testl %r12d, %r12d
jle 0x94d4
movl %eax, %ecx
decl %r12d
decq %rax
cmpb $0x3a, (%r9,%rcx)
jne 0x94be
jmp 0x94d7
movl %r14d, %r12d
movq %rbp, 0x20(%rsp)
cmpl %r8d, %r12d
movq %r13, 0x40(%rsp)
movq %r8, 0x30(%rsp)
jge 0x95c8
leal 0x1(%r12), %eax
cmpl %r8d, %eax
jge 0x956f
movslq %r12d, %r14
addq $0x2, %r14
leal -0x1(%r8), %r13d
xorl %eax, %eax
movb $0x1, %bpl
movsbq -0x1(%r9,%r14), %rbx
cmpq $0x2d, %rbx
jne 0x9519
incl %eax
jmp 0x9549
movl %eax, 0x8(%rsp)
callq 0x35f0
cmpb $0x2c, %bl
je 0x9540
movq (%rax), %rax
movzwl (%rax,%rbx,2), %eax
andl $0x800, %eax            # imm = 0x800
movq 0x18(%rsp), %r9
movl 0x8(%rsp), %eax
jne 0x9549
jmp 0x955b
movq 0x18(%rsp), %r9
movl 0x8(%rsp), %eax
cmpq %r15, %r14
setl %bpl
incq %r14
decl %r13d
cmpl %r13d, %r12d
jne 0x9509
cmpl $0x2, %eax
movq 0x30(%rsp), %r8
cmovgel %r8d, %r12d
testb $0x1, %bpl
cmovnel %r8d, %r12d
movslq %r12d, %rax
movq %rax, 0x48(%rsp)
movb $0x0, (%r9,%rax)
movq 0x10(%rsp), %rax
movl (%rax), %eax
movq %rax, 0x8(%rsp)
testl %eax, %eax
je 0x961e
movsbl (%r9), %esi
xorl %edi, %edi
movl $0x0, %ecx
testl %esi, %esi
je 0x9627
movb 0x1(%r9), %al
testb %al, %al
je 0x9625
leaq 0x2(%r9), %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 0x95b1
jmp 0x9627
movq 0x10(%rsp), %rax
movl (%rax), %eax
movq %rax, 0x8(%rsp)
testl %eax, %eax
je 0x9880
movq 0x20(%rsp), %rdx
movsbl (%rdx), %esi
xorl %edi, %edi
movl $0x0, %ecx
testl %esi, %esi
je 0x971a
movb 0x1(%rdx), %al
testb %al, %al
je 0x9718
addq $0x2, %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 0x9604
jmp 0x971a
xorl %ebx, %ebx
jmp 0x96be
movl %esi, %ecx
movl %ecx, %eax
xorl %edx, %edx
movq 0x8(%rsp), %rsi
divl %esi
movl %edx, %r13d
decl %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %edx, %r14d
incl %r14d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
movl %r13d, %ebx
movq %rsi, 0x38(%rsp)
movl %ebx, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %ebp
leal (%rbx,%rbx), %r15d
andl $0x1e, %r15d
movl %ebp, %eax
movl %r15d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x96b0
testb $0x1, %al
jne 0x969a
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rdi
movq %r9, %rsi
callq 0x3300
movq 0x38(%rsp), %rsi
xorl %edi, %edi
movq 0x18(%rsp), %r9
testl %eax, %eax
je 0x96b0
addl %r14d, %ebx
movq 0x8(%rsp), %rax
cmpl %eax, %ebx
cmovbl %edi, %eax
subl %eax, %ebx
cmpl %r13d, %ebx
jne 0x9654
jmp 0x96c8
movl %r15d, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel 0x8(%rsp), %ebx
cmpl 0x8(%rsp), %ebx
jne 0x987a
cmpl $0x0, 0x8(%rsp)
je 0x9711
movq 0x20(%rsp), %rdx
movsbl (%rdx), %esi
xorl %edi, %edi
movl $0x0, %ecx
testl %esi, %esi
je 0x97bd
movb 0x1(%rdx), %al
testb %al, %al
je 0x97bb
addq $0x2, %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 0x96f7
jmp 0x97bd
xorl %ebx, %ebx
jmp 0x984d
movl %esi, %ecx
movl %ecx, %eax
xorl %edx, %edx
movq 0x8(%rsp), %rsi
divl %esi
movl %edx, %r14d
decl %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %edx, %r13d
incl %r13d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
movl %r14d, %ebx
movq %rsi, 0x38(%rsp)
movl %ebx, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %ebp
leal (%rbx,%rbx), %r15d
andl $0x1e, %r15d
movl %ebp, %eax
movl %r15d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x97a8
testb $0x1, %al
jne 0x978f
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x20(%rsp), %rsi
callq 0x3300
movq 0x38(%rsp), %rsi
xorl %edi, %edi
movq 0x18(%rsp), %r9
testl %eax, %eax
je 0x97a8
addl %r13d, %ebx
movq 0x8(%rsp), %rax
cmpl %eax, %ebx
cmovbl %edi, %eax
subl %eax, %ebx
cmpl %r14d, %ebx
jne 0x9747
jmp 0x9880
movl %r15d, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel 0x8(%rsp), %ebx
jmp 0x987a
movl %esi, %ecx
movl %ecx, %eax
xorl %edx, %edx
movq 0x8(%rsp), %rsi
divl %esi
movl %edx, %ebp
decl %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %edx, %r14d
incl %r14d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r13
movl %ebp, %ebx
movl %ebx, %eax
shrl $0x4, %eax
movl (%r13,%rax,4), %r12d
leal (%rbx,%rbx), %r15d
andl $0x1e, %r15d
movl %r12d, %eax
movl %r15d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x983e
testb $0x1, %al
jne 0x9829
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x20(%rsp), %rsi
callq 0x3300
xorl %edi, %edi
movq 0x18(%rsp), %r9
testl %eax, %eax
je 0x983e
addl %r14d, %ebx
movq 0x8(%rsp), %rax
cmpl %eax, %ebx
cmovbl %edi, %eax
subl %eax, %ebx
cmpl %ebp, %ebx
jne 0x97e3
jmp 0x9853
movl %r15d, %ecx
shrl %cl, %r12d
testb $0x3, %r12b
cmovnel 0x8(%rsp), %ebx
cmpl 0x8(%rsp), %ebx
jne 0x986b
leaq 0x19cb6(%rip), %rax     # 0x23510
cmpl $0x2, (%rax)
jl 0x9880
callq 0x3640
movq 0x18(%rsp), %r9
jmp 0x9880
movq 0x48(%rsp), %rax
movb $0x3a, (%r9,%rax)
movq 0x30(%rsp), %r12
cmpl 0x8(%rsp), %ebx
jne 0x9892
movq %r9, %rdi
callq 0x3060
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x99a5
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movl %ebx, %ecx
movl (%rax,%rcx,4), %eax
movq 0x50(%rsp), %rcx
movl %eax, (%rcx)
movq 0x30(%rsp), %rcx
movl %ecx, %eax
subl %r12d, %eax
jle 0x993f
movq %rcx, %rdx
leal 0x1(%r12), %ebx
movslq %r12d, %rcx
movl %ebx, %r14d
cmpl %edx, %ebx
movq 0x40(%rsp), %r13
jge 0x98f5
leaq (%r9,%rcx), %rdx
movl $0x1, %esi
movl %ebx, %r14d
movb (%rdx,%rsi), %dil
cmpb $0x2c, %dil
je 0x98ee
movslq %r14d, %r8
incl %r14d
movb %dil, (%r9,%r8)
incq %rsi
cmpl %esi, %eax
jne 0x98da
movslq %r14d, %r15
movb $0x0, (%r9,%r15)
leaq (%r9,%rcx), %rdi
incq %rdi
movq %r9, %r12
callq 0x34f0
movl %eax, (%r13)
cmpl %r15d, %ebx
jne 0x995e
movq %r12, %r9
movq 0x28(%rsp), %r15
movl $0x20000000, %ebp       # imm = 0x20000000
cmpl %r14d, %ebx
jge 0x9980
movslq %ebx, %rax
leaq (%r9,%rax), %rdi
incq %rdi
callq 0x34f0
movq 0x18(%rsp), %r9
movl %eax, %ebp
jmp 0x9980
movq 0x40(%rsp), %rcx
movl $0x0, (%rcx)
movq 0x28(%rsp), %rax
movl $0x20000000, (%rax)     # imm = 0x20000000
movl (%rcx), %ebx
movl $0x20000000, %ebp       # imm = 0x20000000
jmp 0x9994
movslq %ebx, %rax
addq %r12, %rax
movq %r12, %r9
movq 0x28(%rsp), %r15
cmpb $0x2d, (%rax)
je 0x991d
incl %ebx
incq %rax
cmpl %ebx, %r14d
jne 0x996c
movl $0x20000000, %ebp       # imm = 0x20000000
movl %ebp, (%r15)
movl (%r13), %ebx
testl %ebx, %ebx
jle 0x9994
decl %ebx
movl %ebx, (%r13)
movl (%r15), %ebp
movq %r9, %rdi
callq 0x3060
xorl %eax, %eax
cmpl %ebp, %ebx
setg %al
negl %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq