// File: /workspace/github_c_makefile_star2_O1/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, %r14
callq 0x62d0
leaq 0x5(%rax), %rdi
movl $0x1, %esi
callq 0x6470
movq %rax, %rbp
leaq 0x2f38f(%rip), %rsi     # 0x99140
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x6170
movq %rbp, %rdi
callq 0x6bac1
testl %eax, %eax
je 0x69ec8
movq %rbp, %rdi
callq 0x62d0
cltq
addq %rbp, %rax
decq %rax
movq %rax, %r15
cmpq %rbp, %rax
jb 0x69df0
leaq -0x1(%r15), %rax
cmpb $0x2f, (%r15)
jne 0x69dde
incq %r15
leaq 0x2c02f(%rip), %rsi     # 0x95e29
movq %r15, %rdi
callq 0x6880
movq %rax, %r13
testq %rax, %rax
jne 0x69f17
leaq 0x245f1(%rip), %rsi     # 0x8e406
movq %rbp, %rdi
callq 0x6b707
testq %rax, %rax
je 0x69fe5
movq %rax, %r12
leaq 0x28d45(%rip), %rsi     # 0x92b75
movq %r15, %rdi
callq 0x6880
testq %rax, %rax
je 0x6a008
movq %rax, %r13
movq %rbp, (%rsp)
movq %r14, 0x8(%rsp)
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x6470
movq %rax, %rbp
movq 0x8(%r12), %rsi
movq 0x10(%r12), %r14
subq %rsi, %r14
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %r14
movl $0x100000, %ebx         # imm = 0x100000
cmovbq %r14, %rbx
movq %rbp, %rdi
movq %rbx, %rdx
callq 0x6570
addq %rbx, 0x8(%r12)
movl $0x100000, %edx         # imm = 0x100000
cmpq $0xfffff, %r14          # imm = 0xFFFFF
ja 0x69eac
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %rcx
callq 0x6b053
movq %rax, %rdx
testl %edx, %edx
jle 0x69edc
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x1, %esi
movq %rbp, %rdi
movq %r13, %rcx
callq 0x6e70
jmp 0x69e5f
leaq 0x24537(%rip), %rsi     # 0x8e406
movq %rbp, %rdi
callq 0x6880
movq %rax, %r13
jmp 0x69f20
movq %rbp, %rdi
callq 0x68a0
movq %r13, %rdi
callq 0x66e0
movq %r12, %rdi
callq 0x6b37e
testl %eax, %eax
movq (%rsp), %rbp
jne 0x6a033
leaq 0x2bf22(%rip), %rsi     # 0x95e29
movq %r15, %rdi
callq 0x6880
movq %rax, %r13
movq 0x8(%rsp), %r14
testq %r13, %r13
je 0x69fc8
testq %r13, %r13
je 0x69fa3
movq %r13, %rdi
callq 0x69b41
movq %rax, %r15
movq %r13, %rdi
callq 0x66e0
leaq 0x244c7(%rip), %rsi     # 0x8e406
movq %r14, %rdi
callq 0x66a24
movq %rax, %rbx
movq %rax, (%r15)
movq %rbp, %rdi
callq 0x68a0
testq %rbx, %rbx
je 0x69fc1
movl $0x60000000, %eax       # imm = 0x60000000
andl (%rbx), %eax
cmpl $0x20000000, %eax       # imm = 0x20000000
jne 0x69fd3
leaq 0x2f1d8(%rip), %rdx     # 0x99147
movq %rbx, %rdi
movq %r14, %rsi
callq 0x68b10
testl %eax, %eax
jns 0x69fd3
movq 0x55053(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x2fedb(%rip), %rsi     # 0x99e6a
movq %r14, %rdx
xorl %eax, %eax
callq 0x6a90
movq %r15, %rdi
callq 0x69954
jmp 0x69fd0
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x7c6e
testb $0x1, %al
je 0x69fd0
movq 0x10(%rsp), %r13
jmp 0x69f25
callq 0x7ceb
jmp 0x69fd0
movq %rbp, %rdi
callq 0x7c46
xorl %r15d, %r15d
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x54fec(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x3001f(%rip), %rsi     # 0x9a015
xorl %r13d, %r13d
movq %rbp, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x69f17
movq 0x54fc9(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x30030(%rip), %rsi     # 0x9a049
xorl %r13d, %r13d
movq %r15, %rdx
xorl %eax, %eax
callq 0x6a90
movq %r12, %rdi
callq 0x6b3d8
jmp 0x69f17
movq 0x54f9e(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x3004d(%rip), %rsi     # 0x9a091
movq %rbp, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x69f00