// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %r8, (%rsp)
movl %ecx, %r15d
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, %r14
movq 0x18(%rdi), %rbp
movq %rbp, %rdi
callq 0x5e74a
cmpl (%rbp), %eax
je 0x5f269
movq 0x20(%rbp), %rdx
movl %eax, %eax
imulq $0x18, %rax, %rsi
cmpl %r12d, %r15d
cmovll %r15d, %r12d
movq 0x8(%rdx,%rsi), %rax
xorl %r13d, %r13d
movl $0x0, %ebp
testl %r12d, %r12d
js 0x5f1bc
movl %r12d, %ecx
movl %r12d, %ebp
cmpq %rcx, %rax
jg 0x5f1bc
leal -0x1(%rax), %ebp
movslq (%rdx,%rsi), %rcx
movl 0x4(%rdx,%rsi), %r8d
movq 0x10(%rdx,%rsi), %rsi
testl %r15d, %r15d
js 0x5f1df
movl %r15d, %edx
movl %r15d, %r13d
cmpq %rdx, %rax
jg 0x5f1df
decl %eax
movl %eax, %r13d
movq (%r14), %rdi
movl %ebp, %eax
cltd
idivl %r8d
cltq
imulq %rcx, %rax
movslq %edx, %rcx
addq %rcx, %rsi
addq %rax, %rsi
xorl %r12d, %r12d
xorl %edx, %edx
callq 0x5db46
testl %eax, %eax
js 0x5f293
subl %ebp, %r13d
leal 0x2(%r13), %eax
movslq %eax, %rdi
callq 0x69d0
movq %rax, %r15
movq (%r14), %rdi
callq 0x5d480
movl %r12d, %ebx
testl %eax, %eax
js 0x5f24b
cmpl %r13d, %r12d
jg 0x5f24b
movl %eax, %ebp
callq 0x6790
movq (%rax), %rax
movl %ebp, %ecx
cmpw $0x0, (%rax,%rcx,2)
jns 0x5f21b
incl %r12d
movb %bpl, (%r15,%rbx)
jmp 0x5f21b
movb $0x0, (%r15,%rbx)
movq (%rsp), %rax
movl %r12d, (%rax)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq 0x53d5e(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x29c73(%rip), %rsi     # 0x88ef7
xorl %r15d, %r15d
movq %r13, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x5f257
movq (%rsp), %rax
orl $-0x1, (%rax)
movq 0x53d37(%rip), %rax     # 0xb2fd8
movq (%rax), %rcx
leaq 0x29c79(%rip), %rdi     # 0x88f24
pushq $0x5a
popq %rsi
pushq $0x1
popq %rdx
callq 0x6e70
xorl %r15d, %r15d
jmp 0x5f257