// File: /workspace/github_c_makefile_star2_O3/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 0x4c675
testq %rax, %rax
je 0x400c6
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 0x40082
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 0x4008c
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 0x400f3
movq %rbx, %rdi
callq 0x4ceb6
jmp 0x400c6
movq (%r15), %rax
movq 0x8(%rax), %rdx
testq $-0x80000000, %rdx      # imm = 0x80000000
je 0x400cd
leaq 0x598fe(%rip), %rsi     # 0x999a1
leaq 0x59910(%rip), %rdx     # 0x999ba
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movq %rbx, %rdi
callq 0x4ceb6
movq %r14, %rdi
callq 0x45c0
xorl %ebx, %ebx
jmp 0x40215
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 0x40137
movq (%r15), %rax
movl 0x20(%rax), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r12)
jmp 0x4014d
jle 0x40152
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 0x401b7
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 0x4018f
cmpl $0x2, (%rax)
jne 0x401d4
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 0x401f6
movups 0x3c(%rax), %xmm0
movups %xmm0, (%r13)
addq $0x10, %r13
movq (%r15), %rax
subq %r14, %r13
movl 0x28(%rax), %eax
leal (%rax,%rax,4), %eax
addl $0x4e, %eax
cltq
cmpq %rax, %r13
jg 0x40227
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 0x597b4(%rip), %rdi     # 0x999e2
leaq 0x597d6(%rip), %rsi     # 0x99a0b
leaq 0x597e2(%rip), %rcx     # 0x99a1e
movl $0x22d, %edx            # imm = 0x22D
callq 0x42f0