// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/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:
	fprintf(stderr, "Unexpected block of type %s\n",
		cram_content_type2str(b->content_type));
	goto err;
    }

    if (s->hdr->num_blocks < 1) {
        fprintf(stderr, "Slice does not include any data blocks.\n");
	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 (min_id >= 0 && max_id < 1024) {
	if (!(s->block_by_id = calloc(1024, sizeof(s->block[0]))))
	    goto err;

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

    /* Initialise encoding/decoding tables */
    s->cigar = NULL;
    s->cigar_alloc = 0;
    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;
    
    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 0x55f49
movq %rax, %r14
movl $0x1, %edi
movl $0x100, %esi            # imm = 0x100
callq 0x6470
movq %rax, %rbx
movq %r14, (%rsp)
testq %r14, %r14
sete %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x5b31c
movq (%rsp), %rsi
movq %rsi, 0x8(%rbx)
movl 0x8(%rsi), %edi
movl %edi, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x5b218
movq %r15, %rdi
callq 0x775c2
movq %rax, (%rbx)
testq %rax, %rax
je 0x5b31c
movl 0x20(%rax), %r12d
testl %r12d, %r12d
jle 0x5b264
movl $0x8, %esi
movq %r12, %rdi
callq 0x6470
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x5b31c
xorl %r14d, %r14d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movq %r15, %rdi
callq 0x55f49
movq 0x10(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
testq %rax, %rax
je 0x5b31c
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rax
cmpl $0x4, 0x8(%rax)
jne 0x5b17f
movl 0xc(%rax), %eax
cmpl %eax, %r13d
cmovlel %eax, %r13d
cmpl %eax, %ebp
cmovgel %eax, %ebp
incq %r14
cmpq %r14, %r12
jne 0x5b149
testl %ebp, %ebp
js 0x5b1e1
cmpl $0x3ff, %r13d           # imm = 0x3FF
jg 0x5b1e1
movl $0x400, %edi            # imm = 0x400
movl $0x8, %esi
callq 0x6470
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x5b31c
cmpl $0x2, %r12d
movl $0x1, %eax
cmovgel %r12d, %eax
xorl %ecx, %ecx
movq 0x10(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
cmpl $0x4, 0x8(%rdx)
jne 0x5b1d9
movq 0x18(%rbx), %rsi
movslq 0xc(%rdx), %rdi
movq %rdx, (%rsi,%rdi,8)
incq %rcx
cmpq %rcx, %rax
jne 0x5b1bf
movl $0x40, %edi
callq 0x69d0
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
testq %rax, %rax
je 0x5b222
movaps 0x3d982(%rip), %xmm1    # 0x98b80
movups %xmm1, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movq %rcx, 0x30(%rax)
movl $0x7, 0x38(%rax)
jmp 0x5b224
callq 0x7962
jmp 0x5b31c
xorl %eax, %eax
movq %rax, 0x68(%rbx)
testq %rax, %rax
je 0x5b31c
movl $0x40, %edi
callq 0x69d0
testq %rax, %rax
je 0x5b26e
movaps 0x3d949(%rip), %xmm0    # 0x98b90
movups %xmm0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movq %rcx, 0x30(%rax)
movl $0x7, 0x38(%rax)
jmp 0x5b270
callq 0x7997
jmp 0x5b31c
xorl %eax, %eax
movq %rax, 0x70(%rbx)
testq %rax, %rax
je 0x5b31c
movl $0x40, %edi
callq 0x69d0
testq %rax, %rax
je 0x5b2b0
movaps 0x3d90d(%rip), %xmm0    # 0x98ba0
movups %xmm0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movq %rcx, 0x30(%rax)
movl $0x7, 0x38(%rax)
jmp 0x5b2b2
xorl %eax, %eax
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x5b31c
movl $0x4, %edi
movl $0x1, %esi
callq 0x55f07
movq %rax, 0x88(%rbx)
testq %rax, %rax
je 0x5b31c
movl $0x4, %edi
movl $0xd, %esi
callq 0x55f07
movq %rax, 0x78(%rbx)
testq %rax, %rax
je 0x5b31c
movl $0x4, %edi
movl $0xe, %esi
callq 0x55f07
movq %rax, 0x80(%rbx)
testq %rax, %rax
je 0x5b31c
movq $0x0, 0x28(%rbx)
movq (%rbx), %rax
movl 0x8(%rax), %eax
movl %eax, 0x20(%rbx)
jmp 0x5b341
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5b32a
callq 0x567c0
testq %rbx, %rbx
je 0x5b33f
movq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x595ed
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq