// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %rsi, %r12
movq %rdi, %rbp
movl $0x0, 0xc(%rsp)
cmpl $0x0, (%rsi)
je 0x38d41
movq %r12, %rdi
callq 0x4ced7
testl %eax, %eax
js 0x38efd
movq 0x20(%r12), %r15
movq %r15, 0x10(%rsp)
movl 0x8(%r12), %ebx
movl %ebx, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x38efd
movslq 0x14(%r12), %r14
movl $0x1, %edi
movl $0x50, %esi
callq 0x4300
testq %rax, %rax
je 0x38efd
movq %rax, %r13
addq %r14, %r15
movl %ebx, (%rax)
cmpl $0x2, %ebx
jne 0x38dfb
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %r14
movq %r15, %rsi
movq %r14, %rdx
callq *0x89b0(%rbp)
movl %eax, 0x4(%r13)
movq %rbp, %rbx
xorl %ebp, %ebp
cmpl $0x400, 0xc(%rbx)       # imm = 0x400
setge %bpl
shll $0x4, %ebp
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq *0x89a8(%rbx,%rbp)
movq %rax, %r14
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
leaq 0xc(%rsp), %rdx
callq *0x89a8(%rbx,%rbp)
movq %r14, 0x8(%r13)
movq %rax, 0x10(%r13)
testq %r14, %r14
js 0x38f11
movq %rbx, %rbp
testq %rax, %rax
js 0x38f11
leaq 0x89a8(%rbp), %rbx
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
movq %r15, %rsi
callq *0x89a8(%rbp)
movl %eax, 0x18(%r13)
movl 0xc(%rbp), %ecx
sarl $0x8, %ecx
movq %rbx, %rax
cmpl $0x2, %ecx
je 0x38e30
jle 0x38e43
leaq 0x89b8(%rbp), %rax
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
movq %r15, %rsi
callq *(%rax)
movq %rax, 0x20(%r13)
movq %rbp, 0x30(%rsp)
movq %rbx, 0x18(%rsp)
leaq 0x10(%rsp), %rbx
leaq 0xc(%rsp), %r14
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq 0x18(%rsp), %rax
callq *(%rax)
movl %eax, 0x28(%r13)
movq %rbx, %rdi
movq 0x18(%rsp), %rbx
movq %r15, %rsi
movq %r14, %rdx
callq *(%rbx)
movq %rax, %rbp
movl %ebp, 0x2c(%r13)
movl $0xffffd8f0, %eax       # imm = 0xFFFFD8F0
leal (%rax,%rbp), %ecx
cmpl %eax, %ecx
jbe 0x38ef5
movl %ebp, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
shlq $0x2, %rdi
callq 0x4680
movq %rax, 0x30(%r13)
testq %rax, %rax
je 0x38ef5
movq %rax, %rdi
movq %r12, 0x28(%rsp)
movq %r13, 0x20(%rsp)
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r13d, %r13d
leaq 0xc(%rsp), %r14
movq %rdi, %r12
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq *(%rbx)
movq %r12, %rdi
movl %eax, (%r12,%r13,4)
incq %r13
cmpq %r13, %rbp
jne 0x38ec3
cmpl $0x0, 0xc(%rsp)
je 0x38f37
callq 0x45c0
movq 0x20(%rsp), %rdi
jmp 0x38ef8
movq %r13, %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x45c0
leaq 0x6032a(%rip), %rsi     # 0x9924a
leaq 0x6033c(%rip), %rdx     # 0x99263
xorl %ebx, %ebx
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x38eff
movq 0x28(%rsp), %rax
cmpl $0x2, 0x8(%rax)
movq 0x20(%rsp), %rbx
jne 0x38f61
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
movq %r15, %rsi
movq 0x18(%rsp), %rax
callq *(%rax)
movq %r12, %rdi
movl %eax, 0x38(%rbx)
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
movq 0x30(%rsp), %rcx
andl 0xc(%rcx), %eax
cmpl $0x100, %eax            # imm = 0x100
je 0x38f8a
movq 0x10(%rsp), %rax
subq %rax, %r15
cmpq $0xf, %r15
jle 0x38f95
movups (%rax), %xmm0
movups %xmm0, 0x3c(%rbx)
cmpl $0x0, 0xc(%rsp)
je 0x38eff
callq 0x45c0
movq %rbx, %rdi
jmp 0x38ef8