// File: /workspace/github_cpp_makefile_star2_O1/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, %r15d
shrl %cl, %r15d
movl 0x50(%rdi), %ebp
movl 0xbc(%rdi), %r13d
addq $0x58, %rdi
leal 0x1(%rbp), %esi
callq 0x1a064
testq %rbp, %rbp
je 0x1cd25
notl %r13d
andl %r12d, %r13d
xorl %eax, %eax
xorl %edx, %edx
movq 0x18(%r14), %rsi
movq 0x60(%r14), %rdi
leal (%rdx,%r15), %ecx
cmpl (%rsi,%rax,4), %r13d
sbbl $-0x1, %ecx
movl %edx, (%rdi,%rax,4)
incq %rax
movl %ecx, %edx
cmpq %rax, %rbp
jne 0x1cd03
jmp 0x1cd27
xorl %ecx, %ecx
movl %r12d, %r15d
movq 0x60(%r14), %rax
movl %ecx, (%rax,%rbp,4)
movl %ecx, %esi
addq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1cbe2
cmpq $0x0, 0x18(%rbx)
je 0x1cd5d
xorl %eax, %eax
movq 0x8(%rbx), %rcx
movl $0xffffffff, (%rcx,%rax,4) # imm = 0xFFFFFFFF
incq %rax
cmpq 0x18(%rbx), %rax
jb 0x1cd49
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x10(%rsp), %r9
testl %ebp, %ebp
je 0x1cd97
xorl %edx, %edx
movq 0x18(%r14), %rsi
movl (%rsi,%rdx,4), %esi
addl %eax, %esi
cmpl %r12d, %esi
ja 0x1cd8b
movq 0x60(%r14), %rdi
movl (%rdi,%rdx,4), %edi
addl %ecx, %edi
movq 0x8(%rbx), %r8
movl %esi, (%r8,%rdi,4)
cmpl %r12d, %esi
ja 0x1cd97
incq %rdx
cmpl %ebp, %edx
jb 0x1cd6c
incl %ecx
addq %r9, %rax
cmpq %r15, %rax
jbe 0x1cd66
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq