// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %rbx
callq 0x8a18
movq 0x20(%rbx), %r13
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, (%r14)
movl %eax, (%r15)
movq %r12, 0x50(%rsp)
movl %eax, (%r12)
movq %rbp, %rdi
callq 0x31e0
movq %rax, %rbx
incl %eax
movslq %eax, %rdi
callq 0x33e0
movq %rax, %r12
testl %ebx, %ebx
jle 0x8e1a
callq 0x35f0
movq (%rax), %rax
movl %ebx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
xorl %r8d, %r8d
movsbq (%rbp,%rdx), %rsi
testb $0x20, 0x1(%rax,%rsi,2)
jne 0x8e10
movslq %r8d, %rdi
incl %r8d
movb %sil, (%r12,%rdi)
incq %rdx
cmpq %rdx, %rcx
jne 0x8df9
jmp 0x8e1d
xorl %r8d, %r8d
movq %rbp, 0x28(%rsp)
movq %r15, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movslq %r8d, %r14
movb $0x0, (%r12,%r14)
movl %r14d, %eax
decq %rax
movl %r8d, 0x1c(%rsp)
movl %r8d, %ebp
testl %ebp, %ebp
jle 0x8e56
movl %eax, %ecx
decl %ebp
decq %rax
cmpb $0x3a, (%r12,%rcx)
jne 0x8e42
jmp 0x8e58
movl %ebx, %ebp
movl 0x1c(%rsp), %ecx
cmpl %ecx, %ebp
jge 0x8f4d
leal 0x1(%rbp), %eax
cmpl %ecx, %eax
setl %bl
movq %r12, 0x10(%rsp)
movq %r13, 0x8(%rsp)
jge 0x8ee7
movslq %ebp, %r12
addq $0x2, %r12
movl %ebp, %r13d
notl %r13d
addl %ecx, %r13d
xorl %ecx, %ecx
movq 0x10(%rsp), %rax
movsbq -0x1(%rax,%r12), %r15
cmpq $0x2d, %r15
jne 0x8e9f
incl %ecx
jmp 0x8ec7
movl %ecx, 0x20(%rsp)
callq 0x35f0
cmpb $0x2c, %r15b
je 0x8ec3
movq (%rax), %rax
movzwl (%rax,%r15,2), %eax
andl $0x800, %eax            # imm = 0x800
movl 0x20(%rsp), %ecx
jne 0x8ec7
jmp 0x8ed5
movl 0x20(%rsp), %ecx
cmpq %r14, %r12
setl %bl
incq %r12
decl %r13d
jne 0x8e8a
cmpl $0x2, %ecx
setge %al
orb %al, %bl
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r13
testb $0x1, %bl
cmovnel 0x1c(%rsp), %ebp
movslq %ebp, %rax
movq %rax, 0x48(%rsp)
movb $0x0, (%r12,%rax)
movl (%r13), %edi
testl %edi, %edi
movq %rdi, 0x20(%rsp)
je 0x8fa2
movsbl (%r12), %esi
xorl %r8d, %r8d
movl $0x0, %ecx
testl %esi, %esi
je 0x8fb4
movb 0x1(%r12), %al
testb %al, %al
je 0x8fb2
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 0x8f36
jmp 0x8fb4
movl (%r13), %r15d
testl %r15d, %r15d
je 0x8faa
movq %r12, 0x10(%rsp)
movq 0x28(%rsp), %rax
movsbl (%rax), %esi
xorl %edi, %edi
movl $0x0, %ecx
testl %esi, %esi
je 0x90b1
movq 0x28(%rsp), %rcx
movb 0x1(%rcx), %al
testb %al, %al
je 0x90af
leaq 0x2(%rcx), %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 0x8f88
jmp 0x90b1
xorl %r15d, %r15d
jmp 0x9050
xorl %r15d, %r15d
jmp 0x9237
movl %esi, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %edx, %r14d
leal -0x1(%rdi), %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
incl %edx
movq 0x10(%r13), %rbx
movl %r14d, %r15d
movl %edx, 0x30(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%rbx,%rax,4), %r13d
leal (%r15,%r15), %r12d
andl $0x1e, %r12d
movl %r13d, %eax
movl %r12d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x9038
testb $0x1, %al
jne 0x901f
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x10(%rsp), %rsi
callq 0x3300
movl 0x30(%rsp), %edx
xorl %r8d, %r8d
movq 0x20(%rsp), %rdi
testl %eax, %eax
je 0x9038
addl %edx, %r15d
cmpl %edi, %r15d
movl %edi, %eax
cmovbl %r8d, %eax
subl %eax, %r15d
cmpl %r14d, %r15d
jne 0x8fd3
movl %edi, %r15d
jmp 0x9046
movl %r12d, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
cmovnel %edi, %r15d
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r13
movb $0x1, %cl
cmpl %edi, %r15d
jne 0x922a
testl %edi, %edi
je 0x90a7
movq 0x28(%rsp), %rax
movsbl (%rax), %esi
xorl %r8d, %r8d
movl $0x0, %ecx
testl %esi, %esi
je 0x915b
movq 0x28(%rsp), %rcx
movb 0x1(%rcx), %al
testb %al, %al
je 0x9159
leaq 0x2(%rcx), %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 0x908d
jmp 0x915b
xorl %r15d, %r15d
jmp 0x91f4
movl %esi, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r15d
movl %edx, %ebx
leal -0x1(%r15), %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
incl %edx
movq %r13, 0x8(%rsp)
movq 0x10(%r13), %rsi
movl %ebx, %r14d
movl %edx, 0x20(%rsp)
movq %rsi, 0x30(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r13d
leal (%r14,%r14), %r12d
andl $0x1e, %r12d
movl %r13d, %eax
movl %r12d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x913c
testb $0x1, %al
jne 0x9126
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x28(%rsp), %rsi
callq 0x3300
movq 0x30(%rsp), %rsi
movl 0x20(%rsp), %edx
xorl %edi, %edi
testl %eax, %eax
je 0x913c
addl %edx, %r14d
cmpl %r15d, %r14d
movl %r15d, %eax
cmovbl %edi, %eax
subl %eax, %r14d
cmpl %ebx, %r14d
jne 0x90db
jmp 0x914a
movl %r12d, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
cmovel %r14d, %r15d
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r13
jmp 0x9237
movl %esi, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %edx, %r14d
leal -0x1(%rdi), %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
incl %edx
movq 0x10(%r13), %rbx
movl %r14d, %r15d
movl %edx, 0x30(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%rbx,%rax,4), %r13d
leal (%r15,%r15), %r12d
andl $0x1e, %r12d
movl %r13d, %eax
movl %r12d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x91df
testb $0x1, %al
jne 0x91c6
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x28(%rsp), %rsi
callq 0x3300
movl 0x30(%rsp), %edx
xorl %r8d, %r8d
movq 0x20(%rsp), %rdi
testl %eax, %eax
je 0x91df
addl %edx, %r15d
cmpl %edi, %r15d
movl %edi, %eax
cmovbl %r8d, %eax
subl %eax, %r15d
cmpl %r14d, %r15d
jne 0x917a
movl %edi, %r15d
jmp 0x91ed
movl %r12d, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
cmovnel %edi, %r15d
movq 0x10(%rsp), %r12
movb $0x1, %cl
cmpl %edi, %r15d
jne 0x9215
leaq 0x19310(%rip), %rax     # 0x22510
cmpl $0x2, (%rax)
jge 0x9341
movq %r12, %rdi
callq 0x3060
xorl %ecx, %ecx
jmp 0x9225
movq 0x48(%rsp), %rax
movb $0x3a, (%r12,%rax)
movl 0x1c(%rsp), %eax
movl %eax, %ebp
movq 0x8(%rsp), %r13
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %cl, %cl
je 0x9332
cmpl (%r13), %r15d
jne 0x924f
movq %r12, %rdi
callq 0x3060
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x9332
movq 0x20(%r13), %rax
movl %r15d, %ecx
movl (%rax,%rcx,4), %eax
movq 0x50(%rsp), %rcx
movl %eax, (%rcx)
movl 0x1c(%rsp), %edx
movl %edx, %eax
subl %ebp, %eax
jle 0x9307
leal 0x1(%rbp), %ebx
movslq %ebp, %rcx
movl %ebx, %ebp
cmpl %edx, %ebx
jge 0x929f
leaq (%r12,%rcx), %rdx
movl $0x1, %esi
movl %ebx, %ebp
movb (%rdx,%rsi), %dil
cmpb $0x2c, %dil
je 0x9298
movslq %ebp, %r8
incl %ebp
movb %dil, (%r12,%r8)
incq %rsi
cmpl %esi, %eax
jne 0x9285
movslq %ebp, %r14
movb $0x0, (%r12,%r14)
leaq (%r12,%rcx), %rdi
incq %rdi
callq 0x34f0
movq 0x38(%rsp), %rcx
movl %eax, (%rcx)
cmpl %r14d, %ebx
je 0x92d5
movslq %ebx, %rax
addq %r12, %rax
cmpb $0x2d, (%rax)
je 0x92d5
incl %ebx
incq %rax
cmpl %ebx, %ebp
jne 0x92c5
movl %ebp, %ebx
movl $0x20000000, %eax       # imm = 0x20000000
cmpl %ebp, %ebx
jge 0x92ed
movslq %ebx, %rax
leaq (%r12,%rax), %rdi
incq %rdi
callq 0x34f0
movq 0x40(%rsp), %rbx
movl %eax, (%rbx)
movq 0x38(%rsp), %r14
movl (%r14), %eax
testl %eax, %eax
jle 0x931e
decl %eax
movl %eax, (%r14)
jmp 0x931e
movq 0x38(%rsp), %r14
movl $0x0, (%r14)
movq 0x40(%rsp), %rbx
movl $0x20000000, (%rbx)     # imm = 0x20000000
movq %r12, %rdi
callq 0x3060
movl (%r14), %ecx
xorl %eax, %eax
cmpl (%rbx), %ecx
setg %al
negl %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3640
jmp 0x9209