void test_bwt_generate_rotations() {
  char *original = "test";
  char **result = (char **)malloc(4 * sizeof(char *));
  char *storage = (char *)malloc((2 * strlen(original) + 1) * sizeof(char));
  strcpy(storage, original);
  strcat(storage, original);
  bwt_generate_rotations(storage, result, strlen(original));
  assert(!strncmp(result[0], "test", 4));
  assert(!strncmp(result[1], "estt", 4));
  assert(!strncmp(result[2], "stte", 4));
  assert(!strncmp(result[3], "ttes", 4));
  printf("\tGenerate rotations test passed\n");
  free(storage);
  free(result);
}


x86 assembly (clang, -O0):
<test_bwt_generate_rotations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe61(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    $0x20,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
shl    $0x1,%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
mov    $0x0,%al
call   10b0 <bwt_generate_rotations@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xddb(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb3(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd8b(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd63(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1080 <assert@plt>
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_bwt_generate_rotations>:
push   %r15
push   %r14
push   %rbx
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0x9,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
movl   $0x74736574,(%rax)
movb   $0x0,0x4(%rax)
lea    0xe60(%rip),%r15
mov    %rax,%rdi
call   1060 <strlen@plt>
movl   $0x74736574,(%rbx,%rax,1)
movb   $0x0,0x4(%rbx,%rax,1)
mov    $0x4,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <bwt_generate_rotations@plt>
mov    (%r14),%rdi
mov    $0x4,%edx
mov    %r15,%rsi
call   1040 <strncmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
xor    %eax,%eax
call   1070 <assert@plt>
mov    0x8(%r14),%rdi
lea    0xe15(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
xor    %eax,%eax
call   1070 <assert@plt>
mov    0x10(%r14),%rdi
lea    0xdf6(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
xor    %eax,%eax
call   1070 <assert@plt>
mov    0x18(%r14),%rdi
lea    0xdd7(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
xor    %eax,%eax
call   1070 <assert@plt>
lea    0xdbc(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@.str.1 = [5 x i8] c"estt\00"
@.str.2 = [5 x i8] c"stte\00"
@.str.3 = [5 x i8] c"ttes\00"
@.str.4 = [33 x i8] c"\09Generate rotations test passed\0A\00"
define void @test_bwt_generate_rotations() {
%1 = alloca i8*
%2 = alloca i8**
%3 = alloca i8*
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %1
%4 = call i8* @malloc(i64 32)
%5 = bitcast i8* %4 to i8**
store i8** %5, i8*** %2
%6 = load i8*, i8** %1
%7 = call i64 @strlen(i8* %6)
%8 = mul i64 2, %7
%9 = add i64 %8, 1
%10 = mul i64 %9, 1
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = load i8*, i8** %1
%14 = call i8* @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = load i8*, i8** %1
%17 = call i8* @strcat(i8* %15, i8* %16)
%18 = load i8*, i8** %3
%19 = load i8**, i8*** %2
%20 = load i8*, i8** %1
%21 = call i64 @strlen(i8* %20)
%22 = call i32 (i8*, i8**, i64, ...) bitcast (i32 (...)* @bwt_generate_rotations to i32 (i8*, i8**, i64, ...)*)(i8* %18, i8** %19, i64 %21)
%23 = load i8**, i8*** %2
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
%29 = zext i1 %28 to i32
%30 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %29)
%31 = load i8**, i8*** %2
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @strncmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4)
%35 = icmp ne i32 %34, 0
%36 = xor i1 %35, true
%37 = zext i1 %36 to i32
%38 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %37)
%39 = load i8**, i8*** %2
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @strncmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4)
%43 = icmp ne i32 %42, 0
%44 = xor i1 %43, true
%45 = zext i1 %44 to i32
%46 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %45)
%47 = load i8**, i8*** %2
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @strncmp(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 4)
%51 = icmp ne i32 %50, 0
%52 = xor i1 %51, true
%53 = zext i1 %52 to i32
%54 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%56 = load i8*, i8** %3
%57 = load i8**, i8*** %2
%58 = bitcast i8** %57 to i8*
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@.str.1 = [5 x i8] c"estt\00"
@.str.2 = [5 x i8] c"stte\00"
@.str.3 = [5 x i8] c"ttes\00"
@str = [32 x i8] c"\09Generate rotations test passed\00"
define void @test_bwt_generate_rotations() {
%1 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
%2 = bitcast i8* %1 to i8**
%3 = tail call dereferenceable_or_null(9) i8* @malloc(i64 9)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %3, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5, i1 false)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = getelementptr i8, i8* %3, i64 %4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %5, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5, i1 false)
%6 = tail call i32 (i8*, i8**, i64, ...) bitcast (i32 (...)* @bwt_generate_rotations to i32 (i8*, i8**, i64, ...)*)(i8* %3, i8** %2, i64 4)
%7 = load i8*, i8** %2
%8 = tail call i32 @strncmp(i8* dereferenceable(1) %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %10)
%12 = getelementptr inbounds i8*, i8** %2, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @strncmp(i8* dereferenceable(1) %13, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %16)
%18 = getelementptr inbounds i8*, i8** %2, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @strncmp(i8* dereferenceable(1) %19, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4)
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %22)
%24 = getelementptr inbounds i8*, i8** %2, i64 3
%25 = load i8*, i8** %24
%26 = tail call i32 @strncmp(i8* dereferenceable(1) %25, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 4)
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
%29 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %28)
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
tail call void @free(i8* %3)
tail call void @free(i8* %1)
ret void
}