// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rsi, %r15
movq %rdi, %r12
leaq 0x20(%rsp), %rsi
pushq $0x12
popq %rdx
callq 0xd4e0
testq %rax, %rax
js 0x9853
movq %rax, %r13
pushq $0x1
popq %rdi
pushq $0x70
popq %rsi
callq 0x4300
testq %rax, %rax
je 0x9853
movq %rax, %rbx
movl $0x20000, %edi          # imm = 0x20000
callq 0x4680
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x984b
movq %rax, %r14
addq $0x10000, %rax          # imm = 0x10000
movq %rax, 0x30(%rbx)
cmpq $0x12, %r13
jne 0x97cd
cmpb $0x1f, 0x20(%rsp)
jne 0x97cd
cmpb $-0x75, 0x21(%rsp)
jne 0x97cd
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 0x97d0
leaq 0x6d7c6(%rip), %rsi     # 0x76edc
leaq 0x6d7ce(%rip), %rdx     # 0x76eeb
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
testq %r15, %r15
je 0x9739
cmpb $0x2d, (%r15)
jne 0x9740
cmpb $0x0, 0x1(%r15)
jne 0x9740
leaq 0x6d7d0(%rip), %r15     # 0x76f10
pushq $-0x10
popq %rsi
pushq $0x2
popq %rdx
movq %r12, %rdi
callq 0xd7cb
testq %rax, %rax
js 0x9803
movq %rax, %r13
leaq 0x18(%rsp), %rsi
pushq $0x8
popq %rdx
movq %r12, %rdi
callq 0xa82f
cmpq $0x8, %rax
jne 0x9803
leaq 0x10(%rsp), %rsi
pushq $0x8
popq %rdx
movq %r12, %rdi
callq 0xa82f
cmpq $0x8, %rax
jne 0x9803
movq 0x18(%rsp), %rax
bswapq %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rcx
bswapq %rcx
movq %rcx, 0x10(%rsp)
cmpq %r13, %rcx
jae 0x9803
movq %rax, (%rsp)
leaq 0x6d761(%rip), %rsi     # 0x76f15
leaq 0x6d764(%rip), %rdx     # 0x76f1f
pushq $0x1
popq %rdi
movq %r15, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x110c6
jmp 0x981e
andl $0x0, (%rbx)
pushq $0x10
popq %rdi
callq 0x4680
movq %rax, 0x38(%rbx)
testq %rax, %rax
je 0x97fe
movq %rax, %r15
pushq $0x1
popq %rdi
pushq $0x28
popq %rsi
callq 0x4300
movq %rax, (%r15)
testq %rax, %rax
je 0x983b
andl $0x0, 0x8(%r15)
jmp 0x9855
movq %r14, %rdi
jmp 0x9846
leaq 0x6d70b(%rip), %rsi     # 0x76f15
leaq 0x6d83d(%rip), %rdx     # 0x7704e
pushq $0x1
popq %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x110c6
movq %r14, %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x45c0
callq 0x4050
movl $0x8, (%rax)
jmp 0x9853
movq %r14, %rdi
callq 0x45c0
movq %r15, %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq