// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/bgzf.c
// Function: bgzf_read_init
static BGZF *bgzf_read_init(hFILE *hfpr, const char *filename)
{
    BGZF *fp;
    uint8_t magic[18];
    ssize_t n = hpeek(hfpr, magic, 18);
    if (n < 0) return NULL;

    fp = (BGZF*)calloc(1, sizeof(BGZF));
    if (fp == NULL) return NULL;

    fp->is_write = 0;
    fp->uncompressed_block = malloc(2 * BGZF_MAX_BLOCK_SIZE);
    if (fp->uncompressed_block == NULL) { free(fp); return NULL; }
    fp->compressed_block = (char *)fp->uncompressed_block + BGZF_MAX_BLOCK_SIZE;
    fp->is_compressed = (n==18 && magic[0]==0x1f && magic[1]==0x8b);
    fp->is_gzip = ( !fp->is_compressed || ((magic[3]&4) && memcmp(&magic[12], "BC\2\0",4)==0) ) ? 0 : 1;
    if (fp->is_compressed && (magic[3]&4) && memcmp(&magic[12], "RAZF", 4)==0) {
        hts_log_error("Cannot decompress legacy RAZF format");
        razf_info(hfpr, filename);
        free(fp->uncompressed_block);
        free(fp);
        errno = EFTYPE;
        return NULL;
    }
#ifdef BGZF_CACHE
    if (!(fp->cache = malloc(sizeof(*fp->cache)))) {
        free(fp->uncompressed_block);
        free(fp);
        return NULL;
    }
    if (!(fp->cache->h = kh_init(cache))) {
        free(fp->uncompressed_block);
        free(fp->cache);
        free(fp);
        return NULL;
    }
    fp->cache->last_pos = 0;
#endif
    return fp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %r12
leaq 0x20(%rsp), %rsi
movl $0x12, %edx
callq 0xf0a9
testq %rax, %rax
js 0xa8dc
movq %rax, %r13
movl $0x1, %edi
movl $0x70, %esi
callq 0x4300
testq %rax, %rax
je 0xa8dc
movq %rax, %rbx
movl $0x20000, %edi          # imm = 0x20000
callq 0x4680
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0xa8d4
movq %rax, %r14
addq $0x10000, %rax          # imm = 0x10000
movq %rax, 0x30(%rbx)
cmpq $0x12, %r13
jne 0xa848
cmpb $0x1f, 0x20(%rsp)
jne 0xa848
cmpb $-0x75, 0x21(%rsp)
jne 0xa848
movb 0x23(%rsp), %al
movl 0x2c(%rsp), %ecx
cmpl $0x24342, %ecx          # imm = 0x24342
movl $0x40000000, %edx       # imm = 0x40000000
movl $0xc0000000, %esi       # imm = 0xC0000000
cmovnel %esi, %edx
testb $0x4, %al
cmovel %esi, %edx
movl %edx, (%rbx)
shrb $0x2, %al
cmpl $0x465a4152, %ecx       # imm = 0x465A4152
sete %cl
testb %cl, %al
je 0xa84e
leaq 0x8a84f(%rip), %rsi     # 0x94f2c
leaq 0x8a857(%rip), %rdx     # 0x94f3b
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
testq %r15, %r15
je 0xa702
cmpb $0x2d, (%r15)
jne 0xa709
cmpb $0x0, 0x1(%r15)
jne 0xa709
leaq 0x8a857(%rip), %r15     # 0x94f60
movq %r12, %rdi
movq $-0x10, %rsi
movl $0x2, %edx
callq 0xf3b3
movq %rax, 0x40(%rsp)
testq %rax, %rax
js 0xa88a
movq %r15, 0x8(%rsp)
movq 0x8(%r12), %r13
movq 0x10(%r12), %rbp
subq %r13, %rbp
cmpq $0x8, %rbp
movl $0x8, %r15d
cmovbq %rbp, %r15
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x43c0
movq %r15, %rax
addq %r15, %r13
movq %r13, 0x8(%r12)
cmpq $0x7, %rbp
ja 0xa789
testb $0x2, 0x30(%r12)
je 0xa789
leaq 0x18(%rsp), %rsi
movl $0x8, %edx
movq %r12, %rdi
movq %rax, %rcx
callq 0xf129
movq 0x8(%rsp), %r15
cmpq $0x8, %rax
jne 0xa88a
movq 0x8(%r12), %r13
movq 0x10(%r12), %rax
subq %r13, %rax
movq %rax, 0x8(%rsp)
cmpq $0x8, %rax
movl $0x8, %ebp
cmovbq %rax, %rbp
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x43c0
addq %rbp, %r13
movq %r13, 0x8(%r12)
cmpq $0x7, 0x8(%rsp)
ja 0xa7f7
testb $0x2, 0x30(%r12)
je 0xa7f7
leaq 0x10(%rsp), %rsi
movl $0x8, %edx
movq %r12, %rdi
movq %rbp, %rcx
callq 0xf129
movq %rax, %rbp
cmpq $0x8, %rbp
jne 0xa88a
movq 0x18(%rsp), %rax
bswapq %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rcx
bswapq %rcx
movq %rcx, 0x10(%rsp)
cmpq 0x40(%rsp), %rcx
jae 0xa88a
movq %rax, (%rsp)
leaq 0x8a738(%rip), %rsi     # 0x94f65
leaq 0x8a73b(%rip), %rdx     # 0x94f6f
movl $0x1, %edi
movq %r15, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x13de5
jmp 0xa8a7
movl $0x0, (%rbx)
movl $0x10, %edi
callq 0x4680
movq %rax, 0x38(%rbx)
testq %rax, %rax
je 0xa885
movq %rax, %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x4300
movq %rax, (%r15)
testq %rax, %rax
je 0xa8c4
movl $0x0, 0x8(%r15)
jmp 0xa8de
movq %r14, %rdi
jmp 0xa8cf
leaq 0x8a6d4(%rip), %rsi     # 0x94f65
leaq 0x8a806(%rip), %rdx     # 0x9509e
movl $0x1, %edi
movq %r15, %rcx
xorl %eax, %eax
callq 0x13de5
movq %r14, %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x45c0
callq 0x4050
movl $0x8, (%rax)
jmp 0xa8dc
movq %r14, %rdi
callq 0x45c0
movq %r15, %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq