// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x18(%rdi), %rax
movq %rax, 0x8(%rsp)
movl (%rax), %r11d
testl %r11d, %r11d
movq %r8, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
je 0x1bde2
movq %rsi, %r13
movl %edx, 0x10(%rsp)
movl %ecx, 0x14(%rsp)
movsbl (%rsi), %r10d
xorl %r9d, %r9d
movl $0x0, %ecx
testl %r10d, %r10d
je 0x1bded
movb 0x1(%r13), %al
testb %al, %al
je 0x1bdea
leaq 0x2(%r13), %rdx
movl %r10d, %ecx
movl %ecx, %r10d
shll $0x5, %r10d
subl %ecx, %r10d
movsbl %al, %ecx
addl %r10d, %ecx
movb (%rdx), %al
incq %rdx
testb %al, %al
jne 0x1bdc7
jmp 0x1bded
xorl %r15d, %r15d
jmp 0x1be93
movl %r10d, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r11d
movl %edx, %ebp
leal -0x1(%r11), %edi
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %edx, %r14d
incl %r14d
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movl %ebp, %r15d
movq %r11, 0x30(%rsp)
movq %rdi, 0x28(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %ebx
leal (%r15,%r15), %r12d
andl $0x1e, %r12d
movl %ebx, %eax
movl %r12d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x1be7f
testb $0x1, %al
jne 0x1be65
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r13, %rsi
callq 0x34e0
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %r11
xorl %r9d, %r9d
testl %eax, %eax
je 0x1be7f
addl %r14d, %r15d
cmpl %r11d, %r15d
movl %r11d, %eax
cmovbl %r9d, %eax
subl %eax, %r15d
cmpl %ebp, %r15d
jne 0x1be1c
jmp 0x1bfa6
movl %r12d, %ecx
shrl %cl, %ebx
testb $0x3, %bl
cmovnel %r11d, %r15d
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %edx
xorl %r13d, %r13d
cmpl %r11d, %r15d
jne 0x1bea3
xorl %r9d, %r9d
jmp 0x1bfa6
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rsi
movl %r15d, %r8d
shlq $0x4, %r8
movq (%rsi,%r8), %r9
cmpl %edx, %ecx
cmovll %ecx, %edx
leal -0x1(%r9), %r14d
cmpl %r9d, %edx
movl %r14d, %r10d
cmovbl %edx, %r10d
testl %edx, %edx
cmovsl %r13d, %r10d
cmpl %ecx, %r9d
cmoval %ecx, %r14d
testl %ecx, %ecx
cmovsl %r13d, %r14d
movq %r9, %rdi
shrq $0x30, %rdi
movl %r10d, %eax
cltd
idivl %edi
movl %edx, %ebx
subl %r10d, %r14d
leal 0x2(%r14), %ecx
movslq %ecx, %rdi
shrq $0x20, %r9
movzwl %r9w, %ecx
imull %ecx, %eax
movslq %eax, %r15
addq 0x8(%rsi,%r8), %r15
callq 0x31d0
movq %rax, %rbp
movq 0x18(%rsp), %rax
movq (%rax), %rdi
movslq %ebx, %rsi
addq %r15, %rsi
movq %rax, %r15
xorl %edx, %edx
callq 0x2284b
movq (%r15), %rdi
leaq 0x7(%rsp), %rsi
movl $0x1, %edx
callq 0x22445
cmpl $0x1, %eax
jne 0x1bf94
testl %r14d, %r14d
movq %rbp, %r9
js 0x1bf97
xorl %r13d, %r13d
callq 0x3310
movq %rbp, %r9
movq %rax, %rbx
leaq 0x7(%rsp), %r12
movq (%rbx), %rcx
movsbq 0x7(%rsp), %rax
cmpw $0x0, (%rcx,%rax,2)
jns 0x1bf75
movslq %r13d, %rcx
incl %r13d
movb %al, (%r9,%rcx)
movq (%r15), %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x22445
cmpl $0x1, %eax
jne 0x1bf94
cmpl %r14d, %r13d
movq %rbp, %r9
jle 0x1bf5b
jmp 0x1bf97
movq %rbp, %r9
movslq %r13d, %rax
movb $0x0, (%r9,%rax)
movq 0x20(%rsp), %rcx
movl %eax, (%rcx)
movq %r9, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq