// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %rdi, %rbx
callq 0x3380
leaq 0x5(%rax), %rdi
movl $0x1, %esi
callq 0x36a0
movq %rax, %r14
leaq 0x24de8(%rip), %rsi     # 0x4f386
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3460
movq %r14, %rdi
callq 0x2c305
testl %eax, %eax
movq %rbx, 0x28(%rsp)
movq %r14, 0x8(%rsp)
je 0x2a6c2
movq %r14, %rdi
callq 0x3380
cltq
addq %r14, %rax
decq %rax
movq %rax, %r15
cmpq %r14, %rax
jb 0x2a5e7
leaq -0x1(%r15), %rax
cmpb $0x2f, (%r15)
jne 0x2a5d5
incq %r15
leaq 0x26c34(%rip), %rsi     # 0x51225
movq %r15, %rdi
callq 0x3250
testq %rax, %rax
jne 0x2a73e
leaq 0x231f9(%rip), %rsi     # 0x4d802
movq %r14, %rdi
callq 0x2bf5d
testq %rax, %rax
je 0x2a8e2
movq %rax, %r12
leaq 0x235be(%rip), %rsi     # 0x4dbe2
movq %r15, %rdi
callq 0x3250
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x2a8ff
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x36a0
movq %rax, %r14
movq 0x8(%r12), %rbp
movq 0x10(%r12), %rbx
subq %rbp, %rbx
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %rbx
movl $0x100000, %r13d        # imm = 0x100000
cmovbq %rbx, %r13
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x3850
addq %r13, %rbp
movq %rbp, 0x8(%r12)
movl $0x100000, %eax         # imm = 0x100000
cmpq $0xfffff, %rbx          # imm = 0xFFFFF
ja 0x2a6a6
movl $0x100000, %edx         # imm = 0x100000
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rcx
callq 0x2b8df
testl %eax, %eax
jle 0x2a6ff
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x1, %esi
movq %r14, %rdi
movq %rax, %rdx
movq 0x30(%rsp), %rcx
callq 0x3770
jmp 0x2a64c
leaq 0x23139(%rip), %rsi     # 0x4d802
movq %r14, %rdi
callq 0x3250
testq %rax, %rax
jne 0x2a73e
leaq 0x10(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x4b6d
testb $0x1, %al
je 0x2a95f
movq 0x18(%rsp), %r15
jmp 0x2a92d
movq %r14, %rdi
callq 0x3370
movq 0x30(%rsp), %rdi
callq 0x36c0
movq %r12, %rdi
callq 0x2bbcf
testl %eax, %eax
movq 0x8(%rsp), %r14
jne 0x2a93f
leaq 0x26af8(%rip), %rsi     # 0x51225
movq %r15, %rdi
callq 0x3250
testq %rax, %rax
je 0x2a922
movq %rax, %r12
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 0x20(%rsp), %rbp
leaq 0x24(%rsp), %rbx
movq %r13, %rdi
movl $0x10000, %esi          # imm = 0x10000
movq %r12, %rdx
callq 0x32d0
testq %rax, %rax
je 0x2a81f
movb (%r13), %r14b
movq %r13, %rdi
testb %r14b, %r14b
je 0x2a7c9
callq 0x3410
movq (%rax), %rax
movq %r13, %rdi
movsbq %r14b, %rcx
cmpw $0x0, (%rax,%rcx,2)
jns 0x2a7c9
movb 0x1(%rdi), %r14b
incq %rdi
testb %r14b, %r14b
jne 0x2a7b2
movb $0x0, (%rdi)
incq %rdi
leaq 0x26119(%rip), %rsi     # 0x508ef
leaq 0x10(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq %rbp, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x3140
movl 0x10(%rsp), %edx
movl 0x24(%rsp), %ecx
movl 0x20(%rsp), %r8d
movq 0x18(%rsp), %r9
movq %r15, %rdi
movq %r13, %rsi
callq 0x29f07
testl %eax, %eax
je 0x2a782
movq %r13, %rdi
callq 0x3370
xorl %r15d, %r15d
jmp 0x2a837
movq %r13, %rdi
callq 0x3370
movq %r12, %rdi
callq 0x33b0
testl %eax, %eax
jne 0x2a8ca
movq 0x8(%rsp), %rbx
movq %r12, %rdi
callq 0x36c0
movq %rbx, %rdi
callq 0x3370
testq %r15, %r15
je 0x2a92a
leaq 0x22fa6(%rip), %rsi     # 0x4d802
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x26f1c
movq %rax, (%r15)
testq %rax, %rax
je 0x2a8c3
movl $0x60000000, %ecx       # imm = 0x60000000
andl (%rax), %ecx
cmpl $0x20000000, %ecx       # imm = 0x20000000
jne 0x2a92d
leaq 0x24b02(%rip), %rdx     # 0x4f38d
movq %rax, %rdi
movq %rbx, %rsi
callq 0x293d2
testl %eax, %eax
jns 0x2a92d
movq 0x34743(%rip), %rax     # 0x5efe8
movq (%rax), %rdi
leaq 0x25da3(%rip), %rsi     # 0x50652
movq %rbx, %rdx
xorl %eax, %eax
callq 0x37e0
movq %r15, %rdi
callq 0x2a1fc
jmp 0x2a92a
callq 0x4c48
jmp 0x2a92a
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4c02
xorl %r15d, %r15d
jmp 0x2a83c
movq 0x346ff(%rip), %rax     # 0x5efe8
movq (%rax), %rdi
leaq 0x25f4b(%rip), %rsi     # 0x5083e
movq %r14, %rdx
xorl %eax, %eax
callq 0x37e0
jmp 0x2a922
movq 0x346e2(%rip), %rax     # 0x5efe8
movq (%rax), %rdi
leaq 0x25f62(%rip), %rsi     # 0x50872
movq %r15, %rdx
xorl %eax, %eax
callq 0x37e0
movq %r12, %rdi
callq 0x2bc29
movq %r14, %rdi
callq 0x4b45
xorl %r15d, %r15d
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x346a2(%rip), %rax     # 0x5efe8
movq (%rax), %rdi
leaq 0x25f6a(%rip), %rsi     # 0x508ba
movq %r14, %rdx
xorl %eax, %eax
callq 0x37e0
jmp 0x2a726
movq 0x10(%rsp), %r12
jmp 0x2a741