// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x494e7
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0x49541
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movq -0x18(%rbp), %rcx
cltd
idivl 0x20(%rcx)
movl %eax, %ecx
movq -0x70(%rbp), %rax
movq -0x18(%rbp), %rdx
imull 0x24(%rdx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movq -0x18(%rbp), %rcx
cltd
idivl 0x20(%rcx)
movq -0x68(%rbp), %rax
movslq %edx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
jmp 0x4954d
movl -0x1c(%rbp), %eax
subl $0x1, %eax
cltq
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0x495b5
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x88(%rbp)
movl -0x20(%rbp), %eax
subl $0x1, %eax
movq -0x18(%rbp), %rcx
cltd
idivl 0x20(%rcx)
movl %eax, %ecx
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rdx
imull 0x24(%rdx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl -0x20(%rbp), %eax
subl $0x1, %eax
movq -0x18(%rbp), %rcx
cltd
idivl 0x20(%rcx)
movq -0x80(%rbp), %rax
movslq %edx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
jmp 0x495c1
movl -0x20(%rbp), %eax
subl $0x1, %eax
cltq
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
subq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x66c20
cmpl $0x0, %eax
jge 0x495fe
leaq 0x33c0c(%rip), %rdi     # 0x7d1f8
callq 0x4480
movq $0x0, -0x8(%rbp)
jmp 0x4979e
cmpq $0x0, -0x30(%rbp)
je 0x49618
movq -0x30(%rbp), %rdi
callq 0x47a0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x49625
movq $0x0, -0x8(%rbp)
jmp 0x4979e
movq -0x30(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x64bb0
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
je 0x49672
leaq 0x33bc0(%rip), %rdi     # 0x7d217
callq 0x4480
movq -0x38(%rbp), %rdi
callq 0x46a0
movq $0x0, -0x8(%rbp)
jmp 0x4979e
movq -0x30(%rbp), %rax
movl -0x20(%rbp), %ecx
subl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x4975a
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x49702
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x21, %eax
jl 0x496f5
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7e, %eax
jg 0x496f5
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x543d0
movb %al, %dl
movq -0x48(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x40(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x496f7
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x496a1
movq -0x48(%rbp), %rax
movslq -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movl -0x20(%rbp), %ecx
subl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x49758
movq 0x4089c(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
leaq 0x33af7(%rip), %rsi     # 0x7d235
movb $0x0, %al
callq 0x4830
movq -0x38(%rbp), %rdi
callq 0x46a0
movq $0x0, -0x8(%rbp)
jmp 0x4979e
jmp 0x49796
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x49794
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x543d0
movb %al, %dl
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x49761
jmp 0x49796
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)