// File: /workspace/github_cpp_makefile_star2_O3/BenLangmead[P]bowtie/./diff_sample.h
// Function: DifferenceCoverSample<SString<char>>::buildSPrime(EList<unsigned int, 128>&, unsigned long)
void DifferenceCoverSample<TStr>::buildSPrime(
	EList<TIndexOffU>& sPrime,
	size_t padding)
{
	const TStr& t = this->text();
	const EList<uint32_t>& ds = this->ds();
	TIndexOffU tlen = (TIndexOffU)t.length();
	uint32_t v = this->v();
	uint32_t d = this->d();
	assert_gt(v, 2);
	assert_lt(d, v);
	// Record where each d section should begin in sPrime
	TIndexOffU tlenDivV = this->divv(tlen);
	uint32_t tlenModV = this->modv(tlen);
	TIndexOffU sPrimeSz = 0;
	assert(_doffs.empty());
	_doffs.resize(d+1);
	for(uint32_t di = 0; di < d; di++) {
		// mu mapping
		TIndexOffU sz = tlenDivV + ((ds[di] <= tlenModV) ? 1 : 0);
		assert_geq(sz, 0);
		_doffs[di] = sPrimeSz;
		sPrimeSz += sz;
	}
	_doffs[d] = sPrimeSz;
#ifndef NDEBUG
	if(tlenDivV > 0) {
		for(size_t i = 0; i < d; i++) {
			assert_gt(_doffs[i+1], _doffs[i]);
			TIndexOffU diff = _doffs[i+1] - _doffs[i];
			assert(diff == tlenDivV || diff == tlenDivV+1);
		}
	}
#endif
	assert_eq(_doffs.size(), d+1);
	// Size sPrime appropriately
	sPrime.resizeExact((size_t)sPrimeSz + padding);
	sPrime.fill(OFF_MASK);
	// Slot suffixes from text into sPrime according to the mu
	// mapping; where the mapping would leave a blank, insert a 0
	TIndexOffU added = 0;
	TIndexOffU i = 0;
	for(uint64_t ti = 0; ti <= tlen; ti += v) {
		for(uint32_t di = 0; di < d; di++) {
			TIndexOffU tti = (TIndexOffU)(ti + ds[di]);
			if(tti > tlen) break;
			TIndexOffU spi = _doffs[di] + i;
			assert_lt(spi, _doffs[di+1]);
			assert_leq(tti, tlen);
			assert_lt(spi, sPrimeSz);
			assert_eq(OFF_MASK, sPrime[spi]);
			sPrime[spi] = tti; added++;
		}
		i++;
	}
	assert_eq(added, sPrimeSz);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, 0x8(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %rax
movq 0x18(%rax), %r12
movl 0x8(%rdi), %eax
movq %rax, 0x10(%rsp)
movb 0xb8(%rdi), %cl
movl %r12d, %r13d
shrl %cl, %r13d
movl 0x50(%rdi), %r15d
movl 0xbc(%rdi), %ebp
addq $0x58, %rdi
leal 0x1(%r15), %esi
callq 0x19fa4
testq %r15, %r15
je 0x1cbcd
notl %ebp
andl %r12d, %ebp
xorl %ecx, %ecx
xorl %eax, %eax
movq 0x18(%r14), %rdx
cmpl (%rdx,%rcx,4), %ebp
movq 0x60(%r14), %rdx
movl %eax, (%rdx,%rcx,4)
leal (%rax,%r13), %eax
sbbl $-0x1, %eax
incq %rcx
cmpq %rcx, %r15
jne 0x1cbab
movq %r15, %rbp
jmp 0x1cbd1
xorl %ebp, %ebp
xorl %eax, %eax
movl %r12d, %r13d
movq 0x60(%r14), %rcx
movl %eax, (%rcx,%rbp,4)
movl %eax, %esi
addq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1ca80
cmpq $0x0, 0x18(%rbx)
je 0x1cc07
xorl %eax, %eax
movq 0x8(%rbx), %rcx
movl $0xffffffff, (%rcx,%rax,4) # imm = 0xFFFFFFFF
incq %rax
cmpq 0x18(%rbx), %rax
jb 0x1cbf3
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x10(%rsp), %r9
testq %r15, %r15
je 0x1cc3e
xorl %edx, %edx
movq 0x18(%r14), %rsi
movl (%rsi,%rdx,4), %esi
addl %eax, %esi
cmpl %r12d, %esi
ja 0x1cc3e
movq 0x60(%r14), %rdi
movl (%rdi,%rdx,4), %edi
addl %ecx, %edi
movq 0x8(%rbx), %r8
movl %esi, (%r8,%rdi,4)
incq %rdx
cmpq %rdx, %rbp
jne 0x1cc17
incl %ecx
addq %r9, %rax
cmpq %r13, %rax
jbe 0x1cc10
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq