// File: /workspace/github_c_makefile_star2_O3/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 %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movq 0x38(%rbx), %r15
testq %r15, %r15
je 0x3e130
movq 0x90(%r15), %rdi
testq %rdi, %rdi
je 0x3e130
movslq 0xe4(%rdi), %rcx
cmpl 0xe0(%rdi), %ecx
jge 0x3e130
movl 0x258(%rbx), %edx
movq 0x30(%rdi), %rax
cmpl $-0x1, %edx
je 0x3e146
cmpl $-0x2, %edx
je 0x3e162
leaq (%rcx,%rcx,8), %rsi
shlq $0x4, %rsi
movl 0x8(%rax,%rsi), %r8d
cmpl %edx, %r8d
setl %r9b
cmpl $-0x1, %r8d
setne %r10b
testb %r10b, %r9b
jne 0x3e155
cmpl %edx, %r8d
jne 0x3e178
cmpl $-0x1, %edx
je 0x3e162
movq 0x18(%rax,%rsi), %rdx
cmpq 0x268(%rbx), %rdx
jg 0x3e178
movq 0x78(%rax,%rsi), %rdx
cmpq 0x260(%rbx), %rdx
jl 0x3e155
jmp 0x3e162
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3da2a
testq %rax, %rax
jne 0x3e0af
jmp 0x3e192
leaq (%rcx,%rcx,8), %rdx
shlq $0x4, %rdx
cmpl $-0x1, 0x8(%rax,%rdx)
je 0x3e162
incl %ecx
movl %ecx, 0xe4(%rdi)
jmp 0x3e0af
leal 0x1(%rcx), %edx
movl %edx, 0xe4(%rdi)
leaq (%rcx,%rcx,8), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
jmp 0x3e194
movl $0x1, 0x8890(%rbx)
callq 0x50127
movq $0x0, 0x90(%r15)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq