// File: /workspace/github_c_makefile_star2_O0/zhou-lab[P]tbmate/htslib/faidx.c
// Function: fai_build
int fai_build(const char *fn)
{
    char *str;
    BGZF *bgzf;
    FILE *fp;
    faidx_t *fai;
    str = (char*)calloc(strlen(fn) + 5, 1);
    sprintf(str, "%s.fai", fn);
    bgzf = bgzf_open(fn, "r");
    if ( !bgzf ) {
        fprintf(stderr, "[fai_build] fail to open the FASTA file %s\n",fn);
        free(str);
        return -1;
    }
    if ( bgzf->is_compressed ) bgzf_index_build_init(bgzf);
    fai = fai_build_core(bgzf);
    if ( !fai )
    {
        if ( bgzf->is_compressed && bgzf->is_gzip ) fprintf(stderr,"Cannot index files compressed with gzip, please use bgzip\n");
        bgzf_close(bgzf);
        free(str);
        return -1;
    }
    if ( bgzf->is_compressed ) {
        if (bgzf_index_dump(bgzf, fn, ".gzi") < 0) {
            fprintf(stderr, "[fai_build] fail to make bgzf index %s.gzi\n", fn);
            fai_destroy(fai); free(str);
            return -1;
        }
    }
    if (bgzf_close(bgzf) < 0) {
        fprintf(stderr, "[fai_build] Error on closing %s\n", fn);
        fai_destroy(fai); free(str);
        return -1;
    }
    fp = fopen(str, "wb");
    if ( !fp ) {
        fprintf(stderr, "[fai_build] fail to write FASTA index %s\n",str);
        fai_destroy(fai); free(str);
        return -1;
    }
    fai_save(fai, fp);
    fclose(fp);
    free(str);
    fai_destroy(fai);
    return 0;
}

// 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 0x383cd(%rip), %rsi     # 0x775a6
movb $0x0, %al
callq 0x3460
movq -0x10(%rbp), %rdi
leaq 0x3a238(%rip), %rsi     # 0x79423
callq 0x39540
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3f22c
movq 0x45de6(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x395b4(%rip), %rsi     # 0x787c4
movb $0x0, %al
callq 0x37f0
movq -0x18(%rbp), %rdi
callq 0x3370
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3f3de
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x1d, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x3f246
movq -0x20(%rbp), %rdi
callq 0x3cbb0
movq -0x20(%rbp), %rdi
callq 0x3e6d0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x3f2af
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x1d, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x3f291
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x3f291
movq 0x45d68(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
leaq 0x39566(%rip), %rsi     # 0x787f0
movb $0x0, %al
callq 0x37f0
movq -0x20(%rbp), %rdi
callq 0x3c070
movq -0x18(%rbp), %rdi
callq 0x3370
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3f3de
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x1d, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x3f315
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0x382de(%rip), %rdx     # 0x775ad
callq 0x3cc10
cmpl $0x0, %eax
jge 0x3f313
movq 0x45d08(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x3953d(%rip), %rsi     # 0x7882b
movb $0x0, %al
callq 0x37f0
movq -0x30(%rbp), %rdi
callq 0x3eec0
movq -0x18(%rbp), %rdi
callq 0x3370
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3f3de
jmp 0x3f315
movq -0x20(%rbp), %rdi
callq 0x3c070
cmpl $0x0, %eax
jge 0x3f35d
movq 0x45cbe(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x3951f(%rip), %rsi     # 0x78857
movb $0x0, %al
callq 0x37f0
movq -0x30(%rbp), %rdi
callq 0x3eec0
movq -0x18(%rbp), %rdi
callq 0x3370
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3f3de
movq -0x18(%rbp), %rdi
leaq 0x36b6f(%rip), %rsi     # 0x75ed7
callq 0x3260
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3f3af
movq 0x45c69(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x394eb(%rip), %rsi     # 0x78878
movb $0x0, %al
callq 0x37f0
movq -0x30(%rbp), %rdi
callq 0x3eec0
movq -0x18(%rbp), %rdi
callq 0x3370
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3f3de
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x3ef40
movq -0x28(%rbp), %rdi
callq 0x36d0
movq -0x18(%rbp), %rdi
callq 0x3370
movq -0x30(%rbp), %rdi
callq 0x3eec0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)