// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_io.c
// Function: cram_read_slice
cram_slice *cram_read_slice(cram_fd *fd) {
    cram_block *b = cram_read_block(fd);
    cram_slice *s = calloc(1, sizeof(*s));
    int i, n, max_id, min_id;

    if (!b || !s)
        goto err;

    s->hdr_block = b;
    switch (b->content_type) {
    case MAPPED_SLICE:
    case UNMAPPED_SLICE:
        if (!(s->hdr = cram_decode_slice_header(fd, b)))
            goto err;
        break;

    default:
        hts_log_error("Unexpected block of type %s",
                      cram_content_type2str(b->content_type));
        goto err;
    }

    if (s->hdr->num_blocks < 1) {
        hts_log_error("Slice does not include any data blocks");
        goto err;
    }

    s->block = calloc(n = s->hdr->num_blocks, sizeof(*s->block));
    if (!s->block)
        goto err;

    for (max_id = i = 0, min_id = INT_MAX; i < n; i++) {
        if (!(s->block[i] = cram_read_block(fd)))
            goto err;

        if (s->block[i]->content_type == EXTERNAL) {
            if (max_id < s->block[i]->content_id)
                max_id = s->block[i]->content_id;
            if (min_id > s->block[i]->content_id)
                min_id = s->block[i]->content_id;
        }
    }

    if (!(s->block_by_id = calloc(512, sizeof(s->block[0]))))
        goto err;

    for (i = 0; i < n; i++) {
        if (s->block[i]->content_type != EXTERNAL)
            continue;
        uint32_t v = s->block[i]->content_id;
        if (v >= 256)
            v = 256 + v % 251;
        s->block_by_id[v] = s->block[i];
    }

    /* Initialise encoding/decoding tables */
    s->cigar_alloc = 1024;
    if (!(s->cigar = malloc(s->cigar_alloc * sizeof(*s->cigar)))) goto err;
    s->ncigar = 0;

    if (!(s->seqs_blk = cram_new_block(EXTERNAL, 0)))      goto err;
    if (!(s->qual_blk = cram_new_block(EXTERNAL, DS_QS)))  goto err;
    if (!(s->name_blk = cram_new_block(EXTERNAL, DS_RN)))  goto err;
    if (!(s->aux_blk  = cram_new_block(EXTERNAL, DS_aux))) goto err;
    if (!(s->base_blk = cram_new_block(EXTERNAL, DS_IN)))  goto err;
    if (!(s->soft_blk = cram_new_block(EXTERNAL, DS_SC)))  goto err;

    s->crecs = NULL;

    s->last_apos = s->hdr->ref_seq_start;
    s->decode_md = fd->decode_md;

    return s;

 err:
    if (b)
        cram_free_block(b);
    if (s) {
        s->hdr_block = NULL;
        cram_free_slice(s);
    }
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
callq 0x4c6b7
movq %rax, %r14
movl $0x1, %edi
movl $0xf0, %esi
callq 0x4300
movq %rax, %rbx
testq %r14, %r14
sete %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x516d6
movq %r14, 0x8(%rbx)
movl 0x8(%r14), %eax
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x2, %ecx
jne 0x516dd
movq %r15, %rdi
movq %r14, %rsi
callq 0x38d10
movq %rax, (%rbx)
testq %rax, %rax
je 0x51713
movq %rax, %r12
movslq 0x28(%rax), %rbp
testq %rbp, %rbp
jle 0x51744
movl $0x8, %esi
movq %rbp, %rdi
callq 0x4300
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x51713
movq %rax, %r13
movq %r12, (%rsp)
xorl %r12d, %r12d
movq %r15, %rdi
callq 0x4c6b7
movq %rax, (%r13,%r12,8)
testq %rax, %rax
je 0x516d6
incq %r12
cmpq %r12, %rbp
jne 0x51576
movl $0x200, %edi            # imm = 0x200
movl $0x8, %esi
callq 0x4300
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x516d6
movl %ebp, %ecx
xorl %edx, %edx
movl $0x828cbfbf, %esi       # imm = 0x828CBFBF
movq (%r13,%rdx,8), %rdi
cmpl $0x4, 0x8(%rdi)
jne 0x515f7
movl 0xc(%rdi), %r8d
cmpl $0x100, %r8d            # imm = 0x100
jb 0x515f0
movl %r8d, %r9d
imulq %rsi, %r9
shrq $0x27, %r9
imull $0xfb, %r9d, %r9d
negl %r9d
addl %r9d, %r8d
addl $0x100, %r8d            # imm = 0x100
movl %r8d, %r8d
movq %rdi, (%rax,%r8,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x515b9
movl $0x400, 0x40(%rbx)      # imm = 0x400
movl $0x1000, %edi           # imm = 0x1000
callq 0x4680
movq %rax, 0x38(%rbx)
testq %rax, %rax
je 0x516d6
movl $0x4, %edi
xorl %esi, %esi
callq 0x4c675
movq %rax, 0x70(%rbx)
testq %rax, %rax
je 0x516d6
movl $0x4, %edi
movl $0xc, %esi
callq 0x4c675
movq %rax, 0x78(%rbx)
testq %rax, %rax
je 0x516d6
movl $0x4, %edi
movl $0xb, %esi
callq 0x4c675
movq %rax, 0x68(%rbx)
testq %rax, %rax
je 0x516d6
movl $0x4, %edi
movl $0x1, %esi
callq 0x4c675
movq %rax, 0x90(%rbx)
testq %rax, %rax
je 0x516d6
movl $0x4, %edi
movl $0xd, %esi
callq 0x4c675
movq %rax, 0x80(%rbx)
testq %rax, %rax
je 0x516d6
movl $0x4, %edi
movl $0xe, %esi
callq 0x4c675
movq %rax, 0x88(%rbx)
testq %rax, %rax
je 0x516d6
movq (%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rbx)
movl 0x210(%r15), %eax
movl %eax, 0xdc(%rbx)
jmp 0x51732
testq %r14, %r14
jne 0x51713
jmp 0x5171b
cmpl $0x5, %eax
ja 0x516f2
leaq 0x494ab(%rip), %rdx     # 0x9ab94
movslq (%rdx,%rax,4), %rcx
addq %rdx, %rcx
jmp 0x516f9
leaq 0x46906(%rip), %rcx     # 0x97fff
leaq 0x49ac0(%rip), %rsi     # 0x9b1c0
leaq 0x49ac9(%rip), %rdx     # 0x9b1d0
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movq %r14, %rdi
callq 0x4ceb6
testq %rbx, %rbx
je 0x51730
movq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x50127
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x49a75(%rip), %rsi     # 0x9b1c0
leaq 0x49a9a(%rip), %rdx     # 0x9b1ec
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x51713