// File: karel-brinda[P]ococo/ext/htslib/cram/cram_index.c
// Function: cram_index_build_multiref
static int cram_index_build_multiref(cram_fd *fd,
				     cram_container *c,
				     cram_slice *s,
				     zfp *fp,
				     off_t cpos,
				     int32_t landmark,
				     int sz) {
    int i, ref = -2, ref_start = 0, ref_end;
    char buf[1024];

    if (0 != cram_decode_slice(fd, c, s, fd->header))
	return -1;

    ref_end = INT_MIN;
    for (i = 0; i < s->hdr->num_records; i++) {
	if (s->crecs[i].ref_id == ref) {
	    if (ref_end < s->crecs[i].aend)
		ref_end = s->crecs[i].aend;
	    continue;
	}

	if (ref != -2) {
	    sprintf(buf, "%d\t%d\t%d\t%"PRId64"\t%d\t%d\n",
		    ref, ref_start, ref_end - ref_start + 1,
		    (int64_t)cpos, landmark, sz);
	    zfputs(buf, fp);
	}

	ref = s->crecs[i].ref_id;
	ref_start = s->crecs[i].apos;
	ref_end = INT_MIN;
    }

    if (ref != -2) {
	sprintf(buf, "%d\t%d\t%d\t%"PRId64"\t%d\t%d\n",
		ref, ref_start, ref_end - ref_start + 1,
		(int64_t)cpos, landmark, sz);
	zfputs(buf, fp);
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x460, %rsp            # imm = 0x460
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl $0xfffffffe, -0x3c(%rbp) # imm = 0xFFFFFFFE
movl $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
callq 0x27920
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x42c81
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x42de4
movl $0x80000000, -0x44(%rbp) # imm = 0x80000000
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x10(%rcx), %eax
jge 0x42d8d
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x3c(%rbp), %eax
jne 0x42cf6
movl -0x44(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movslq -0x38(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x5c(%rcx), %eax
jge 0x42cf1
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x5c(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x42d7f
cmpl $-0x2, -0x3c(%rbp)
je 0x42d46
leaq -0x450(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
movl -0x44(%rbp), %r8d
subl -0x40(%rbp), %r8d
addl $0x1, %r8d
movq -0x30(%rbp), %r9
movl -0x34(%rbp), %r10d
movl 0x10(%rbp), %eax
leaq 0x39c0d(%rip), %rsi     # 0x7c934
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x4100
leaq -0x450(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x61b30
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x40(%rbp)
movl $0x80000000, -0x44(%rbp) # imm = 0x80000000
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x42c8f
cmpl $-0x2, -0x3c(%rbp)
je 0x42ddd
leaq -0x450(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
movl -0x44(%rbp), %r8d
subl -0x40(%rbp), %r8d
addl $0x1, %r8d
movq -0x30(%rbp), %r9
movl -0x34(%rbp), %r10d
movl 0x10(%rbp), %eax
leaq 0x39b76(%rip), %rsi     # 0x7c934
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x4100
leaq -0x450(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x61b30
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x460, %rsp            # imm = 0x460
popq %rbp
retq