#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 */
typedef char uint8_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void time_function(void triple(uint8_t *, const uint8_t *), const char *name,
                   uint8_t *dst, const uint8_t *src, size_t triples) {
  struct timeval start, end;
  double duration, rate;
  gettimeofday(&start, NULL);
  for (size_t i = 0; i < triples; ++i) {
    triple(dst + i, src + i);
  }
  gettimeofday(&end, NULL);
  duration = (end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec);
  rate = 3 * triples / duration / 1e6;
  fprintf(stderr, "%s\t%zu B %9.3f ms\t%9.3f MB/s\t", name, 3 * triples,
          1e3 * duration, rate);
  dst[16] = 0;
  fprintf(stderr, "%s\n", dst);
}


x86 assembly (clang, -O0):
<time_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1186 <time_function+0x66>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rdi
add    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    -0x50(%rbp),%rsi
call   *%rax
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1151 <time_function+0x31>
xor    %eax,%eax
mov    %eax,%esi
lea    -0x38(%rbp),%rdi
call   1030 <gettimeofday@plt>
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%eax
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%ecx
sub    %esi,%edx
cvtsi2sd %edx,%xmm1
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe5d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
lea    (%rax,%rax,2),%rax
movq   %rax,%xmm0
movaps 0xe4c(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe50(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  0xe0c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
imul   $0x3,-0x28(%rbp),%rcx
movsd  0xde1(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
lea    0xe10(%rip),%rsi
mov    $0x2,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x10(%rax)
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_function>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,0x10(%rsp)
mov    %rdi,%r13
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %r14,%r14
je     1177 <time_function+0x57>
mov    %r15,%rbp
mov    %r14,%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   *%r13
add    $0x1,%rbx
add    $0x1,%rbp
add    $0xffffffffffffffff,%r12
jne    1160 <time_function+0x40>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x8(%rsp),%eax
cvtsi2sd %eax,%xmm1
sub    0xc(%rsp),%ecx
cvtsi2sd %ecx,%xmm0
mulsd  0xe60(%rip),%xmm0
lea    (%r14,%r14,2),%rcx
movq   %rcx,%xmm2
punpckldq 0xe6f(%rip),%xmm2
addsd  %xmm1,%xmm0
subpd  0xe73(%rip),%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm0,%xmm1
divsd  0xe33(%rip),%xmm1
mov    0x2e04(%rip),%rbx
mov    (%rbx),%edi
mulsd  0xe2a(%rip),%xmm0
lea    0xe53(%rip),%rsi
mov    0x10(%rsp),%rdx
mov    $0x2,%al
call   1040 <fprintf@plt>
movb   $0x0,0x10(%r15)
mov    (%rbx),%edi
lea    0xe57(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [30 x i8] c"%s\09%zu B %9.3f ms\09%9.3f MB/s\09\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @time_function(void (i8*, i8*)* %0, i8* %1, i8* %2, i8* %3, i64 %4) {
%6 = alloca void (i8*, i8*)*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.timeval
%12 = alloca %struct.timeval
%13 = alloca double
%14 = alloca double
%15 = alloca i64
store void (i8*, i8*)* %0, void (i8*, i8*)** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%16 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
store i64 0, i64* %15
br label %17
17: ; preds = %29, %5
%18 = load i64, i64* %15
%19 = load i64, i64* %10
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = load void (i8*, i8*)*, void (i8*, i8*)** %6
%23 = load i8*, i8** %8
%24 = load i64, i64* %15
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8*, i8** %9
%27 = load i64, i64* %15
%28 = getelementptr inbounds i8, i8* %26, i64 %27
br label %29
29: ; preds = %21
%30 = load i64, i64* %15
%31 = add i64 %30, 1
store i64 %31, i64* %15
br label %17
32: ; preds = %17
%33 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%37 = load i32, i32* %36
%38 = sub nsw i32 %35, %37
%39 = sitofp i32 %38 to double
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%43 = load i32, i32* %42
%44 = sub nsw i32 %41, %43
%45 = sitofp i32 %44 to double
%46 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %45, double %39)
store double %46, double* %13
%47 = load i64, i64* %10
%48 = mul i64 3, %47
%49 = uitofp i64 %48 to double
%50 = load double, double* %13
%51 = fdiv double %49, %50
%52 = fdiv double %51, 1.000000e+06
store double %52, double* %14
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %7
%55 = load i64, i64* %10
%56 = mul i64 3, %55
%57 = load double, double* %13
%58 = fmul double 1.000000e+03, %57
%59 = load double, double* %14
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %54, i64 %56, double %58, double %59)
%61 = load i8*, i8** %8
%62 = getelementptr inbounds i8, i8* %61, i64 16
store i8 0, i8* %62
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %8
%65 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %64)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [30 x i8] c"%s\09%zu B %9.3f ms\09%9.3f MB/s\09\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @time_function(void (i8*, i8*)* nocapture %0, i8* %1, i8* %2, i8* %3, i64 %4) {
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = bitcast %struct.timeval* %6 to i8*
%9 = bitcast %struct.timeval* %7 to i8*
%10 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%11 = icmp eq i64 %4, 0
br i1 %11, label %12, label %37
12: ; preds = %37, %5
%13 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%17 = load i32, i32* %16
%18 = sub nsw i32 %15, %17
%19 = sitofp i32 %18 to double
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%23 = load i32, i32* %22
%24 = sub nsw i32 %21, %23
%25 = sitofp i32 %24 to double
%26 = tail call double @llvm.fmuladd.f64(double %25, double 0x3EB0C6F7A0B5ED8D, double %19)
%27 = mul i64 %4, 3
%28 = uitofp i64 %27 to double
%29 = fdiv double %28, %26
%30 = fdiv double %29, 1.000000e+06
%31 = load i32, i32* @stderr
%32 = fmul double %26, 1.000000e+03
%33 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %1, i64 %27, double %32, double %30)
%34 = getelementptr inbounds i8, i8* %2, i64 16
store i8 0, i8* %34
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret void
37: ; preds = %5, %37
%38 = phi i64 [ %41, %37 ], [ 0, %5 ]
%39 = getelementptr inbounds i8, i8* %2, i64 %38
%40 = getelementptr inbounds i8, i8* %3, i64 %38
tail call void %0(i8* %39, i8* %40)
%41 = add nuw i64 %38, 1
%42 = icmp eq i64 %41, %4
br i1 %42, label %12, label %37
}