// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
andq $0x0, 0xa0(%rsp)
movaps %xmm0, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
leaq 0x135ad(%rip), %rsi     # 0x7a526
callq 0x9596
testq %rax, %rax
je 0x6744f
movq %rax, %r14
testb $0x40, 0x3(%rax)
je 0x66faf
movq %r14, %rdi
callq 0xc47b
testl %eax, %eax
je 0x66faf
leaq 0x1bf2b(%rip), %rsi     # 0x82ece
leaq 0x1bf54(%rip), %rdx     # 0x82efe
jmp 0x676d0
movq %r12, 0xb0(%rsp)
movq %r15, 0x58(%rsp)
movq %rbx, 0x38(%rsp)
pushq $0x1
popq %r13
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
pushq $0x1
popq %rdi
pushq $0x28
popq %rsi
callq 0x4300
movq %rax, %r12
callq 0x689eb
movq %rax, 0x18(%r12)
xorl %ecx, %ecx
movq $0x0, 0x68(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x30(%rsp)
xorl %ebp, %ebp
movq %r12, 0x28(%rsp)
movl %ecx, %eax
movq %rax, 0x18(%rsp)
movb $0x1, %bl
movq %r14, %rdi
callq 0x689f6
testl %eax, %eax
js 0x67481
movl %eax, %r15d
movl %ebp, %eax
cmpl $0x4, %ebp
ja 0x6740f
leaq 0x1bd67(%rip), %rcx     # 0x82dc4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x20(%r12), %eax
cmpl $0x1, %eax
jne 0x6708a
pushq $0x1
popq %rbp
cmpl $0x3e, %r15d
je 0x67038
cmpl $0xa, %r15d
jne 0x672f9
incl %r13d
xorl %ebp, %ebp
jmp 0x67036
cmpl $0x2, %eax
jne 0x672ed
cmpl $0x2b, %r15d
jne 0x67436
movq %r14, %rdi
callq 0x689f6
testl %eax, %eax
js 0x670ae
cmpl $0xa, %eax
jne 0x6709d
movq %r14, %rdi
callq 0xcaed
movq %rax, 0x50(%rsp)
incl %r13d
pushq $0x4
popq %rbp
jmp 0x67036
cmpl $0xa, %r15d
jne 0x670e4
cmpl $0x0, 0x18(%rsp)
je 0x67830
incl %r13d
xorl %ebp, %ebp
pushq $0x1
popq %rax
jmp 0x67031
cmpl $0x40, %r15d
movq 0x18(%rsp), %rcx
jne 0x670fc
pushq $0x1
popq %rbp
movl %ebp, %eax
testl %ecx, %ecx
jne 0x67031
pushq $0x1
popq %rbx
xorl %r12d, %r12d
addb $-0x21, %r15b
cmpb $0x5e, %r15b
adcq $0x0, %r12
movq %r14, %rdi
callq 0x689f6
incq %rbx
testl %eax, %eax
js 0x67125
movl %eax, %r15d
cmpl $0xa, %eax
jne 0x67102
movq 0x30(%rsp), %rcx
cmpq %rbx, %rcx
jb 0x67947
movq 0x60(%rsp), %rdx
addq %r12, %rdx
pushq $0x1
popq %rax
cmpq 0x40(%rsp), %rdx
movq 0x28(%rsp), %r12
je 0x6715e
ja 0x67962
movq 0x18(%rsp), %rax
cmpq %rbx, %rcx
ja 0x6797d
movq %rdx, 0x60(%rsp)
incl %r13d
movl %eax, %ecx
pushq $0x4
popq %rbp
jmp 0x6702f
cmpl $0x0, 0x18(%rsp)
leaq 0xc0(%rsp), %rbx
je 0x671b4
movq 0xd0(%rsp), %rsi
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movq 0x40(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x68(%rsp), %r9
callq 0x68a16
testl %eax, %eax
jne 0x676a4
andq $0x0, 0xc0(%rsp)
callq 0x4510
movq %rax, %r12
movq (%r12), %rax
movl %r15d, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
movq 0xc0(%rsp), %rsi
jne 0x67212
addq $0x2, %rsi
movq %rbx, %rdi
callq 0x69024
testl %eax, %eax
js 0x6721d
movq 0xc0(%rsp), %rax
movq 0xd0(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xc0(%rsp)
movb %r15b, (%rcx,%rax)
movb $0x0, 0x1(%rcx,%rax)
jmp 0x6721d
cmpl $0xa, %r15d
je 0x67234
testq %rsi, %rsi
jne 0x67234
movq %r14, %rdi
callq 0x689f6
movl %eax, %r15d
testl %eax, %eax
jns 0x671c5
movq 0xc0(%rsp), %rsi
cmpq $-0x2, %rsi
jae 0x6737c
addq $0x2, %rsi
movq %rbx, %rdi
callq 0x69024
testl %eax, %eax
movq 0x28(%rsp), %r12
js 0x6738c
movq 0xc0(%rsp), %rax
movq 0xd0(%rsp), %rcx
movb $0x0, (%rcx,%rax)
jmp 0x6738c
cmpl $0xa, %r15d
je 0x6740a
cmpl $0xd, %r15d
je 0x673ea
cmpl $0x40, %r15d
movq 0x18(%rsp), %rcx
je 0x67419
cmpl $0x3e, %r15d
jne 0x67892
cmpl $0x2, 0x20(%r12)
je 0x678e5
movl $0x1, 0x20(%r12)
pushq $0x1
popq %rbp
jmp 0x6702f
cmpl $0x2b, %r15d
jne 0x6775f
movq %r14, %rdi
callq 0x689f6
testl %eax, %eax
js 0x672d5
cmpl $0xa, %eax
jne 0x672c4
movq %r14, %rdi
callq 0xcaed
movq %rax, 0x50(%rsp)
incl %r13d
pushq $0x4
popq %rbp
jmp 0x6740f
movl %r13d, 0x24(%rsp)
pushq $0x3
popq %rbp
xorl %ebx, %ebx
jmp 0x67300
movl %r13d, 0x24(%rsp)
xorl %ebp, %ebp
pushq $0x1
popq %r13
xorl %r12d, %r12d
addb $-0x21, %r15b
cmpb $0x5e, %r15b
adcq $0x0, %r12
movq %r14, %rdi
callq 0x689f6
incq %r13
testl %eax, %eax
js 0x6732a
movl %eax, %r15d
cmpl $0xa, %eax
jne 0x67307
testb %bl, %bl
pushq $0x1
popq %rax
movq 0x18(%rsp), %rcx
cmovnel %eax, %ecx
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x67355
cmpq %r13, %rax
ja 0x67360
pushq $0x2
popq %rbp
movl 0x24(%rsp), %r13d
jae 0x67365
jmp 0x67803
movq %r12, 0x48(%rsp)
movq %r13, %rax
pushq $0x2
popq %rbp
movl 0x24(%rsp), %r13d
movq %rax, 0x30(%rsp)
addq %r12, 0x40(%rsp)
incl %r13d
movq 0x28(%rsp), %r12
jmp 0x6702f
callq 0x4050
movl $0x4b, (%rax)
movq 0x28(%rsp), %r12
testl %r15d, %r15d
js 0x67782
cmpl $0xa, %r15d
je 0x673ac
movq %r14, %rdi
callq 0x689f6
testl %eax, %eax
js 0x673ac
cmpl $0xa, %eax
jne 0x6739b
movq %r14, %rdi
callq 0xcaed
movq %rax, 0x68(%rsp)
incl %r13d
xorl %ecx, %ecx
movq $0x0, 0x40(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x30(%rsp)
pushq $0x2
popq %rbp
jmp 0x6702f
movq %r14, %rdi
callq 0x689f6
cmpl $0xa, %eax
movq 0x18(%rsp), %rcx
jne 0x678f8
incl %r13d
xorl %ebp, %ebp
jmp 0x6702f
incl %r13d
xorl %ebp, %ebp
movq 0x18(%rsp), %rcx
jmp 0x6702f
cmpl $0x1, 0x20(%r12)
je 0x6790b
movl $0x2, 0x20(%r12)
pushq $0x1
popq %rbp
jmp 0x6702f
cmpl $0xa, %r15d
je 0x6779d
movl %r13d, 0x24(%rsp)
xorl %ebx, %ebx
pushq $0x3
popq %rbp
jmp 0x67300
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x1ba6c(%rip), %rsi     # 0x82ece
leaq 0x1ba75(%rip), %rdx     # 0x82ede
xorl %r14d, %r14d
pushq $0x1
popq %rdi
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x110c6
jmp 0x676df
cmpl $0x0, 0x18(%rsp)
je 0x67689
movq 0xd0(%rsp), %r15
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq 0x40(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x68(%rsp), %r9
callq 0x68a16
testl %eax, %eax
jne 0x676a4
movq %r15, %rdi
callq 0x45c0
testq %r12, %r12
je 0x676b9
cmpl $0x1, 0x20(%r12)
leaq 0x108e9(%rip), %rax     # 0x77dcb
leaq 0x108e8(%rip), %r15     # 0x77dd1
cmoveq %rax, %r15
cmpq $0x0, 0x38(%rsp)
movq 0xb0(%rsp), %rbx
jne 0x6752d
leaq 0x15eb2(%rip), %rsi     # 0x7d3b6
leaq 0x90(%rsp), %rdi
movq 0x58(%rsp), %rdx
xorl %eax, %eax
callq 0x8c78
testl %eax, %eax
js 0x676e2
movq 0xa0(%rsp), %rax
movq %rax, 0x38(%rsp)
testq %rbx, %rbx
jne 0x6755a
leaq 0x1ba1d(%rip), %rsi     # 0x82f56
leaq 0x70(%rsp), %rdi
movq 0x58(%rsp), %rdx
xorl %eax, %eax
callq 0x8c78
testl %eax, %eax
js 0x676e2
movq 0x80(%rsp), %rbx
testb $0x40, 0x3(%r14)
je 0x67576
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xc5e0
testl %eax, %eax
js 0x677e3
movq %r14, %rdi
callq 0xbc96
testl %eax, %eax
js 0x6772e
leaq 0xf88d(%rip), %rsi      # 0x76e1a
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe19b
testq %rax, %rax
je 0x677b8
movq %rax, %r14
leaq 0xc0(%rsp), %r13
xorl %ebp, %ebp
movslq 0x8(%r12), %rax
cmpq %rax, %rbp
jge 0x6784b
movq 0x10(%r12), %rax
movq %r12, %rbx
movq 0x18(%r12), %r12
movq (%rax,%rbp,8), %rsi
movq %r12, %rdi
callq 0x684a5
cmpl (%r12), %eax
jae 0x67998
movq 0x20(%r12), %rdx
movl %eax, %eax
imulq $0x28, %rax, %rsi
movl 0x4(%rdx,%rsi), %eax
movl 0x8(%rdx,%rsi), %r9d
movq 0x10(%rdx,%rsi), %rcx
movq 0x18(%rdx,%rsi), %r8
cmpl $0x1, 0x20(%rbx)
movq %rbx, %r12
jne 0x6761c
movl %eax, (%rsp)
movq %r13, %rdi
pushq $0x60
popq %rsi
leaq 0x1bd11(%rip), %rdx     # 0x8332b
jmp 0x67638
addq %rsi, %rdx
movq 0x20(%rdx), %rdx
movq %rdx, 0x8(%rsp)
movl %eax, (%rsp)
movq %r13, %rdi
pushq $0x60
popq %rsi
leaq 0x1bd03(%rip), %rdx     # 0x8333b
xorl %eax, %eax
callq 0x4800
movq 0x10(%r12), %rax
movq (%rax,%rbp,8), %rdi
movq %r14, %rsi
callq 0x69079
testl %eax, %eax
jne 0x6766a
movq %r13, %rdi
movq %r14, %rsi
callq 0x69079
incq %rbp
testl %eax, %eax
je 0x675b2
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x1b851(%rip), %rsi     # 0x82ece
leaq 0x1b92f(%rip), %rdx     # 0x82fb3
jmp 0x67875
leaq 0x1b967(%rip), %rsi     # 0x82ff7
leaq 0x1bbe1(%rip), %rdx     # 0x83278
pushq $0x1
popq %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x110c6
movq 0xd0(%rsp), %rdi
callq 0x45c0
movq %r12, %rdi
callq 0x66ebc
cmpl $0xc0000000, (%r14)     # imm = 0xC0000000
jb 0x676df
leaq 0x1b805(%rip), %rsi     # 0x82ece
leaq 0x1b84c(%rip), %rdx     # 0x82f1c
xorl %r12d, %r12d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x676e2
xorl %r12d, %r12d
callq 0x4050
movq %rax, %r15
movl (%rax), %ebx
movq 0xa0(%rsp), %rdi
callq 0x45c0
movq 0x80(%rsp), %rdi
callq 0x45c0
movq %r14, %rdi
callq 0xbc96
movq %r12, %rdi
callq 0x66ebc
movl %ebx, (%r15)
pushq $-0x1
popq %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x1b78d(%rip), %rsi     # 0x82ece
leaq 0x1b832(%rip), %rdx     # 0x82f7a
xorl %r14d, %r14d
pushq $0x1
popq %rdi
movq 0x58(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x110c6
jmp 0x676e2
leaq 0x1b891(%rip), %rsi     # 0x82ff7
leaq 0x1b9f9(%rip), %rdx     # 0x83166
pushq $0x1
popq %rdi
movl %r15d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x110c6
jmp 0x676a4
movq 0xd0(%rsp), %rcx
leaq 0x1b866(%rip), %rsi     # 0x82ff7
leaq 0x1b92f(%rip), %rdx     # 0x830c7
jmp 0x678d3
movq 0xd0(%rsp), %rcx
leaq 0x1b84b(%rip), %rsi     # 0x82ff7
leaq 0x1b943(%rip), %rdx     # 0x830f6
jmp 0x678d3
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x1b703(%rip), %rsi     # 0x82ece
leaq 0x1b7c1(%rip), %rdx     # 0x82f93
xorl %r14d, %r14d
pushq $0x1
popq %rdi
movq %r15, %rcx
movq %rbx, %r8
jmp 0x67883
leaq 0x1b6e4(%rip), %rsi     # 0x82ece
leaq 0x1b76c(%rip), %rdx     # 0x82f5d
pushq $0x1
popq %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x110c6
jmp 0x676e2
movq 0xd0(%rsp), %rcx
leaq 0x1b7e5(%rip), %rsi     # 0x82ff7
leaq 0x1b91b(%rip), %rdx     # 0x83134
pushq $0x1
popq %rdi
movl %r13d, %r8d
xorl %eax, %eax
callq 0x110c6
movq 0x28(%rsp), %r12
jmp 0x676a4
movq 0xd0(%rsp), %rcx
leaq 0x1b7b8(%rip), %rsi     # 0x82ff7
leaq 0x1b951(%rip), %rdx     # 0x83197
jmp 0x678d3
movq %r14, %rdi
callq 0xd8ee
testl %eax, %eax
je 0x6791e
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x1b660(%rip), %rsi     # 0x82ece
leaq 0x1b75f(%rip), %rdx     # 0x82fd4
xorl %r14d, %r14d
pushq $0x1
popq %rdi
movq %r15, %rcx
movq 0x38(%rsp), %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x110c6
jmp 0x676e2
leaq 0xbc(%rsp), %rbx
movb $0x22, (%rbx)
movb %r15b, 0x1(%rbx)
movw $0x22, 0x2(%rbx)
callq 0x4510
movq (%rax), %rax
movl %r15d, %ecx
movzwl (%rax,%rcx,2), %eax
btl $0xe, %eax
leaq 0x12222(%rip), %rcx     # 0x79ae3
cmovbq %rbx, %rcx
leaq 0x1b72b(%rip), %rsi     # 0x82ff7
leaq 0x1b7cd(%rip), %rdx     # 0x830a0
pushq $0x1
popq %rdi
movl %r13d, %r8d
xorl %eax, %eax
callq 0x110c6
jmp 0x676a4
leaq 0x1b70b(%rip), %rsi     # 0x82ff7
leaq 0x1b713(%rip), %rdx     # 0x83006
jmp 0x67697
leaq 0x1b6f8(%rip), %rsi     # 0x82ff7
leaq 0x1b758(%rip), %rdx     # 0x8305e
jmp 0x67697
leaq 0x1b6e5(%rip), %rsi     # 0x82ff7
leaq 0x1b719(%rip), %rdx     # 0x83032
jmp 0x67697
movq 0xa0(%rsp), %rdi
callq 0x45c0
movq 0x80(%rsp), %rdi
callq 0x45c0
movq %r12, %rdi
callq 0x66ebc
xorl %eax, %eax
jmp 0x6771c
movq 0xd0(%rsp), %rcx
leaq 0x1b6a1(%rip), %rsi     # 0x82ff7
leaq 0x1b883(%rip), %rdx     # 0x831e0
jmp 0x67819
movq 0xd0(%rsp), %rcx
leaq 0x1b686(%rip), %rsi     # 0x82ff7
leaq 0x1b898(%rip), %rdx     # 0x83210
jmp 0x678d3
movq 0xd0(%rsp), %rcx
leaq 0x1b66b(%rip), %rsi     # 0x82ff7
leaq 0x1b8b4(%rip), %rdx     # 0x83247
jmp 0x678d3
leaq 0x1b947(%rip), %rdi     # 0x832e6
leaq 0x1b956(%rip), %rsi     # 0x832fc
leaq 0x1b957(%rip), %rcx     # 0x83304
movl $0x168, %edx            # imm = 0x168
callq 0x42f0