// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x7e250
movq %rax, -0x18(%rbp)
movl $0x1, %edi
movl $0x100, %esi            # imm = 0x100
callq 0x6460
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x87eea
cmpq $0x0, -0x20(%rbp)
jne 0x87eef
jmp 0x88235
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 0x87f2d
jmp 0x87f0c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xb2010
movq -0x20(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x87f2b
jmp 0x88235
jmp 0x87f61
movq 0x7d09c(%rip), %rax     # 0x104fd0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x80b10
movq -0x38(%rbp), %rdi
movq %rax, %rdx
leaq 0x5afcc(%rip), %rsi     # 0xe2f21
movb $0x0, %al
callq 0x6a80
jmp 0x88235
movq -0x20(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, 0x20(%rax)
jge 0x87f8b
movq 0x7d05b(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
leaq 0x5afbf(%rip), %rsi     # 0xe2f3e
movb $0x0, %al
callq 0x6a80
jmp 0x88235
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, -0x28(%rbp)
movslq %eax, %rdi
movl $0x8, %esi
callq 0x6460
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x87fc0
jmp 0x88235
movl $0x0, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x7fffffff, -0x30(%rbp) # imm = 0x7FFFFFFF
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x88089
movq -0x10(%rbp), %rdi
callq 0x7e250
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x24(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x88005
jmp 0x88235
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x4, 0x8(%rax)
jne 0x88079
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 0x88049
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 0x88077
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 0x88079
jmp 0x8807b
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x87fd5
cmpl $0x0, -0x30(%rbp)
jl 0x88126
cmpl $0x400, -0x2c(%rbp)     # imm = 0x400
jge 0x88126
movl $0x400, %edi            # imm = 0x400
movl $0x8, %esi
callq 0x6460
movq -0x20(%rbp), %rcx
movq %rax, 0x18(%rcx)
cmpq $0x0, %rax
jne 0x880c2
jmp 0x88235
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x88124
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x4, 0x8(%rax)
je 0x880e9
jmp 0x88119
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
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x24(%rbp), %rsi
movq (%rcx,%rsi,8), %rcx
movslq 0xc(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x880c9
jmp 0x88126
movq -0x20(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x3c(%rax)
movl $0x4, %edi
xorl %esi, %esi
callq 0x7e1a0
movq -0x20(%rbp), %rcx
movq %rax, 0x68(%rcx)
cmpq $0x0, %rax
jne 0x88167
jmp 0x88235
movl $0x4, %edi
movl $0xc, %esi
callq 0x7e1a0
movq -0x20(%rbp), %rcx
movq %rax, 0x70(%rcx)
cmpq $0x0, %rax
jne 0x88189
jmp 0x88235
movl $0x4, %edi
movl $0xb, %esi
callq 0x7e1a0
movq -0x20(%rbp), %rcx
movq %rax, 0x60(%rcx)
cmpq $0x0, %rax
jne 0x881ab
jmp 0x88235
movl $0x4, %edi
movl $0x1, %esi
callq 0x7e1a0
movq -0x20(%rbp), %rcx
movq %rax, 0x88(%rcx)
cmpq $0x0, %rax
jne 0x881cd
jmp 0x88235
movl $0x4, %edi
movl $0xd, %esi
callq 0x7e1a0
movq -0x20(%rbp), %rcx
movq %rax, 0x78(%rcx)
cmpq $0x0, %rax
jne 0x881ec
jmp 0x88235
movl $0x4, %edi
movl $0xe, %esi
callq 0x7e1a0
movq -0x20(%rbp), %rcx
movq %rax, 0x80(%rcx)
cmpq $0x0, %rax
jne 0x8820e
jmp 0x88235
movq -0x20(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x88269
cmpq $0x0, -0x18(%rbp)
je 0x88245
movq -0x18(%rbp), %rdi
callq 0x7f750
cmpq $0x0, -0x20(%rbp)
je 0x88261
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x20(%rbp), %rdi
callq 0x83eb0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)