// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %r15
pushq $0x1
popq %rdi
pushq $0x70
popq %rsi
callq 0x4300
testq %rax, %rax
je 0x99a1
movq %rax, %rbx
movq %r15, %rax
movzbl (%rax), %r14d
testl %r14d, %r14d
je 0x98a0
leal -0x30(%r14), %ecx
incq %rax
cmpb $0x9, %cl
ja 0x988b
xorl %r12d, %r12d
cmpl $0x1, %r14d
sbbl %r12d, %r12d
pushq $0x75
popq %rsi
movq %r15, %rdi
callq 0x4190
testq %rax, %rax
jne 0x99cc
addl $-0x30, %r14d
orl %r14d, %r12d
cmpl $-0x2, %r12d
je 0x99cc
movl $0x40020000, (%rbx)     # imm = 0x40020000
movl $0x20000, %edi          # imm = 0x20000
callq 0x4680
movq %rax, %r14
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x99d4
leaq 0x10000(%r14), %rax
movq %rax, 0x30(%rbx)
testl %r12d, %r12d
pushq $-0x1
popq %rbp
cmovnsl %r12d, %ebp
movl %ebp, %r12d
shll $0x14, %r12d
andl $0x1ff00000, %r12d      # imm = 0x1FF00000
leal 0x40020000(%r12), %eax
movl %eax, (%rbx)
pushq $0x67
popq %rsi
movq %r15, %rdi
callq 0x4190
testq %rax, %rax
je 0x9a18
orl $0xc0020000, %r12d      # imm = 0xC0020000
movl %r12d, (%rbx)
pushq $0x1
popq %rdi
pushq $0x70
popq %rsi
callq 0x4300
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x99d4
movq %rax, %r15
shll $0x17, %ebp
sarl $0x17, %ebp
leaq 0x6d00e(%rip), %rax     # 0x76970
pushq $0x1f
popq %rcx
pushq $0x8
popq %rdx
movq %r15, %rdi
movl %ebp, %esi
movl %edx, %r8d
xorl %r9d, %r9d
pushq $0x70
pushq %rax
callq 0x4080
addq $0x10, %rsp
testl %eax, %eax
je 0x9a18
movl %eax, %edi
movq %r15, %rsi
callq 0x9cf6
leaq 0x6d75c(%rip), %rsi     # 0x770f4
leaq 0x6cfe6(%rip), %rdx     # 0x76985
jmp 0x99f1
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x6d740(%rip), %rsi     # 0x770f4
leaq 0x70a6e(%rip), %rdx     # 0x7a429
xorl %ebx, %ebx
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x110c6
jmp 0x9a18
movl $0x20000, (%rbx)        # imm = 0x20000
jmp 0x9a18
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x6d70d(%rip), %rsi     # 0x770f4
leaq 0x70a3b(%rip), %rdx     # 0x7a429
xorl %r15d, %r15d
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x110c6
movq %r14, %rdi
callq 0x45c0
movq %r15, %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq