// File: karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: sanitise_SQ_lines
static void sanitise_SQ_lines(cram_fd *fd) {
    int i;

    if (!fd->header)
	return;

    if (!fd->refs || !fd->refs->h_meta)
	return;

    for (i = 0; i < fd->header->nref; i++) {
	char *name = fd->header->ref[i].name;
	khint_t k = kh_get(refs, fd->refs->h_meta, name);
	ref_entry *r;

	// We may have @SQ lines which have no known .fai, but do not
	// in themselves pose a problem because they are unused in the file.
	if (k == kh_end(fd->refs->h_meta))
	    continue;

	if (!(r = (ref_entry *)kh_val(fd->refs->h_meta, k)))
	    continue;

	if (r->length && r->length != fd->header->ref[i].len) {
	    assert(strcmp(r->name, fd->header->ref[i].name) == 0);

	    // Should we also check MD5sums here to ensure the correct
	    // reference was given?
	    fprintf(stderr, "WARNING: Header @SQ length mismatch for "
		    "ref %s, %d vs %d\n",
		    r->name, fd->header->ref[i].len, (int)r->length);

	    // Fixing the parsed @SQ header will make MD:Z: strings work
	    // and also stop it producing N for the sequence.
	    fd->header->ref[i].len = r->length;
	}
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x4b08c
jmp 0x4b238
movq -0x8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x4b0a6
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x8(%rax)
jne 0x4b0ab
jmp 0x4b238
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl 0x38(%rcx), %eax
jge 0x4b238
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x40(%rax), %rax
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x48840
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rcx
movq 0x8(%rcx), %rcx
cmpl (%rcx), %eax
jne 0x4b114
jmp 0x4b22a
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x4b13a
jmp 0x4b22a
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x4b228
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x40(%rcx), %rcx
movslq -0xc(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
je 0x4b228
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x40(%rax), %rax
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x4810
cmpl $0x0, %eax
jne 0x4b1a1
jmp 0x4b1c0
leaq 0x32279(%rip), %rdi     # 0x7d421
leaq 0x31bb7(%rip), %rsi     # 0x7cd66
movl $0x790, %edx            # imm = 0x790
leaq 0x32294(%rip), %rcx     # 0x7d44f
callq 0x4360
movq 0x3ee09(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x40(%rax), %rax
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %r8d
leaq 0x32274(%rip), %rsi     # 0x7d471
movb $0x0, %al
callq 0x4830
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x40(%rax), %rax
movslq -0xc(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
jmp 0x4b22a
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x4b0b2
addq $0x30, %rsp
popq %rbp
retq
nop