// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rsi
callq 0x36b0
movq %rax, %r14
leaq 0x1e021(%rip), %rsi     # 0x411c1
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3460
movq %r14, %rdi
callq 0x2497d
testl %eax, %eax
movq %r14, 0x8(%rsp)
movq %rbx, 0x28(%rsp)
je 0x232c3
movq %r14, %rdi
callq 0x3380
cltq
addq %r14, %rax
decq %rax
movq %rax, %r15
cmpq %r14, %rax
jb 0x231e9
leaq -0x1(%r15), %rax
cmpb $0x2f, (%r15)
jne 0x231d7
incq %r15
leaq 0x1fd86(%rip), %rsi     # 0x42f79
movq %r15, %rdi
callq 0x3250
testq %rax, %rax
jne 0x23380
leaq 0x1c5f7(%rip), %rsi     # 0x3f802
movq %r14, %rdi
callq 0x2460c
testq %rax, %rax
je 0x23553
movq %rax, %r12
leaq 0x1c9bc(%rip), %rsi     # 0x3fbe2
movq %r15, %rdi
callq 0x3250
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x23570
pushq $0x1
popq %rsi
movl $0x100000, %edi         # imm = 0x100000
callq 0x36b0
movq %rax, %r14
movq 0x8(%r12), %rbx
movq 0x10(%r12), %r13
subq %rbx, %r13
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %r13
movl $0x100000, %ebp         # imm = 0x100000
cmovbq %r13, %rbp
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x3860
addq %rbp, %rbx
movq %rbx, 0x8(%r12)
movl $0x100000, %eax         # imm = 0x100000
cmpq $0xfffff, %r13          # imm = 0xFFFFF
ja 0x232a9
movl $0x100000, %edx         # imm = 0x100000
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rcx
callq 0x23fcb
testl %eax, %eax
jle 0x23341
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r14, %rdi
pushq $0x1
popq %rsi
movq %rax, %rdx
movq 0x20(%rsp), %rcx
callq 0x3780
jmp 0x2324c
leaq 0x1c538(%rip), %rsi     # 0x3f802
movq %r14, %rdi
callq 0x3250
testq %rax, %rax
jne 0x23380
movq %rbx, %r15
movq 0x2fd03(%rip), %rbx     # 0x52fe8
movq (%rbx), %rcx
leaq 0x1f114(%rip), %rdi     # 0x42403
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
callq 0x3780
movq %r15, %rdi
callq 0x22fce
testl %eax, %eax
js 0x235dd
leaq 0x1c4f1(%rip), %rsi     # 0x3f802
movq %r14, %rdi
callq 0x3250
testq %rax, %rax
jne 0x23380
movq (%rbx), %rbx
callq 0x35e0
movl (%rax), %edi
callq 0x34e0
leaq 0x1f0ee(%rip), %rsi     # 0x42422
xorl %ebp, %ebp
movq %rbx, %rdi
movq %rax, %rdx
jmp 0x235a9
movq %r14, %rdi
callq 0x3370
movq 0x20(%rsp), %rdi
callq 0x36d0
movq %r12, %rdi
callq 0x242a6
testl %eax, %eax
movq 0x8(%rsp), %r14
jne 0x235bd
leaq 0x1fc0a(%rip), %rsi     # 0x42f79
movq %r15, %rdi
callq 0x3250
testq %rax, %rax
je 0x23593
movq %rax, %r12
pushq $0x1
popq %rbx
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x36b0
movq %rax, %rbp
callq 0x22b28
movq %rax, 0x18(%rbp)
movl $0x10000, %edi          # imm = 0x10000
movq %rbx, %rsi
callq 0x36b0
movq %rax, %r13
movq %rax, %rbx
incq %rbx
movq %r13, %rdi
movl $0x10000, %esi          # imm = 0x10000
movq %r12, %rdx
callq 0x32d0
testq %rax, %rax
je 0x23445
movq %rbx, %r14
movsbq -0x1(%r14), %r15
testq %r15, %r15
je 0x233ea
callq 0x3410
movq (%rax), %rax
cmpw $0x0, (%rax,%r15,2)
jns 0x233ea
incq %r14
jmp 0x233cb
movb $0x0, -0x1(%r14)
movq %r14, %rdi
leaq 0x1f316(%rip), %rsi     # 0x4270f
leaq 0x1c(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x14(%rsp), %r8
leaq 0x18(%rsp), %r9
xorl %eax, %eax
callq 0x3140
movl 0x1c(%rsp), %edx
movl 0x18(%rsp), %ecx
movl 0x14(%rsp), %r8d
movq 0x30(%rsp), %r9
movq %rbp, %rdi
movq %r13, %rsi
callq 0x22b33
testl %eax, %eax
je 0x233b3
movq %r13, %rdi
callq 0x3370
xorl %ebp, %ebp
jmp 0x2345d
movq %r13, %rdi
callq 0x3370
movq %r12, %rdi
callq 0x33b0
testl %eax, %eax
jne 0x23512
movq 0x8(%rsp), %rbx
movq %r12, %rdi
callq 0x36d0
movq %rbx, %rdi
callq 0x3370
testq %rbp, %rbp
je 0x234fe
leaq 0x1c380(%rip), %rsi     # 0x3f802
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x1fde4
movq %rax, (%rbp)
testq %rax, %rax
je 0x234e2
movl $0x60000000, %ecx       # imm = 0x60000000
andl (%rax), %ecx
cmpl $0x20000000, %ecx       # imm = 0x20000000
jne 0x23500
leaq 0x1dd1a(%rip), %rdx     # 0x411c8
movq %rax, %rdi
movq %rbx, %rsi
callq 0x22004
testl %eax, %eax
jns 0x23500
movq 0x2fb24(%rip), %rax     # 0x52fe8
movq (%rax), %rdi
leaq 0x1efa4(%rip), %rsi     # 0x42472
movq %rbx, %rdx
xorl %eax, %eax
callq 0x37f0
movq %rbp, %rdi
callq 0x22e1e
jmp 0x234fe
movq 0x2faff(%rip), %rax     # 0x52fe8
movq (%rax), %rcx
leaq 0x1ef5a(%rip), %rdi     # 0x4244d
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x3780
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2facf(%rip), %rax     # 0x52fe8
movq (%rax), %rbx
callq 0x35e0
movl (%rax), %edi
callq 0x34e0
leaq 0x1f1eb(%rip), %rsi     # 0x4271a
movq %rbx, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x37f0
movq %rbp, %rdi
callq 0x22e1e
xorl %ebp, %ebp
jmp 0x23462
movq 0x2fa8e(%rip), %rax     # 0x52fe8
movq (%rax), %rdi
leaq 0x1f0fa(%rip), %rsi     # 0x4265e
movq %r14, %rdx
xorl %eax, %eax
callq 0x37f0
jmp 0x23593
movq 0x2fa71(%rip), %rax     # 0x52fe8
movq (%rax), %rdi
leaq 0x1f111(%rip), %rsi     # 0x42692
movq %r15, %rdx
xorl %eax, %eax
callq 0x37f0
movq %r12, %rdi
callq 0x242fe
movq 0x2fa4e(%rip), %rax     # 0x52fe8
movq (%rax), %rdi
leaq 0x1ee2e(%rip), %rsi     # 0x423d2
xorl %ebp, %ebp
movq %r14, %rdx
xorl %eax, %eax
callq 0x37f0
movq %r14, %rdi
callq 0x3370
jmp 0x23500
movq 0x2fa24(%rip), %rax     # 0x52fe8
movq (%rax), %rdi
leaq 0x1f10c(%rip), %rsi     # 0x426da
movq %r14, %rdx
xorl %eax, %eax
callq 0x37f0
jmp 0x23368
movq %r14, %rdi
callq 0x3370
jmp 0x234fe