// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq %rdi, %r15
callq 0x32631
movq %rax, %r14
movl $0x1, %edi
movl $0x100, %esi            # imm = 0x100
callq 0x4360
movq %rax, %rbx
movq %r14, (%rsp)
testq %r14, %r14
sete %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x37c26
movq (%rsp), %rsi
movq %rsi, 0x8(%rbx)
movl 0x8(%rsi), %edi
movl %edi, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x37b22
movq %r15, %rdi
callq 0x1f022
movq %rax, (%rbx)
testq %rax, %rax
je 0x37c26
movl 0x20(%rax), %r12d
testl %r12d, %r12d
jle 0x37b6e
movl $0x8, %esi
movq %r12, %rdi
callq 0x4360
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x37c26
xorl %r14d, %r14d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movq %r15, %rdi
callq 0x32631
movq 0x10(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
testq %rax, %rax
je 0x37c26
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rax
cmpl $0x4, 0x8(%rax)
jne 0x37a89
movl 0xc(%rax), %eax
cmpl %eax, %r13d
cmovlel %eax, %r13d
cmpl %eax, %ebp
cmovgel %eax, %ebp
incq %r14
cmpq %r14, %r12
jne 0x37a53
testl %ebp, %ebp
js 0x37aeb
cmpl $0x3ff, %r13d           # imm = 0x3FF
jg 0x37aeb
movl $0x400, %edi            # imm = 0x400
movl $0x8, %esi
callq 0x4360
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x37c26
cmpl $0x2, %r12d
movl $0x1, %eax
cmovgel %r12d, %eax
xorl %ecx, %ecx
movq 0x10(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
cmpl $0x4, 0x8(%rdx)
jne 0x37ae3
movq 0x18(%rbx), %rsi
movslq 0xc(%rdx), %rdi
movq %rdx, (%rsi,%rdi,8)
incq %rcx
cmpq %rcx, %rax
jne 0x37ac9
movl $0x40, %edi
callq 0x4700
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
testq %rax, %rax
je 0x37b2c
movaps 0x1cd18(%rip), %xmm1    # 0x54820
movups %xmm1, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movq %rcx, 0x30(%rax)
movl $0x7, 0x38(%rax)
jmp 0x37b2e
callq 0x581e
jmp 0x37c26
xorl %eax, %eax
movq %rax, 0x68(%rbx)
testq %rax, %rax
je 0x37c26
movl $0x40, %edi
callq 0x4700
testq %rax, %rax
je 0x37b78
movaps 0x1ccdf(%rip), %xmm0    # 0x54830
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)
jmp 0x37b7a
callq 0x5853
jmp 0x37c26
xorl %eax, %eax
movq %rax, 0x70(%rbx)
testq %rax, %rax
je 0x37c26
movl $0x40, %edi
callq 0x4700
testq %rax, %rax
je 0x37bba
movaps 0x1cca3(%rip), %xmm0    # 0x54840
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)
jmp 0x37bbc
xorl %eax, %eax
movq %rax, 0x60(%rbx)
testq %rax, %rax
je 0x37c26
movl $0x4, %edi
movl $0x1, %esi
callq 0x325ef
movq %rax, 0x88(%rbx)
testq %rax, %rax
je 0x37c26
movl $0x4, %edi
movl $0xd, %esi
callq 0x325ef
movq %rax, 0x78(%rbx)
testq %rax, %rax
je 0x37c26
movl $0x4, %edi
movl $0xe, %esi
callq 0x325ef
movq %rax, 0x80(%rbx)
testq %rax, %rax
je 0x37c26
movq $0x0, 0x28(%rbx)
movq (%rbx), %rax
movl 0x8(%rax), %eax
movl %eax, 0x20(%rbx)
jmp 0x37c4b
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x37c34
callq 0x32ea8
testq %rbx, %rbx
je 0x37c49
movq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x35ef7
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq