// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movq %rdi, %r12
callq 0x56347
movq %rax, %rbx
movl $0x1, %edi
movl $0x100, %esi            # imm = 0x100
callq 0x6470
movq %rbx, 0x8(%rsp)
testq %rbx, %rbx
sete %dl
movq %rax, (%rsp)
testq %rax, %rax
sete %cl
orb %dl, %cl
jne 0x5b500
movq (%rsp), %rbx
movq 0x8(%rsp), %r14
movq %r14, 0x8(%rbx)
movl 0x8(%r14), %edi
movl %edi, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x5b53c
movq %r12, %rdi
movq %r14, %rsi
callq 0x7721c
movq %rax, (%rbx)
testq %rax, %rax
je 0x5b50e
movq %rax, %r15
movslq 0x20(%rax), %rbp
testq %rbp, %rbp
jle 0x5b543
movl $0x8, %esi
movq %rbp, %rdi
callq 0x6470
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x5b50e
movq %rax, %r13
movq %r15, 0x10(%rsp)
xorl %ebx, %ebx
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x56347
movq %rax, (%r13,%rbx,8)
testq %rax, %rax
je 0x5b500
cmpl $0x4, 0x8(%rax)
jne 0x5b38d
movl 0xc(%rax), %eax
cmpl %eax, %r14d
cmovlel %eax, %r14d
cmpl %eax, %r15d
cmovgel %eax, %r15d
incq %rbx
cmpq %rbx, %rbp
jne 0x5b360
testl %r15d, %r15d
js 0x5b3e2
cmpl $0x3ff, %r14d           # imm = 0x3FF
jg 0x5b3e2
movl $0x400, %edi            # imm = 0x400
movl $0x8, %esi
callq 0x6470
movq (%rsp), %rcx
movq %rax, 0x18(%rcx)
testq %rax, %rax
je 0x5b500
movl %ebp, %ecx
xorl %edx, %edx
movq (%r13,%rdx,8), %rsi
cmpl $0x4, 0x8(%rsi)
jne 0x5b3da
movslq 0xc(%rsi), %rdi
movq %rsi, (%rax,%rdi,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x5b3c7
movl $0x40, %edi
callq 0x69d0
testq %rax, %rax
je 0x5b500
movaps 0x3d8c4(%rip), %xmm0    # 0x98cc0
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)
movq (%rsp), %rcx
movq %rax, 0x68(%rcx)
movl $0x40, %edi
callq 0x69d0
testq %rax, %rax
je 0x5b500
movaps 0x3d897(%rip), %xmm0    # 0x98cd0
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)
movq (%rsp), %rcx
movq %rax, 0x70(%rcx)
movl $0x40, %edi
callq 0x69d0
testq %rax, %rax
je 0x5b500
movaps 0x3d86a(%rip), %xmm0    # 0x98ce0
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)
movq (%rsp), %rbx
movq %rax, 0x60(%rbx)
movl $0x4, %edi
movl $0x1, %esi
callq 0x56309
movq %rax, 0x88(%rbx)
testq %rax, %rax
je 0x5b500
movl $0x4, %edi
movl $0xd, %esi
callq 0x56309
movq (%rsp), %rcx
movq %rax, 0x78(%rcx)
testq %rax, %rax
je 0x5b500
movl $0x4, %edi
movl $0xe, %esi
callq 0x56309
movq (%rsp), %rcx
movq %rax, 0x80(%rcx)
testq %rax, %rax
je 0x5b500
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ecx
movq (%rsp), %rax
movl %ecx, 0x20(%rax)
jmp 0x5b52d
movq 0x8(%rsp), %r14
testq %r14, %r14
movq (%rsp), %rbx
je 0x5b516
movq %r14, %rdi
callq 0x56a50
testq %rbx, %rbx
je 0x5b52b
movq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x59823
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x790c
jmp 0x5b50e
callq 0x7944
jmp 0x5b50e