// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/htslib/faidx.c
// Function: fai_load
faidx_t *fai_load(const char *fn)
{
    char *str;
    FILE *fp;
    faidx_t *fai;
    str = (char*)calloc(strlen(fn) + 5, 1);
    sprintf(str, "%s.fai", fn);

    if (hisremote(str))
    {
        fp = download_and_open(str);
        if ( !fp )
        {
            fprintf(stderr, "[fai_load] failed to open remote FASTA index %s\n", str);
            free(str);
            return 0;
        }
    }
    else
        fp = fopen(str, "rb");

    if (fp == 0) {
        fprintf(stderr, "[fai_load] build FASTA index.\n");
        fai_build(fn);
        fp = fopen(str, "rb");
        if (fp == 0) {
            fprintf(stderr, "[fai_load] fail to open FASTA index.\n");
            free(str);
            return 0;
        }
    }

    fai = fai_read(fp);
    fclose(fp);

    fai->bgzf = bgzf_open(fn, "rb");
    free(str);
    if (fai->bgzf == 0) {
        fprintf(stderr, "[fai_load] fail to open FASTA file.\n");
        return 0;
    }
    if ( fai->bgzf->is_compressed==1 )
    {
        if ( bgzf_index_load(fai->bgzf, fn, ".gzi") < 0 )
        {
            fprintf(stderr, "[fai_load] failed to load .gzi index: %s[.gzi]\n", fn);
            fai_destroy(fai);
            return NULL;
        }
    }
    return fai;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbp
callq 0x62d0
leaq 0x5(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x6470
movq %rax, %r13
leaq 0x29673(%rip), %rsi     # 0x880f6
movq %rax, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x6170
movq %r13, %rdi
callq 0x6012b
testl %eax, %eax
je 0x5eba4
movq %r13, %rdi
callq 0x62d0
cltq
addq %r13, %rax
decq %rax
movq %rax, %r15
cmpq %r13, %rax
jb 0x5eac2
leaq -0x1(%r15), %rax
cmpb $0x2f, (%r15)
jne 0x5eab0
incq %r15
leaq 0x2633d(%rip), %rsi     # 0x84e09
movq %r15, %rdi
callq 0x6880
testq %rax, %rax
jne 0x5ec59
leaq 0x1e902(%rip), %rsi     # 0x7d3e6
movq %r13, %rdi
callq 0x5fdb8
testq %rax, %rax
je 0x5ed0d
movq %rax, %r12
leaq 0x23047(%rip), %rsi     # 0x81b46
movq %r15, %rdi
callq 0x6880
movq %rax, (%rsp)
testq %rax, %rax
je 0x5ed2a
movq %rbp, 0x8(%rsp)
movq %r13, 0x10(%rsp)
pushq $0x1
popq %rsi
movl $0x100000, %edi         # imm = 0x100000
callq 0x6470
movq %rax, %r14
movq 0x8(%r12), %rbp
movq 0x10(%r12), %r13
subq %rbp, %r13
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %r13
movl $0x100000, %ebx         # imm = 0x100000
cmovbq %r13, %rbx
movq %r14, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x6570
addq %rbx, %rbp
movq %rbp, 0x8(%r12)
movl $0x100000, %eax         # imm = 0x100000
cmpq $0xfffff, %r13          # imm = 0xFFFFF
ja 0x5eb8b
movl $0x100000, %edx         # imm = 0x100000
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x5f777
testl %eax, %eax
jle 0x5ec16
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r14, %rdi
pushq $0x1
popq %rsi
movq %rax, %rdx
movq (%rsp), %rcx
callq 0x6e70
jmp 0x5eb2e
leaq 0x1e83b(%rip), %rsi     # 0x7d3e6
movq %r13, %rdi
callq 0x6880
testq %rax, %rax
jne 0x5ec59
movq 0x54415(%rip), %rbx     # 0xb2fd8
movq (%rbx), %rcx
leaq 0x2a1e3(%rip), %rdi     # 0x88db0
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
callq 0x6e70
movq %rbp, %rdi
callq 0x5e8f9
leaq 0x1e7ff(%rip), %rsi     # 0x7d3e6
movq %r13, %rdi
callq 0x6880
testq %rax, %rax
jne 0x5ec59
movq (%rbx), %rcx
leaq 0x2a1d1(%rip), %rdi     # 0x88dcf
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x6e70
movq %r13, %rdi
callq 0x68a0
jmp 0x5ed08
movq %r14, %rdi
callq 0x68a0
movq (%rsp), %rdi
callq 0x66e0
movq %r12, %rdi
callq 0x5fa52
testl %eax, %eax
movq 0x10(%rsp), %r13
jne 0x5ed78
leaq 0x261c6(%rip), %rsi     # 0x84e09
movq %r15, %rdi
callq 0x6880
testq %rax, %rax
movq 0x8(%rsp), %rbp
je 0x5ed4d
movq %rax, %r14
movq %rax, %rdi
callq 0x5e80b
movq %rax, %r15
movq %r14, %rdi
callq 0x66e0
leaq 0x1e770(%rip), %rsi     # 0x7d3e6
movq %rbp, %rdi
callq 0x5bd04
movq %rax, %rbx
movq %rax, (%r15)
movq %r13, %rdi
callq 0x68a0
testq %rbx, %rbx
je 0x5ecc7
movl $0x60000000, %eax       # imm = 0x60000000
andl (%rbx), %eax
cmpl $0x20000000, %eax       # imm = 0x20000000
jne 0x5ecb5
leaq 0x29457(%rip), %rdx     # 0x880fd
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x5d8e7
testl %eax, %eax
js 0x5ece5
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5430a(%rip), %rax     # 0xb2fd8
movq (%rax), %rcx
leaq 0x2a11d(%rip), %rdi     # 0x88df5
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x6e70
jmp 0x5ed08
movq 0x542ec(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x2a124(%rip), %rsi     # 0x88e1a
movq %rbp, %rdx
xorl %eax, %eax
callq 0x6a90
movq %r15, %rdi
callq 0x5e65b
xorl %r15d, %r15d
jmp 0x5ecb5
movq 0x542c4(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x2a2a7(%rip), %rsi     # 0x88fc5
movq %r13, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x5ed4d
movq 0x542a7(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x2a2be(%rip), %rsi     # 0x88ff9
movq %r15, %rdx
xorl %eax, %eax
callq 0x6a90
movq %r12, %rdi
callq 0x5faaa
movq 0x54284(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x2a021(%rip), %rsi     # 0x88d7f
xorl %r15d, %r15d
movq %r13, %rdx
xorl %eax, %eax
callq 0x6a90
movq %r13, %rdi
callq 0x68a0
jmp 0x5ecb5
movq 0x54259(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x2a2b8(%rip), %rsi     # 0x89041
movq %r13, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x5ec3c