// File: /workspace/github_c_makefile_star2_O2/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 0x3f467
movq %rax, %r14
pushq $0x1
popq %rdi
movl $0xf0, %esi
callq 0x4300
movq %rax, %rbx
testq %r14, %r14
sete %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x4395e
movq %r14, 0x8(%rbx)
movl 0x8(%r14), %edi
movl %edi, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x43809
movq %r15, %rdi
movq %r14, %rsi
callq 0x2e6bf
movq %rax, (%rbx)
testq %rax, %rax
je 0x43963
movq %rax, %r12
movslq 0x28(%rax), %r13
testq %r13, %r13
jle 0x4382e
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x4300
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x43963
movq %rax, %rbp
movq %r12, (%rsp)
xorl %r12d, %r12d
cmpq %r12, %r13
je 0x4384b
movq %r15, %rdi
callq 0x3f467
movq %rax, (%rbp,%r12,8)
incq %r12
testq %rax, %rax
jne 0x437ea
jmp 0x4395e
callq 0x407e0
leaq 0x397ab(%rip), %rsi     # 0x7cfc0
leaq 0x397b4(%rip), %rdx     # 0x7cfd0
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x110c6
jmp 0x43963
leaq 0x3978b(%rip), %rsi     # 0x7cfc0
leaq 0x397b0(%rip), %rdx     # 0x7cfec
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x43963
pushq $0x8
popq %rsi
movl $0x200, %edi            # imm = 0x200
callq 0x4300
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x4395e
movq %rax, %rcx
xorl %esi, %esi
movl $0xfb, %edi
cmpq %rsi, %r13
je 0x438a1
movq (%rbp,%rsi,8), %r8
cmpl $0x4, 0x8(%r8)
jne 0x4389c
movl 0xc(%r8), %eax
cmpl $0x100, %eax            # imm = 0x100
jb 0x43896
xorl %edx, %edx
divl %edi
movl %edx, %eax
orl $0x100, %eax            # imm = 0x100
movl %eax, %eax
movq %r8, (%rcx,%rax,8)
incq %rsi
jmp 0x4386f
movl $0x400, 0x40(%rbx)      # imm = 0x400
movl $0x1000, %edi           # imm = 0x1000
callq 0x4680
movq %rax, 0x38(%rbx)
testq %rax, %rax
je 0x4395e
pushq $0x4
popq %rdi
xorl %esi, %esi
callq 0x3f426
movq %rax, 0x70(%rbx)
testq %rax, %rax
je 0x4395e
pushq $0x4
popq %rdi
pushq $0xc
popq %rsi
callq 0x3f426
movq %rax, 0x78(%rbx)
testq %rax, %rax
je 0x4395e
pushq $0x4
popq %rdi
pushq $0xb
popq %rsi
callq 0x3f426
movq %rax, 0x68(%rbx)
testq %rax, %rax
je 0x4395e
pushq $0x4
popq %rdi
pushq $0x1
popq %rsi
callq 0x3f426
movq %rax, 0x90(%rbx)
testq %rax, %rax
je 0x4395e
pushq $0x4
popq %rdi
pushq $0xd
popq %rsi
callq 0x3f426
movq %rax, 0x80(%rbx)
testq %rax, %rax
je 0x4395e
pushq $0x4
popq %rdi
pushq $0xe
popq %rsi
callq 0x3f426
movq %rax, 0x88(%rbx)
testq %rax, %rax
je 0x4395e
movq (%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rbx)
movl 0x210(%r15), %eax
movl %eax, 0xdc(%rbx)
jmp 0x4397f
testq %r14, %r14
je 0x4396b
movq %r14, %rdi
callq 0x3f8fc
testq %rbx, %rbx
je 0x4397d
andq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x42611
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq