// File: /workspace/github_c_makefile_star2_O1/zhou-lab[P]tbmate/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");
        if (fai_build(fn) < 0) {
            free(str);
            return 0;
        }
        fp = fopen(str, "rb");
        if (fp == 0) {
            fprintf(stderr, "[fai_load] failed to open FASTA index: %s\n", strerror(errno));
            free(str);
            return 0;
        }
    }

    fai = fai_read(fp, str);
    fclose(fp);
    free(str);
    if (fai == NULL) {
        return NULL;
    }

    fai->bgzf = bgzf_open(fn, "rb");
    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, %rbx
callq 0x3380
leaq 0x5(%rax), %rdi
movl $0x1, %esi
callq 0x36a0
movq %rax, %r14
leaq 0x24a9c(%rip), %rsi     # 0x4f1cb
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3460
movq %r14, %rdi
callq 0x2c563
testl %eax, %eax
movq %rbx, 0x20(%rsp)
movq %r14, (%rsp)
je 0x2a844
movq %r14, %rdi
callq 0x3380
cltq
addq %r14, %rax
decq %rax
movq %rax, %r15
cmpq %r14, %rax
jb 0x2a777
leaq -0x1(%r15), %rax
cmpb $0x2f, (%r15)
jne 0x2a765
incq %r15
leaq 0x268dc(%rip), %rsi     # 0x5105d
movq %r15, %rdi
callq 0x3250
movq %rax, %r12
testq %rax, %rax
jne 0x2a88e
leaq 0x23062(%rip), %rsi     # 0x4d7fe
movq %r14, %rdi
callq 0x2c1ab
testq %rax, %rax
je 0x2aa80
movq %rax, %r13
leaq 0x2342b(%rip), %rsi     # 0x4dbe2
movq %r15, %rdi
callq 0x3250
testq %rax, %rax
je 0x2aaa7
movq %rax, %rbx
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x36a0
movq %rax, %r14
movq 0x8(%r13), %rsi
movq 0x10(%r13), %rbp
subq %rsi, %rbp
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %rbp
movl $0x100000, %r12d        # imm = 0x100000
cmovbq %rbp, %r12
movq %r14, %rdi
movq %r12, %rdx
callq 0x3850
addq %r12, 0x8(%r13)
movl $0x100000, %edx         # imm = 0x100000
cmpq $0xfffff, %rbp          # imm = 0xFFFFF
ja 0x2a828
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rcx
callq 0x2baf7
movq %rax, %rdx
testl %edx, %edx
jle 0x2a858
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x1, %esi
movq %r14, %rdi
movq %rbx, %rcx
callq 0x3770
jmp 0x2a7dd
leaq 0x22fb3(%rip), %rsi     # 0x4d7fe
movq %r14, %rdi
callq 0x3250
movq %rax, %r12
jmp 0x2a897
movq %r14, %rdi
callq 0x3370
movq %rbx, %rdi
callq 0x36c0
movq %r13, %rdi
callq 0x2be22
testl %eax, %eax
movq (%rsp), %r14
jne 0x2aad6
leaq 0x267da(%rip), %rsi     # 0x5105d
movq %r15, %rdi
callq 0x3250
movq %rax, %r12
testq %r12, %r12
je 0x2aa3b
testq %r12, %r12
je 0x2aa19
movl $0x1, %edi
movl $0x20, %esi
callq 0x36a0
movq %rax, %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x36a0
movq %rax, 0x18(%r15)
movl $0x10000, %edi          # imm = 0x10000
movl $0x1, %esi
callq 0x36a0
movq %rax, %r13
leaq 0x18(%rsp), %rbp
leaq 0x1c(%rsp), %rbx
movq %r13, %rdi
movl $0x10000, %esi          # imm = 0x10000
movq %r12, %rdx
callq 0x32d0
testq %rax, %rax
je 0x2a97e
movb (%r13), %r14b
movq %r13, %rdi
testb %r14b, %r14b
je 0x2a928
callq 0x3410
movq (%rax), %rax
movq %r13, %rdi
movsbq %r14b, %rcx
cmpw $0x0, (%rax,%rcx,2)
jns 0x2a928
movb 0x1(%rdi), %r14b
incq %rdi
testb %r14b, %r14b
jne 0x2a911
movb $0x0, (%rdi)
incq %rdi
leaq 0x25dea(%rip), %rsi     # 0x5071f
leaq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbp, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x3140
movl 0x8(%rsp), %edx
movl 0x1c(%rsp), %ecx
movl 0x18(%rsp), %r8d
movq 0x10(%rsp), %r9
movq %r15, %rdi
movq %r13, %rsi
callq 0x2a075
testl %eax, %eax
je 0x2a8e1
movq %r13, %rdi
callq 0x3370
xorl %r15d, %r15d
jmp 0x2a996
movq %r13, %rdi
callq 0x3370
movq %r12, %rdi
callq 0x33b0
testl %eax, %eax
jne 0x2aa69
movq (%rsp), %rbx
movq %r12, %rdi
callq 0x36c0
movq %rbx, %rdi
callq 0x3370
testq %r15, %r15
je 0x2aa4a
leaq 0x22e44(%rip), %rsi     # 0x4d7fe
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x270a0
movq %rax, (%r15)
testq %rax, %rax
je 0x2aa45
movl $0x60000000, %ecx       # imm = 0x60000000
andl (%rax), %ecx
cmpl $0x20000000, %ecx       # imm = 0x20000000
jne 0x2aa4d
leaq 0x247ed(%rip), %rdx     # 0x4f1d2
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2950e
testl %eax, %eax
jns 0x2aa4d
movq 0x335ed(%rip), %rax     # 0x5dfe8
movq (%rax), %rdi
leaq 0x25a7d(%rip), %rsi     # 0x50482
movq %rbx, %rdx
xorl %eax, %eax
callq 0x37e0
movq %r15, %rdi
callq 0x2a38d
jmp 0x2aa4a
leaq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x4c27
testb $0x1, %al
je 0x2aa5f
movq 0x10(%rsp), %r15
jmp 0x2aa4d
movq %r14, %rdi
callq 0x4bff
jmp 0x2aa4a
callq 0x4d02
xorl %r15d, %r15d
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %r12
jmp 0x2a8a0
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4cbc
xorl %r15d, %r15d
jmp 0x2a99a
movq 0x33561(%rip), %rax     # 0x5dfe8
movq (%rax), %rdi
leaq 0x25bdd(%rip), %rsi     # 0x5066e
xorl %r12d, %r12d
movq (%rsp), %r14
movq %r14, %rdx
xorl %eax, %eax
callq 0x37e0
jmp 0x2a88e
movq 0x3353a(%rip), %rax     # 0x5dfe8
movq (%rax), %rdi
leaq 0x25bea(%rip), %rsi     # 0x506a2
xorl %r12d, %r12d
movq %r15, %rdx
xorl %eax, %eax
callq 0x37e0
movq %r13, %rdi
callq 0x2be7c
movq (%rsp), %r14
jmp 0x2a88e
movq 0x3350b(%rip), %rax     # 0x5dfe8
movq (%rax), %rdi
leaq 0x25c03(%rip), %rsi     # 0x506ea
movq %r14, %rdx
xorl %eax, %eax
callq 0x37e0
jmp 0x2a87c