// File: /workspace/github_c_makefile_star2_O1/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
movq %rsi, %r12
movq %rdi, %r13
movl $0x0, 0x4(%rsp)
cmpl $0x0, (%rsi)
je 0x3a2f2
movq %r12, %rdi
callq 0x4f84e
testl %eax, %eax
js 0x3a550
movq 0x20(%r12), %r15
movq %r15, 0x8(%rsp)
movl 0x8(%r12), %ebp
movl %ebp, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x3a550
movslq 0x14(%r12), %r14
movl $0x1, %edi
movl $0x50, %esi
callq 0x4300
testq %rax, %rax
je 0x3a550
movq %rax, %rbx
addq %r14, %r15
movl %ebp, (%rax)
cmpl $0x2, %ebp
jne 0x3a3b3
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rbp
movq %r15, %rsi
movq %rbp, %rdx
callq *0x89b0(%r13)
movl %eax, 0x4(%rbx)
movq %r13, %r14
xorl %r13d, %r13d
cmpl $0x400, 0xc(%r14)       # imm = 0x400
setge %r13b
shll $0x4, %r13d
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq *0x89a8(%r14,%r13)
movq %rax, %rbp
movq %rax, 0x8(%rbx)
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
leaq 0x4(%rsp), %rdx
callq *0x89a8(%r14,%r13)
movq %rax, 0x10(%rbx)
testq %rbp, %rbp
js 0x3a4ba
movq %r14, %r13
cmpq $0x0, 0x10(%rbx)
js 0x3a4ba
leaq 0x89a8(%r13), %rbp
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rdx
movq %r15, %rsi
callq *0x89a8(%r13)
movl %eax, 0x18(%rbx)
movq $0x0, 0x20(%rbx)
movl 0xc(%r13), %ecx
sarl $0x8, %ecx
movq %rbp, %rax
cmpl $0x2, %ecx
je 0x3a3f1
jle 0x3a404
leaq 0x89b8(%r13), %rax
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rdx
movq %r15, %rsi
callq *(%rax)
movq %rax, 0x20(%rbx)
movq %r13, 0x20(%rsp)
leaq 0x8(%rsp), %r14
leaq 0x4(%rsp), %r13
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq *(%rbp)
movl %eax, 0x28(%rbx)
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, 0x18(%rsp)
callq *(%rbp)
movq %rax, %rbp
movl %ebp, 0x2c(%rbx)
movl $0xffffd8f0, %eax       # imm = 0xFFFFD8F0
leal (%rax,%rbp), %ecx
cmpl %eax, %ecx
jbe 0x3a548
movl %ebp, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
shlq $0x2, %rdi
callq 0x4680
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x3a548
movq %rax, %rdi
movq %rbx, 0x10(%rsp)
testl %ebp, %ebp
movq 0x18(%rsp), %r13
jle 0x3a4a4
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq %rdi, %rbx
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
leaq 0x4(%rsp), %rdx
callq *(%r13)
movq %rbx, %rdi
movl %eax, (%rbx,%r14,4)
incq %r14
cmpq %r14, %rbp
jne 0x3a481
cmpl $0x0, 0x4(%rsp)
je 0x3a4e0
callq 0x45c0
movq 0x10(%rsp), %rdi
jmp 0x3a54b
movq %rbx, %rdi
callq 0x45c0
leaq 0x61d08(%rip), %rsi     # 0x9c1d1
leaq 0x61d1a(%rip), %rdx     # 0x9c1ea
xorl %ebx, %ebx
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x3a552
cmpl $0x2, 0x8(%r12)
movq 0x10(%rsp), %rbx
jne 0x3a50a
movq %rdi, %r14
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rdx
movq %r15, %rsi
movq 0x18(%rsp), %rax
callq *(%rax)
movq %r14, %rdi
movl %eax, 0x38(%rbx)
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
movq 0x20(%rsp), %rcx
andl 0xc(%rcx), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x3a523
xorps %xmm0, %xmm0
jmp 0x3a534
movq 0x8(%rsp), %rax
subq %rax, %r15
cmpq $0xf, %r15
jle 0x3a543
movups (%rax), %xmm0
movups %xmm0, 0x3c(%rbx)
cmpl $0x0, 0x4(%rsp)
je 0x3a552
movq 0x30(%rbx), %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