// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/faidx.c
// Function: fai_build3_core
static int fai_build3_core(const char *fn, const char *fnfai, const char *fngzi)
{
    kstring_t fai_kstr = { 0, 0, NULL };
    kstring_t gzi_kstr = { 0, 0, NULL };
    BGZF *bgzf = NULL;
    hFILE *fp = NULL;
    faidx_t *fai = NULL;
    int save_errno, res;
    char *file_type;

    bgzf = bgzf_open(fn, "r");

    if ( !bgzf ) {
        hts_log_error("Failed to open the file %s : %s", fn, strerror(errno));
        goto fail;
    }

    if ( bgzf->is_compressed ) {
        if (bgzf_index_build_init(bgzf) != 0) {
            hts_log_error("Failed to allocate bgzf index");
            goto fail;
        }
    }

    fai = fai_build_core(bgzf);

    if ( !fai ) {
        if (bgzf->is_compressed && bgzf->is_gzip) {
            hts_log_error("Cannot index files compressed with gzip, please use bgzip");
        }
        goto fail;
    }

    if (fai->format == FAI_FASTA) {
        file_type   = "FASTA";
    } else {
        file_type   = "FASTQ";
    }

    if (!fnfai) {
        if (ksprintf(&fai_kstr, "%s.fai", fn) < 0) goto fail;
        fnfai = fai_kstr.s;
    }

    if (!fngzi) {
        if (ksprintf(&gzi_kstr, "%s.gzi", fn) < 0) goto fail;
        fngzi = gzi_kstr.s;
    }

    if ( bgzf->is_compressed ) {
        if (bgzf_index_dump(bgzf, fngzi, NULL) < 0) {
            hts_log_error("Failed to make bgzf index %s", fngzi);
            goto fail;
        }
    }

    res = bgzf_close(bgzf);
    bgzf = NULL;

    if (res < 0) {
        hts_log_error("Error on closing %s : %s", fn, strerror(errno));
        goto fail;
    }

    fp = hopen(fnfai, "wb");

    if ( !fp ) {
        hts_log_error("Failed to open %s index %s : %s", file_type, fnfai, strerror(errno));
        goto fail;
    }

    if (fai_save(fai, fp) != 0) {
        hts_log_error("Failed to write %s index %s : %s", file_type, fnfai, strerror(errno));
        goto fail;
    }

    if (hclose(fp) != 0) {
        hts_log_error("Failed on closing %s index %s : %s", file_type, fnfai, strerror(errno));
        goto fail;
    }

    free(fai_kstr.s);
    free(gzi_kstr.s);
    fai_destroy(fai);
    return 0;

 fail:
    save_errno = errno;
    free(fai_kstr.s);
    free(gzi_kstr.s);
    bgzf_close(bgzf);
    fai_destroy(fai);
    errno = save_errno;
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x4250
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x4250
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1f0e7(%rip), %rsi     # 0xf2af1
callq 0xc090
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xd3a54
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0x80(%rbp), %rcx
movq %rax, %r8
movl $0x1, %edi
leaq 0x23e79(%rip), %rsi     # 0xf78ba
leaq 0x23e82(%rip), %rdx     # 0xf78ca
movb $0x0, %al
callq 0x1b030
jmp 0xd3d60
movq -0x58(%rbp), %rax
movl (%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd3a94
movq -0x58(%rbp), %rdi
callq 0x11200
cmpl $0x0, %eax
je 0xd3a92
movl $0x1, %edi
leaq 0x23e3b(%rip), %rsi     # 0xf78ba
leaq 0x23e64(%rip), %rdx     # 0xf78ea
movb $0x0, %al
callq 0x1b030
jmp 0xd3d60
jmp 0xd3a94
movq -0x58(%rbp), %rdi
callq 0xd54f0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0xd3ae6
movq -0x58(%rbp), %rax
movl (%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd3ae1
movq -0x58(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xd3ae1
movl $0x1, %edi
leaq 0x23de7(%rip), %rsi     # 0xf78ba
leaq 0x23e2e(%rip), %rdx     # 0xf7908
movb $0x0, %al
callq 0x1b030
jmp 0xd3d60
movq -0x68(%rbp), %rax
cmpl $0x1, 0x20(%rax)
jne 0xd3afd
leaq 0x1c51b(%rip), %rax     # 0xf0012
movq %rax, -0x78(%rbp)
jmp 0xd3b08
leaq 0x1c514(%rip), %rax     # 0xf0018
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xd3b37
movq -0x10(%rbp), %rdx
leaq -0x38(%rbp), %rdi
leaq 0x22270(%rip), %rsi     # 0xf5d8e
movb $0x0, %al
callq 0xb040
cmpl $0x0, %eax
jge 0xd3b2f
jmp 0xd3d60
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xd3b66
movq -0x10(%rbp), %rdx
leaq -0x50(%rbp), %rdi
leaq 0x23df5(%rip), %rsi     # 0xf7942
movb $0x0, %al
callq 0xb040
cmpl $0x0, %eax
jge 0xd3b5e
jmp 0xd3d60
movq -0x40(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd3bb2
movq -0x58(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x11460
cmpl $0x0, %eax
jge 0xd3bb0
movq -0x20(%rbp), %rcx
movl $0x1, %edi
leaq 0x23d1d(%rip), %rsi     # 0xf78ba
leaq 0x23da5(%rip), %rdx     # 0xf7949
movb $0x0, %al
callq 0x1b030
jmp 0xd3d60
jmp 0xd3bb2
movq -0x58(%rbp), %rdi
callq 0x103d0
movl %eax, -0x70(%rbp)
movq $0x0, -0x58(%rbp)
cmpl $0x0, -0x70(%rbp)
jge 0xd3c0c
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0x88(%rbp), %rcx
movq %rax, %r8
movl $0x1, %edi
leaq 0x23cc1(%rip), %rsi     # 0xf78ba
leaq 0x23d66(%rip), %rdx     # 0xf7966
movb $0x0, %al
callq 0x1b030
jmp 0xd3d60
movq -0x18(%rbp), %rdi
leaq 0x1b418(%rip), %rsi     # 0xef02f
movb $0x0, %al
callq 0x158b0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0xd3c7b
movq -0x78(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0x98(%rbp), %rcx
movq -0x90(%rbp), %r8
movq %rax, %r9
movl $0x1, %edi
leaq 0x23c52(%rip), %rsi     # 0xf78ba
leaq 0x23d10(%rip), %rdx     # 0xf797f
movb $0x0, %al
callq 0x1b030
jmp 0xd3d60
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0xd5db0
cmpl $0x0, %eax
je 0xd3cdf
movq -0x78(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xa0(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0xa8(%rbp), %rcx
movq -0xa0(%rbp), %r8
movq %rax, %r9
movl $0x1, %edi
leaq 0x23bee(%rip), %rsi     # 0xf78ba
leaq 0x23ccc(%rip), %rdx     # 0xf799f
movb $0x0, %al
callq 0x1b030
jmp 0xd3d60
movq -0x60(%rbp), %rdi
callq 0x14920
cmpl $0x0, %eax
je 0xd3d3c
movq -0x78(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0xb8(%rbp), %rcx
movq -0xb0(%rbp), %r8
movq %rax, %r9
movl $0x1, %edi
leaq 0x23b8e(%rip), %rsi     # 0xf78ba
leaq 0x23c8d(%rip), %rdx     # 0xf79c0
movb $0x0, %al
callq 0x1b030
jmp 0xd3d60
movq -0x28(%rbp), %rdi
callq 0x45a0
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0x68(%rbp), %rdi
callq 0xd38a0
movl $0x0, -0x4(%rbp)
jmp 0xd3dab
callq 0x4050
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x45a0
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0x58(%rbp), %rdi
callq 0x103d0
movq -0x68(%rbp), %rdi
callq 0xd38a0
movl -0x6c(%rbp), %eax
movl %eax, -0xbc(%rbp)
callq 0x4050
movl -0xbc(%rbp), %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)