// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bwt.c
// Function: bwt_occ4
void bwt_occ4(const bwt_t *bwt, bwtint_t k, bwtint_t cnt[VALUE_DOMAIN])
{
	uint32_t *p, *end;

	// If K is set to max, set counts to 0
	if (k == (bwtint_t)(-1)) {
		memset(cnt, 0, VALUE_DOMAIN * sizeof(bwtint_t));
		return;
	}

	k -= (k >= bwt->primary); // because $ is not in bwt

	// Copy current occurrence interval
	p = getOccInterval(bwt, k);
	memcpy(cnt, p, VALUE_DOMAIN * sizeof(bwtint_t));

	// Loop from end of interval to K in unpacked space
	p += sizeof(bwtint_t) / sizeof(uint32_t) * VALUE_DOMAIN;
	end = p + (((k / 16) - ((k&~OCC_INTV_MASK) / 16)) * 4) + ((k % 16) - (k % 4))/4;
	int supercount = 0;

	for (; p < end; ++p) {
		cnt[unpackBWTValue(bwt, k/128*128 + supercount)]++;
		cnt[unpackBWTValue(bwt, k/128*128 + supercount+1)]++;
		cnt[unpackBWTValue(bwt, k/128*128 + supercount+2)]++;
		cnt[unpackBWTValue(bwt, k/128*128 + supercount+3)]++;
		supercount+=4;
	}

	int testIdx;

	for (testIdx = 0 ; testIdx < (k % 4) + 1 ; testIdx++) {
		cnt[unpackBWTValue(bwt, k/128*128 + supercount++)]++;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $-0x1, -0x10(%rbp)
jne 0x14110
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x3130
jmp 0x14332
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
setae %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x13be0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x3250
movq -0x20(%rbp), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
shrq $0x4, %rcx
movq -0x10(%rbp), %rdx
andq $-0x80, %rdx
shrq $0x4, %rdx
subq %rdx, %rcx
shlq $0x2, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
andq $0xf, %rcx
movq -0x10(%rbp), %rdx
andq $0x3, %rdx
subq %rdx, %rcx
shrq $0x2, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x142c9
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
shrq $0x7, %rsi
shlq $0x7, %rsi
movslq -0x2c(%rbp), %rax
addq %rax, %rsi
callq 0x13c30
movb %al, %cl
movq -0x50(%rbp), %rax
movzbl %cl, %ecx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
shrq $0x7, %rsi
shlq $0x7, %rsi
movslq -0x2c(%rbp), %rax
addq %rax, %rsi
addq $0x1, %rsi
callq 0x13c30
movb %al, %cl
movq -0x48(%rbp), %rax
movzbl %cl, %ecx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
shrq $0x7, %rsi
shlq $0x7, %rsi
movslq -0x2c(%rbp), %rax
addq %rax, %rsi
addq $0x2, %rsi
callq 0x13c30
movb %al, %cl
movq -0x40(%rbp), %rax
movzbl %cl, %ecx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
shrq $0x7, %rsi
shlq $0x7, %rsi
movslq -0x2c(%rbp), %rax
addq %rax, %rsi
addq $0x3, %rsi
callq 0x13c30
movb %al, %cl
movq -0x38(%rbp), %rax
movzbl %cl, %ecx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
jmp 0x141b1
movl $0x0, -0x30(%rbp)
movslq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
andq $0x3, %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x14332
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
shrq $0x7, %rsi
shlq $0x7, %rsi
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
cltq
addq %rax, %rsi
callq 0x13c30
movb %al, %cl
movq -0x58(%rbp), %rax
movzbl %cl, %ecx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x142d0
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)