// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/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 0x31aab
movq %rax, %rbx
movl $0x1, %edi
movl $0x100, %esi            # imm = 0x100
callq 0x4360
movq %rbx, 0x8(%rsp)
testq %rbx, %rbx
sete %dl
movq %rax, (%rsp)
testq %rax, %rax
sete %cl
orb %dl, %cl
jne 0x36dfd
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 0x36e39
movq %r12, %rdi
movq %r14, %rsi
callq 0x1ece0
movq %rax, (%rbx)
testq %rax, %rax
je 0x36e0b
movq %rax, %r15
movslq 0x20(%rax), %rbp
testq %rbp, %rbp
jle 0x36e40
movl $0x8, %esi
movq %rbp, %rdi
callq 0x4360
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x36e0b
movq %rax, %r13
movq %r15, 0x10(%rsp)
xorl %ebx, %ebx
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x31aab
movq %rax, (%r13,%rbx,8)
testq %rax, %rax
je 0x36dfd
cmpl $0x4, 0x8(%rax)
jne 0x36c8a
movl 0xc(%rax), %eax
cmpl %eax, %r14d
cmovlel %eax, %r14d
cmpl %eax, %r15d
cmovgel %eax, %r15d
incq %rbx
cmpq %rbx, %rbp
jne 0x36c5d
testl %r15d, %r15d
js 0x36cdf
cmpl $0x3ff, %r14d           # imm = 0x3FF
jg 0x36cdf
movl $0x400, %edi            # imm = 0x400
movl $0x8, %esi
callq 0x4360
movq (%rsp), %rcx
movq %rax, 0x18(%rcx)
testq %rax, %rax
je 0x36dfd
movl %ebp, %ecx
xorl %edx, %edx
movq (%r13,%rdx,8), %rsi
cmpl $0x4, 0x8(%rsi)
jne 0x36cd7
movslq 0xc(%rsi), %rdi
movq %rsi, (%rax,%rdi,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x36cc4
movl $0x40, %edi
callq 0x4700
testq %rax, %rax
je 0x36dfd
movaps 0x1bcd7(%rip), %xmm0    # 0x529d0
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 0x4700
testq %rax, %rax
je 0x36dfd
movaps 0x1bcaa(%rip), %xmm0    # 0x529e0
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 0x4700
testq %rax, %rax
je 0x36dfd
movaps 0x1bc7d(%rip), %xmm0    # 0x529f0
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 0x31a6d
movq %rax, 0x88(%rbx)
testq %rax, %rax
je 0x36dfd
movl $0x4, %edi
movl $0xd, %esi
callq 0x31a6d
movq (%rsp), %rcx
movq %rax, 0x78(%rcx)
testq %rax, %rax
je 0x36dfd
movl $0x4, %edi
movl $0xe, %esi
callq 0x31a6d
movq (%rsp), %rcx
movq %rax, 0x80(%rcx)
testq %rax, %rax
je 0x36dfd
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ecx
movq (%rsp), %rax
movl %ecx, 0x20(%rax)
jmp 0x36e2a
movq 0x8(%rsp), %r14
testq %r14, %r14
movq (%rsp), %rbx
je 0x36e13
movq %r14, %rdi
callq 0x321b4
testq %rbx, %rbx
je 0x36e28
movq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x35120
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5765
jmp 0x36e0b
callq 0x579d
jmp 0x36e0b