// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rdi, %r14
callq 0x62d0
leaq 0x5(%rax), %rdi
movl $0x1, %esi
callq 0x6470
movq %rax, %r13
leaq 0x2f4c1(%rip), %rsi     # 0x9934b
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x6170
movq %r13, %rdi
callq 0x6bacc
testl %eax, %eax
je 0x69fad
movq %r13, %rdi
callq 0x62d0
cltq
addq %r13, %rax
decq %rax
movq %rax, %r15
cmpq %r13, %rax
jb 0x69ec9
leaq -0x1(%r15), %rax
cmpb $0x2f, (%r15)
jne 0x69eb7
incq %r15
leaq 0x2c036(%rip), %rsi     # 0x95f09
movq %r15, %rdi
callq 0x6880
testq %rax, %rax
jne 0x6a024
leaq 0x2455b(%rip), %rsi     # 0x8e446
movq %r13, %rdi
callq 0x6b721
testq %rax, %rax
je 0x6a0b0
movq %rax, %r12
leaq 0x28d40(%rip), %rsi     # 0x92c46
movq %r15, %rdi
callq 0x6880
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x6a0cd
movq %r13, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x6470
movq %rax, %rbp
movq 0x8(%r12), %r14
movq 0x10(%r12), %r13
subq %r14, %r13
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %r13
movl $0x100000, %ebx         # imm = 0x100000
cmovbq %r13, %rbx
movq %rbp, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x6570
addq %rbx, %r14
movq %r14, 0x8(%r12)
movl $0x100000, %eax         # imm = 0x100000
cmpq $0xfffff, %r13          # imm = 0xFFFFF
ja 0x69f91
movl $0x100000, %edx         # imm = 0x100000
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %rcx
callq 0x6b0a3
testl %eax, %eax
jle 0x69fe0
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x1, %esi
movq %rbp, %rdi
movq %rax, %rdx
movq 0x8(%rsp), %rcx
callq 0x6e70
jmp 0x69f38
leaq 0x24492(%rip), %rsi     # 0x8e446
movq %r13, %rdi
callq 0x6880
testq %rax, %rax
jne 0x6a024
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x7c1a
testb $0x1, %al
je 0x6a0f8
movq 0x20(%rsp), %r12
jmp 0x6a027
movq %rbp, %rdi
callq 0x68a0
movq 0x8(%rsp), %rdi
callq 0x66e0
movq %r12, %rdi
callq 0x6b393
testl %eax, %eax
movq 0x10(%rsp), %r13
jne 0x6a10d
leaq 0x2befb(%rip), %rsi     # 0x95f09
movq %r15, %rdi
callq 0x6880
testq %rax, %rax
movq 0x18(%rsp), %r14
je 0x6a0f0
movq %rax, %r12
movq %r12, %rdi
callq 0x69c1a
movq %rax, %r15
movq %r12, %rdi
callq 0x66e0
leaq 0x24405(%rip), %rsi     # 0x8e446
movq %r14, %rdi
callq 0x66abc
movq %rax, %rbx
movq %rax, (%r15)
movq %r13, %rdi
callq 0x68a0
testq %rbx, %rbx
je 0x6a0a9
movl $0x60000000, %eax       # imm = 0x60000000
andl (%rbx), %eax
cmpl $0x20000000, %eax       # imm = 0x20000000
jne 0x6a0fb
leaq 0x2f2dd(%rip), %rdx     # 0x99352
movq %rbx, %rdi
movq %r14, %rsi
callq 0x68c01
testl %eax, %eax
jns 0x6a0fb
movq 0x54f4d(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x30005(%rip), %rsi     # 0x9a09a
movq %r14, %rdx
xorl %eax, %eax
callq 0x6a90
movq %r15, %rdi
callq 0x69a2d
jmp 0x6a0f8
callq 0x7c97
jmp 0x6a0f8
movq 0x54f21(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x30184(%rip), %rsi     # 0x9a245
movq %r13, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x6a0f0
movq 0x54f04(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x3019b(%rip), %rsi     # 0x9a279
movq %r15, %rdx
xorl %eax, %eax
callq 0x6a90
movq %r12, %rdi
callq 0x6b3ed
movq %r13, %rdi
callq 0x7bf2
xorl %r15d, %r15d
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x54ec4(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x301a3(%rip), %rsi     # 0x9a2c1
movq %r13, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x6a007