// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x726bd
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x7272a
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq -0x18(%rbp), %rcx
movslq 0x28(%rcx), %rcx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rdx
movslq 0x2c(%rdx), %rdx
imulq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq -0x18(%rbp), %rcx
movslq 0x28(%rcx), %rcx
cqto
idivq %rcx
movq -0x80(%rbp), %rax
addq %rdx, %rax
movq %rax, -0x78(%rbp)
jmp 0x72736
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x727b4
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rax
subq $0x1, %rax
movq -0x18(%rbp), %rcx
movslq 0x28(%rcx), %rcx
cqto
idivq %rcx
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq -0x18(%rbp), %rdx
movslq 0x2c(%rdx), %rdx
imulq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
subq $0x1, %rax
movq -0x18(%rbp), %rcx
movslq 0x28(%rcx), %rcx
cqto
idivq %rcx
movq -0x98(%rbp), %rax
addq %rdx, %rax
movq %rax, -0x90(%rbp)
jmp 0x727c3
movq -0x28(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
subq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x11a20
cmpl $0x0, %eax
jge 0x72803
leaq 0x835d5(%rip), %rdi     # 0xf5dc6
callq 0x43c0
movq $0x0, -0x8(%rbp)
jmp 0x72aca
cmpq $0x0, -0x38(%rbp)
je 0x7281d
movq -0x38(%rbp), %rdi
callq 0x4650
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x7282a
movq $0x0, -0x8(%rbp)
jmp 0x72aca
movq -0x38(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0xe620
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
je 0x72877
leaq 0x83589(%rip), %rdi     # 0xf5de5
callq 0x43c0
movq -0x40(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x72aca
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
subq -0x20(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
je 0x72a86
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x72903
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x7c5e0
cmpl $0x0, %eax
jne 0x728f1
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
andl $-0x21, %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x728f3
jmp 0x72903
jmp 0x728f5
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x728a8
jmp 0x72905
movq -0x48(%rbp), %rcx
xorl %eax, %eax
cmpq -0x38(%rbp), %rcx
movb %al, -0xa9(%rbp)
jge 0x72934
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x7c5e0
cmpl $0x0, %eax
setne %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x72940
jmp 0x7294e
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x72905
jmp 0x72950
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rdx
movslq 0x2c(%rdx), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jge 0x729d6
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x28(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x68(%rbp), %rax
jge 0x729b9
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movsbl (%rax,%rcx), %eax
andl $-0x21, %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x7297b
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x28(%rcx), %eax
cltq
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x72950
jmp 0x729d8
movq -0x48(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x72a2f
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x7c5e0
cmpl $0x0, %eax
jne 0x72a1f
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
andl $-0x21, %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x72a21
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x729d8
movq -0x58(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movq -0x28(%rbp), %rcx
subq -0x20(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
je 0x72a84
movl $0x1, %edi
leaq 0x833a0(%rip), %rsi     # 0xf5e03
leaq 0x833aa(%rip), %rdx     # 0xf5e14
movb $0x0, %al
callq 0x1b030
movq -0x40(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x72aca
jmp 0x72ac2
movl $0x0, -0x6c(%rbp)
movslq -0x6c(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x72ac0
movq -0x40(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x7c610
movb %al, %dl
movq -0x40(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x72a8d
jmp 0x72ac2
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)