// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: load_ref_portion
static char *load_ref_portion(BGZF *fp, ref_entry *e, int start, int 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.
     */
    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) {
	int i, j;
	char *cp = seq;
	char *cp_to;

	for (i = j = 0; i < len; i++) {
	    if (cp[i] >= '!' && cp[i] <= '~')
		cp[j++] = toupper_c(cp[i]);
	}
	cp_to = cp+j;

	if (cp_to - seq != end-start+1) {
	    fprintf(stderr, "Malformed reference file?\n");
	    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
movl %ecx, %ebx
movl %edx, %r15d
movq %rdi, %r13
cmpl %edx, %ecx
cmovlel %edx, %ebx
movl 0x24(%rsi), %ecx
testl %ecx, %ecx
je 0x34622
leal -0x1(%r15), %eax
cltd
idivl 0x20(%rsi)
movl %edx, %r14d
imull %ecx, %eax
cltq
addq 0x18(%rsi), %rax
addq %rax, %r14
jmp 0x34626
leal -0x1(%r15), %r14d
testl %ecx, %ecx
je 0x34641
leal -0x1(%rbx), %eax
cltd
idivl 0x20(%rsi)
movl %edx, %ebp
imull %ecx, %eax
cltq
addq 0x18(%rsi), %rax
addq %rax, %rbp
jmp 0x34644
leal -0x1(%rbx), %ebp
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x45d91
testl %eax, %eax
js 0x3470f
subq %r14, %rbp
movq %rbp, %r12
incq %r12
je 0x34731
movq %r12, %rdi
callq 0x4700
testq %rax, %rax
je 0x34731
movq %rax, %r14
movq %r13, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x4489c
cmpq %rax, %r12
jne 0x3471d
subl %r15d, %ebx
incl %ebx
movslq %ebx, %rax
cmpq %rax, %r12
jne 0x346c9
testq %rbp, %rbp
js 0x34734
xorl %ebx, %ebx
callq 0x40c0
movzbl (%r14,%rbx), %ecx
movq (%rax), %rdx
movb (%rdx,%rcx,4), %cl
movb %cl, (%r14,%rbx)
incq %rbx
cmpq %rbx, %r12
jne 0x346b0
jmp 0x34734
testq %rbp, %rbp
js 0x346ff
xorl %r15d, %r15d
xorl %ebp, %ebp
movzbl (%r14,%r15), %r13d
leal -0x7f(%r13), %eax
cmpb $-0x5e, %al
jb 0x346f5
callq 0x40c0
movq (%rax), %rax
movb (%rax,%r13,4), %al
movslq %ebp, %rcx
incl %ebp
movb %al, (%r14,%rcx)
incq %r15
cmpq %r15, %r12
jne 0x346d3
jmp 0x34701
xorl %ebp, %ebp
cmpl %ebx, %ebp
je 0x34734
movq %r14, %rdi
callq 0x5705
jmp 0x34731
leaq 0x206f7(%rip), %rdi     # 0x54e0d
callq 0x4440
jmp 0x34731
leaq 0x20708(%rip), %rdi     # 0x54e2c
callq 0x4440
movq %r14, %rdi
callq 0x4610
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq