// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_io.c
// Function: refs_load_fai
static refs_t *refs_load_fai(refs_t *r_orig, const char *fn, int is_err) {
    hFILE *fp = NULL;
    char fai_fn[PATH_MAX];
    char line[8192];
    refs_t *r = r_orig;
    size_t fn_l = strlen(fn);
    int id = 0, id_alloc = 0;

    RP("refs_load_fai %s\n", fn);

    if (!r)
        if (!(r = refs_create()))
            goto err;

    if (r->fp)
        if (bgzf_close(r->fp) != 0)
            goto err;
    r->fp = NULL;

    /* Look for a FASTA##idx##FAI format */
    char *fn_delim = strstr(fn, HTS_IDX_DELIM);
    if (fn_delim) {
        if (!(r->fn = string_ndup(r->pool, fn, fn_delim - fn)))
            goto err;
        fn_delim += strlen(HTS_IDX_DELIM);
        snprintf(fai_fn, PATH_MAX, "%s", fn_delim);
    } else {
        /* An index file was provided, instead of the actual reference file */
        if (fn_l > 4 && strcmp(&fn[fn_l-4], ".fai") == 0) {
            if (!r->fn) {
                if (!(r->fn = string_ndup(r->pool, fn, fn_l-4)))
                    goto err;
            }
            snprintf(fai_fn, PATH_MAX, "%s", fn);
        } else {
        /* Only the reference file provided. Get the index file name from it */
            if (!(r->fn = string_dup(r->pool, fn)))
                goto err;
            snprintf(fai_fn, PATH_MAX, "%.*s.fai", PATH_MAX-5, fn);
        }
    }

    if (!(r->fp = bgzf_open_ref(r->fn, "r", 0))) {
        hts_log_error("Failed to open reference file '%s'", r->fn);
        goto err;
    }

    if (!(fp = hopen(fai_fn, "r"))) {
        hts_log_error("Failed to open index file '%s'", fai_fn);
        if (is_err)
            perror(fai_fn);
        goto err;
    }
    while (hgets(line, 8192, fp) != NULL) {
        ref_entry *e = malloc(sizeof(*e));
        char *cp;
        int n;
        khint_t k;

        if (!e)
            return NULL;

        // id
        for (cp = line; *cp && !isspace_c(*cp); cp++)
            ;
        *cp++ = 0;
        e->name = string_dup(r->pool, line);

        // length
        while (*cp && isspace_c(*cp))
            cp++;
        e->length = strtoll(cp, &cp, 10);

        // offset
        while (*cp && isspace_c(*cp))
            cp++;
        e->offset = strtoll(cp, &cp, 10);

        // bases per line
        while (*cp && isspace_c(*cp))
            cp++;
        e->bases_per_line = strtol(cp, &cp, 10);

        // line length
        while (*cp && isspace_c(*cp))
            cp++;
        e->line_length = strtol(cp, &cp, 10);

        // filename
        e->fn = r->fn;

        e->count = 0;
        e->seq = NULL;
        e->mf = NULL;
        e->is_md5 = 0;
        e->validated_md5 = 0;

        k = kh_put(refs, r->h_meta, e->name, &n);
        if (-1 == n)  {
            free(e);
            return NULL;
        }

        if (n) {
            kh_val(r->h_meta, k) = e;
        } else {
            ref_entry *re = kh_val(r->h_meta, k);
            if (re && (re->count != 0 || re->length != 0)) {
                /* Keep old */
                free(e);
            } else {
                /* Replace old */
                if (re)
                    free(re);
                kh_val(r->h_meta, k) = e;
            }
        }

        if (id >= id_alloc) {
            ref_entry **new_refs;
            int x;

            id_alloc = id_alloc ?id_alloc*2 : 16;
            new_refs = realloc(r->ref_id, id_alloc * sizeof(*r->ref_id));
            if (!new_refs)
                goto err;
            r->ref_id = new_refs;

            for (x = id; x < id_alloc; x++)
                r->ref_id[x] = NULL;
        }
        r->ref_id[id] = e;
        r->nref = ++id;
    }

    if(hclose(fp) < 0)
        goto err;
    return r;

 err:
    if (fp)
        hclose_abruptly(fp);

    if (!r_orig)
        refs_free(r);

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3090, %rsp           # imm = 0x3090
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x3038(%rbp)
movq -0x18(%rbp), %rdi
callq 0x41b0
movq %rax, -0x3040(%rbp)
movl $0x0, -0x3044(%rbp)
movl $0x0, -0x3048(%rbp)
cmpq $0x0, -0x3038(%rbp)
jne 0x73c80
callq 0x74660
movq %rax, -0x3038(%rbp)
cmpq $0x0, %rax
jne 0x73c7e
jmp 0x74427
jmp 0x73c80
movq -0x3038(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x73caa
movq -0x3038(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x103d0
cmpl $0x0, %eax
je 0x73ca8
jmp 0x74427
jmp 0x73caa
movq -0x3038(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x18(%rbp), %rdi
leaq 0x7c454(%rip), %rsi     # 0xf0118
callq 0x40c0
movq %rax, -0x3050(%rbp)
cmpq $0x0, -0x3050(%rbp)
je 0x73d49
movq -0x3038(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x3050(%rbp), %rdx
movq -0x18(%rbp), %rax
subq %rax, %rdx
callq 0x82650
movq -0x3038(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x73d11
jmp 0x74427
movq -0x3050(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x3050(%rbp)
leaq -0x1030(%rbp), %rdi
movq -0x3050(%rbp), %rcx
movl $0x1000, %esi           # imm = 0x1000
leaq 0x7ecb7(%rip), %rdx     # 0xf29f4
movb $0x0, %al
callq 0x47e0
jmp 0x73e2c
cmpq $0x4, -0x3040(%rbp)
jbe 0x73dde
movq -0x18(%rbp), %rdi
movq -0x3040(%rbp), %rax
subq $0x4, %rax
addq %rax, %rdi
leaq 0x82020(%rip), %rsi     # 0xf5d90
callq 0x4690
cmpl $0x0, %eax
jne 0x73dde
movq -0x3038(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x73dbe
movq -0x3038(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x3040(%rbp), %rdx
subq $0x4, %rdx
callq 0x82650
movq -0x3038(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x73dbc
jmp 0x74427
jmp 0x73dbe
leaq -0x1030(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1000, %esi           # imm = 0x1000
leaq 0x7ec1f(%rip), %rdx     # 0xf29f4
movb $0x0, %al
callq 0x47e0
jmp 0x73e2a
movq -0x3038(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x82610
movq -0x3038(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x73e07
jmp 0x74427
leaq -0x1030(%rbp), %rdi
movq -0x18(%rbp), %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x8210f(%rip), %rdx     # 0xf5f2d
movl $0xffb, %ecx            # imm = 0xFFB
movb $0x0, %al
callq 0x47e0
jmp 0x73e2c
movq -0x3038(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x7ecb3(%rip), %rsi     # 0xf2af1
xorl %edx, %edx
callq 0x72550
movq -0x3038(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
jne 0x73e80
movq -0x3038(%rbp), %rax
movq 0x20(%rax), %rcx
movl $0x1, %edi
leaq 0x820c9(%rip), %rsi     # 0xf5f36
leaq 0x820d0(%rip), %rdx     # 0xf5f44
movb $0x0, %al
callq 0x1b030
jmp 0x74427
leaq -0x1030(%rbp), %rdi
leaq 0x7ec63(%rip), %rsi     # 0xf2af1
movb $0x0, %al
callq 0x158b0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x73ed7
leaq -0x1030(%rbp), %rcx
movl $0x1, %edi
leaq 0x82084(%rip), %rsi     # 0xf5f36
leaq 0x7cea9(%rip), %rdx     # 0xf0d62
movb $0x0, %al
callq 0x1b030
cmpl $0x0, -0x1c(%rbp)
je 0x73ed2
leaq -0x1030(%rbp), %rdi
callq 0x43c0
jmp 0x74427
jmp 0x73ed9
leaq -0x3030(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x2000, %esi           # imm = 0x2000
callq 0x14000
cmpq $0x0, %rax
je 0x7440a
movl $0x50, %edi
callq 0x4650
movq %rax, -0x3058(%rbp)
cmpq $0x0, -0x3058(%rbp)
jne 0x73f20
movq $0x0, -0x8(%rbp)
jmp 0x74452
leaq -0x3030(%rbp), %rax
movq %rax, -0x3060(%rbp)
movq -0x3060(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x307d(%rbp)
je 0x73f62
movq -0x3060(%rbp), %rax
movsbl (%rax), %edi
callq 0x7c5e0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x307d(%rbp)
movb -0x307d(%rbp), %al
testb $0x1, %al
jne 0x73f6e
jmp 0x73f84
jmp 0x73f70
movq -0x3060(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3060(%rbp)
jmp 0x73f2e
movq -0x3060(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x3060(%rbp)
movb $0x0, (%rax)
movq -0x3038(%rbp), %rax
movq (%rax), %rdi
leaq -0x3030(%rbp), %rsi
callq 0x82610
movq %rax, %rcx
movq -0x3058(%rbp), %rax
movq %rcx, (%rax)
movq -0x3060(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x307e(%rbp)
je 0x73ff1
movq -0x3060(%rbp), %rax
movsbl (%rax), %edi
callq 0x7c5e0
cmpl $0x0, %eax
setne %al
movb %al, -0x307e(%rbp)
movb -0x307e(%rbp), %al
testb $0x1, %al
jne 0x73ffd
jmp 0x74011
movq -0x3060(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3060(%rbp)
jmp 0x73fbf
movq -0x3060(%rbp), %rdi
leaq -0x3060(%rbp), %rsi
movl $0xa, %edx
callq 0x40a0
movq %rax, %rcx
movq -0x3058(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x3060(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x307f(%rbp)
je 0x74069
movq -0x3060(%rbp), %rax
movsbl (%rax), %edi
callq 0x7c5e0
cmpl $0x0, %eax
setne %al
movb %al, -0x307f(%rbp)
movb -0x307f(%rbp), %al
testb $0x1, %al
jne 0x74075
jmp 0x74089
movq -0x3060(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3060(%rbp)
jmp 0x74037
movq -0x3060(%rbp), %rdi
leaq -0x3060(%rbp), %rsi
movl $0xa, %edx
callq 0x40a0
movq %rax, %rcx
movq -0x3058(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x3060(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x3080(%rbp)
je 0x740e1
movq -0x3060(%rbp), %rax
movsbl (%rax), %edi
callq 0x7c5e0
cmpl $0x0, %eax
setne %al
movb %al, -0x3080(%rbp)
movb -0x3080(%rbp), %al
testb $0x1, %al
jne 0x740ed
jmp 0x74101
movq -0x3060(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3060(%rbp)
jmp 0x740af
movq -0x3060(%rbp), %rdi
leaq -0x3060(%rbp), %rsi
movl $0xa, %edx
callq 0x46a0
movl %eax, %ecx
movq -0x3058(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x3060(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x3081(%rbp)
je 0x74157
movq -0x3060(%rbp), %rax
movsbl (%rax), %edi
callq 0x7c5e0
cmpl $0x0, %eax
setne %al
movb %al, -0x3081(%rbp)
movb -0x3081(%rbp), %al
testb $0x1, %al
jne 0x74163
jmp 0x74177
movq -0x3060(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3060(%rbp)
jmp 0x74125
movq -0x3060(%rbp), %rdi
leaq -0x3060(%rbp), %rsi
movl $0xa, %edx
callq 0x46a0
movl %eax, %ecx
movq -0x3058(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x3038(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x3058(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x3058(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x3058(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x3058(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x3058(%rbp), %rax
movl $0x0, 0x48(%rax)
movq -0x3058(%rbp), %rax
movl $0x0, 0x4c(%rax)
movq -0x3038(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x3058(%rbp), %rax
movq (%rax), %rsi
leaq -0x3064(%rbp), %rdx
callq 0x7bd70
movl %eax, -0x3068(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x3064(%rbp), %eax
jne 0x74247
movq -0x3058(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x74452
cmpl $0x0, -0x3064(%rbp)
je 0x74275
movq -0x3058(%rbp), %rdx
movq -0x3038(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movl -0x3068(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x74301
movq -0x3038(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movl -0x3068(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x3070(%rbp)
cmpq $0x0, -0x3070(%rbp)
je 0x742c9
movq -0x3070(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x742bb
movq -0x3070(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x742c9
movq -0x3058(%rbp), %rdi
callq 0x45a0
jmp 0x742ff
cmpq $0x0, -0x3070(%rbp)
je 0x742df
movq -0x3070(%rbp), %rdi
callq 0x45a0
movq -0x3058(%rbp), %rdx
movq -0x3038(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movl -0x3068(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x74301
movl -0x3044(%rbp), %eax
cmpl -0x3048(%rbp), %eax
jl 0x743cf
cmpl $0x0, -0x3048(%rbp)
je 0x7432c
movl -0x3048(%rbp), %eax
shll %eax
movl %eax, -0x3088(%rbp)
jmp 0x74339
movl $0x10, %eax
movl %eax, -0x3088(%rbp)
jmp 0x74339
movl -0x3088(%rbp), %eax
movl %eax, -0x3048(%rbp)
movq -0x3038(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x3048(%rbp), %rsi
shlq $0x3, %rsi
callq 0x4820
movq %rax, -0x3078(%rbp)
cmpq $0x0, -0x3078(%rbp)
jne 0x74376
jmp 0x74427
movq -0x3078(%rbp), %rcx
movq -0x3038(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x3044(%rbp), %eax
movl %eax, -0x307c(%rbp)
movl -0x307c(%rbp), %eax
cmpl -0x3048(%rbp), %eax
jge 0x743cd
movq -0x3038(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x307c(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x307c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x307c(%rbp)
jmp 0x74394
jmp 0x743cf
movq -0x3058(%rbp), %rdx
movq -0x3038(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x3044(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x3044(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x3044(%rbp)
movq -0x3038(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0x73ed9
movq -0x28(%rbp), %rdi
callq 0x14920
cmpl $0x0, %eax
jge 0x7441a
jmp 0x74427
movq -0x3038(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x74452
cmpq $0x0, -0x28(%rbp)
je 0x74437
movq -0x28(%rbp), %rdi
callq 0x149d0
cmpq $0x0, -0x10(%rbp)
jne 0x7444a
movq -0x3038(%rbp), %rdi
callq 0x717d0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x3090, %rsp           # imm = 0x3090
popq %rbp
retq
nop