// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %r15
callq 0x4ee88
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 0x54255
movq %r14, 0x8(%rbx)
movl 0x8(%r14), %eax
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x2, %ecx
jne 0x54222
movq %r15, %rdi
movq %r14, %rsi
callq 0x3a2c1
movq %rax, (%rbx)
testq %rax, %rax
je 0x54255
movl 0x28(%rax), %r12d
testl %r12d, %r12d
jle 0x54286
movl $0x8, %esi
movq %r12, %rdi
callq 0x4300
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x54255
xorl %r13d, %r13d
movq %r15, %rdi
callq 0x4ee88
movq 0x10(%rbx), %rcx
movq %rax, (%rcx,%r13,8)
testq %rax, %rax
je 0x54255
incq %r13
cmpq %r13, %r12
jne 0x5409b
movl $0x200, %edi            # imm = 0x200
movl $0x8, %esi
callq 0x4300
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x54255
cmpl $0x2, %r12d
movl $0x1, %eax
cmovgel %r12d, %eax
xorl %ecx, %ecx
movl $0x828cbfbf, %edx       # imm = 0x828CBFBF
movq 0x10(%rbx), %rsi
movq (%rsi,%rcx,8), %rsi
cmpl $0x4, 0x8(%rsi)
jne 0x5412d
movl 0xc(%rsi), %edi
cmpl $0x100, %edi            # imm = 0x100
jb 0x54123
movl %edi, %r8d
imulq %rdx, %r8
shrq $0x27, %r8
imull $0xfb, %r8d, %r8d
negl %r8d
addl %r8d, %edi
addl $0x100, %edi            # imm = 0x100
movq 0x18(%rbx), %r8
movl %edi, %edi
movq %rsi, (%r8,%rdi,8)
incq %rcx
cmpq %rcx, %rax
jne 0x540ec
movl $0x400, 0x40(%rbx)      # imm = 0x400
movl $0x1000, %edi           # imm = 0x1000
callq 0x4680
movq %rax, 0x38(%rbx)
testq %rax, %rax
je 0x54255
movl $0x0, 0x44(%rbx)
movl $0x4, %edi
xorl %esi, %esi
callq 0x4ee42
movq %rax, 0x70(%rbx)
testq %rax, %rax
je 0x54255
movl $0x4, %edi
movl $0xc, %esi
callq 0x4ee42
movq %rax, 0x78(%rbx)
testq %rax, %rax
je 0x54255
movl $0x4, %edi
movl $0xb, %esi
callq 0x4ee42
movq %rax, 0x68(%rbx)
testq %rax, %rax
je 0x54255
movl $0x4, %edi
movl $0x1, %esi
callq 0x4ee42
movq %rax, 0x90(%rbx)
testq %rax, %rax
je 0x54255
movl $0x4, %edi
movl $0xd, %esi
callq 0x4ee42
movq %rax, 0x80(%rbx)
testq %rax, %rax
je 0x54255
movl $0x4, %edi
movl $0xe, %esi
callq 0x4ee42
movq %rax, 0x88(%rbx)
testq %rax, %rax
je 0x54255
movq $0x0, 0x30(%rbx)
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rbx)
movl 0x210(%r15), %eax
movl %eax, 0xdc(%rbx)
jmp 0x54279
cmpl $0x5, %eax
ja 0x54234
leaq 0x646fa(%rip), %rcx     # 0xb8928
movq (%rcx,%rax,8), %rcx
jmp 0x5423b
leaq 0x46db1(%rip), %rcx     # 0x9afec
leaq 0x49d86(%rip), %rsi     # 0x9dfc8
leaq 0x49d8f(%rip), %rdx     # 0x9dfd8
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
testq %r14, %r14
je 0x54262
movq %r14, %rdi
callq 0x4f82d
testq %rbx, %rbx
je 0x54277
movq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x52c5d
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x49d3b(%rip), %rsi     # 0x9dfc8
leaq 0x49d60(%rip), %rdx     # 0x9dff4
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x54255