// File: /workspace/github_c_makefile_star2_O2/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 0x4dbb3
movq %rax, %rbx
pushq $0x1
popq %rdi
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 0x52565
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 0x5259e
movq %r12, %rdi
movq %r14, %rsi
callq 0x68195
movq %rax, (%rbx)
testq %rax, %rax
je 0x52573
movq %rax, %r15
movslq 0x20(%rax), %r13
testq %r13, %r13
jle 0x525c3
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x6470
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x52573
movq %rax, %rbp
movq %r15, 0x10(%rsp)
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %ebx, %ebx
xorl %r15d, %r15d
cmpq %rbx, %r13
je 0x52470
movq %r12, %rdi
callq 0x4dbb3
movq %rax, (%rbp,%rbx,8)
testq %rax, %rax
je 0x52565
cmpl $0x4, 0x8(%rax)
jne 0x5246b
movl 0xc(%rax), %eax
cmpl %eax, %r15d
cmovlel %eax, %r15d
cmpl %eax, %r14d
cmovgel %eax, %r14d
incq %rbx
jmp 0x52439
testl %r14d, %r14d
movq (%rsp), %rbx
js 0x524bf
cmpl $0x3ff, %r15d           # imm = 0x3FF
jg 0x524bf
pushq $0x8
popq %rsi
movl $0x400, %edi            # imm = 0x400
callq 0x6470
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x52565
xorl %ecx, %ecx
movq (%rsp), %rbx
cmpq %rcx, %r13
je 0x524bf
movq (%rbp,%rcx,8), %rdx
cmpl $0x4, 0x8(%rdx)
jne 0x524ba
movslq 0xc(%rdx), %rsi
movq %rdx, (%rax,%rsi,8)
incq %rcx
jmp 0x524a2
pushq $0x4
popq %rdi
xorl %esi, %esi
callq 0x4db76
movq %rax, 0x68(%rbx)
testq %rax, %rax
je 0x52565
pushq $0x4
popq %rdi
pushq $0xc
popq %rsi
callq 0x4db76
movq (%rsp), %rcx
movq %rax, 0x70(%rcx)
testq %rax, %rax
je 0x52565
pushq $0x4
popq %rdi
pushq $0xb
popq %rsi
callq 0x4db76
movq (%rsp), %rcx
movq %rax, 0x60(%rcx)
testq %rax, %rax
je 0x52565
pushq $0x4
popq %rdi
pushq $0x1
popq %rsi
callq 0x4db76
movq (%rsp), %rcx
movq %rax, 0x88(%rcx)
testq %rax, %rax
je 0x52565
pushq $0x4
popq %rdi
pushq $0xd
popq %rsi
callq 0x4db76
movq (%rsp), %rcx
movq %rax, 0x78(%rcx)
testq %rax, %rax
je 0x52565
pushq $0x4
popq %rdi
pushq $0xe
popq %rsi
callq 0x4db76
movq (%rsp), %rcx
movq %rax, 0x80(%rcx)
testq %rax, %rax
je 0x52565
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ecx
movq (%rsp), %rax
movl %ecx, 0x20(%rax)
jmp 0x5258f
movq 0x8(%rsp), %r14
testq %r14, %r14
movq (%rsp), %rbx
je 0x5257b
movq %r14, %rdi
callq 0x4e18f
testq %rbx, %rbx
je 0x5258d
andq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x50b17
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x60a33(%rip), %rax     # 0xb2fd8
movq (%rax), %r15
callq 0x4edde
leaq 0x3596d(%rip), %rsi     # 0x87f21
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x52573
movq 0x60a0e(%rip), %rax     # 0xb2fd8
movq (%rax), %rcx
leaq 0x3596a(%rip), %rdi     # 0x87f3e
pushq $0x28
popq %rsi
pushq $0x1
popq %rdx
callq 0x6e70
jmp 0x52573