// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3380
movq %rax, %rdi
addq $0x5, %rdi
movl $0x1, %esi
callq 0x36b0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x3817d(%rip), %rsi     # 0x775a6
movb $0x0, %al
callq 0x3460
movq -0x18(%rbp), %rdi
callq 0x41f60
cmpl $0x0, %eax
je 0x3f486
movq -0x18(%rbp), %rdi
callq 0x3f640
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3f484
movq 0x45b8f(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x3943b(%rip), %rsi     # 0x788a2
movb $0x0, %al
callq 0x37f0
movq -0x18(%rbp), %rdi
callq 0x3370
movq $0x0, -0x8(%rbp)
jmp 0x3f629
jmp 0x3f49a
movq -0x18(%rbp), %rdi
leaq 0x363f1(%rip), %rsi     # 0x75882
callq 0x3260
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3f543
movq 0x45b3c(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
leaq 0x3941d(%rip), %rsi     # 0x788d3
movb $0x0, %al
callq 0x37f0
movq -0x10(%rbp), %rdi
callq 0x3f1a0
cmpl $0x0, %eax
jge 0x3f4e1
movq -0x18(%rbp), %rdi
callq 0x3370
movq $0x0, -0x8(%rbp)
jmp 0x3f629
movq -0x18(%rbp), %rdi
leaq 0x36396(%rip), %rsi     # 0x75882
callq 0x3260
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3f541
movq 0x45ae5(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
callq 0x35d0
movl (%rax), %edi
callq 0x34e0
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0x393ce(%rip), %rsi     # 0x788f2
movb $0x0, %al
callq 0x37f0
movq -0x18(%rbp), %rdi
callq 0x3370
movq $0x0, -0x8(%rbp)
jmp 0x3f629
jmp 0x3f543
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3f810
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x36d0
movq -0x18(%rbp), %rdi
callq 0x3370
cmpq $0x0, -0x28(%rbp)
jne 0x3f57a
movq $0x0, -0x8(%rbp)
jmp 0x3f629
movq -0x10(%rbp), %rdi
leaq 0x362fd(%rip), %rsi     # 0x75882
callq 0x39540
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x3f5c0
movq 0x45a43(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
leaq 0x3936e(%rip), %rsi     # 0x7891d
movb $0x0, %al
callq 0x37f0
movq $0x0, -0x8(%rbp)
jmp 0x3f629
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
shrl $0x1d, %eax
andl $0x3, %eax
cmpl $0x1, %eax
jne 0x3f621
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
leaq 0x37fc7(%rip), %rdx     # 0x775ad
callq 0x3d020
cmpl $0x0, %eax
jge 0x3f61f
movq 0x459f1(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x3933d(%rip), %rsi     # 0x78942
movb $0x0, %al
callq 0x37f0
movq -0x28(%rbp), %rdi
callq 0x3eec0
movq $0x0, -0x8(%rbp)
jmp 0x3f629
jmp 0x3f621
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)