// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/bgzf.c
// Function: bgzf_write_init
static BGZF *bgzf_write_init(const char *mode)
{
    BGZF *fp;
    fp = (BGZF*)calloc(1, sizeof(BGZF));
    if (fp == NULL) goto mem_fail;
    fp->is_write = 1;
    int compress_level = mode2level(mode);
    if ( compress_level==-2 )
    {
        fp->is_compressed = 0;
        return fp;
    }
    fp->is_compressed = 1;

    fp->uncompressed_block = malloc(2 * BGZF_MAX_BLOCK_SIZE);
    if (fp->uncompressed_block == NULL) goto mem_fail;
    fp->compressed_block = (char *)fp->uncompressed_block + BGZF_MAX_BLOCK_SIZE;

    fp->compress_level = compress_level < 0? Z_DEFAULT_COMPRESSION : compress_level; // Z_DEFAULT_COMPRESSION==-1
    if (fp->compress_level > 9) fp->compress_level = Z_DEFAULT_COMPRESSION;
    if ( strchr(mode,'g') )
    {
        // gzip output
        fp->is_gzip = 1;
        fp->gz_stream = (z_stream*)calloc(1,sizeof(z_stream));
        if (fp->gz_stream == NULL) goto mem_fail;
        fp->gz_stream->zalloc = NULL;
        fp->gz_stream->zfree  = NULL;
        fp->gz_stream->msg    = NULL;

        int ret = deflateInit2(fp->gz_stream, fp->compress_level, Z_DEFLATED, 15|16, 8, Z_DEFAULT_STRATEGY);
        if (ret!=Z_OK) {
            hts_log_error("Call to deflateInit2 failed: %s", bgzf_zerr(ret, fp->gz_stream));
            goto fail;
        }
    }
    return fp;

mem_fail:
    hts_log_error("%s", strerror(errno));

fail:
    if (fp != NULL) {
        free(fp->uncompressed_block);
        free(fp->gz_stream);
        free(fp);
    }
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl $0x1, %edi
movl $0x70, %esi
callq 0x42f0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xc4ab
jmp 0xc69d
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $0xfffdffff, %ecx       # imm = 0xFFFDFFFF
orl $0x20000, %ecx          # imm = 0x20000
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
callq 0x12010
movl %eax, -0x1c(%rbp)
cmpl $-0x2, -0x1c(%rbp)
jne 0xc4ef
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc6f8
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, (%rax)
movl $0x20000, %edi          # imm = 0x20000
callq 0x4650
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0xc528
jmp 0xc69d
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x10000, %rcx          # imm = 0x10000
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
cmpl $0x0, -0x1c(%rbp)
jge 0xc54f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x24(%rbp)
jmp 0xc555
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %edx
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $0x1ff, %edx            # imm = 0x1FF
shll $0x14, %edx
andl $0xe00fffff, %ecx       # imm = 0xE00FFFFF
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x3, %eax
sarl $0x17, %eax
cmpl $0x9, %eax
jle 0xc596
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $0xe00fffff, %ecx       # imm = 0xE00FFFFF
orl $0x1ff00000, %ecx       # imm = 0x1FF00000
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
movl $0x67, %esi
callq 0x4170
cmpq $0x0, %rax
je 0xc693
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
movl $0x1, %edi
movl $0x70, %esi
callq 0x42f0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0xc5ec
jmp 0xc69d
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq $0x0, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq $0x0, 0x48(%rax)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq $0x0, 0x30(%rax)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
shll $0x3, %esi
sarl $0x17, %esi
movl $0x8, %r8d
movl $0x1f, %ecx
xorl %r9d, %r9d
leaq 0xe2540(%rip), %rax     # 0xeeb85
movl %r8d, %edx
movq %rax, (%rsp)
movl $0x70, 0x8(%rsp)
callq 0x4080
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0xc691
movl -0x20(%rbp), %edi
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0xcd40
movq %rax, %rcx
movl $0x1, %edi
leaq 0xe2c8d(%rip), %rsi     # 0xef30e
leaq 0xe2512(%rip), %rdx     # 0xeeb9a
movb $0x0, %al
callq 0x1b030
jmp 0xc6c6
jmp 0xc693
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc6f8
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq %rax, %rcx
movl $0x1, %edi
leaq 0xe2c56(%rip), %rsi     # 0xef30e
leaq 0xe6335(%rip), %rdx     # 0xf29f4
movb $0x0, %al
callq 0x1b030
cmpq $0x0, -0x18(%rbp)
je 0xc6f0
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x45a0
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x45a0
movq -0x18(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)