// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/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 0x38f95
cmpl (%rbp), %eax
je 0x39b41
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 0x39a94
movl %r12d, %ecx
movl %r12d, %ebp
cmpq %rcx, %rax
jg 0x39a94
leal -0x1(%rax), %ebp
movslq (%rdx,%rsi), %rcx
movl 0x4(%rdx,%rsi), %r8d
movq 0x10(%rdx,%rsi), %rsi
testl %r15d, %r15d
js 0x39ab7
movl %r15d, %edx
movl %r15d, %r13d
cmpq %rdx, %rax
jg 0x39ab7
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 0x38372
testl %eax, %eax
js 0x39b6b
subl %ebp, %r13d
leal 0x2(%r13), %eax
movslq %eax, %rdi
callq 0x46f0
movq %rax, %r15
movq (%r14), %rdi
callq 0x37c4a
movl %r12d, %ebx
testl %eax, %eax
js 0x39b23
cmpl %r13d, %r12d
jg 0x39b23
movl %eax, %ebp
callq 0x4580
movq (%rax), %rax
movl %ebp, %ecx
cmpw $0x0, (%rax,%rcx,2)
jns 0x39af3
incl %r12d
movb %bpl, (%r15,%rbx)
jmp 0x39af3
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 0x1d47e(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
leaq 0xd6f6(%rip), %rsi      # 0x47252
xorl %r15d, %r15d
movq %r13, %rdx
xorl %eax, %eax
callq 0x4770
jmp 0x39b2f
movq (%rsp), %rax
orl $-0x1, (%rax)
movq 0x1d457(%rip), %rax     # 0x56fd0
movq (%rax), %rcx
leaq 0xd6fc(%rip), %rdi      # 0x4727f
pushq $0x5a
popq %rsi
pushq $0x1
popq %rdx
callq 0x4a20
xorl %r15d, %r15d
jmp 0x39b2f