// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/faidx.c
// Function: faidx_fetch_seq
char *faidx_fetch_seq(const faidx_t *fai, char *c_name, int p_beg_i, int p_end_i, int *len)
{
	int l;
	char c;
    khiter_t iter;
    faidx1_t val;
	char *seq=NULL;

    // Adjust position
    iter = kh_get(s, fai->hash, c_name);
    if(iter == kh_end(fai->hash)) return 0;
    val = kh_value(fai->hash, iter);
	if(p_end_i < p_beg_i) p_beg_i = p_end_i;
    if(p_beg_i < 0) p_beg_i = 0;
    else if(val.len <= p_beg_i) p_beg_i = val.len - 1;
    if(p_end_i < 0) p_end_i = 0;
    else if(val.len <= p_end_i) p_end_i = val.len - 1;

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

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movl %edx, 0x4c(%rsp)
movl %ecx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x50(%rsp), %rsi
callq 0x36e870
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
movq 0x58(%rsp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
jne 0x36f59a
movq $0x0, 0x60(%rsp)
jmp 0x36f73a
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x34(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
movl 0x48(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x36f5de
movl 0x48(%rsp), %eax
movl %eax, 0x4c(%rsp)
cmpl $0x0, 0x4c(%rsp)
jge 0x36f5ef
movl $0x0, 0x4c(%rsp)
jmp 0x36f60d
movq 0x20(%rsp), %rax
movslq 0x4c(%rsp), %rcx
cmpq %rcx, %rax
jg 0x36f60b
movq 0x20(%rsp), %rax
subq $0x1, %rax
movl %eax, 0x4c(%rsp)
jmp 0x36f60d
cmpl $0x0, 0x48(%rsp)
jge 0x36f61e
movl $0x0, 0x48(%rsp)
jmp 0x36f63c
movq 0x20(%rsp), %rax
movslq 0x48(%rsp), %rcx
cmpq %rcx, %rax
jg 0x36f63a
movq 0x20(%rsp), %rax
subq $0x1, %rax
movl %eax, 0x48(%rsp)
jmp 0x36f63c
movl $0x0, 0x3c(%rsp)
movl 0x48(%rsp), %eax
subl 0x4c(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rdi
callq 0x19ef8
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq (%rax), %rdi
movq 0x28(%rsp), %rsi
movl 0x4c(%rsp), %eax
cltd
idivl 0x1c(%rsp)
imull 0x18(%rsp), %eax
cltq
addq %rax, %rsi
movl 0x4c(%rsp), %eax
cltd
idivl 0x1c(%rsp)
movslq %edx, %rax
addq %rax, %rsi
xorl %edx, %edx
callq 0x4fceb0
movq 0x58(%rsp), %rax
movq (%rax), %rdi
leaq 0x3b(%rsp), %rsi
movl $0x1, %edx
callq 0x4fc520
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x1, %ecx
movb %al, 0xf(%rsp)
jne 0x36f6ce
movl 0x3c(%rsp), %eax
movl 0x48(%rsp), %ecx
subl 0x4c(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
setl %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x36f6d8
jmp 0x36f717
callq 0x197c0
movq (%rax), %rax
movsbl 0x3b(%rsp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x36f712
movb 0x3b(%rsp), %dl
movq 0x10(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x3c(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x36f692
movq 0x10(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movl 0x3c(%rsp), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)