// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bwt.c
// Function: bwt_cal_sa
void bwt_cal_sa(bwt_t *bwt, int intv) {
	bwtint_t isa, sa, i; // S(isa) = sa
	int intv_round = intv;

	// Sanity checking
	kv_roundup32(intv_round);
	xassert(intv_round == intv, "SA sample interval is not a power of 2.");
	xassert(bwt->bwt, "bwt_t::bwt is not initialized.");

	// Initialize Suffix Array
	if (bwt->sa) free(bwt->sa);
	bwt->sa_intv = intv;
	bwt->n_sa = (bwt->seq_len + intv) / intv;
	bwt->sa = (bwtint_t*)calloc(bwt->n_sa, sizeof(bwtint_t));

	// Calculate Suffix Array Value
	isa = 0; sa = bwt->seq_len;
	for (i = 0; i < bwt->seq_len; ++i) {
		if (isa % intv == 0) bwt->sa[isa/intv] = sa;
		--sa;
		isa = bwt_invPsi(bwt, isa);
	}
	if (isa % intv == 0) bwt->sa[isa/intv] = sa;

	// SA[0] is currently set to sequence length - set to maximum value
	bwt->sa[0] = (bwtint_t)-1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
sarl %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
sarl $0x2, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
sarl $0x4, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
sarl $0x8, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
sarl $0x10, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x13d98
leaq 0x26267(%rip), %rdi     # 0x39ff3
leaq 0x2626b(%rip), %rsi     # 0x39ffe
callq 0x12bd0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x120(%rax)
jne 0x13db9
leaq 0x26246(%rip), %rdi     # 0x39ff3
leaq 0x26272(%rip), %rsi     # 0x3a026
callq 0x12bd0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x138(%rax)
je 0x13dd7
movq -0x8(%rbp), %rax
movq 0x138(%rax), %rdi
callq 0x3380
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x128(%rax)
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
movslq -0xc(%rbp), %rcx
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x130(%rax)
movq -0x8(%rbp), %rax
movq 0x130(%rax), %rdi
movl $0x8, %esi
leaq 0x26221(%rip), %rdx     # 0x3a045
movl $0x4a, %ecx
leaq 0x261c3(%rip), %r8      # 0x39ff3
callq 0x31bf0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x138(%rax)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x110(%rcx), %rax
jae 0x13ee7
movq -0x18(%rbp), %rax
movslq -0xc(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x13eb9
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x138(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movslq -0xc(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movq -0x40(%rbp), %rdx
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x13f50
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x13e62
movq -0x18(%rbp), %rax
movslq -0xc(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x13f2d
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x138(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movslq -0xc(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movq -0x50(%rbp), %rdx
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq 0x138(%rax), %rax
movq $-0x1, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)