// File: /workspace/github_c_makefile_star2_O1/samtools[P]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->slice->curr_rec < c->slice->max_rec) {
            s = c->slice;
        } else {
            if (!(s = cram_next_slice(fd, &c)))
                return NULL;
            continue; /* In case slice contains no records */
        }

        // No need to lock here as get_seq is running in the main thread,
        // which is also the same one that does the range modifications.
        if (fd->range.refid != -2) {
            if (fd->range.refid == -1 && s->crecs[s->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
                s->curr_rec++;
                continue;
            }
            if (s->crecs[s->curr_rec].ref_id < fd->range.refid &&
                s->crecs[s->curr_rec].ref_id != -1) {
                // Looking for a mapped read, but not there yet.  Special case
                // as -1 (unmapped) shouldn't be considered < refid.
                s->curr_rec++;
                continue;
            }

            if (s->crecs[s->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[s->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[s->curr_rec].aend < fd->range.start) {
                s->curr_rec++;
                continue;
            }
        }

        break;
    }

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

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movq %rsp, %r15
xorl %ebx, %ebx
movq 0x38(%r14), %r12
movq %r12, (%rsp)
testq %r12, %r12
je 0x40177
movq 0x90(%r12), %rdi
testq %rdi, %rdi
je 0x40177
movslq 0xe4(%rdi), %rax
cmpl 0xe0(%rdi), %eax
jge 0x40177
movl 0x258(%r14), %ecx
cmpl $-0x1, %ecx
je 0x4018c
cmpl $-0x2, %ecx
jne 0x4019f
jmp 0x40200
movq %r14, %rdi
movq %r15, %rsi
callq 0x3f9cb
testq %rax, %rax
jne 0x40138
jmp 0x40235
movq 0x30(%rdi), %rdx
leaq (%rax,%rax,8), %rsi
shlq $0x4, %rsi
cmpl $-0x1, 0x8(%rdx,%rsi)
jne 0x401f3
movq 0x30(%rdi), %rdx
leaq (%rax,%rax,8), %rsi
shlq $0x4, %rsi
movl 0x8(%rdx,%rsi), %r8d
cmpl %ecx, %r8d
setl %r9b
cmpl $-0x1, %r8d
setne %r8b
testb %r8b, %r9b
jne 0x401f3
cmpl %ecx, 0x8(%rdx,%rsi)
jne 0x40217
cmpl $-0x1, %ecx
je 0x40200
leaq (%rdx,%rsi), %r8
movq 0x18(%r8), %r8
cmpq 0x268(%r14), %r8
jg 0x40217
cmpl $-0x1, %ecx
je 0x40200
movq 0x78(%rdx,%rsi), %rcx
cmpq 0x260(%r14), %rcx
jge 0x40200
incl %eax
movl %eax, 0xe4(%rdi)
jmp 0x40138
leal 0x1(%rax), %ecx
movl %ecx, 0xe4(%rdi)
leaq (%rax,%rax,8), %rbx
shlq $0x4, %rbx
addq 0x30(%rdi), %rbx
jmp 0x40235
movl $0x1, 0x8890(%r14)
callq 0x52c5d
movq $0x0, 0x90(%r12)
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq