void test_find_pattern(char *output, char *input) {
  unsigned long long t1, t2;
  *output = '\0';
  __asm__ __volatile__("rdtsc" : "=A"(t1) : :);
  ;
  old_find_pattern(output, input);
  __asm__ __volatile__("rdtsc" : "=A"(t2) : :);
  ;
  printf("old - (%5llu) %s\n", t2 - t1, output);
  *output = '\0';
  __asm__ __volatile__("rdtsc" : "=A"(t1) : :);
  ;
  new_find_pattern(output, input);
  __asm__ __volatile__("rdtsc" : "=A"(t2) : :);
  ;
  printf("new - (%5llu) %s\n", t2 - t1, output);
  *output = '\0';
  __asm__ __volatile__("rdtsc" : "=A"(t1) : :);
  ;
  asm_find_pattern(output, input);
  __asm__ __volatile__("rdtsc" : "=A"(t2) : :);
  ;
  printf("asm - (%5llu) %s\n\n", t2 - t1, output);
}


x86 assembly (clang, -O0):
<test_find_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
rdtsc
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <old_find_pattern@plt>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
sub    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
rdtsc
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1060 <new_find_pattern@plt>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
sub    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
rdtsc
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1030 <asm_find_pattern@plt>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
sub    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_find_pattern>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,(%rdi)
rdtsc
mov    %rax,%r15
xor    %eax,%eax
call   1040 <old_find_pattern@plt>
rdtsc
sub    %r15,%rax
lea    0xe9a(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
movb   $0x0,(%rbx)
rdtsc
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <new_find_pattern@plt>
rdtsc
sub    %r15,%rax
lea    0xe7e(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
movb   $0x0,(%rbx)
rdtsc
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <asm_find_pattern@plt>
rdtsc
sub    %r15,%rax
lea    0xe62(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <printf@plt>

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

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