// File: /workspace/github_c_makefile_star2_O0/zhou-lab[P]tbmate/htslib/bgzf.c
// Function: bgzf_compress
int bgzf_compress(void *_dst, size_t *dlen, const void *src, size_t slen, int level)
{
    uint32_t crc;
    z_stream zs;
    uint8_t *dst = (uint8_t*)_dst;

    // compress the body
    zs.zalloc = NULL; zs.zfree = NULL;
    zs.msg = NULL;
    zs.next_in  = (Bytef*)src;
    zs.avail_in = slen;
    zs.next_out = dst + BLOCK_HEADER_LENGTH;
    zs.avail_out = *dlen - BLOCK_HEADER_LENGTH - BLOCK_FOOTER_LENGTH;
    int ret = deflateInit2(&zs, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); // -15 to disable zlib header/footer
    if (ret!=Z_OK) {
        if (hts_verbose >= 1) {
            fprintf(stderr, "[E::%s] deflateInit2 failed: %s\n",
                    __func__, bgzf_zerr(ret, &zs));
        }
        return -1;
    }
    if ((ret = deflate(&zs, Z_FINISH)) != Z_STREAM_END) {
        if (hts_verbose >= 1) {
            fprintf(stderr, "[E::%s] deflate failed: %s\n",
                    __func__, bgzf_zerr(ret, ret == Z_DATA_ERROR ? &zs : NULL));
        }
        return -1;
    }
    if ((ret = deflateEnd(&zs)) != Z_OK) {
        if (hts_verbose >= 1) {
            fprintf(stderr, "[E::%s] deflateEnd failed: %s\n",
                    __func__, bgzf_zerr(ret, NULL));
        }
        return -1;
    }
    *dlen = zs.total_out + BLOCK_HEADER_LENGTH + BLOCK_FOOTER_LENGTH;
    // write the header
    memcpy(dst, g_magic, BLOCK_HEADER_LENGTH); // the last two bytes are a place holder for the length of the block
    packInt16(&dst[16], *dlen - 1); // write the compressed length; -1 to fit 2 bytes
    // write the footer
    crc = crc32(crc32(0L, NULL, 0L), (Bytef*)src, slen);
    packInt32((uint8_t*)&dst[*dlen - 8], crc);
    packInt32((uint8_t*)&dst[*dlen - 4], slen);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rax
movl %eax, -0x98(%rbp)
movq -0xa8(%rbp), %rax
addq $0x12, %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
subq $0x12, %rax
subq $0x8, %rax
movl %eax, -0x80(%rbp)
movl -0x2c(%rbp), %esi
leaq -0xa0(%rbp), %rdi
movl $0x8, %r8d
movl $0xfffffff1, %ecx       # imm = 0xFFFFFFF1
xorl %r9d, %r9d
leaq 0x3cb8c(%rip), %rax     # 0x76a56
movl %r8d, %edx
movq %rax, (%rsp)
movl $0x70, 0x8(%rsp)
callq 0x3690
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
je 0x39f47
leaq 0x4b59c(%rip), %rax     # 0x85490
cmpl $0x1, (%rax)
jl 0x39f3b
movq 0x4b0e8(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
movl -0xac(%rbp), %edi
leaq -0xa0(%rbp), %rsi
callq 0x3a130
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
leaq 0x3e277(%rip), %rsi     # 0x781a4
leaq 0x3e291(%rip), %rdx     # 0x781c5
movb $0x0, %al
callq 0x37f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3a11e
leaq -0xa0(%rbp), %rdi
movl $0x4, %esi
callq 0x3200
movl %eax, -0xac(%rbp)
cmpl $0x1, %eax
je 0x39ff1
leaq 0x4b522(%rip), %rax     # 0x85490
cmpl $0x1, (%rax)
jl 0x39fe5
movq 0x4b06e(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xbc(%rbp)
cmpl $-0x3, -0xac(%rbp)
jne 0x39fa9
leaq -0xa0(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x39fb4
xorl %eax, %eax
movq %rax, -0xd0(%rbp)
jmp 0x39fb4
movl -0xbc(%rbp), %edi
movq -0xd0(%rbp), %rsi
callq 0x3a130
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
leaq 0x3e1fc(%rip), %rsi     # 0x781d3
leaq 0x3e1e7(%rip), %rdx     # 0x781c5
movb $0x0, %al
callq 0x37f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3a11e
leaq -0xa0(%rbp), %rdi
callq 0x33d0
movl %eax, -0xac(%rbp)
cmpl $0x0, %eax
je 0x3a05f
leaq 0x4b481(%rip), %rax     # 0x85490
cmpl $0x1, (%rax)
jl 0x3a053
movq 0x4afcd(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
movl -0xac(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x3a130
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
leaq 0x3e1aa(%rip), %rsi     # 0x781ef
leaq 0x3e179(%rip), %rdx     # 0x781c5
movb $0x0, %al
callq 0x37f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3a11e
movq -0x78(%rbp), %rcx
addq $0x12, %rcx
addq $0x8, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0xa8(%rbp), %rax
movq 0x3e020(%rip), %rcx     # 0x780a0
movq %rcx, (%rax)
movq 0x3e01e(%rip), %rcx     # 0x780a8
movq %rcx, 0x8(%rax)
movw 0x3e01b(%rip), %cx      # 0x780b0
movw %cx, 0x10(%rax)
movq -0xa8(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
subq $0x1, %rax
movzwl %ax, %esi
callq 0x3a210
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
movq %rsi, %rdi
callq 0x3390
movq %rax, %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movl %eax, %edx
callq 0x3390
movl %eax, -0x30(%rbp)
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
subq $0x8, %rax
addq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0x3a240
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
subq $0x4, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rax
movl %eax, %esi
callq 0x3a240
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopw (%rax,%rax)