// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, 0x18(%rsp)
movq 0x18(%rdi), %rax
movq %rax, 0x10(%rsp)
movl (%rax), %r10d
testl %r10d, %r10d
movq %r8, 0x20(%rsp)
je 0x1b54e
movq %rsi, %r12
movl %edx, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movsbl (%rsi), %edi
xorl %r9d, %r9d
movl $0x0, %ecx
testl %edi, %edi
je 0x1b558
movb 0x1(%r12), %al
testb %al, %al
je 0x1b556
leaq 0x2(%r12), %rdx
movl %edi, %ecx
movl %ecx, %edi
shll $0x5, %edi
subl %ecx, %edi
movsbl %al, %ecx
addl %edi, %ecx
movb (%rdx), %al
incq %rdx
testb %al, %al
jne 0x1b537
jmp 0x1b558
xorl %r14d, %r14d
jmp 0x1b5ff
movl %edi, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r10d
movl %edx, %ebx
leal -0x1(%r10), %edi
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %edx, %r15d
incl %r15d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movl %ebx, %r14d
movq %r10, 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 0x1b5ea
testb $0x1, %al
jne 0x1b5d0
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r12, %rsi
callq 0x34e0
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %r10
xorl %r9d, %r9d
testl %eax, %eax
je 0x1b5ea
addl %r15d, %r14d
cmpl %r10d, %r14d
movl %r10d, %eax
cmovbl %r9d, %eax
subl %eax, %r14d
cmpl %ebx, %r14d
jne 0x1b587
movl %r10d, %r14d
jmp 0x1b5f7
movl %ebp, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
cmovnel %r10d, %r14d
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %edx
xorl %r13d, %r13d
cmpl %r10d, %r14d
jne 0x1b60f
xorl %r15d, %r15d
jmp 0x1b708
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rsi
movl %r14d, %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, %r12
addq 0x8(%rsi,%r8), %r12
callq 0x31d0
movq %rax, %r15
movq 0x18(%rsp), %rbp
movq (%rbp), %rdi
movslq %ebx, %rsi
addq %r12, %rsi
xorl %edx, %edx
callq 0x22d4c
movq (%rbp), %rdi
leaq 0x7(%rsp), %rsi
movl $0x1, %edx
callq 0x2292b
cmpl $0x1, %eax
jne 0x1b6f9
testl %r14d, %r14d
js 0x1b6f9
xorl %r13d, %r13d
callq 0x3310
movq %rax, %rbx
leaq 0x7(%rsp), %r12
movq (%rbx), %rcx
movsbq 0x7(%rsp), %rax
cmpw $0x0, (%rcx,%rax,2)
jns 0x1b6da
movslq %r13d, %rcx
incl %r13d
movb %al, (%r15,%rcx)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x2292b
cmpl $0x1, %eax
jne 0x1b6f9
cmpl %r14d, %r13d
jle 0x1b6c0
movslq %r13d, %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