// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/htslib/faidx.c
// Function: faidx_fetch_seq
char *faidx_fetch_seq(const faidx_t *fai, const char *c_name, int p_beg_i, int p_end_i, int *len)
{
    int l, 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))
    {
        *len = -2;
        fprintf(stderr, "[fai_fetch_seq] The sequence \"%s\" not found\n", c_name);
        return NULL;
    }
    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
    int ret = bgzf_useek(fai->bgzf, val.offset + p_beg_i / val.line_blen * val.line_len + p_beg_i % val.line_blen, SEEK_SET);
    if ( ret<0 )
    {
        *len = -1;
        fprintf(stderr, "[fai_fetch_seq] Error: fai_fetch failed. (Seeking in a compressed, .gzi unindexed, file?)\n");
        return NULL;
    }
    l = 0;
    seq = (char*)malloc(p_end_i - p_beg_i + 2);
    while ( (c=bgzf_getc(fai->bgzf))>=0 && 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 %rsi, %r9
movq 0x18(%rdi), %rax
movq %rax, 0x8(%rsp)
movl (%rax), %esi
testl %esi, %esi
movq %r8, (%rsp)
movq %rdi, 0x20(%rsp)
movl %ecx, 0x14(%rsp)
movl %edx, 0x10(%rsp)
je 0x6a8e9
leal -0x1(%rsi), %ebx
movsbl (%r9), %r15d
testl %r15d, %r15d
movq %rsi, 0x18(%rsp)
je 0x6a8f1
movb 0x1(%r9), %al
testb %al, %al
je 0x6a8f4
leaq 0x2(%r9), %rcx
movl %r15d, %edx
shll $0x5, %edx
subl %r15d, %edx
movsbl %al, %r15d
addl %edx, %r15d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x6a8ce
jmp 0x6a8f4
xorl %r12d, %r12d
jmp 0x6a97e
xorl %r15d, %r15d
andl %ebx, %r15d
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdx
movl $0x1, %r14d
movl %r15d, %r12d
movq %r9, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movl %r12d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %ebp
leal (%r12,%r12), %r13d
andl $0x1e, %r13d
movl %ebp, %eax
movl %r13d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x6a96c
testb $0x1, %al
jne 0x6a959
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r9, %rsi
callq 0x6a50
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %r9
testl %eax, %eax
je 0x6a96c
addl %r14d, %r12d
andl %ebx, %r12d
incl %r14d
cmpl %r15d, %r12d
jne 0x6a913
jmp 0x6aa8d
movl %r13d, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
movq 0x18(%rsp), %rsi
cmovnel %esi, %r12d
cmpl %esi, %r12d
je 0x6aa8d
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdx
movl %r12d, %eax
leaq (%rax,%rax,2), %rsi
movl 0x14(%rsp), %edi
movl 0x10(%rsp), %r8d
cmpl %r8d, %edi
cmovll %edi, %r8d
movq 0x8(%rdx,%rsi,8), %rax
xorl %r13d, %r13d
movl $0x0, %r12d
testl %r8d, %r8d
js 0x6a9c9
movl %r8d, %ecx
movl %r8d, %r12d
cmpq %rcx, %rax
jg 0x6a9c9
leal -0x1(%rax), %r12d
movslq (%rdx,%rsi,8), %rcx
movl 0x4(%rdx,%rsi,8), %r8d
movq 0x10(%rdx,%rsi,8), %rsi
testl %edi, %edi
movq 0x20(%rsp), %r14
js 0x6a9ef
movl %edi, %edx
movl %edi, %r13d
cmpq %rdx, %rax
jg 0x6a9ef
decl %eax
movl %eax, %r13d
movq (%r14), %rdi
movl %r12d, %eax
cltd
idivl %r8d
cltq
imulq %rcx, %rax
movslq %edx, %rcx
addq %rcx, %rsi
addq %rax, %rsi
xorl %ebx, %ebx
xorl %edx, %edx
callq 0x68ea3
testl %eax, %eax
js 0x6aab7
subl %r12d, %r13d
leal 0x2(%r13), %eax
movslq %eax, %rdi
callq 0x69d0
movq %rax, %r15
movq (%r14), %rdi
callq 0x68744
movl %eax, %ebp
orl %r13d, %eax
js 0x6aa6d
xorl %ebx, %ebx
callq 0x6790
movq %rax, %r12
movq (%r12), %rax
movl %ebp, %ecx
cmpw $0x0, (%rax,%rcx,2)
jns 0x6aa5a
movslq %ebx, %rax
incl %ebx
movb %bpl, (%r15,%rax)
movq (%r14), %rdi
callq 0x68744
testl %eax, %eax
js 0x6aa6d
movl %eax, %ebp
cmpl %r13d, %ebx
jle 0x6aa44
movslq %ebx, %rax
movb $0x0, (%r15,%rax)
movq (%rsp), %rcx
movl %eax, (%rcx)
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq 0x5453a(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x2f6cf(%rip), %rsi     # 0x9a177
xorl %r15d, %r15d
movq %r9, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x6aa7b
movq (%rsp), %rdi
callq 0x7cd2
xorl %r15d, %r15d
jmp 0x6aa7b