void test_lcol(char *dst, const char *src, int width) {
  unsigned long t1, t2;
  char *r1 = malloc(strlen(src) + strlen(dst) * 2);
  char *r2 = malloc(strlen(src) + strlen(dst) * 2);
  char *r3 = malloc(strlen(src) + strlen(dst) * 2);
  asm volatile("rdtsc" : "=A"(t1) : :);
  ;
  old_str_lcol(r1, src, width);
  asm volatile("rdtsc" : "=A"(t2) : :);
  ;
  printf("old - %5lu cycles - \n%s\n", t2 - t1, r1);
  asm volatile("rdtsc" : "=A"(t1) : :);
  ;
  new_str_lcol(r2, src, width);
  asm volatile("rdtsc" : "=A"(t2) : :);
  ;
  printf("new - %5lu cycles - \n%s\n", t2 - t1, r2);
  asm volatile("rdtsc" : "=A"(t1) : :);
  ;
  asm_str_lcol(r3, src, width);
  asm volatile("rdtsc" : "=A"(t2) : :);
  ;
  printf("asm - %5lu cycles - \n%s\n\n", t2 - t1, r3);
  free(r1);
  free(r2);
  free(r3);
}


x86 assembly (clang, -O0):
<test_lcol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
shl    $0x1,%rax
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
shl    $0x1,%rax
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
shl    $0x1,%rax
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1090 <old_str_lcol@plt>
rdtsc
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1080 <new_str_lcol@plt>
rdtsc
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1070 <asm_str_lcol@plt>
rdtsc
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_lcol>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x0(,%rax,2),%rbx
add    %rbp,%rbx
mov    %rbx,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
rdtsc
mov    %rax,%rbp
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1090 <old_str_lcol@plt>
rdtsc
sub    %rbp,%rax
lea    0xe1c(%rip),%rdi
mov    %rax,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
rdtsc
mov    %rax,%rbp
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <new_str_lcol@plt>
rdtsc
sub    %rbp,%rax
lea    0xe07(%rip),%rdi
mov    %rax,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
rdtsc
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <asm_str_lcol@plt>
rdtsc
sub    %rbp,%rax
lea    0xdf2(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"old - %5lu cycles - \0A%s\0A\00"
@.str.1 = [25 x i8] c"new - %5lu cycles - \0A%s\0A\00"
@.str.2 = [26 x i8] c"asm - %5lu cycles - \0A%s\0A\0A\00"
define void @test_lcol(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
%16 = mul i64 %15, 2
%17 = add i64 %13, %16
%18 = call i8* @malloc(i64 %17)
store i8* %18, i8** %9
%19 = load i8*, i8** %5
%20 = call i64 @strlen(i8* %19)
%21 = load i8*, i8** %4
%22 = call i64 @strlen(i8* %21)
%23 = mul i64 %22, 2
%24 = add i64 %20, %23
%25 = call i8* @malloc(i64 %24)
store i8* %25, i8** %10
%26 = load i8*, i8** %5
%27 = call i64 @strlen(i8* %26)
%28 = load i8*, i8** %4
%29 = call i64 @strlen(i8* %28)
%30 = mul i64 %29, 2
%31 = add i64 %27, %30
%32 = call i8* @malloc(i64 %31)
store i8* %32, i8** %11
%33 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %33, i64* %7
%34 = load i8*, i8** %9
%35 = load i8*, i8** %5
%36 = load i32, i32* %6
%37 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @old_str_lcol to i32 (i8*, i8*, i32, ...)*)(i8* %34, i8* %35, i32 %36)
%38 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %38, i64* %8
%39 = load i64, i64* %8
%40 = load i64, i64* %7
%41 = sub i64 %39, %40
%42 = load i8*, i8** %9
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %41, i8* %42)
%44 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %44, i64* %7
%45 = load i8*, i8** %10
%46 = load i8*, i8** %5
%47 = load i32, i32* %6
%48 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @new_str_lcol to i32 (i8*, i8*, i32, ...)*)(i8* %45, i8* %46, i32 %47)
%49 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %49, i64* %8
%50 = load i64, i64* %8
%51 = load i64, i64* %7
%52 = sub i64 %50, %51
%53 = load i8*, i8** %10
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %52, i8* %53)
%55 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %55, i64* %7
%56 = load i8*, i8** %11
%57 = load i8*, i8** %5
%58 = load i32, i32* %6
%59 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @asm_str_lcol to i32 (i8*, i8*, i32, ...)*)(i8* %56, i8* %57, i32 %58)
%60 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %60, i64* %8
%61 = load i64, i64* %8
%62 = load i64, i64* %7
%63 = sub i64 %61, %62
%64 = load i8*, i8** %11
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %63, i8* %64)
%66 = load i8*, i8** %9
%67 = load i8*, i8** %10
%68 = load i8*, i8** %11
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"old - %5lu cycles - \0A%s\0A\00"
@.str.1 = [25 x i8] c"new - %5lu cycles - \0A%s\0A\00"
@.str.2 = [26 x i8] c"asm - %5lu cycles - \0A%s\0A\0A\00"
define void @test_lcol(i8* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = shl i64 %5, 1
%7 = add i64 %6, %4
%8 = tail call i8* @malloc(i64 %7)
%9 = tail call i8* @malloc(i64 %7)
%10 = tail call i8* @malloc(i64 %7)
%11 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%12 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @old_str_lcol to i32 (i8*, i8*, i32, ...)*)(i8* %8, i8* %1, i32 %2)
%13 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%14 = sub i64 %13, %11
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %14, i8* %8)
%16 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%17 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @new_str_lcol to i32 (i8*, i8*, i32, ...)*)(i8* %9, i8* %1, i32 %2)
%18 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%19 = sub i64 %18, %16
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %19, i8* %9)
%21 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%22 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @asm_str_lcol to i32 (i8*, i8*, i32, ...)*)(i8* %10, i8* %1, i32 %2)
%23 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%24 = sub i64 %23, %21
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %24, i8* %10)
tail call void @free(i8* %8)
tail call void @free(i8* %9)
tail call void @free(i8* %10)
ret void
}