void bwt_transform(const char *src, char *dst, int len) {
  char *rotations_storage = (char *)malloc((2 * len + 1) * sizeof(char));
  char **rotations = (char **)malloc(len * sizeof(char *));
  strcpy(rotations_storage, src);
  strcat(rotations_storage, src);
  bwt_generate_rotations(rotations_storage, rotations, len);
  bwt_sort_strings(rotations, len);
  bwt_get_last_column(rotations, dst, len);
  free(rotations);
  free(rotations_storage);
}


x86 assembly (clang, -O0):
<bwt_transform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
movslq %eax,%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0x14(%rbp),%rdi
shl    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1090 <bwt_generate_rotations@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x0,%al
call   1060 <bwt_sort_strings@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1050 <bwt_get_last_column@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bwt_transform>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r13
lea    (%rbx,%rbx,1),%eax
add    $0x1,%eax
movslq %eax,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
movslq %ebx,%r12
lea    0x0(,%r12,8),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <bwt_generate_rotations@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <bwt_sort_strings@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <bwt_get_last_column@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @bwt_transform(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = mul nsw i32 2, %9
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %7
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 8
%18 = call i8* @malloc(i64 %17)
%19 = bitcast i8* %18 to i8**
store i8** %19, i8*** %8
%20 = load i8*, i8** %7
%21 = load i8*, i8** %4
%22 = call i8* @strcpy(i8* %20, i8* %21)
%23 = load i8*, i8** %7
%24 = load i8*, i8** %4
%25 = call i8* @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %7
%27 = load i8**, i8*** %8
%28 = load i32, i32* %6
%29 = call i32 (i8*, i8**, i32, ...) bitcast (i32 (...)* @bwt_generate_rotations to i32 (i8*, i8**, i32, ...)*)(i8* %26, i8** %27, i32 %28)
%30 = load i8**, i8*** %8
%31 = load i32, i32* %6
%32 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @bwt_sort_strings to i32 (i8**, i32, ...)*)(i8** %30, i32 %31)
%33 = load i8**, i8*** %8
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = call i32 (i8**, i8*, i32, ...) bitcast (i32 (...)* @bwt_get_last_column to i32 (i8**, i8*, i32, ...)*)(i8** %33, i8* %34, i32 %35)
%37 = load i8**, i8*** %8
%38 = bitcast i8** %37 to i8*
%39 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
define void @bwt_transform(i8* nocapture %0, i8* %1, i32 %2) {
%4 = shl nsw i32 %2, 1
%5 = or i32 %4, 1
%6 = sext i32 %5 to i64
%7 = tail call i8* @malloc(i64 %6)
%8 = sext i32 %2 to i64
%9 = shl nsw i64 %8, 3
%10 = tail call i8* @malloc(i64 %9)
%11 = bitcast i8* %10 to i8**
%12 = tail call i8* @strcpy(i8* dereferenceable(1) %7, i8* dereferenceable(1) %0)
%13 = tail call i8* @strcat(i8* dereferenceable(1) %7, i8* dereferenceable(1) %0)
%14 = tail call i32 (i8*, i8**, i32, ...) bitcast (i32 (...)* @bwt_generate_rotations to i32 (i8*, i8**, i32, ...)*)(i8* %7, i8** %11, i32 %2)
%15 = tail call i32 (i8**, i32, ...) bitcast (i32 (...)* @bwt_sort_strings to i32 (i8**, i32, ...)*)(i8** %11, i32 %2)
%16 = tail call i32 (i8**, i8*, i32, ...) bitcast (i32 (...)* @bwt_get_last_column to i32 (i8**, i8*, i32, ...)*)(i8** %11, i8* %1, i32 %2)
tail call void @free(i8* %10)
tail call void @free(i8* %7)
ret void
}