// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51b4d
movq -0x18(%rbp), %rdi
callq 0x6f980
cmpl $0x0, %eax
jge 0x51b4b
movq $0x0, -0x8(%rbp)
jmp 0x51f57
jmp 0x51b4d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x14(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x2, 0x8(%rax)
je 0x51b8d
movq -0x18(%rbp), %rax
cmpl $0x3, 0x8(%rax)
je 0x51b8d
movq $0x0, -0x8(%rbp)
jmp 0x51f57
movl $0x1, %edi
movl $0x50, %esi
callq 0x42f0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x51bb3
movq $0x0, -0x8(%rbp)
jmp 0x51f57
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpl $0x2, 0x8(%rax)
jne 0x51cd9
movq -0x10(%rbp), %rax
movq 0x89b0(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x4, %eax
jl 0x51c49
movq -0x10(%rbp), %rax
movq 0x89b8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x89b8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x51c91
movq -0x10(%rbp), %rax
movq 0x89a8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x89a8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jl 0x51ca7
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jge 0x51cd7
movq -0x20(%rbp), %rdi
callq 0x45a0
movl $0x1, %edi
leaq 0xa1ae9(%rip), %rsi     # 0xf37a5
leaq 0xa1afb(%rip), %rdx     # 0xf37be
movb $0x0, %al
callq 0x1b030
movq $0x0, -0x8(%rbp)
jmp 0x51f57
jmp 0x51cd9
movq -0x10(%rbp), %rax
movq 0x89a8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x2, %eax
jne 0x51d3c
movq -0x10(%rbp), %rax
movq 0x89a8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x51d71
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x3, %eax
jl 0x51d6f
movq -0x10(%rbp), %rax
movq 0x89b8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x51d71
movq -0x10(%rbp), %rax
movq 0x89a8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x89a8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x20(%rbp), %rax
cmpl $0x1, 0x2c(%rax)
jl 0x51dcc
movq -0x20(%rbp), %rax
cmpl $0x2710, 0x2c(%rax)     # imm = 0x2710
jl 0x51de2
movq -0x20(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x51f57
movq -0x20(%rbp), %rax
movslq 0x2c(%rax), %rdi
shlq $0x2, %rdi
callq 0x4650
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x51e1f
movq -0x20(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x51f57
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jge 0x51e67
movq -0x10(%rbp), %rax
movq 0x89a8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x51e26
cmpl $0x0, -0x38(%rbp)
je 0x51e90
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x45a0
movq -0x20(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x51f57
movq -0x18(%rbp), %rax
cmpl $0x2, 0x8(%rax)
jne 0x51ebc
movq -0x10(%rbp), %rax
movq 0x89a8(%rax), %rax
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq *%rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
je 0x51f15
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
cmpq $0x10, %rax
jge 0x51efc
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x45a0
movq -0x20(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x51f57
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, 0x3c(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x44(%rax)
jmp 0x51f29
movq -0x20(%rbp), %rdi
addq $0x3c, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x4250
cmpl $0x0, -0x38(%rbp)
jne 0x51f39
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x51f57
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x45a0
movq -0x20(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)