// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rdi, %r15
leaq 0x20(%rsp), %rsi
movl $0x12, %edx
callq 0xf24d
testq %rax, %rax
js 0xa854
movq %rax, %r13
movl $0x1, %edi
movl $0x70, %esi
callq 0x4300
testq %rax, %rax
je 0xa854
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %eax
andl $0xfffdffff, %eax       # imm = 0xFFFDFFFF
movl %eax, (%rbx)
movl $0x20000, %edi          # imm = 0x20000
callq 0x4680
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0xa84c
movq %rax, %r12
addq $0x10000, %rax          # imm = 0x10000
movq %rax, 0x30(%rbx)
cmpq $0x12, %r13
setne %al
cmpb $0x1f, 0x20(%rsp)
setne %cl
orb %al, %cl
cmpb $-0x75, 0x21(%rsp)
setne %al
orb %cl, %al
movl %eax, %ecx
xorb $0x1, %cl
movzbl %cl, %ecx
shll $0x1e, %ecx
andl $0xbffdffff, %ebp       # imm = 0xBFFDFFFF
orl %ecx, %ebp
movl %ebp, (%rbx)
testb %al, %al
je 0xa668
andl $0x7ffdffff, %ebp       # imm = 0x7FFDFFFF
movl %ebp, (%rbx)
movl $0x10, %edi
callq 0x4680
movq %rax, 0x38(%rbx)
testq %rax, %rax
je 0xa7fc
movq %rax, %r14
movl $0x1, %edi
movl $0x28, %esi
callq 0x4300
movq %rax, (%r14)
testq %rax, %rax
je 0xa83c
movl $0x0, 0x8(%r14)
jmp 0xa856
xorl %eax, %eax
cmpl $0x24342, 0x2c(%rsp)    # imm = 0x24342
setne %al
shll $0x1f, %eax
testb $0x4, 0x23(%rsp)
movl $0x80000000, %ecx       # imm = 0x80000000
cmovnel %eax, %ecx
andl $0x7ffdffff, %ebp       # imm = 0x7FFDFFFF
orl %ecx, %ebp
movl %ebp, (%rbx)
testb $0x4, 0x23(%rsp)
je 0xa626
cmpl $0x465a4152, 0x2c(%rsp) # imm = 0x465A4152
jne 0xa626
leaq 0x8d845(%rip), %rsi     # 0x97eec
leaq 0x8d84d(%rip), %rdx     # 0x97efb
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
testq %r14, %r14
je 0xa6d2
leaq 0x907fe(%rip), %rsi     # 0x9aec4
movq %r14, %rdi
callq 0x46c0
testl %eax, %eax
jne 0xa6d9
leaq 0x8d847(%rip), %r14     # 0x97f20
movq %r15, %rdi
movq $-0x10, %rsi
movl $0x2, %edx
callq 0xf583
movq %rax, 0x40(%rsp)
testq %rax, %rax
js 0xa801
movq 0x8(%r15), %rbp
movq 0x10(%r15), %r12
subq %rbp, %r12
cmpq $0x8, %r12
movl $0x8, %r13d
cmovbq %r12, %r13
leaq 0x18(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x43c0
addq %r13, %rbp
movq %rbp, 0x8(%r15)
cmpq $0x7, %r12
ja 0xa750
testb $0x2, 0x30(%r15)
je 0xa750
leaq 0x18(%rsp), %rsi
movl $0x8, %edx
movq %r15, %rdi
movq %r13, %rcx
callq 0xf2cd
movq %rax, %r13
cmpq $0x8, %r13
jne 0xa801
movq 0x8(%r15), %rbp
movq 0x10(%r15), %r12
subq %rbp, %r12
cmpq $0x8, %r12
movl $0x8, %r13d
cmovbq %r12, %r13
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x43c0
addq %r13, %rbp
movq %rbp, 0x8(%r15)
cmpq $0x7, %r12
ja 0xa7af
testb $0x2, 0x30(%r15)
je 0xa7af
leaq 0x10(%rsp), %rsi
movl $0x8, %edx
movq %r15, %rdi
movq %r13, %rcx
callq 0xf2cd
movq %rax, %r13
cmpq $0x8, %r13
jne 0xa801
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 0xa801
movq %rax, (%rsp)
leaq 0x8d744(%rip), %rsi     # 0x97f25
leaq 0x8d747(%rip), %rdx     # 0x97f2f
movl $0x1, %edi
movq %r14, %r8
movq %r14, %r9
xorl %eax, %eax
callq 0x14378
jmp 0xa81e
movq %r12, %rdi
jmp 0xa847
leaq 0x8d71d(%rip), %rsi     # 0x97f25
leaq 0x8d84f(%rip), %rdx     # 0x9805e
movl $0x1, %edi
movq %r14, %rcx
xorl %eax, %eax
callq 0x14378
movq 0x28(%rbx), %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x45c0
callq 0x4050
movl $0x8, (%rax)
jmp 0xa854
movq %r12, %rdi
callq 0x45c0
movq %r14, %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