// File: /workspace/github_cpp_makefile_star2_O2/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 0x27b4b
movq %rax, %rbx
pushq $0x1
popq %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x4370
movq %rbx, 0x8(%rsp)
testq %rbx, %rbx
sete %dl
movq %rax, (%rsp)
testq %rax, %rax
sete %cl
orb %dl, %cl
jne 0x2c5e2
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 0x2c61b
movq %r12, %rdi
movq %r14, %rsi
callq 0x17aa5
movq %rax, (%rbx)
testq %rax, %rax
je 0x2c5f0
movq %rax, %r15
movslq 0x20(%rax), %r13
testq %r13, %r13
jle 0x2c640
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x4370
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x2c5f0
movq %rax, %rbp
movq %r15, 0x10(%rsp)
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %ebx, %ebx
xorl %r15d, %r15d
cmpq %rbx, %r13
je 0x2c4ed
movq %r12, %rdi
callq 0x27b4b
movq %rax, (%rbp,%rbx,8)
testq %rax, %rax
je 0x2c5e2
cmpl $0x4, 0x8(%rax)
jne 0x2c4e8
movl 0xc(%rax), %eax
cmpl %eax, %r15d
cmovlel %eax, %r15d
cmpl %eax, %r14d
cmovgel %eax, %r14d
incq %rbx
jmp 0x2c4b6
testl %r14d, %r14d
movq (%rsp), %rbx
js 0x2c53c
cmpl $0x3ff, %r15d           # imm = 0x3FF
jg 0x2c53c
pushq $0x8
popq %rsi
movl $0x400, %edi            # imm = 0x400
callq 0x4370
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x2c5e2
xorl %ecx, %ecx
movq (%rsp), %rbx
cmpq %rcx, %r13
je 0x2c53c
movq (%rbp,%rcx,8), %rdx
cmpl $0x4, 0x8(%rdx)
jne 0x2c537
movslq 0xc(%rdx), %rsi
movq %rdx, (%rax,%rsi,8)
incq %rcx
jmp 0x2c51f
pushq $0x4
popq %rdi
xorl %esi, %esi
callq 0x27b0e
movq %rax, 0x68(%rbx)
testq %rax, %rax
je 0x2c5e2
pushq $0x4
popq %rdi
pushq $0xc
popq %rsi
callq 0x27b0e
movq (%rsp), %rcx
movq %rax, 0x70(%rcx)
testq %rax, %rax
je 0x2c5e2
pushq $0x4
popq %rdi
pushq $0xb
popq %rsi
callq 0x27b0e
movq (%rsp), %rcx
movq %rax, 0x60(%rcx)
testq %rax, %rax
je 0x2c5e2
pushq $0x4
popq %rdi
pushq $0x1
popq %rsi
callq 0x27b0e
movq (%rsp), %rcx
movq %rax, 0x88(%rcx)
testq %rax, %rax
je 0x2c5e2
pushq $0x4
popq %rdi
pushq $0xd
popq %rsi
callq 0x27b0e
movq (%rsp), %rcx
movq %rax, 0x78(%rcx)
testq %rax, %rax
je 0x2c5e2
pushq $0x4
popq %rdi
pushq $0xe
popq %rsi
callq 0x27b0e
movq (%rsp), %rcx
movq %rax, 0x80(%rcx)
testq %rax, %rax
je 0x2c5e2
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ecx
movq (%rsp), %rax
movl %ecx, 0x20(%rax)
jmp 0x2c60c
movq 0x8(%rsp), %r14
testq %r14, %r14
movq (%rsp), %rbx
je 0x2c5f8
movq %r14, %rdi
callq 0x28127
testq %rbx, %rbx
je 0x2c60a
andq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x2ab94
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2a9ae(%rip), %rax     # 0x56fd0
movq (%rax), %r15
callq 0x28d76
leaq 0x19608(%rip), %rsi     # 0x45c39
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4770
jmp 0x2c5f0
movq 0x2a989(%rip), %rax     # 0x56fd0
movq (%rax), %rcx
leaq 0x19605(%rip), %rdi     # 0x45c56
pushq $0x28
popq %rsi
pushq $0x1
popq %rdx
callq 0x4a20
jmp 0x2c5f0