#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 rusage {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
long getElapsedSystemTime(struct rusage *);
long getElapsedUserTime(struct rusage *);
char *getNameFromMode(int);
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
int vectorOps(void *, void *, void *, int, int, int);
int executeSpeedTest(void *a, void *b, void *c, int nsize, int niters, int mode,
                     FILE *fp) {
  struct rusage ru1, ru2, ru3;
  char *opname = getNameFromMode(mode);
  double mflops;
  long ticks;
  double dticks;
  double dops;
  int rc1, rc2;
  long dt12, dt23;
  long ut1, ut2, ut3, st1, st2, st3;
  getrusage(RUSAGE_SELF, &ru1);
  rc1 = vectorOps(a, b, c, nsize, niters, mode);
  getrusage(RUSAGE_SELF, &ru2);
  rc2 = vectorOps(a, b, c, nsize, niters, 0);
  getrusage(RUSAGE_SELF, &ru3);
  if (rc1 == 0 || rc2 == 0)
    return 0L;
  ut1 = getElapsedUserTime(&ru1);
  st1 = getElapsedSystemTime(&ru1);
  fprintf(fp, "Before loop: user %12ld, system %12ld\n", ut1, st1);
  ut2 = getElapsedUserTime(&ru2);
  st2 = getElapsedSystemTime(&ru2);
  fprintf(fp, "After loop:  user %12ld, system %12ld\n", ut2, st2);
  ut3 = getElapsedUserTime(&ru3);
  st3 = getElapsedSystemTime(&ru3);
  fprintf(fp, "After nops:  user %12ld, system %12ld\n", ut3, st3);
  dt12 = ut2 - ut1;
  dt23 = ut3 - ut2;
  ticks = dt12 - dt23;
  dticks = (double)ticks;
  dops = (double)nsize * (double)niters;
  mflops = dops / dticks;
  fprintf(fp, "\n");
  fprintf(fp, "It took %.3lf seconds to perform %.3lf million %s.\n",
          dticks / 1.0e6, dops / 1.0e6, opname);
  fprintf(fp, "That corresponds to %.3lf million ops/second.\n", mflops);
  fflush(fp);
  return rc1;
}


