// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/faidx.c
// Function: fai_fetch
char *fai_fetch(const faidx_t *fai, const char *str, int *len)
{
    char *s;
    int c, i, l, k, name_end;
    khiter_t iter;
    faidx1_t val;
    khash_t(s) *h;
    int beg, end;

    beg = end = -1;
    h = fai->hash;
    name_end = l = strlen(str);
    s = (char*)malloc(l+1);
    // remove space
    for (i = k = 0; i < l; ++i)
        if (!isspace(str[i])) s[k++] = str[i];
    s[k] = 0; l = k;
    // determine the sequence name
    for (i = l - 1; i >= 0; --i) if (s[i] == ':') break; // look for colon from the end
    if (i >= 0) name_end = i;
    if (name_end < l) { // check if this is really the end
        int n_hyphen = 0;
        for (i = name_end + 1; i < l; ++i) {
            if (s[i] == '-') ++n_hyphen;
            else if (!isdigit(s[i]) && s[i] != ',') break;
        }
        if (i < l || n_hyphen > 1) name_end = l; // malformated region string; then take str as the name
        s[name_end] = 0;
        iter = kh_get(s, h, s);
        if (iter == kh_end(h)) { // cannot find the sequence name
            iter = kh_get(s, h, str); // try str as the name
            if (iter == kh_end(h)) {
                *len = 0;
            free(s); return 0;
            } else s[name_end] = ':', name_end = l;
        }
    } else iter = kh_get(s, h, str);
    if(iter == kh_end(h)) {
        fprintf(stderr, "[fai_fetch] Warning - Reference %s not found in FASTA file, returning empty sequence\n", str);
        free(s);
        *len = -2;
        return 0;
    };
    val = kh_value(h, iter);
    // parse the interval
    if (name_end < l) {
        for (i = k = name_end + 1; i < l; ++i)
            if (s[i] != ',') s[k++] = s[i];
        s[k] = 0;
        beg = atoi(s + name_end + 1);
        for (i = name_end + 1; i != k; ++i) if (s[i] == '-') break;
        end = i < k? atoi(s + i + 1) : val.len;
        if (beg > 0) --beg;
    } else beg = 0, end = val.len;
    if (beg >= val.len) beg = val.len;
    if (end >= val.len) end = val.len;
    if (beg > end) beg = end;
    free(s);

    // now retrieve the sequence
    int ret = bgzf_useek(fai->bgzf, val.offset + beg / val.line_blen * val.line_len + beg % val.line_blen, SEEK_SET);
    if ( ret<0 )
    {
        *len = -1;
        fprintf(stderr, "[fai_fetch] Error: fai_fetch failed. (Seeking in a compressed, .gzi unindexed, file?)\n");
        return NULL;
    }
    l = 0;
    s = (char*)malloc(end - beg + 2);
    while ( (c=bgzf_getc(fai->bgzf))>=0 && l < end - beg )
        if (isgraph(c)) s[l++] = c;
    s[l] = '\0';
    *len = l;
    return s;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0xffffffff, -0x68(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x64(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0x62c0
movl %eax, -0x34(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x69c0
movq %rax, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xa08aa
callq 0x6780
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq -0x30(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0xa089d
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x38(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0xa089f
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa0850
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jl 0xa08eb
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0xa08de
jmp 0xa08eb
jmp 0xa08e0
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa08c5
cmpl $0x0, -0x30(%rbp)
jl 0xa08f7
movl -0x30(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xa0a0a
movl $0x0, -0x6c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xa097e
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0xa0937
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xa0971
callq 0x6780
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x30(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0xa096f
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
je 0xa096f
jmp 0xa097e
jmp 0xa0971
jmp 0xa0973
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa0913
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jl 0xa098c
cmpl $0x1, -0x6c(%rbp)
jle 0xa0992
movl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x60(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x9ff70
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl (%rcx), %eax
jne 0xa0a08
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x9ff70
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl (%rcx), %eax
jne 0xa09f4
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rdi
callq 0x6880
movq $0x0, -0x8(%rbp)
jmp 0xa0cd2
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb $0x3a, (%rax,%rcx)
movl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0xa0a08
jmp 0xa0a1a
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x9ff70
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl (%rcx), %eax
jne 0xa0a61
movq 0x645a4(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x43505(%rip), %rsi     # 0xe3f3f
movb $0x0, %al
callq 0x6a80
movq -0x28(%rbp), %rdi
callq 0x6880
movq -0x20(%rbp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq $0x0, -0x8(%rbp)
jmp 0xa0cd2
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xa0b80
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xa0ae8
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
je 0xa0adb
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x38(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0xa0add
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa0aa2
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rdi
movslq -0x3c(%rbp), %rax
addq %rax, %rdi
addq $0x1, %rdi
callq 0x6bd0
movl %eax, -0x64(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0xa0b3c
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0xa0b2f
jmp 0xa0b3c
jmp 0xa0b31
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa0b14
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0xa0b60
movq -0x28(%rbp), %rdi
movslq -0x30(%rbp), %rax
addq %rax, %rdi
addq $0x1, %rdi
callq 0x6bd0
cltq
movq %rax, -0x78(%rbp)
jmp 0xa0b68
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl %eax, -0x68(%rbp)
cmpl $0x0, -0x64(%rbp)
jle 0xa0b7e
movl -0x64(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xa0b8e
movl $0x0, -0x64(%rbp)
movq -0x50(%rbp), %rax
movl %eax, -0x68(%rbp)
movslq -0x64(%rbp), %rax
cmpq -0x50(%rbp), %rax
jl 0xa0b9f
movq -0x50(%rbp), %rax
movl %eax, -0x64(%rbp)
movslq -0x68(%rbp), %rax
cmpq -0x50(%rbp), %rax
jl 0xa0bb0
movq -0x50(%rbp), %rax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
jle 0xa0bbe
movl -0x68(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x28(%rbp), %rdi
callq 0x6880
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rsi
movl -0x64(%rbp), %eax
cltd
idivl -0x54(%rbp)
imull -0x58(%rbp), %eax
cltq
addq %rax, %rsi
movl -0x64(%rbp), %eax
cltd
idivl -0x54(%rbp)
movslq %edx, %rax
addq %rax, %rsi
xorl %edx, %edx
callq 0x9e5b0
movl %eax, -0x70(%rbp)
cmpl $0x0, -0x70(%rbp)
jge 0xa0c2e
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x643c0(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
leaq 0x4337b(%rip), %rsi     # 0xe3f95
movb $0x0, %al
callq 0x6a80
movq $0x0, -0x8(%rbp)
jmp 0xa0cd2
movl $0x0, -0x34(%rbp)
movl -0x68(%rbp), %eax
subl -0x64(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdi
callq 0x69c0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x9da40
movl %eax, %ecx
movl %ecx, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x79(%rbp)
jl 0xa0c76
movl -0x34(%rbp), %eax
movl -0x68(%rbp), %ecx
subl -0x64(%rbp), %ecx
cmpl %ecx, %eax
setl %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0xa0c7f
jmp 0xa0cb5
callq 0x6780
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0xa0cb3
movl -0x2c(%rbp), %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0xa0c4a
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nop