// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/cram/cram_encode.c
// Function: cram_next_container
static cram_container *cram_next_container(cram_fd *fd, bam_seq_t *b) {
    cram_container *c = fd->ctr;
    cram_slice *s;
    int i;

    /* First occurence */
    if (c->curr_ref == -2)
	c->curr_ref = bam_ref(b);

    if (c->slice) {
	s = c->slice;
	if (c->multi_seq) {
	    s->hdr->ref_seq_id    = -2;
	    s->hdr->ref_seq_start = 0;
	    s->hdr->ref_seq_span  = 0;
	} else {
	    s->hdr->ref_seq_id    = c->curr_ref;
	    s->hdr->ref_seq_start = c->first_base;
	    s->hdr->ref_seq_span  = c->last_base - c->first_base + 1;
	}
	s->hdr->num_records   = c->curr_rec;

	if (c->curr_slice == 0) {
	    if (c->ref_seq_id != s->hdr->ref_seq_id)
		c->ref_seq_id  = s->hdr->ref_seq_id;
	    c->ref_seq_start = c->first_base;
	}

	c->curr_slice++;
    }

    /* Flush container */
    if (c->curr_slice == c->max_slice ||
	(bam_ref(b) != c->curr_ref && !c->multi_seq)) {
	c->ref_seq_span = fd->last_base - c->ref_seq_start + 1;
	if (fd->verbose)
	    fprintf(stderr, "Flush container %d/%d..%d\n",
		    c->ref_seq_id, c->ref_seq_start,
		    c->ref_seq_start + c->ref_seq_span -1);

	/* Encode slices */
	if (fd->pool) {
	    if (-1 == cram_flush_container_mt(fd, c))
		return NULL;
	} else {
	    if (-1 == cram_flush_container(fd, c))
		return NULL;

	    // Move to sep func, as we need cram_flush_container for
	    // the closing phase to flush the partial container.
	    for (i = 0; i < c->max_slice; i++) {
		cram_free_slice(c->slices[i]);
		c->slices[i] = NULL;
	    }

	    c->slice = NULL;
	    c->curr_slice = 0;

	    /* Easy approach for purposes of freeing stats */
	    cram_free_container(c);
	}

	c = fd->ctr = cram_new_container(fd->seqs_per_slice,
					 fd->slices_per_container);
	if (!c)
	    return NULL;
	c->record_counter = fd->record_counter;
	c->curr_ref = bam_ref(b);
    }

    c->last_pos = c->first_base = c->last_base = bam_pos(b)+1;

    /* New slice */
    c->slice = c->slices[c->curr_slice] =
	cram_new_slice(MAPPED_SLICE, c->max_rec);
    if (!c->slice)
	return NULL;

    if (c->multi_seq) {
	c->slice->hdr->ref_seq_id = -2;
	c->slice->hdr->ref_seq_start = 0;
	c->slice->last_apos = 1;
    } else {
	c->slice->hdr->ref_seq_id = bam_ref(b);
	// wrong for unsorted data, will fix during encoding.
	c->slice->hdr->ref_seq_start = bam_pos(b)+1;
	c->slice->last_apos = bam_pos(b)+1;
    }

    c->curr_rec = 0;

    return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $-0x2, 0x6c(%rax)
jne 0xc41d3
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0xc42d0
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x94(%rax)
je 0xc422d
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl $0xfffffffe, 0x4(%rax)  # imm = 0xFFFFFFFE
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0x8(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0xc(%rax)
jmp 0xc4273
movq -0x20(%rbp), %rax
movl 0x6c(%rax), %ecx
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
movl 0xa0(%rax), %ecx
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl 0xa4(%rax), %ecx
movq -0x20(%rbp), %rax
subl 0xa0(%rax), %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movl 0x5c(%rax), %ecx
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jne 0xc42c3
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x4(%rcx), %eax
je 0xc42b2
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
movl 0xa0(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl 0x54(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x54(%rax)
movq -0x20(%rbp), %rax
movl 0x54(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x50(%rcx), %eax
je 0xc4304
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
je 0xc4480
movq -0x20(%rbp), %rax
cmpl $0x0, 0x94(%rax)
jne 0xc4480
movq -0x10(%rbp), %rax
movl 0x44(%rax), %ecx
movq -0x20(%rbp), %rax
subl 0x8(%rax), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1fc(%rax)
je 0xc4363
movq 0x40ca0(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movl 0x8(%rax), %r8d
movq -0x20(%rbp), %rax
addl 0xc(%rax), %r8d
subl $0x1, %r8d
leaq 0x21409(%rip), %rsi     # 0xe5765
movb $0x0, %al
callq 0x6a80
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8860(%rax)
je 0xc439b
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x87970
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0xc4396
movq $0x0, -0x8(%rbp)
jmp 0xc459b
jmp 0xc442a
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x87760
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0xc43c0
movq $0x0, -0x8(%rbp)
jmp 0xc459b
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jge 0xc4407
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x83eb0
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xc43c7
movq -0x20(%rbp), %rax
movq $0x0, 0x80(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x54(%rax)
movq -0x20(%rbp), %rdi
callq 0x83b70
movq -0x10(%rbp), %rax
movl 0x200(%rax), %edi
movq -0x10(%rbp), %rax
movl 0x204(%rax), %esi
callq 0x838a0
movq -0x10(%rbp), %rcx
movq %rax, 0x38(%rcx)
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xc4463
movq $0x0, -0x8(%rbp)
jmp 0xc459b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xa4(%rax)
movq -0x20(%rbp), %rax
movl %ecx, 0xa0(%rax)
movq -0x20(%rbp), %rax
movl %ecx, 0x70(%rax)
movq -0x20(%rbp), %rax
movl 0x58(%rax), %esi
movl $0x2, %edi
callq 0x87c50
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x20(%rbp), %rdx
movslq 0x54(%rdx), %rdx
movq %rcx, (%rax,%rdx,8)
movq -0x20(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x80(%rax)
jne 0xc44f3
movq $0x0, -0x8(%rbp)
jmp 0xc459b
movq -0x20(%rbp), %rax
cmpl $0x0, 0x94(%rax)
je 0xc453e
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movq (%rax), %rax
movl $0xfffffffe, 0x4(%rax)  # imm = 0xFFFFFFFE
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movq (%rax), %rax
movl $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movl $0x1, 0x20(%rax)
jmp 0xc4588
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movq (%rax), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movq (%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movl %ecx, 0x20(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)