// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/faidx.c
// Function: fai_fetch
char *fai_fetch(const faidx_t *fai, const char *str, int *len)
{
	char *s, c;
	int i, l, k, name_end;
	khiter_t iter;
	faidx1_t val;
	khash_t(s) *h;
	int beg, end;

	beg = end = -1;
	h = fai->hash;
	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)) {
				*len = 0;
			free(s); return 0;
			} else s[name_end] = ':', name_end = l;
		}
	} else iter = kh_get(s, h, str);
	val = kh_value(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) : val.len;
		if (beg > 0) --beg;
	} else beg = 0, end = val.len;
	if (beg >= val.len) beg = val.len;
	if (end >= val.len) end = val.len;
	if (beg > end) beg = end;
	free(s);

	// now retrieve the sequence
	l = 0;
	s = (char*)malloc(end - beg + 2);
	razf_seek(fai->rz, val.offset + beg / val.line_blen * val.line_len + beg % val.line_blen, SEEK_SET);
	while (razf_read(fai->rz, &c, 1) == 1 && l < end - beg && !fai->rz->z_err)
		if (isgraph(c)) s[l++] = c;
	s[l] = '\0';
	*len = l;
	return s;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
movq 0x78(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x70(%rsp), %rdi
callq 0x192b0
movl %eax, 0x54(%rsp)
movl %eax, 0x4c(%rsp)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x19ef8
movq %rax, 0x60(%rsp)
movl $0x0, 0x50(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x36ef1f
callq 0x197c0
movq (%rax), %rax
movq 0x70(%rsp), %rcx
movslq 0x58(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x36ef10
movq 0x70(%rsp), %rax
movslq 0x58(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x60(%rsp), %rax
movl 0x50(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x50(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x36ef12
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x36eeba
movq 0x60(%rsp), %rax
movslq 0x50(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movl 0x50(%rsp), %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x58(%rsp)
cmpl $0x0, 0x58(%rsp)
jl 0x36ef6b
movq 0x60(%rsp), %rax
movslq 0x58(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x36ef5c
jmp 0x36ef6b
jmp 0x36ef5e
movl 0x58(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x36ef40
cmpl $0x0, 0x58(%rsp)
jl 0x36ef7a
movl 0x58(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x36f0b9
movl $0x0, 0x1c(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x36f012
movq 0x60(%rsp), %rax
movslq 0x58(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x36efc5
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x36f003
callq 0x197c0
movq (%rax), %rax
movq 0x60(%rsp), %rcx
movslq 0x58(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x36f001
movq 0x60(%rsp), %rax
movslq 0x58(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
je 0x36f001
jmp 0x36f012
jmp 0x36f003
jmp 0x36f005
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x36ef9b
movl 0x58(%rsp), %eax
cmpl 0x54(%rsp), %eax
jl 0x36f023
cmpl $0x1, 0x1c(%rsp)
jle 0x36f02b
movl 0x54(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x60(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x28(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x36e870
movl %eax, 0x48(%rsp)
movl 0x48(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x36f0b7
movq 0x28(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x36e870
movl %eax, 0x48(%rsp)
movl 0x48(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x36f09f
movq 0x68(%rsp), %rax
movl $0x0, (%rax)
movq 0x60(%rsp), %rdi
callq 0x19ef0
movq $0x0, 0x80(%rsp)
jmp 0x36f387
movq 0x60(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movb $0x3a, (%rax,%rcx)
movl 0x54(%rsp), %eax
movl %eax, 0x4c(%rsp)
jmp 0x36f0b7
jmp 0x36f0cc
movq 0x28(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x36e870
movl %eax, 0x48(%rsp)
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x48(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x40(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x36f219
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
movl %eax, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x36f168
movq 0x60(%rsp), %rax
movslq 0x58(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
je 0x36f159
movq 0x60(%rsp), %rax
movslq 0x58(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x60(%rsp), %rax
movl 0x50(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x50(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x36f15b
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x36f117
movq 0x60(%rsp), %rax
movslq 0x50(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x60(%rsp), %rdi
movslq 0x4c(%rsp), %rax
addq %rax, %rdi
addq $0x1, %rdi
callq 0x19b30
movl %eax, 0x24(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x50(%rsp), %eax
je 0x36f1c9
movq 0x60(%rsp), %rax
movslq 0x58(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x36f1ba
jmp 0x36f1c9
jmp 0x36f1bc
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x36f19b
movl 0x58(%rsp), %eax
cmpl 0x50(%rsp), %eax
jge 0x36f1f2
movq 0x60(%rsp), %rdi
movslq 0x58(%rsp), %rax
addq %rax, %rdi
addq $0x1, %rdi
callq 0x19b30
cltq
movq %rax, 0x10(%rsp)
jmp 0x36f1fc
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x24(%rsp)
jle 0x36f217
movl 0x24(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x36f22a
movl $0x0, 0x24(%rsp)
movq 0x38(%rsp), %rax
movl %eax, 0x20(%rsp)
movslq 0x24(%rsp), %rax
cmpq 0x38(%rsp), %rax
jl 0x36f23f
movq 0x38(%rsp), %rax
movl %eax, 0x24(%rsp)
movslq 0x20(%rsp), %rax
cmpq 0x38(%rsp), %rax
jl 0x36f254
movq 0x38(%rsp), %rax
movl %eax, 0x20(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x20(%rsp), %eax
jle 0x36f266
movl 0x20(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x60(%rsp), %rdi
callq 0x19ef0
movl $0x0, 0x54(%rsp)
movl 0x20(%rsp), %eax
subl 0x24(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rdi
callq 0x19ef8
movq %rax, 0x60(%rsp)
movq 0x78(%rsp), %rax
movq (%rax), %rdi
movq 0x40(%rsp), %rsi
movl 0x24(%rsp), %eax
cltd
idivl 0x34(%rsp)
imull 0x30(%rsp), %eax
cltq
addq %rax, %rsi
movl 0x24(%rsp), %eax
cltd
idivl 0x34(%rsp)
movslq %edx, %rax
addq %rax, %rsi
xorl %edx, %edx
callq 0x4fceb0
movq 0x78(%rsp), %rax
movq (%rax), %rdi
leaq 0x5f(%rsp), %rsi
movl $0x1, %edx
callq 0x4fc520
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x1, %ecx
movb %al, 0xf(%rsp)
jne 0x36f318
movl 0x54(%rsp), %ecx
movl 0x20(%rsp), %edx
subl 0x24(%rsp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, 0xf(%rsp)
jge 0x36f318
movq 0x78(%rsp), %rax
movq (%rax), %rax
cmpl $0x0, 0x88(%rax)
setne %al
xorb $-0x1, %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x36f322
jmp 0x36f361
callq 0x197c0
movq (%rax), %rax
movsbl 0x5f(%rsp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x36f35c
movb 0x5f(%rsp), %dl
movq 0x60(%rsp), %rax
movl 0x54(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x54(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x36f2c6
movq 0x60(%rsp), %rax
movslq 0x54(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movl 0x54(%rsp), %ecx
movq 0x68(%rsp), %rax
movl %ecx, (%rax)
movq 0x60(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
addq $0x88, %rsp
retq
nopw (%rax,%rax)