// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/faidx.c
// Function: fai_read
static faidx_t *fai_read(hFILE *fp, const char *fname, int format)
{
    faidx_t *fai;
    char *buf = NULL, *p;
    ssize_t l, lnum = 1;

    fai = (faidx_t*)calloc(1, sizeof(faidx_t));
    if (!fai) return NULL;

    fai->hash = kh_init(s);
    if (!fai->hash) goto fail;

    buf = (char*)calloc(0x10000, 1);
    if (!buf) goto fail;

    while ((l = hgetln(buf, 0x10000, fp)) > 0) {
        uint32_t line_len, line_blen, n;
        uint64_t len;
        uint64_t seq_offset;
        uint64_t qual_offset = 0;

        for (p = buf; *p && !isspace_c(*p); ++p);

        if (p - buf < l) {
            *p = 0; ++p;
        }

        if (format == FAI_FASTA) {
            n = sscanf(p, "%"SCNu64"%"SCNu64"%"SCNu32"%"SCNu32, &len, &seq_offset, &line_blen, &line_len);

            if (n != 4) {
                hts_log_error("Could not understand FASTA index %s line %zd", fname, lnum);
                goto fail;
            }
        } else {
            n = sscanf(p, "%"SCNu64"%"SCNu64"%"SCNu32"%"SCNu32"%"SCNu64, &len, &seq_offset, &line_blen, &line_len, &qual_offset);

            if (n != 5) {
                if (n == 4) {
                    hts_log_error("Possibly this is a FASTA index, try using faidx.  Problem in %s line %zd", fname, lnum);
                } else {
                    hts_log_error("Could not understand FASTQ index %s line %zd", fname, lnum);
                }

                goto fail;
            }
        }

        if (fai_insert_index(fai, buf, len, line_len, line_blen, seq_offset, qual_offset) != 0) {
            goto fail;
        }

        if (buf[l - 1] == '\n') ++lnum;
    }

    if (l < 0) {
        hts_log_error("Error while reading %s: %s", fname, strerror(errno));
        goto fail;
    }
    free(buf);
    return fai;

 fail:
    free(buf);
    fai_destroy(fai);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x1, -0x48(%rbp)
movl $0x1, %edi
movl $0x28, %esi
callq 0x42f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xd6dad
movq $0x0, -0x8(%rbp)
jmp 0xd7022
callq 0xd5f40
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xd6dcd
jmp 0xd7008
movl $0x10000, %edi          # imm = 0x10000
movl $0x1, %esi
callq 0x42f0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xd6dec
jmp 0xd7008
jmp 0xd6dee
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x10000, %esi          # imm = 0x10000
callq 0xd7030
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jle 0xd6fb7
movq $0x0, -0x70(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x71(%rbp)
je 0xd6e46
movq -0x38(%rbp), %rax
movsbl (%rax), %edi
callq 0xd7060
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0xd6e4f
jmp 0xd6e5f
jmp 0xd6e51
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xd6e1e
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
cmpq -0x40(%rbp), %rax
jge 0xd6e83
movq -0x38(%rbp), %rax
movb $0x0, (%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpl $0x1, -0x1c(%rbp)
jne 0xd6ee0
movq -0x38(%rbp), %rdi
leaq 0x20f37(%rip), %rsi     # 0xf7dcb
leaq -0x60(%rbp), %rdx
leaq -0x68(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0x4c(%rbp), %r9
movb $0x0, %al
callq 0x4490
movl %eax, -0x54(%rbp)
cmpl $0x4, -0x54(%rbp)
je 0xd6edb
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %r8
movl $0x1, %edi
leaq 0x20f0e(%rip), %rsi     # 0xf7dd6
leaq 0x20f10(%rip), %rdx     # 0xf7ddf
movb $0x0, %al
callq 0x1b030
jmp 0xd7008
jmp 0xd6f66
movq -0x38(%rbp), %rdi
leaq 0x20f21(%rip), %rsi     # 0xf7e0c
leaq -0x60(%rbp), %rdx
leaq -0x68(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0x4c(%rbp), %r9
leaq -0x70(%rbp), %rax
movq %rax, (%rsp)
movb $0x0, %al
callq 0x4490
movl %eax, -0x54(%rbp)
cmpl $0x5, -0x54(%rbp)
je 0xd6f64
cmpl $0x4, -0x54(%rbp)
jne 0xd6f3d
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %r8
movl $0x1, %edi
leaq 0x20ea9(%rip), %rsi     # 0xf7dd6
leaq 0x20ee6(%rip), %rdx     # 0xf7e1a
movb $0x0, %al
callq 0x1b030
jmp 0xd6f5f
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %r8
movl $0x1, %edi
leaq 0x20e85(%rip), %rsi     # 0xf7dd6
leaq 0x20f0b(%rip), %rdx     # 0xf7e63
movb $0x0, %al
callq 0x1b030
jmp 0xd7008
jmp 0xd6f66
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x60(%rbp), %rdx
movl -0x4c(%rbp), %ecx
movl -0x50(%rbp), %r8d
movq -0x68(%rbp), %r9
movq -0x70(%rbp), %rax
movq %rax, (%rsp)
callq 0xd5fd0
cmpl $0x0, %eax
je 0xd6f91
jmp 0xd7008
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0xd6fb2
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xd6dee
cmpq $0x0, -0x40(%rbp)
jge 0xd6ff5
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0x80(%rbp), %rcx
movq %rax, %r8
movl $0x1, %edi
leaq 0x20df1(%rip), %rsi     # 0xf7dd6
leaq 0x20ea4(%rip), %rdx     # 0xf7e90
movb $0x0, %al
callq 0x1b030
jmp 0xd7008
movq -0x30(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xd7022
movq -0x30(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rdi
callq 0xd38a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nop