// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/cram/cram_decode.c
// Function: cram_decode_slice_header
cram_block_slice_hdr *cram_decode_slice_header(cram_fd *fd, cram_block *b) {
    cram_block_slice_hdr *hdr;
    unsigned char *cp;
    unsigned char *cp_end;
    int i, err = 0;

    if (b->method != RAW) {
        /* Spec. says slice header should be RAW, but we can future-proof
           by trying to decode it if it isn't. */
        if (cram_uncompress_block(b) < 0)
            return NULL;
    }
    cp =  (unsigned char *)BLOCK_DATA(b);
    cp_end = cp + b->uncomp_size;

    if (b->content_type != MAPPED_SLICE &&
        b->content_type != UNMAPPED_SLICE)
        return NULL;

    if (!(hdr  = calloc(1, sizeof(*hdr))))
        return NULL;

    hdr->content_type = b->content_type;

    if (b->content_type == MAPPED_SLICE) {
        hdr->ref_seq_id = fd->vv.varint_get32s((char **)&cp, (char *)cp_end, &err);
        if (CRAM_MAJOR_VERS(fd->version) >= 4) {
            hdr->ref_seq_start = fd->vv.varint_get64((char **)&cp, (char *)cp_end, &err);
            hdr->ref_seq_span  = fd->vv.varint_get64((char **)&cp, (char *)cp_end, &err);
        } else {
            hdr->ref_seq_start = fd->vv.varint_get32((char **)&cp, (char *)cp_end, &err);
            hdr->ref_seq_span  = fd->vv.varint_get32((char **)&cp, (char *)cp_end, &err);
        }
        if (hdr->ref_seq_start < 0 || hdr->ref_seq_span < 0) {
            free(hdr);
            hts_log_error("Negative values not permitted for header "
                          "sequence start or span fields");
            return NULL;
        }
    }
    hdr->num_records = fd->vv.varint_get32((char **)&cp, (char *) cp_end, &err);
    hdr->record_counter = 0;
    if (CRAM_MAJOR_VERS(fd->version) == 2) {
        hdr->record_counter = fd->vv.varint_get32((char **)&cp, (char *)cp_end, &err);
    } else if (CRAM_MAJOR_VERS(fd->version) >= 3) {
        hdr->record_counter = fd->vv.varint_get64((char **)&cp, (char *)cp_end, &err);
    }
    hdr->num_blocks      = fd->vv.varint_get32((char **)&cp, (char *)cp_end, &err);
    hdr->num_content_ids = fd->vv.varint_get32((char **)&cp, (char *)cp_end, &err);
    if (hdr->num_content_ids < 1 ||
        hdr->num_content_ids >= 10000) {
        // Slice must have at least one data block, and there is no need
        // for more than 2 per possible aux-tag plus ancillary.
        free(hdr);
        return NULL;
    }
    hdr->block_content_ids = malloc(hdr->num_content_ids * sizeof(int32_t));
    if (!hdr->block_content_ids) {
        free(hdr);
        return NULL;
    }

    for (i = 0; i < hdr->num_content_ids; i++)
        hdr->block_content_ids[i] = fd->vv.varint_get32((char **)&cp,
                                                         (char *)cp_end,
                                                         &err);
    if (err) {
        free(hdr->block_content_ids);
        free(hdr);
        return NULL;
    }

    if (b->content_type == MAPPED_SLICE)
        hdr->ref_base_id = fd->vv.varint_get32((char **)&cp, (char *) cp_end, &err);

    if (CRAM_MAJOR_VERS(fd->version) != 1) {
        if (cp_end - cp < 16) {
            free(hdr->block_content_ids);
            free(hdr);
            return NULL;
        }
        memcpy(hdr->md5, cp, 16);
    } else {
        memset(hdr->md5, 0, 16);
    }

    if (!err)
        return hdr;

    free(hdr->block_content_ids);
    free(hdr);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
andl $0x0, 0x4(%rsp)
movq %rsi, %r12
movq %rdi, %r13
cmpl $0x0, (%rsi)
je 0x2e6ed
movq %r12, %rdi
callq 0x3f918
testl %eax, %eax
js 0x2e927
movq 0x20(%r12), %r15
movq %r15, 0x8(%rsp)
movl 0x8(%r12), %ebx
movl %ebx, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x2e927
movslq 0x14(%r12), %r14
pushq $0x1
popq %rdi
pushq $0x50
popq %rsi
callq 0x4300
testq %rax, %rax
je 0x2e927
movq %rax, %rbp
addq %r14, %r15
movl %ebx, (%rax)
cmpl $0x2, %ebx
jne 0x2e7a5
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %r14
movq %r15, %rsi
movq %r14, %rdx
callq *0x89b0(%r13)
movl %eax, 0x4(%rbp)
xorl %ebx, %ebx
cmpl $0x400, 0xc(%r13)       # imm = 0x400
setge %bl
shll $0x4, %ebx
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq *0x89a8(%r13,%rbx)
movq %r13, %r14
movq %rax, %r13
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
leaq 0x4(%rsp), %rdx
callq *0x89a8(%r14,%rbx)
movq %r13, 0x8(%rbp)
movq %rax, 0x10(%rbp)
testq %r13, %r13
js 0x2e889
movq %r14, %r13
testq %rax, %rax
js 0x2e889
leaq 0x89a8(%r13), %rbx
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rdx
movq %r15, %rsi
callq *0x89a8(%r13)
movl %eax, 0x18(%rbp)
movl 0xc(%r13), %ecx
sarl $0x8, %ecx
movq %rbx, 0x10(%rsp)
movq %rbx, %rax
cmpl $0x2, %ecx
je 0x2e7e0
jle 0x2e7f3
leaq 0x89b8(%r13), %rax
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rdx
movq %r15, %rsi
callq *(%rax)
movq %rax, 0x20(%rbp)
movq %r13, 0x20(%rsp)
leaq 0x8(%rsp), %r14
leaq 0x4(%rsp), %r13
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rbx
callq *(%rbx)
movl %eax, 0x28(%rbp)
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq *(%rbx)
movq %rbp, %rbx
movq %rax, %rbp
movl %ebp, 0x2c(%rbx)
movl $0xffffd8f0, %eax       # imm = 0xFFFFD8F0
leal (%rax,%rbp), %ecx
cmpl %eax, %ecx
jbe 0x2e91f
movl %ebp, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
shlq $0x2, %rdi
callq 0x4680
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x2e91f
movq %rax, %r13
movq %rbx, 0x18(%rsp)
movl %ebp, %ebx
xorl %ebp, %ebp
leaq 0x4(%rsp), %r14
cmpq %rbp, %rbx
je 0x2e8ad
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
movq 0x10(%rsp), %rax
callq *(%rax)
movl %eax, (%r13,%rbp,4)
incq %rbp
jmp 0x2e868
movq %rbp, %rdi
callq 0x45c0
leaq 0x4c922(%rip), %rsi     # 0x7b1ba
leaq 0x4c934(%rip), %rdx     # 0x7b1d3
xorl %ebx, %ebx
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x2e929
cmpl $0x0, 0x4(%rsp)
je 0x2e8c3
movq %r13, %rdi
callq 0x45c0
movq 0x18(%rsp), %rdi
jmp 0x2e922
cmpl $0x2, 0x8(%r12)
movq 0x18(%rsp), %rbx
jne 0x2e8e7
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rdx
movq %r15, %rsi
movq 0x10(%rsp), %rax
callq *(%rax)
movl %eax, 0x38(%rbx)
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
movq 0x20(%rsp), %rcx
andl 0xc(%rcx), %eax
cmpl $0x100, %eax            # imm = 0x100
je 0x2e910
movq 0x8(%rsp), %rax
subq %rax, %r15
cmpq $0xf, %r15
jle 0x2e917
movups (%rax), %xmm0
movups %xmm0, 0x3c(%rbx)
cmpl $0x0, 0x4(%rsp)
je 0x2e929
movq %r13, %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq