// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_io.c
// Function: cram_write_block
int cram_write_block(cram_fd *fd, cram_block *b) {
    char vardata[100];
    int vardata_o = 0;

    assert(b->method != RAW || (b->comp_size == b->uncomp_size));

    if (hputc(b->method,       fd->fp)  == EOF) return -1;
    if (hputc(b->content_type, fd->fp)  == EOF) return -1;
    vardata_o += fd->vv.varint_put32(vardata          , vardata+100, b->content_id);
    vardata_o += fd->vv.varint_put32(vardata+vardata_o, vardata+100, b->comp_size);
    vardata_o += fd->vv.varint_put32(vardata+vardata_o, vardata+100, b->uncomp_size);
    if (vardata_o != hwrite(fd->fp, vardata, vardata_o))
        return -1;

    if (b->data) {
        if (b->method == RAW) {
            if (b->uncomp_size != hwrite(fd->fp, b->data, b->uncomp_size))
                return -1;
        } else {
            if (b->comp_size != hwrite(fd->fp, b->data, b->comp_size))
                return -1;
        }
    } else {
        // Absent blocks should be size 0
        assert(b->method == RAW && b->uncomp_size == 0);
    }

    if (CRAM_MAJOR_VERS(fd->version) >= 3) {
        char dat[100], *cp = (char *)dat;
        uint32_t crc;

        *cp++ = b->method;
        *cp++ = b->content_type;
        cp += fd->vv.varint_put32(cp, dat+100, b->content_id);
        cp += fd->vv.varint_put32(cp, dat+100, b->comp_size);
        cp += fd->vv.varint_put32(cp, dat+100, b->uncomp_size);
        crc = crc32(0L, (uc *)dat, cp-dat);

        if (b->method == RAW) {
            b->crc32 = crc32(crc, b->data ? b->data : (uc*)"", b->uncomp_size);
        } else {
            b->crc32 = crc32(crc, b->data ? b->data : (uc*)"", b->comp_size);
        }

        if (-1 == int32_encode(fd, b->crc32))
            return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl (%rsi), %eax
testl %eax, %eax
jne 0x4f38a
movl 0x10(%r14), %ecx
cmpl 0x14(%r14), %ecx
jne 0x4f754
movq (%rbx), %rsi
movq 0x8(%rsi), %rcx
cmpq 0x18(%rsi), %rcx
jae 0x4f3a3
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rsi)
movb %al, (%rcx)
jmp 0x4f3aa
movl %eax, %edi
callq 0xf491
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x4f740
movl 0x8(%r14), %eax
movq (%rbx), %rsi
movq 0x8(%rsi), %rcx
cmpq 0x18(%rsi), %rcx
jae 0x4f3d5
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rsi)
movb %al, (%rcx)
jmp 0x4f3dc
movl %eax, %edi
callq 0xf491
cmpl $-0x1, %eax
je 0x4f740
leaq 0x74(%rsp), %r15
movl 0xc(%r14), %edx
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq *0x89c8(%rbx)
movslq %eax, %r12
leaq (%rsp,%r12), %rdi
addq $0x10, %rdi
movl 0x10(%r14), %edx
movq %r15, %rsi
callq *0x89c8(%rbx)
addl %eax, %r12d
movslq %r12d, %r12
leaq (%rsp,%r12), %rdi
addq $0x10, %rdi
movl 0x14(%r14), %edx
movq %r15, %rsi
callq *0x89c8(%rbx)
addl %eax, %r12d
movslq %r12d, %r15
movq (%rbx), %r12
testb $0x2, 0x30(%r12)
jne 0x4f46b
movq 0x18(%r12), %rsi
movq %rsi, %rax
subq 0x8(%r12), %rax
cmpq %r15, %rax
jae 0x4f46b
addq %r15, %rsi
subq (%r12), %rsi
movq %r12, %rdi
callq 0xefdd
movq 0x18(%r12), %rax
movq %rax, 0x10(%r12)
movq 0x8(%r12), %rdi
movq 0x18(%r12), %rbp
subq %rdi, %rbp
cmpq %r15, %rbp
ja 0x4f483
cmpq (%r12), %rdi
je 0x4f4b4
cmpq %r15, %rbp
movq %r15, %r13
cmovbq %rbp, %r13
leaq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0x43c0
addq %r13, 0x8(%r12)
cmpq %r15, %rbp
jae 0x4f4c9
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %r13, %rcx
jmp 0x4f4c1
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xf4c6
movq %rax, %r13
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq %r15, %r13
jne 0x4f740
movq 0x20(%r14), %rdx
movl (%r14), %ecx
testq %rdx, %rdx
je 0x4f587
movq (%rbx), %r12
movb 0x30(%r12), %al
testl %ecx, %ecx
je 0x4f5b5
movslq 0x10(%r14), %r15
testb $0x2, %al
jne 0x4f530
movq 0x18(%r12), %rsi
movq %rsi, %rax
subq 0x8(%r12), %rax
cmpq %r15, %rax
jae 0x4f530
addq %r15, %rsi
subq (%r12), %rsi
movq %r12, %rdi
movq %rdx, %r13
callq 0xefdd
movq %r13, %rdx
movq 0x18(%r12), %rax
movq %rax, 0x10(%r12)
movq 0x8(%r12), %rdi
movq 0x18(%r12), %rbp
subq %rdi, %rbp
cmpq %r15, %rbp
ja 0x4f54c
cmpq (%r12), %rdi
je 0x4f640
cmpq %r15, %rbp
movq %r15, %r13
cmovbq %rbp, %r13
movq %rdx, %rsi
movq %rdx, 0x8(%rsp)
movq %r13, %rdx
callq 0x43c0
addq %r13, 0x8(%r12)
cmpq %r15, %rbp
jae 0x4f653
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
movq %r13, %rcx
jmp 0x4f64b
testl %ecx, %ecx
jne 0x4f596
cmpl $0x0, 0x14(%r14)
je 0x4f682
leaq 0x4e6e2(%rip), %rdi     # 0x9dc7f
leaq 0x4e69e(%rip), %rsi     # 0x9dc42
leaq 0x4e6a6(%rip), %rcx     # 0x9dc51
movl $0x5fb, %edx            # imm = 0x5FB
callq 0x42f0
movslq 0x14(%r14), %r13
testb $0x2, %al
movq %r13, (%rsp)
jne 0x4f5f6
movq 0x18(%r12), %rsi
movq %rsi, %rax
subq 0x8(%r12), %rax
cmpq %r13, %rax
jae 0x4f5f6
addq %r13, %rsi
subq (%r12), %rsi
movq %r12, %rdi
movq %rdx, %r15
callq 0xefdd
movq (%rsp), %r13
movq %r15, %rdx
movq 0x18(%r12), %rax
movq %rax, 0x10(%r12)
movq 0x8(%r12), %rdi
movq 0x18(%r12), %r15
subq %rdi, %r15
cmpq %r13, %r15
ja 0x4f60e
cmpq (%r12), %rdi
je 0x4f662
cmpq %r13, %r15
cmovbq %r15, %r13
movq %rdx, %rsi
movq %rdx, 0x8(%rsp)
movq %r13, %rdx
callq 0x43c0
movq (%rsp), %rdx
addq %r13, 0x8(%r12)
cmpq %rdx, %r15
jae 0x4f679
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rcx
jmp 0x4f66d
movq %r12, %rdi
movq %rdx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xf4c6
movq %rax, %r13
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq %r15, %r13
je 0x4f682
jmp 0x4f740
movq %r12, %rdi
movq %rdx, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xf4c6
movq (%rsp), %rdx
movq %rax, %r13
cmpq %rdx, %r13
jne 0x4f740
cmpl $0x300, 0xc(%rbx)       # imm = 0x300
jl 0x4f73e
movb (%r14), %al
leaq 0x82(%rsp), %rdi
movb %al, -0x2(%rdi)
movb 0x8(%r14), %al
movb %al, -0x1(%rdi)
leaq 0xe4(%rsp), %r15
movl 0xc(%r14), %edx
movq %r15, %rsi
callq *0x89c8(%rbx)
cltq
leaq (%rsp,%rax), %r12
addq $0x82, %r12
movl 0x10(%r14), %edx
movq %r12, %rdi
movq %r15, %rsi
callq *0x89c8(%rbx)
movslq %eax, %r13
addq %r12, %r13
movl 0x14(%r14), %edx
movq %r13, %rdi
movq %r15, %rsi
callq *0x89c8(%rbx)
addl %eax, %r13d
leaq 0x80(%rsp), %rsi
subl %esi, %r13d
xorl %edi, %edi
movl %r13d, %edx
callq 0x4320
xorl %ecx, %ecx
cmpl $0x0, (%r14)
sete %cl
movl %eax, %edi
movq 0x20(%r14), %rax
testq %rax, %rax
leaq 0x495b0(%rip), %rsi     # 0x98ccd
cmovneq %rax, %rsi
movl 0x10(%r14,%rcx,4), %edx
callq 0x4320
movl %eax, 0x18(%r14)
movq %rbx, %rdi
movl %eax, %esi
callq 0x4f773
cmpl $-0x1, %eax
je 0x4f740
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e4b2(%rip), %rdi     # 0x9dc0d
leaq 0x4e4e0(%rip), %rsi     # 0x9dc42
leaq 0x4e4e8(%rip), %rcx     # 0x9dc51
movl $0x5e7, %edx            # imm = 0x5E7
callq 0x42f0