// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_encode.c
// Function: cram_encode_slice_header
cram_block *cram_encode_slice_header(cram_fd *fd, cram_slice *s) {
    char *buf;
    char *cp;
    cram_block *b = cram_new_block(MAPPED_SLICE, 0);
    int j;

    if (!b)
        return NULL;

    cp = buf = malloc(22+16+5*(8+s->hdr->num_blocks));
    if (NULL == buf) {
        cram_free_block(b);
        return NULL;
    }

    cp += fd->vv.varint_put32s(cp, NULL, s->hdr->ref_seq_id);
    if (CRAM_MAJOR_VERS(fd->version) >= 4) {
        cp += fd->vv.varint_put64(cp, NULL, s->hdr->ref_seq_start);
        cp += fd->vv.varint_put64(cp, NULL, s->hdr->ref_seq_span);
    } else {
        if (s->hdr->ref_seq_start < 0 || s->hdr->ref_seq_start > INT_MAX) {
            hts_log_error("Reference position too large for CRAM 3");
            cram_free_block(b);
            free(buf);
            return NULL;
        }
        cp += fd->vv.varint_put32(cp, NULL, s->hdr->ref_seq_start);
        cp += fd->vv.varint_put32(cp, NULL, s->hdr->ref_seq_span);
    }
    cp += fd->vv.varint_put32(cp, NULL, s->hdr->num_records);
    if (CRAM_MAJOR_VERS(fd->version) == 2)
        cp += fd->vv.varint_put32(cp, NULL, s->hdr->record_counter);
    else if (CRAM_MAJOR_VERS(fd->version) >= 3)
        cp += fd->vv.varint_put64(cp, NULL, s->hdr->record_counter);
    cp += fd->vv.varint_put32(cp, NULL, s->hdr->num_blocks);
    cp += fd->vv.varint_put32(cp, NULL, s->hdr->num_content_ids);
    for (j = 0; j < s->hdr->num_content_ids; j++) {
        cp += fd->vv.varint_put32(cp, NULL, s->hdr->block_content_ids[j]);
    }
    if (s->hdr->content_type == MAPPED_SLICE)
        cp += fd->vv.varint_put32(cp, NULL, s->hdr->ref_base_id);

    if (CRAM_MAJOR_VERS(fd->version) != 1) {
        memcpy(cp, s->hdr->md5, 16); cp += 16;
    }

    assert(cp-buf <= 22+16+5*(8+s->hdr->num_blocks));

    b->data = (unsigned char *)buf;
    b->comp_size = b->uncomp_size = cp-buf;

    return b;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r12
movl $0x2, %edi
xorl %esi, %esi
callq 0x4ee42
testq %rax, %rax
je 0x420f0
movq %rax, %rbx
movq (%r15), %r13
movl 0x28(%r13), %eax
leal (%rax,%rax,4), %eax
addl $0x4e, %eax
movslq %eax, %rdi
callq 0x4680
testq %rax, %rax
je 0x420ac
movq %rax, %r14
movl 0x4(%r13), %edx
movq %rax, %rdi
xorl %esi, %esi
callq *0x89d0(%r12)
movslq %eax, %r13
addq %r14, %r13
cmpl $0x400, 0xc(%r12)       # imm = 0x400
jl 0x420b6
movq (%r15), %rax
movq 0x8(%rax), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89d8(%r12)
movslq %eax, %rbp
movq %r13, %rdi
addq %rbp, %rdi
movq (%r15), %rax
movq 0x10(%rax), %rdx
xorl %esi, %esi
callq *0x89d8(%r12)
jmp 0x4211d
movq %rbx, %rdi
callq 0x4f82d
jmp 0x420f0
movq (%r15), %rax
movq 0x8(%rax), %rdx
testq $-0x80000000, %rdx      # imm = 0x80000000
je 0x420f7
leaq 0x5a874(%rip), %rsi     # 0x9c941
leaq 0x5a886(%rip), %rdx     # 0x9c95a
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
movq %rbx, %rdi
callq 0x4f82d
movq %r14, %rdi
callq 0x45c0
xorl %ebx, %ebx
jmp 0x4223e
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
movslq %eax, %rbp
movq %r13, %rdi
addq %rbp, %rdi
movq (%r15), %rax
movl 0x10(%rax), %edx
xorl %esi, %esi
callq *0x89c8(%r12)
addq %rbp, %r13
movslq %eax, %rbp
addq %r13, %rbp
movq (%r15), %rax
movl 0x18(%rax), %edx
movq %rbp, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
movslq %eax, %r13
addq %rbp, %r13
movl 0xc(%r12), %eax
sarl $0x8, %eax
cmpl $0x2, %eax
jne 0x42161
movq (%r15), %rax
movl 0x20(%rax), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
jmp 0x42177
jle 0x4217c
movq (%r15), %rax
movq 0x20(%rax), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89d8(%r12)
cltq
addq %rax, %r13
movq (%r15), %rax
movl 0x28(%rax), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
movslq %eax, %rbp
addq %r13, %rbp
movq (%r15), %rax
movl 0x2c(%rax), %edx
movq %rbp, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
movslq %eax, %r13
addq %rbp, %r13
movq (%r15), %rax
cmpl $0x0, 0x2c(%rax)
jle 0x421e1
xorl %ebp, %ebp
movq 0x30(%rax), %rax
movl (%rax,%rbp,4), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
cltq
addq %rax, %r13
incq %rbp
movq (%r15), %rax
movslq 0x2c(%rax), %rcx
cmpq %rcx, %rbp
jl 0x421b9
cmpl $0x2, (%rax)
jne 0x421fb
movl 0x38(%rax), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
cltq
addq %rax, %r13
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%r12), %eax
cmpl $0x100, %eax            # imm = 0x100
je 0x4221c
movq (%r15), %rax
movups 0x3c(%rax), %xmm0
movups %xmm0, (%r13)
addq $0x10, %r13
subq %r14, %r13
movq (%r15), %rax
movl 0x28(%rax), %eax
leal (%rax,%rax,4), %eax
addl $0x4e, %eax
cltq
cmpq %rax, %r13
jg 0x42250
movq %r14, 0x20(%rbx)
movl %r13d, 0x14(%rbx)
movl %r13d, 0x10(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5a72b(%rip), %rdi     # 0x9c982
leaq 0x5a74d(%rip), %rsi     # 0x9c9ab
leaq 0x5a759(%rip), %rcx     # 0x9c9be
movl $0x22d, %edx            # imm = 0x22D
callq 0x42f0