// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6eec0
movq %rax, -0x18(%rbp)
movl $0x1, %edi
movl $0xf0, %esi
callq 0x42f0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x771fa
cmpq $0x0, -0x20(%rbp)
jne 0x771ff
jmp 0x77580
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
addl $-0x2, %eax
subl $0x1, %eax
ja 0x7723d
jmp 0x7721c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x51b10
movq -0x20(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x7723b
jmp 0x77580
jmp 0x7726b
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x71740
movq %rax, %rcx
movl $0x1, %edi
leaq 0x7e740(%rip), %rsi     # 0xf5998
leaq 0x7e749(%rip), %rdx     # 0xf59a8
movb $0x0, %al
callq 0x1b030
jmp 0x77580
movq -0x20(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, 0x28(%rax)
jge 0x77297
movl $0x1, %edi
leaq 0x7e714(%rip), %rsi     # 0xf5998
leaq 0x7e739(%rip), %rdx     # 0xf59c4
movb $0x0, %al
callq 0x1b030
jmp 0x77580
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x28(%rax), %eax
movl %eax, -0x28(%rbp)
movslq %eax, %rdi
movl $0x8, %esi
callq 0x42f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x772cc
jmp 0x77580
movl $0x0, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x7fffffff, -0x30(%rbp) # imm = 0x7FFFFFFF
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x77395
movq -0x10(%rbp), %rdi
callq 0x6eec0
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x24(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x77311
jmp 0x77580
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x4, 0x8(%rax)
jne 0x77385
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x24(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl 0xc(%rcx), %eax
jge 0x77355
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0xc(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x24(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl 0xc(%rcx), %eax
jle 0x77383
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0xc(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x77385
jmp 0x77387
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x772e1
movl $0x200, %edi            # imm = 0x200
movl $0x8, %esi
callq 0x42f0
movq -0x20(%rbp), %rcx
movq %rax, 0x18(%rcx)
cmpq $0x0, %rax
jne 0x773b7
jmp 0x77580
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x7743c
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x4, 0x8(%rax)
je 0x773de
jmp 0x77431
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0xc(%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0x100, -0x34(%rbp)     # imm = 0x100
jb 0x77412
movl -0x34(%rbp), %eax
movl $0xfb, %ecx
xorl %edx, %edx
divl %ecx
addl $0x100, %edx            # imm = 0x100
movl %edx, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x34(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x773be
movq -0x20(%rbp), %rax
movl $0x400, 0x40(%rax)      # imm = 0x400
movq -0x20(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x4650
movq -0x20(%rbp), %rcx
movq %rax, 0x38(%rcx)
cmpq $0x0, %rax
jne 0x7746c
jmp 0x77580
movq -0x20(%rbp), %rax
movl $0x0, 0x44(%rax)
movl $0x4, %edi
xorl %esi, %esi
callq 0x6ede0
movq -0x20(%rbp), %rcx
movq %rax, 0x70(%rcx)
cmpq $0x0, %rax
jne 0x77496
jmp 0x77580
movl $0x4, %edi
movl $0xc, %esi
callq 0x6ede0
movq -0x20(%rbp), %rcx
movq %rax, 0x78(%rcx)
cmpq $0x0, %rax
jne 0x774b8
jmp 0x77580
movl $0x4, %edi
movl $0xb, %esi
callq 0x6ede0
movq -0x20(%rbp), %rcx
movq %rax, 0x68(%rcx)
cmpq $0x0, %rax
jne 0x774da
jmp 0x77580
movl $0x4, %edi
movl $0x1, %esi
callq 0x6ede0
movq -0x20(%rbp), %rcx
movq %rax, 0x90(%rcx)
cmpq $0x0, %rax
jne 0x774ff
jmp 0x77580
movl $0x4, %edi
movl $0xd, %esi
callq 0x6ede0
movq -0x20(%rbp), %rcx
movq %rax, 0x80(%rcx)
cmpq $0x0, %rax
jne 0x77521
jmp 0x77580
movl $0x4, %edi
movl $0xe, %esi
callq 0x6ede0
movq -0x20(%rbp), %rcx
movq %rax, 0x88(%rcx)
cmpq $0x0, %rax
jne 0x77543
jmp 0x77580
movq -0x20(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0x210(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xdc(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x775b4
cmpq $0x0, -0x18(%rbp)
je 0x77590
movq -0x18(%rbp), %rdi
callq 0x6f940
cmpq $0x0, -0x20(%rbp)
je 0x775ac
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x20(%rbp), %rdi
callq 0x74f20
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop