// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, 0x20(%rsp)
movl %ecx, 0x14(%rsp)
movq 0x18(%rdi), %rax
movq %rax, 0x8(%rsp)
movl (%rax), %r11d
testl %r11d, %r11d
movq %rdi, 0x18(%rsp)
je 0x14874
movq %rsi, %r12
movsbl (%rsi), %r9d
xorl %r10d, %r10d
movl $0x0, %ecx
testl %r9d, %r9d
je 0x1487f
movb 0x1(%r12), %al
testb %al, %al
je 0x1487c
leaq 0x2(%r12), %r8
movl %r9d, %ecx
movl %ecx, %r9d
shll $0x5, %r9d
subl %ecx, %r9d
movsbl %al, %ecx
addl %r9d, %ecx
movb (%r8), %al
incq %r8
testb %al, %al
jne 0x14858
jmp 0x1487f
xorl %r14d, %r14d
jmp 0x14926
movl %r9d, %ecx
movl %edx, 0x10(%rsp)
movl %ecx, %eax
xorl %edx, %edx
divl %r11d
movl %edx, %ebx
leal -0x1(%r11), %edi
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %edx, %r15d
incl %r15d
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movl %ebx, %r14d
movq %r11, 0x30(%rsp)
movq %rdi, 0x28(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %r13d
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %r13d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x14915
testb $0x1, %al
jne 0x148fb
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r12, %rsi
callq 0x3300
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %r11
xorl %r10d, %r10d
testl %eax, %eax
je 0x14915
addl %r15d, %r14d
cmpl %r11d, %r14d
movl %r11d, %eax
cmovbl %r10d, %eax
subl %eax, %r14d
cmpl %ebx, %r14d
jne 0x148b2
movl %r11d, %r14d
jmp 0x14922
movl %ebp, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
cmovnel %r11d, %r14d
movl 0x10(%rsp), %edx
xorl %r12d, %r12d
cmpl %r11d, %r14d
jne 0x14936
xorl %r15d, %r15d
jmp 0x14a42
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movl %r14d, %eax
leaq (%rax,%rax,2), %r8
movq 0x8(%rcx,%r8,8), %rax
movl 0x14(%rsp), %edi
cmpl %edx, %edi
cmovll %edi, %edx
testl %edx, %edx
js 0x14966
movl %edx, %esi
movl %edx, %r12d
cmpq %rsi, %rax
jg 0x14966
leal -0x1(%rax), %r12d
movslq (%rcx,%r8,8), %rdx
movq %rdx, 0x8(%rsp)
movl 0x4(%rcx,%r8,8), %r13d
movq 0x10(%rcx,%r8,8), %rbx
xorl %ebp, %ebp
movl $0x0, %r14d
testl %edi, %edi
js 0x14994
movl %edi, %ecx
movl %edi, %r14d
cmpq %rcx, %rax
jg 0x14994
decl %eax
movl %eax, %r14d
subl %r12d, %r14d
leal 0x2(%r14), %eax
movslq %eax, %rdi
callq 0x33e0
movq %rax, %r15
movq 0x18(%rsp), %rcx
movq (%rcx), %rdi
movl %r12d, %eax
cltd
idivl %r13d
movq %rcx, %r13
cltq
imulq 0x8(%rsp), %rax
movslq %edx, %rcx
addq %rcx, %rbx
addq %rax, %rbx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x12f74
movq (%r13), %rdi
leaq 0x7(%rsp), %rsi
movl $0x1, %edx
callq 0x12b53
cmpl $0x1, %eax
jne 0x14a33
testl %r14d, %r14d
js 0x14a33
xorl %ebp, %ebp
callq 0x35f0
movq %rax, %rbx
leaq 0x7(%rsp), %r12
movq (%rbx), %rcx
movsbq 0x7(%rsp), %rax
cmpw $0x0, (%rcx,%rax,2)
jns 0x14a18
movslq %ebp, %rcx
incl %ebp
movb %al, (%r15,%rcx)
movq (%r13), %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x12b53
cmpl $0x1, %eax
jne 0x14a33
cmpl %r14d, %ebp
jle 0x149ff
movslq %ebp, %rax
movb $0x0, (%r15,%rax)
movq 0x20(%rsp), %rcx
movl %eax, (%rcx)
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq