// File: /workspace/github_cpp_makefile_star2_O3/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
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 0x469af
leal -0x1(%rsi), %ebx
movsbl (%r9), %r15d
testl %r15d, %r15d
movq %rsi, 0x18(%rsp)
je 0x469b7
movb 0x1(%r9), %al
testb %al, %al
je 0x469ba
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 0x46994
jmp 0x469ba
xorl %r12d, %r12d
jmp 0x46a44
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 0x46a32
testb $0x1, %al
jne 0x46a1f
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r9, %rsi
callq 0x4750
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %r9
testl %eax, %eax
je 0x46a32
addl %r14d, %r12d
andl %ebx, %r12d
incl %r14d
cmpl %r15d, %r12d
jne 0x469d9
jmp 0x46b53
movl %r13d, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
movq 0x18(%rsp), %rsi
cmovnel %esi, %r12d
cmpl %esi, %r12d
je 0x46b53
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 0x46a8f
movl %r8d, %ecx
movl %r8d, %r12d
cmpq %rcx, %rax
jg 0x46a8f
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 0x46ab5
movl %edi, %edx
movl %edi, %r13d
cmpq %rdx, %rax
jg 0x46ab5
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 0x44e67
testl %eax, %eax
js 0x46b7d
subl %r12d, %r13d
leal 0x2(%r13), %eax
movslq %eax, %rdi
callq 0x4700
movq %rax, %r15
movq (%r14), %rdi
callq 0x4476a
movl %eax, %ebp
orl %r13d, %eax
js 0x46b33
xorl %ebx, %ebx
callq 0x4580
movq %rax, %r12
movq (%r12), %rax
movl %ebp, %ecx
cmpw $0x0, (%rax,%rcx,2)
jns 0x46b20
movslq %ebx, %rax
incl %ebx
movb %bpl, (%r15,%rax)
movq (%r14), %rdi
callq 0x4476a
testl %eax, %eax
js 0x46b33
movl %eax, %ebp
cmpl %r13d, %ebx
jle 0x46b0a
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 0x1b464(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
leaq 0xd994(%rip), %rsi      # 0x54502
xorl %r15d, %r15d
movq %r9, %rdx
xorl %eax, %eax
callq 0x4770
jmp 0x46b41
movq (%rsp), %rdi
callq 0x606f
xorl %r15d, %r15d
jmp 0x46b41