// File: /workspace/github_cpp_makefile_star2_O1/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 %r8, %r14
movq %rsi, %r8
movq %rdi, %rbp
movq 0x18(%rdi), %rax
movq %rax, 0x10(%rsp)
movl (%rax), %esi
testl %esi, %esi
movq %r14, 0x8(%rsp)
je 0x4798d
leal -0x1(%rsi), %edi
movsbl (%r8), %r15d
testl %r15d, %r15d
movq %rbp, 0x28(%rsp)
movl %ecx, 0x4(%rsp)
movl %edx, (%rsp)
movq %rsi, 0x20(%rsp)
je 0x47995
movb 0x1(%r8), %al
testb %al, %al
je 0x47998
leaq 0x2(%r8), %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 0x47972
jmp 0x47998
xorl %r12d, %r12d
jmp 0x47a36
xorl %r15d, %r15d
andl %edi, %r15d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rbx
movl $0x1, %r14d
movl %r15d, %r12d
movl %edi, 0x1c(%rsp)
movq %r8, 0x30(%rsp)
movl %r12d, %eax
shrl $0x4, %eax
movl (%rbx,%rax,4), %ebp
leal (%r12,%r12), %r13d
andl $0x1e, %r13d
movl %ebp, %eax
movl %r13d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x47a13
testb $0x1, %al
jne 0x479fb
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r8, %rsi
callq 0x4750
movl 0x1c(%rsp), %edi
movq 0x30(%rsp), %r8
testl %eax, %eax
je 0x47a13
addl %r14d, %r12d
andl %edi, %r12d
incl %r14d
cmpl %r15d, %r12d
jne 0x479b6
movq 0x20(%rsp), %rsi
movl %esi, %r12d
jmp 0x47a25
movl %r13d, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
movq 0x20(%rsp), %rsi
cmovnel %esi, %r12d
movq 0x8(%rsp), %r14
movq 0x28(%rsp), %rbp
movl 0x4(%rsp), %ecx
movl (%rsp), %edx
cmpl %esi, %r12d
je 0x47b39
movq 0x10(%rsp), %rax
movq 0x20(%rax), %r10
movl %r12d, %eax
leaq (%rax,%rax,2), %rsi
cmpl %edx, %ecx
cmovll %ecx, %edx
movq 0x8(%r10,%rsi,8), %rax
xorl %r13d, %r13d
movl $0x0, %r12d
testl %edx, %edx
js 0x47a74
movl %edx, %edi
movl %edx, %r12d
cmpq %rdi, %rax
jg 0x47a74
leal -0x1(%rax), %r12d
movslq (%r10,%rsi,8), %r9
movl 0x4(%r10,%rsi,8), %r8d
movq 0x10(%r10,%rsi,8), %rsi
testl %ecx, %ecx
js 0x47a95
movl %ecx, %edx
movl %ecx, %r13d
cmpq %rdx, %rax
jg 0x47a95
decl %eax
movl %eax, %r13d
movq (%rbp), %rdi
movl %r12d, %eax
cltd
idivl %r8d
cltq
imulq %r9, %rax
movslq %edx, %rcx
addq %rcx, %rsi
addq %rax, %rsi
xorl %ebx, %ebx
xorl %edx, %edx
callq 0x45d91
testl %eax, %eax
js 0x47b60
subl %r12d, %r13d
leal 0x2(%r13), %eax
movslq %eax, %rdi
callq 0x4700
movq %rax, %r15
movq %rbp, %r14
movq (%rbp), %rdi
callq 0x456b0
movl %eax, %ebp
orl %r13d, %eax
js 0x47b18
xorl %ebx, %ebx
callq 0x4580
movq %rax, %r12
movq (%r12), %rax
movl %ebp, %ecx
cmpw $0x0, (%rax,%rcx,2)
jns 0x47b05
movslq %ebx, %rax
incl %ebx
movb %bpl, (%r15,%rax)
movq (%r14), %rdi
callq 0x456b0
testl %eax, %eax
js 0x47b18
movl %eax, %ebp
cmpl %r13d, %ebx
jle 0x47aef
movslq %ebx, %rax
movb $0x0, (%r15,%rax)
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffffffe, (%r14)     # imm = 0xFFFFFFFE
movq 0x1c481(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
leaq 0xe6f1(%rip), %rsi      # 0x56242
xorl %r15d, %r15d
movq %r8, %rdx
xorl %eax, %eax
callq 0x4770
jmp 0x47b27
movq %r14, %rdi
callq 0x6111
xorl %r15d, %r15d
jmp 0x47b27