// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x2
popq %rdi
xorl %esi, %esi
callq 0x3f426
testq %rax, %rax
je 0x34d96
movq %rax, %rbx
movq (%r15), %r14
movl 0x28(%r14), %eax
leal (%rax,%rax,4), %eax
addl $0x4e, %eax
movslq %eax, %rdi
callq 0x4680
testq %rax, %rax
je 0x34d54
movq %rax, %rbp
movl 0x4(%r14), %edx
movq %rax, %rdi
xorl %esi, %esi
callq *0x89d0(%r12)
movslq %eax, %r13
addq %rbp, %r13
cmpl $0x400, 0xc(%r12)       # imm = 0x400
jl 0x34d5e
movq %rbp, (%rsp)
movq (%r15), %rax
movq 0x8(%rax), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89d8(%r12)
movslq %eax, %r14
leaq (%r14,%r13), %rdi
movq (%r15), %rax
movq 0x10(%rax), %rdx
xorl %esi, %esi
callq *0x89d8(%r12)
jmp 0x34dc5
movq %rbx, %rdi
callq 0x3f8fc
jmp 0x34d96
movq (%r15), %rax
movq 0x8(%rax), %rdx
testq $-0x80000000, %rdx      # imm = 0x80000000
je 0x34d9d
leaq 0x46ba4(%rip), %rsi     # 0x7b919
leaq 0x46bb6(%rip), %rdx     # 0x7b932
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
movq %rbx, %rdi
callq 0x3f8fc
movq %rbp, %rdi
callq 0x45c0
xorl %ebx, %ebx
jmp 0x34ee6
movq %rbp, (%rsp)
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
movslq %eax, %r14
leaq (%r14,%r13), %rdi
movq (%r15), %rax
movl 0x10(%rax), %edx
xorl %esi, %esi
callq *0x89c8(%r12)
addq %r14, %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 0x34e09
movq (%r15), %rax
movl 0x20(%rax), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
jmp 0x34e1f
jle 0x34e24
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
xorl %r14d, %r14d
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 (%rsp), %rbp
movq (%r15), %rax
movslq 0x2c(%rax), %rcx
cmpq %rcx, %r14
jge 0x34e88
movq 0x30(%rax), %rax
movl (%rax,%r14,4), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
cltq
addq %rax, %r13
incq %r14
jmp 0x34e5d
cmpl $0x2, (%rax)
jne 0x34ea5
movl 0x38(%rax), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
cltq
addq %rax, %r13
movq (%r15), %rax
movl $0xffffff00, %ecx       # imm = 0xFFFFFF00
andl 0xc(%r12), %ecx
cmpl $0x100, %ecx            # imm = 0x100
je 0x34ec7
movups 0x3c(%rax), %xmm0
movups %xmm0, (%r13)
addq $0x10, %r13
movq (%r15), %rax
subq %rbp, %r13
movl 0x28(%rax), %eax
leal (%rax,%rax,4), %eax
addl $0x4e, %eax
cltq
cmpq %rax, %r13
jg 0x34ef8
movq %rbp, 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 0x46a5b(%rip), %rdi     # 0x7b95a
leaq 0x46a7d(%rip), %rsi     # 0x7b983
leaq 0x46a89(%rip), %rcx     # 0x7b996
movl $0x22d, %edx            # imm = 0x22D
callq 0x42f0