// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bwtindex.c
// Function: bwt_bwtupdate_core
void bwt_bwtupdate_core(bwt_t *bwt) {
	int64_t i, k, counts[VALUE_DOMAIN], n_occ;
	uint32_t * bwtBuf;

	// Initialize counts array
	memset(counts, 0, sizeof(counts));

	// Adjust the FM-Index size by the number of interleaved occurrence counts
	n_occ = (bwt->seq_len + OCC_INTERVAL - 1) / OCC_INTERVAL + 1;
	bwt->bwt_size += n_occ * sizeof(bwtint_t) / sizeof(uint32_t) * VALUE_DOMAIN;
	bwtBuf = (uint32_t*)calloc(bwt->bwt_size, sizeof(uint32_t));

	// Iterate through each packed value in the current FM-Index
	for (i = k = 0; i < bwt->seq_len; ++i) {
		// For each occurrence interval, insert the number of running occurrences
		if (i % OCC_INTERVAL == 0) {
			memcpy(bwtBuf + k, counts, sizeof(bwtint_t) * VALUE_DOMAIN);
			k += sizeof(bwtint_t) / sizeof(uint32_t) * VALUE_DOMAIN;
		}

		// Copy packed value
		if (i % 4 == 0) bwtBuf[k++] = bwt->bwt[i/4];

		// Unpack and record current occurrence
		++counts[unpackValue(bwt, i)];
	}

	// Record last element
	memcpy(bwtBuf + k, counts, sizeof(bwtint_t) * VALUE_DOMAIN);
	xassert(k + sizeof(bwtint_t) / sizeof(uint32_t) * VALUE_DOMAIN == bwt->bwt_size, "inconsistent bwt_size");

	// Update FM-Index
	free(bwt->bwt);
	bwt->bwt = bwtBuf;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
leaq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x3130
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
addq $0x80, %rax
subq $0x1, %rax
shrq $0x7, %rax
addq $0x1, %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rcx
shlq $0x3, %rcx
shrq $0x2, %rcx
shlq $0x5, %rcx
movq -0x8(%rbp), %rax
addq 0x118(%rax), %rcx
movq %rcx, 0x118(%rax)
movq -0x8(%rbp), %rax
movq 0x118(%rax), %rdi
movl $0x4, %esi
leaq 0x31dc2(%rip), %rdx     # 0x370d4
movl $0xc2, %ecx
leaq 0x31df8(%rip), %r8      # 0x37116
callq 0x31bf0
movq %rax, -0x130(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x110(%rcx), %rax
jae 0x5421
movq -0x10(%rbp), %rax
movl $0x80, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x5392
movq -0x130(%rbp), %rdi
movq -0x18(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
leaq -0x120(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x3250
movq -0x18(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl $0x4, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x53ec
movq -0x8(%rbp), %rax
movq 0x120(%rax), %rax
movq %rax, -0x138(%rbp)
movq -0x10(%rbp), %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x138(%rbp), %rax
movl (%rax,%rcx,4), %edx
movq -0x130(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x18(%rbp)
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4e90
movzbl %al, %eax
movq -0x120(%rbp,%rax,8), %rcx
addq $0x1, %rcx
movq %rcx, -0x120(%rbp,%rax,8)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x533a
movq -0x130(%rbp), %rdi
movq -0x18(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
leaq -0x120(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x3250
movq -0x18(%rbp), %rax
addq $0x40, %rax
movq -0x8(%rbp), %rcx
cmpq 0x118(%rcx), %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5477
leaq 0x31cab(%rip), %rdi     # 0x37116
leaq 0x31cb7(%rip), %rsi     # 0x37129
callq 0x12bd0
movq -0x8(%rbp), %rax
movq 0x120(%rax), %rdi
callq 0x3380
movq -0x130(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x120(%rax)
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)