// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/cram/cram_io.c
// Function: load_ref_portion
static char *load_ref_portion(BGZF *fp, ref_entry *e,
                              hts_pos_t start, hts_pos_t end) {
    off_t offset, len;
    char *seq;

    if (end < start)
        end = start;

    /*
     * Compute locations in file. This is trivial for the MD5 files, but
     * is still necessary for the fasta variants.
     *
     * Note the offset here, as with faidx, has the assumption that white-
     * space (the diff between line_length and bases_per_line) only occurs
     * at the end of a line of text.
     */
    offset = e->line_length
        ? e->offset + (start-1)/e->bases_per_line * e->line_length +
          (start-1) % e->bases_per_line
        : start-1;

    len = (e->line_length
           ? e->offset + (end-1)/e->bases_per_line * e->line_length +
             (end-1) % e->bases_per_line
           : end-1) - offset + 1;

    if (bgzf_useek(fp, offset, SEEK_SET) < 0) {
        perror("bgzf_useek() on reference file");
        return NULL;
    }

    if (len == 0 || !(seq = malloc(len))) {
        return NULL;
    }

    if (len != bgzf_read(fp, seq, len)) {
        perror("bgzf_read() on reference file");
        free(seq);
        return NULL;
    }

    /* Strip white-space if required. */
    if (len != end-start+1) {
        hts_pos_t i, j;
        char *cp = seq;
        char *cp_to;

        // Copy up to the first white-space, and then repeatedly just copy
        // bases_per_line verbatim, and use the slow method to end again.
        //
        // This may seem excessive, but this code can be a significant
        // portion of total CRAM decode CPU time for shallow data sets.
        for (i = j = 0; i < len; i++) {
            if (!isspace_c(cp[i]))
                cp[j++] = cp[i] & ~0x20;
            else
                break;
        }
        while (i < len && isspace_c(cp[i]))
            i++;
        while (i < len - e->line_length) {
            hts_pos_t j_end = j + e->bases_per_line;
            while (j < j_end)
                cp[j++] = cp[i++] & ~0x20; // toupper equiv
            i += e->line_length - e->bases_per_line;
        }
        for (; i < len; i++) {
            if (!isspace_c(cp[i]))
                cp[j++] = cp[i] & ~0x20;
        }

        cp_to = cp+j;

        if (cp_to - seq != end-start+1) {
            hts_log_error("Malformed reference file");
            free(seq);
            return NULL;
        }
    } else {
        int i;
        for (i = 0; i < len; i++) {
            seq[i] = toupper_c(seq[i]);
        }
    }

    return seq;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %r13
cmpq %rdx, %rcx
cmovleq %rdx, %rbx
movslq 0x2c(%rsi), %rsi
testq %rsi, %rsi
je 0x41097
movq 0x20(%r12), %rdi
leaq -0x1(%rbp), %rax
movslq 0x28(%r12), %r8
cqto
idivq %r8
movq %rax, %rcx
movq %rdx, %r14
leaq -0x1(%rbx), %rax
cqto
idivq %r8
movq %rdx, %r15
imulq %rsi, %rcx
addq %rdi, %r14
addq %rcx, %r14
imulq %rsi, %rax
addq %rdi, %r15
addq %rax, %r15
jmp 0x4109f
leaq -0x1(%rbp), %r14
leaq -0x1(%rbx), %r15
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0xc960
testl %eax, %eax
js 0x411e7
movq %r13, (%rsp)
subq %r14, %r15
movq %r15, %r13
incq %r13
je 0x411f3
movq %r13, %rdi
callq 0x4680
testq %rax, %rax
je 0x411f3
movq %rax, %r14
movq (%rsp), %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xab95
cmpq %rax, %r13
jne 0x41208
subq %rbp, %rbx
cmpq %rbx, %r15
jne 0x41119
xorl %ebx, %ebx
cmpq %rbx, %r15
jl 0x411f6
movsbl (%r14,%rbx), %edi
callq 0x466d1
movb %al, (%r14,%rbx)
incq %rbx
jmp 0x410fd
incq %rbx
movq %rbx, (%rsp)
xorl %ebp, %ebp
cmpq %r15, %rbp
jg 0x41143
movb (%r14,%rbp), %bl
movsbl %bl, %edi
callq 0x466b8
testl %eax, %eax
jne 0x41143
andb $-0x21, %bl
movb %bl, (%r14,%rbp)
incq %rbp
jmp 0x41122
movq %rbp, %rbx
cmpq %r15, %rbx
jg 0x4115e
movsbl (%r14,%rbx), %edi
callq 0x466b8
testl %eax, %eax
je 0x4115e
incq %rbx
jmp 0x41146
movslq 0x2c(%r12), %rax
subq %rax, %r13
cmpq %r13, %rbx
jge 0x411ba
movslq 0x28(%r12), %rcx
movq %rcx, %rdx
addq %rbp, %rdx
cmpq %rdx, %rbp
jge 0x4118f
movb (%r14,%rbx), %sil
incq %rbx
andb $-0x21, %sil
movb %sil, (%r14,%rbp)
incq %rbp
jmp 0x41176
movl %eax, %edx
subl %ecx, %edx
movslq %edx, %rcx
addq %rcx, %rbx
jmp 0x41166
movb (%r14,%rbx), %r12b
movsbl %r12b, %edi
callq 0x466b8
testl %eax, %eax
jne 0x411b7
andb $-0x21, %r12b
movb %r12b, (%r14,%rbp)
incq %rbp
incq %rbx
cmpq %r15, %rbx
jle 0x4119b
cmpq (%rsp), %rbp
je 0x411f6
leaq 0x3c25f(%rip), %rsi     # 0x7d42b
leaq 0x3c269(%rip), %rdx     # 0x7d43c
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
movq %r14, %rdi
callq 0x45c0
jmp 0x411f3
leaq 0x3c200(%rip), %rdi     # 0x7d3ee
callq 0x43d0
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3c1fe(%rip), %rdi     # 0x7d40d
callq 0x43d0
jmp 0x411dd