x86 assembly (clang, -O0):
<executeSpeedTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <getNameFromMode@plt>
mov    %rax,-0x48(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1090 <getrusage@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
call   1070 <vectorOps@plt>
mov    %eax,-0x6c(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1090 <getrusage@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
xor    %r9d,%r9d
call   1070 <vectorOps@plt>
mov    %eax,-0x70(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1090 <getrusage@plt>
cmpl   $0x0,-0x6c(%rbp)
je     1229 <executeSpeedTest+0xb9>
cmpl   $0x0,-0x70(%rbp)
jne    1235 <executeSpeedTest+0xc5>
movl   $0x0,-0x4(%rbp)
jmp    13c2 <executeSpeedTest+0x252>
lea    -0x30(%rbp),%rdi
call   1030 <getElapsedUserTime@plt>
mov    %rax,-0x88(%rbp)
lea    -0x30(%rbp),%rdi
call   1080 <getElapsedSystemTime@plt>
mov    %rax,-0xa0(%rbp)
mov    0x10(%rbp),%rdi
mov    -0x88(%rbp),%rdx
mov    -0xa0(%rbp),%rcx
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x38(%rbp),%rdi
call   1030 <getElapsedUserTime@plt>
mov    %rax,-0x90(%rbp)
lea    -0x38(%rbp),%rdi
call   1080 <getElapsedSystemTime@plt>
mov    %rax,-0xa8(%rbp)
mov    0x10(%rbp),%rdi
mov    -0x90(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <getElapsedUserTime@plt>
mov    %rax,-0x98(%rbp)
lea    -0x40(%rbp),%rdi
call   1080 <getElapsedSystemTime@plt>
mov    %rax,-0xb0(%rbp)
mov    0x10(%rbp),%rdi
mov    -0x98(%rbp),%rdx
mov    -0xb0(%rbp),%rcx
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x90(%rbp),%rax
sub    -0x88(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x98(%rbp),%rax
sub    -0x90(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x78(%rbp),%rax
sub    -0x80(%rbp),%rax
mov    %rax,-0x58(%rbp)
cvtsi2sdq -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    0x10(%rbp),%rdi
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x10(%rbp),%rdi
movsd  -0x60(%rbp),%xmm0
movsd  0xc8b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x68(%rbp),%xmm1
movsd  0xc7a(%rip),%xmm2
divsd  %xmm2,%xmm1
mov    -0x48(%rbp),%rdx
lea    0xce8(%rip),%rsi
mov    $0x2,%al
call   1040 <fprintf@plt>
mov    0x10(%rbp),%rdi
movsd  -0x50(%rbp),%xmm0
lea    0xd05(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    0x10(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<executeSpeedTest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%ebp
mov    %r8d,%r12d
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbx
mov    %r9d,%edi
call   1060 <getNameFromMode@plt>
mov    %rax,0x30(%rsp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0x20(%rsp),%rsi
call   10a0 <getrusage@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %ebp,%r9d
call   1080 <vectorOps@plt>
mov    %eax,%ebp
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
call   10a0 <getrusage@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r15d,(%rsp)
mov    %r15d,%ecx
mov    %r12d,0x8(%rsp)
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1080 <vectorOps@plt>
mov    %eax,%ebx
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   10a0 <getrusage@plt>
test   %ebp,%ebp
je     1363 <executeSpeedTest+0x1e3>
test   %ebx,%ebx
mov    $0x0,%eax
je     1365 <executeSpeedTest+0x1e5>
mov    %ebp,%r12d
mov    0x70(%rsp),%r15
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <getElapsedUserTime@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1090 <getElapsedSystemTime@plt>
lea    0xdab(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <getElapsedUserTime@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1090 <getElapsedSystemTime@plt>
lea    0xda3(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0x10(%rsp),%r13
mov    %r13,%rdi
call   1030 <getElapsedUserTime@plt>
mov    %rax,%rbp
mov    %r13,%rdi
call   1090 <getElapsedSystemTime@plt>
lea    0xd9b(%rip),%rsi
mov    %r15,%rdi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    %r14,%r14
add    %rbp,%rbx
sub    %rbx,%r14
cvtsi2sd %r14,%xmm1
movsd  %xmm1,0x28(%rsp)
cvtsi2sdl (%rsp),%xmm0
cvtsi2sdl 0x8(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
movapd %xmm2,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xa,%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
movsd  0xcea(%rip),%xmm2
movsd  0x28(%rsp),%xmm0
divsd  %xmm2,%xmm0
movsd  (%rsp),%xmm1
divsd  %xmm2,%xmm1
lea    0xd4d(%rip),%rsi
mov    %r15,%rdi
mov    0x30(%rsp),%rdx
mov    $0x2,%al
call   1050 <fprintf@plt>
lea    0xd6b(%rip),%rsi
mov    %r15,%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1070 <fflush@plt>
mov    %r12d,%eax
jmp    1365 <executeSpeedTest+0x1e5>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rusage = type { i32 }
@RUSAGE_SELF = global i32 0
@.str = [39 x i8] c"Before loop: user %12ld, system %12ld\0A\00"
@.str.1 = [39 x i8] c"After loop: user %12ld, system %12ld\0A\00"
@.str.2 = [39 x i8] c"After nops: user %12ld, system %12ld\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [52 x i8] c"It took %.3lf seconds to perform %.3lf million %s.\0A\00"
@.str.5 = [47 x i8] c"That corresponds to %.3lf million ops/second.\0A\00"
define i32 @executeSpeedTest(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5, i32* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca %struct.rusage
%17 = alloca %struct.rusage
%18 = alloca %struct.rusage
%19 = alloca i8*
%20 = alloca double
%21 = alloca i64
%22 = alloca double
%23 = alloca double
%24 = alloca i32
%25 = alloca i32
%26 = alloca i64
%27 = alloca i64
%28 = alloca i64
%29 = alloca i64
%30 = alloca i64
%31 = alloca i64
%32 = alloca i64
%33 = alloca i64
store i8* %0, i8** %9
store i8* %1, i8** %10
store i8* %2, i8** %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32* %6, i32** %15
%34 = load i32, i32* %14
%35 = call i8* @getNameFromMode(i32 %34)
store i8* %35, i8** %19
%36 = load i32, i32* @RUSAGE_SELF
%37 = call i32 @getrusage(i32 %36, %struct.rusage* %16)
%38 = load i8*, i8** %9
%39 = load i8*, i8** %10
%40 = load i8*, i8** %11
%41 = load i32, i32* %12
%42 = load i32, i32* %13
%43 = load i32, i32* %14
%44 = call i32 @vectorOps(i8* %38, i8* %39, i8* %40, i32 %41, i32 %42, i32 %43)
store i32 %44, i32* %24
%45 = load i32, i32* @RUSAGE_SELF
%46 = call i32 @getrusage(i32 %45, %struct.rusage* %17)
%47 = load i8*, i8** %9
%48 = load i8*, i8** %10
%49 = load i8*, i8** %11
%50 = load i32, i32* %12
%51 = load i32, i32* %13
%52 = call i32 @vectorOps(i8* %47, i8* %48, i8* %49, i32 %50, i32 %51, i32 0)
store i32 %52, i32* %25
%53 = load i32, i32* @RUSAGE_SELF
%54 = call i32 @getrusage(i32 %53, %struct.rusage* %18)
%55 = load i32, i32* %24
%56 = icmp eq i32 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %7
%58 = load i32, i32* %25
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %57, %7
store i32 0, i32* %8
br label %114
61: ; preds = %57
%62 = call i64 @getElapsedUserTime(%struct.rusage* %16)
store i64 %62, i64* %28
%63 = call i64 @getElapsedSystemTime(%struct.rusage* %16)
store i64 %63, i64* %31
%64 = load i32*, i32** %15
%65 = load i64, i64* %28
%66 = load i64, i64* %31
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %65, i64 %66)
%68 = call i64 @getElapsedUserTime(%struct.rusage* %17)
store i64 %68, i64* %29
%69 = call i64 @getElapsedSystemTime(%struct.rusage* %17)
store i64 %69, i64* %32
%70 = load i32*, i32** %15
%71 = load i64, i64* %29
%72 = load i64, i64* %32
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i64 %71, i64 %72)
%74 = call i64 @getElapsedUserTime(%struct.rusage* %18)
store i64 %74, i64* %30
%75 = call i64 @getElapsedSystemTime(%struct.rusage* %18)
store i64 %75, i64* %33
%76 = load i32*, i32** %15
%77 = load i64, i64* %30
%78 = load i64, i64* %33
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i64 %77, i64 %78)
%80 = load i64, i64* %29
%81 = load i64, i64* %28
%82 = sub nsw i64 %80, %81
store i64 %82, i64* %26
%83 = load i64, i64* %30
%84 = load i64, i64* %29
%85 = sub nsw i64 %83, %84
store i64 %85, i64* %27
%86 = load i64, i64* %26
%87 = load i64, i64* %27
%88 = sub nsw i64 %86, %87
store i64 %88, i64* %21
%89 = load i64, i64* %21
%90 = sitofp i64 %89 to double
store double %90, double* %22
%91 = load i32, i32* %12
%92 = sitofp i32 %91 to double
%93 = load i32, i32* %13
%94 = sitofp i32 %93 to double
%95 = fmul double %92, %94
store double %95, double* %23
%96 = load double, double* %23
%97 = load double, double* %22
%98 = fdiv double %96, %97
store double %98, double* %20
%99 = load i32*, i32** %15
%100 = call i32 (i32*, i8*, ...) @fprintf(i32* %99, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%101 = load i32*, i32** %15
%102 = load double, double* %22
%103 = fdiv double %102, 1.000000e+06
%104 = load double, double* %23
%105 = fdiv double %104, 1.000000e+06
%106 = load i8*, i8** %19
%107 = call i32 (i32*, i8*, ...) @fprintf(i32* %101, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), double %103, double %105, i8* %106)
%108 = load i32*, i32** %15
%109 = load double, double* %20
%110 = call i32 (i32*, i8*, ...) @fprintf(i32* %108, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), double %109)
%111 = load i32*, i32** %15
%112 = call i32 @fflush(i32* %111)
%113 = load i32, i32* %24
store i32 %113, i32* %8
br label %114
114: ; preds = %61, %60
%115 = load i32, i32* %8
ret i32 %115
}

LLVM IR (-O2):
%struct.rusage = type { i32 }
@RUSAGE_SELF = global i32 0
@.str = [39 x i8] c"Before loop: user %12ld, system %12ld\0A\00"
@.str.1 = [39 x i8] c"After loop: user %12ld, system %12ld\0A\00"
@.str.2 = [39 x i8] c"After nops: user %12ld, system %12ld\0A\00"
@.str.4 = [52 x i8] c"It took %.3lf seconds to perform %.3lf million %s.\0A\00"
@.str.5 = [47 x i8] c"That corresponds to %.3lf million ops/second.\0A\00"
define i32 @executeSpeedTest(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5, i32* nocapture %6) {
%8 = alloca %struct.rusage
%9 = alloca %struct.rusage
%10 = alloca %struct.rusage
%11 = bitcast %struct.rusage* %8 to i8*
%12 = bitcast %struct.rusage* %9 to i8*
%13 = bitcast %struct.rusage* %10 to i8*
%14 = tail call i8* @getNameFromMode(i32 %5)
%15 = load i32, i32* @RUSAGE_SELF
%16 = call i32 @getrusage(i32 %15, %struct.rusage* %8)
%17 = call i32 @vectorOps(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5)
%18 = load i32, i32* @RUSAGE_SELF
%19 = call i32 @getrusage(i32 %18, %struct.rusage* %9)
%20 = call i32 @vectorOps(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 0)
%21 = load i32, i32* @RUSAGE_SELF
%22 = call i32 @getrusage(i32 %21, %struct.rusage* %10)
%23 = icmp eq i32 %17, 0
%24 = icmp eq i32 %20, 0
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %50, label %26
26: ; preds = %7
%27 = call i64 @getElapsedUserTime(%struct.rusage* %8)
%28 = call i64 @getElapsedSystemTime(%struct.rusage* %8)
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %27, i64 %28)
%30 = call i64 @getElapsedUserTime(%struct.rusage* %9)
%31 = call i64 @getElapsedSystemTime(%struct.rusage* %9)
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i64 %30, i64 %31)
%33 = call i64 @getElapsedUserTime(%struct.rusage* %10)
%34 = call i64 @getElapsedSystemTime(%struct.rusage* %10)
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i64 %33, i64 %34)
%36 = shl i64 %30, 1
%37 = add i64 %27, %33
%38 = sub i64 %36, %37
%39 = sitofp i64 %38 to double
%40 = sitofp i32 %3 to double
%41 = sitofp i32 %4 to double
%42 = fmul double %40, %41
%43 = fdiv double %42, %39
%44 = call i32 @fputc(i32 10, i32* %6)
%45 = fdiv double %39, 1.000000e+06
%46 = fdiv double %42, 1.000000e+06
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), double %45, double %46, i8* %14)
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), double %43)
%49 = call i32 @fflush(i32* %6)
br label %50
50: ; preds = %7, %26
%51 = phi i32 [ %17, %26 ], [ 0, %7 ]
ret i32 %51
}