// File: karel-brinda[P]ococo/ext/htslib/cram/cram_decode.c
// Function: cram_get_seq
cram_record *cram_get_seq(cram_fd *fd) {
    cram_container *c;
    cram_slice *s;

    for (;;) {
	c = fd->ctr;
	if (c && c->slice && c->curr_rec < c->max_rec) {
	    s = c->slice;
	} else {
	    if (!(s = cram_next_slice(fd, &c)))
		return NULL;
	    continue; /* In case slice contains no records */
	}

	if (fd->range.refid != -2) {
	    if (fd->range.refid == -1 && s->crecs[c->curr_rec].ref_id != -1) {
		// Special case when looking for unmapped blocks at end.
		// If these are mixed in with mapped data (c->ref_id == -2)
		// then we need skip until we find the unmapped data, if at all
		c->curr_rec++;
		continue;
	    }
	    if (s->crecs[c->curr_rec].ref_id < fd->range.refid &&
		s->crecs[c->curr_rec].ref_id != -1) {
		// Looking for a mapped read, but not there yet.  Special case
		// as -1 (unmapped) shouldn't be considered < refid.
		c->curr_rec++;
		continue;
	    }

	    if (s->crecs[c->curr_rec].ref_id != fd->range.refid) {
		fd->eof = 1;
		cram_free_slice(s);
		c->slice = NULL;
		return NULL;
	    }

	    if (fd->range.refid != -1 && s->crecs[c->curr_rec].apos > fd->range.end) {
		fd->eof = 1;
		cram_free_slice(s);
		c->slice = NULL;
		return NULL;
	    }

	    if (fd->range.refid != -1 && s->crecs[c->curr_rec].aend < fd->range.start) {
		c->curr_rec++;
		continue;
	    }
	}

	break;
    }

    fd->ctr = c;
    c->slice = s;
    return &s->crecs[c->curr_rec++];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x2df3e
movq -0x18(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x2df3e
movq -0x18(%rbp), %rax
movl 0x5c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jge 0x2df3e
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x2df64
movq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x2e160
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x2df62
movq $0x0, -0x8(%rbp)
jmp 0x2e14e
jmp 0x2defc
movq -0x10(%rbp), %rax
cmpl $-0x2, 0x228(%rax)
je 0x2e10c
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x228(%rax)
jne 0x2dfb1
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x5c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x8(%rax)
je 0x2dfb1
movq -0x18(%rbp), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x2defc
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x5c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x228(%rcx), %eax
jge 0x2e006
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x5c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x8(%rax)
je 0x2e006
movq -0x18(%rbp), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x2defc
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x5c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x228(%rcx), %eax
je 0x2e05f
movq -0x10(%rbp), %rax
movl $0x1, 0x8848(%rax)
movq -0x20(%rbp), %rdi
callq 0x4b920
movq -0x18(%rbp), %rax
movq $0x0, 0x80(%rax)
movq $0x0, -0x8(%rbp)
jmp 0x2e14e
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x228(%rax)
je 0x2e0c5
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x5c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x230(%rcx), %eax
jle 0x2e0c5
movq -0x10(%rbp), %rax
movl $0x1, 0x8848(%rax)
movq -0x20(%rbp), %rdi
callq 0x4b920
movq -0x18(%rbp), %rax
movq $0x0, 0x80(%rax)
movq $0x0, -0x8(%rbp)
jmp 0x2e14e
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x228(%rax)
je 0x2e10a
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x5c(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x5c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x22c(%rcx), %eax
jge 0x2e10a
movq -0x18(%rbp), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x2defc
jmp 0x2e10c
jmp 0x2e10e
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rdx
movl 0x5c(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x5c(%rdx)
movslq %ecx, %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)