// File: /workspace/github_c_makefile_star2_O0/skoren[P]bacValidation/bamcat.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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x7920
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rdi
callq 0x3150
movl %eax, -0x40(%rbp)
movl %eax, -0x48(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x3520
movq %rax, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x8018
callq 0x3440
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x800b
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x44(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x800d
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x7fbe
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x44(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x8059
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x804c
jmp 0x8059
jmp 0x804e
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x8033
cmpl $0x0, -0x3c(%rbp)
jl 0x8065
movl -0x3c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x8195
movl $0x0, -0x5c(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x80ec
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x80a5
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x80df
callq 0x3440
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x80dd
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
je 0x80dd
jmp 0x80ec
jmp 0x80df
jmp 0x80e1
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x8081
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jl 0x80fa
cmpl $0x1, -0x5c(%rbp)
jle 0x8100
movl -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x58(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x7dd0
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x8193
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x7dd0
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x817f
cmpl $0x2, 0xf277(%rip)      # 0x173c0
jl 0x816a
movq 0xee7e(%rip), %rax      # 0x16fd0
movq (%rax), %rdi
leaq 0xa03d(%rip), %rsi      # 0x12199
leaq 0xa061(%rip), %rdx      # 0x121c4
movb $0x0, %al
callq 0x3590
movq -0x38(%rbp), %rdi
callq 0x3490
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8312
movq -0x38(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb $0x3a, (%rax,%rcx)
movl -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x8193
jmp 0x81a5
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x7dd0
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x81c5
movq -0x38(%rbp), %rdi
callq 0x3490
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8312
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x48(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x82da
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x8237
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
je 0x822a
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x44(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x822c
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x81f1
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
movslq -0x48(%rbp), %rax
addq %rax, %rdi
addq $0x1, %rdi
callq 0x3610
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
je 0x8290
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x8283
jmp 0x8290
jmp 0x8285
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x8268
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x82b1
movq -0x38(%rbp), %rdi
movslq -0x3c(%rbp), %rax
addq %rax, %rdi
addq $0x1, %rdi
callq 0x3610
movl %eax, -0x60(%rbp)
jmp 0x82bb
movl $0x20000000, %eax       # imm = 0x20000000
movl %eax, -0x60(%rbp)
jmp 0x82bb
movl -0x60(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x82d8
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
jmp 0x82ee
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rax
movl $0x20000000, (%rax)     # imm = 0x20000000
movq -0x38(%rbp), %rdi
callq 0x3490
movq -0x28(%rbp), %rax
movl (%rax), %edx
movq -0x30(%rbp), %rax
movl (%rax), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpl %esi, %edx
cmovlel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)