void test_str_interleave(const char *s1, const char *s2) {
  char *output = calloc(128, 1);
  unsigned long t1, t2;
  asm volatile("rdtsc" : "=A"(t1) : :);
  ;
  old_str_interleave(output, s1, s2);
  asm volatile("rdtsc" : "=A"(t2) : :);
  ;
  printf("old - (%5lu) %s\n", t2 - t1, output);
  asm volatile("rdtsc" : "=A"(t1) : :);
  ;
  new_str_interleave(output, s1, s2);
  asm volatile("rdtsc" : "=A"(t2) : :);
  ;
  printf("new - (%5lu) %s\n", t2 - t1, output);
  asm volatile("rdtsc" : "=A"(t1) : :);
  ;
  asm_str_interleave(output, s1, s2);
  asm volatile("rdtsc" : "=A"(t2) : :);
  ;
  printf("asm - (%5lu) %s\n", t2 - t1, output);
  free(output);
}


x86 assembly (clang, -O0):
<test_str_interleave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x80,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1060 <old_str_interleave@plt>
rdtsc
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <new_str_interleave@plt>
rdtsc
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1070 <asm_str_interleave@plt>
rdtsc
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_str_interleave>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x80,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
rdtsc
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <old_str_interleave@plt>
rdtsc
sub    %r12,%rax
lea    0xe5f(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
rdtsc
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <new_str_interleave@plt>
rdtsc
sub    %r12,%rax
lea    0xe42(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
rdtsc
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <asm_str_interleave@plt>
rdtsc
sub    %r12,%rax
lea    0xe25(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"old - (%5lu) %s\0A\00"
@.str.1 = [17 x i8] c"new - (%5lu) %s\0A\00"
@.str.2 = [17 x i8] c"asm - (%5lu) %s\0A\00"
define void @test_str_interleave(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = call i8* @calloc(i64 128, i64 1)
store i8* %8, i8** %5
%9 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %9, i64* %6
%10 = load i8*, i8** %5
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @old_str_interleave to i32 (i8*, i8*, i8*, ...)*)(i8* %10, i8* %11, i8* %12)
%14 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = load i64, i64* %6
%17 = sub i64 %15, %16
%18 = load i8*, i8** %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %17, i8* %18)
%20 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %20, i64* %6
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = load i8*, i8** %4
%24 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @new_str_interleave to i32 (i8*, i8*, i8*, ...)*)(i8* %21, i8* %22, i8* %23)
%25 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %25, i64* %7
%26 = load i64, i64* %7
%27 = load i64, i64* %6
%28 = sub i64 %26, %27
%29 = load i8*, i8** %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %28, i8* %29)
%31 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %31, i64* %6
%32 = load i8*, i8** %5
%33 = load i8*, i8** %3
%34 = load i8*, i8** %4
%35 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @asm_str_interleave to i32 (i8*, i8*, i8*, ...)*)(i8* %32, i8* %33, i8* %34)
%36 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %36, i64* %7
%37 = load i64, i64* %7
%38 = load i64, i64* %6
%39 = sub i64 %37, %38
%40 = load i8*, i8** %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i64 %39, i8* %40)
%42 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"old - (%5lu) %s\0A\00"
@.str.1 = [17 x i8] c"new - (%5lu) %s\0A\00"
@.str.2 = [17 x i8] c"asm - (%5lu) %s\0A\00"
define void @test_str_interleave(i8* %0, i8* %1) {
%3 = tail call dereferenceable_or_null(128) i8* @calloc(i64 128, i64 1)
%4 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%5 = tail call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @old_str_interleave to i32 (i8*, i8*, i8*, ...)*)(i8* %3, i8* %0, i8* %1)
%6 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%7 = sub i64 %6, %4
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %7, i8* %3)
%9 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%10 = tail call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @new_str_interleave to i32 (i8*, i8*, i8*, ...)*)(i8* %3, i8* %0, i8* %1)
%11 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%12 = sub i64 %11, %9
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %12, i8* %3)
%14 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%15 = tail call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @asm_str_interleave to i32 (i8*, i8*, i8*, ...)*)(i8* %3, i8* %0, i8* %1)
%16 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%17 = sub i64 %16, %14
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i64 %17, i8* %3)
tail call void @free(i8* %3)
ret void
}