#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct timespec {
  double tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, int, double);
int test_strlen(char *);
void bench_test(char *s) {
  struct timespec ts_start, ts_end;
  int i;
  clock_gettime(CLOCK_MONOTONIC, &ts_start);
  for (i = 0; i < 100000; i++)
    test_strlen(s);
  clock_gettime(CLOCK_MONOTONIC, &ts_end);
  printf("len %3.3d : time = %.6f\n", test_strlen(s),
         ts_end.tv_sec - ts_start.tv_sec +
             (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
}


x86 assembly (clang, -O0):
<bench_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <clock_gettime@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x186a0,-0x2c(%rbp)
jge    1179 <bench_test+0x49>
mov    -0x8(%rbp),%rdi
call   1030 <test_strlen@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1155 <bench_test+0x25>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x8(%rbp),%rdi
call   1030 <test_strlen@plt>
mov    %eax,%esi
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%eax
sub    -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe4e(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
lea    0xe47(%rip),%rdi
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bench_test>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    0x2ea6(%rip),%r14
mov    (%r14),%edi
lea    0x10(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    $0x186a0,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <test_strlen@plt>
add    $0xffffffff,%ebp
jne    1160 <bench_test+0x30>
mov    (%r14),%edi
mov    %rsp,%rsi
call   1040 <clock_gettime@plt>
mov    %rbx,%rdi
call   1030 <test_strlen@plt>
movsd  (%rsp),%xmm1
subsd  0x10(%rsp),%xmm1
mov    0x8(%rsp),%ecx
sub    0x18(%rsp),%ecx
cvtsi2sd %ecx,%xmm0
divsd  0xe61(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xe5e(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { double, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [25 x i8] c"len %3.3d : time = %.6f\0A\00"
define void @bench_test(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i32, i32* @CLOCK_MONOTONIC
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %3)
store i32 0, i32* %5
br label %8
8: ; preds = %14, %1
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 100000
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i8*, i8** %2
%13 = call i32 @test_strlen(i8* %12)
br label %14
14: ; preds = %11
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5
br label %8
17: ; preds = %8
%18 = load i32, i32* @CLOCK_MONOTONIC
%19 = call i32 @clock_gettime(i32 %18, %struct.timespec* %4)
%20 = load i8*, i8** %2
%21 = call i32 @test_strlen(i8* %20)
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%23 = load double, double* %22
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%25 = load double, double* %24
%26 = fsub double %23, %25
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%30 = load i32, i32* %29
%31 = sub nsw i32 %28, %30
%32 = sitofp i32 %31 to double
%33 = fdiv double %32, 1.000000e+09
%34 = fadd double %26, %33
%35 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %21, double %34)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [25 x i8] c"len %3.3d : time = %.6f\0A\00"
define void @bench_test(i8* %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = load i32, i32* @CLOCK_MONOTONIC
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %2)
br label %8
8: ; preds = %1, %8
%9 = phi i32 [ 0, %1 ], [ %11, %8 ]
%10 = call i32 @test_strlen(i8* %0)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, 100000
br i1 %12, label %13, label %8
13: ; preds = %8
%14 = load i32, i32* @CLOCK_MONOTONIC
%15 = call i32 @clock_gettime(i32 %14, %struct.timespec* %3)
%16 = call i32 @test_strlen(i8* %0)
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%18 = load double, double* %17
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%20 = load double, double* %19
%21 = fsub double %18, %20
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%25 = load i32, i32* %24
%26 = sub nsw i32 %23, %25
%27 = sitofp i32 %26 to double
%28 = fdiv double %27, 1.000000e+09
%29 = fadd double %21, %28
%30 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %16, double %29)
ret void
}