#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 scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int atoi(int /*<<< orphan*/);
scalar_t__ check_arrays();
scalar_t__ clock();
int /*<<< orphan*/ fill_arrays();
int /*<<< orphan*/ foo();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int getopt(int, char **, char *);
int /*<<< orphan*/ isprint(char);
int /*<<< orphan*/ optarg;
scalar_t__ opterr;
char optopt;
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  clock_t t;
  double avg_time_taken;
  double time_taken;
  fill_arrays();
  int delay_value = 0;
  int index;
  int c;
  opterr = 0;
  while ((c = getopt(argc, argv, "hd:")) != -1)
    switch (c) {
    case 'h':
      print_help();
      return 0;
    case 'd':
      delay_value = atoi(optarg);
      break;
    case '?':
      if (optopt == 'd')
        fprintf(stderr, "Option -%c requires an argument.\n", optopt);
      else if (isprint(optopt))
        fprintf(stderr, "Unknown option `-%c'.\n", optopt);
      else
        fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
      return -1;
    }
  t = clock();
  for (int x = 0; x < 1000000; x++) {
    foo();
    if (delay_value) {
      usleep(delay_value);
    }
  }
  t = clock() - t;
  time_taken = ((double)t) / CLOCKS_PER_SEC;
  double delayin_sec = (double)delay_value / 1000000;
  avg_time_taken = (((double)t) / CLOCKS_PER_SEC) / 1000000;
  if (check_arrays())
    return -1;
  printf("Loops: %d\n", 1000000);
  printf("Delay per function: %.9g in seconds \n", (delayin_sec));
  printf("Total time: %.9g seconds to execute \n", time_taken);
  printf("foo() took %.9g seconds in avg to execute \n", avg_time_taken);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10c0 <fill_arrays@plt>
movl   $0x0,-0x2c(%rbp)
mov    0x2de5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe18(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1308 <main+0x158>
mov    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x3f,%eax
je     1260 <main+0xb0>
jmp    1215 <main+0x65>
mov    -0x44(%rbp),%eax
sub    $0x64,%eax
je     124a <main+0x9a>
jmp    1226 <main+0x76>
mov    -0x44(%rbp),%eax
sub    $0x68,%eax
jne    1303 <main+0x153>
jmp    1237 <main+0x87>
mov    $0x0,%al
call   10a0 <print_help@plt>
movl   $0x0,-0x4(%rbp)
jmp    141b <main+0x26b>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x2c(%rbp)
jmp    1303 <main+0x153>
mov    0x2d71(%rip),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
jne    1297 <main+0xe7>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
mov    0x2d4e(%rip),%rax
movsbl (%rax),%edx
call   1050 <fprintf@plt>
jmp    12f7 <main+0x147>
mov    0x2d3a(%rip),%rax
movsbl (%rax),%edi
call   1070 <isprint@plt>
cmp    $0x0,%eax
je     12d3 <main+0x123>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
mov    0x2d12(%rip),%rax
movsbl (%rax),%edx
call   1050 <fprintf@plt>
jmp    12f2 <main+0x142>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
mov    0x2cee(%rip),%rax
movsbl (%rax),%edx
call   1050 <fprintf@plt>
jmp    12f7 <main+0x147>
movl   $0xffffffff,-0x4(%rbp)
jmp    141b <main+0x26b>
jmp    11e2 <main+0x32>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0xf4240,-0x38(%rbp)
jge    1353 <main+0x1a3>
mov    $0x0,%al
call   1060 <foo@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1340 <main+0x190>
mov    -0x2c(%rbp),%edi
call   10d0 <usleep@plt>
jmp    1345 <main+0x195>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    131a <main+0x16a>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
mov    0x2c71(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  0xc7b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
mov    0x2c45(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xc59(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   10b0 <check_arrays@plt>
cmp    $0x0,%rax
je     13cd <main+0x21d>
movl   $0xffffffff,-0x4(%rbp)
jmp    141b <main+0x26b>
lea    0xc93(%rip),%rdi
movsd  0xc24(%rip),%xmm0
call   1040 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xc85(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xc9a(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xcaf(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   10c0 <fill_arrays@plt>
mov    0x2dee(%rip),%rax
movq   $0x0,(%rax)
lea    0xe28(%rip),%r15
mov    0x2e11(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    $0x63,%eax
jg     1210 <main+0x60>
cmp    $0xffffffff,%eax
je     122a <main+0x7a>
cmp    $0x3f,%eax
jne    11f0 <main+0x40>
jmp    125b <main+0xab>
xchg   %ax,%ax
cmp    $0x64,%eax
je     121c <main+0x6c>
cmp    $0x68,%eax
jne    11f0 <main+0x40>
jmp    1286 <main+0xd6>
mov    (%r12),%edi
call   1090 <atoi@plt>
mov    %eax,%r14d
jmp    11f0 <main+0x40>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    $0xf4240,%ebp
jmp    1245 <main+0x95>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
je     1294 <main+0xe4>
xor    %eax,%eax
call   1060 <foo@plt>
test   %r14d,%r14d
je     1240 <main+0x90>
mov    %r14d,%edi
call   10d0 <usleep@plt>
jmp    1240 <main+0x90>
mov    0x2d76(%rip),%rbx
mov    (%rbx),%al
cmp    $0x64,%al
jne    1339 <main+0x189>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
mov    $0x64,%edx
jmp    1363 <main+0x1b3>
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <print_help@plt>
jmp    136d <main+0x1bd>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2d36(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   10b0 <check_arrays@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    136d <main+0x1bd>
movsd  0xd2f(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0xd6d(%rip),%rdi
call   1040 <printf@plt>
lea    0xd6c(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xd80(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xd94(%rip),%rdi
movsd  0x18(%rsp),%xmm0
call   1040 <printf@plt>
xor    %ebx,%ebx
jmp    136d <main+0x1bd>
movsbl %al,%edi
call   1070 <isprint@plt>
mov    0x2c80(%rip),%rcx
mov    (%rcx),%edi
mov    (%rbx),%cl
movsbl %cl,%edx
test   %eax,%eax
je     135c <main+0x1ac>
lea    0xcd4(%rip),%rsi
jmp    1363 <main+0x1b3>
lea    0xce2(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@opterr = global i64 0
@.str = [4 x i8] c"hd:\00"
@optarg = global i32 0
@optopt = global i8 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Option -%c requires an argument.\0A\00"
@.str.2 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@.str.3 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [11 x i8] c"Loops: %d\0A\00"
@.str.5 = [38 x i8] c"Delay per function: %.9g in seconds \0A\00"
@.str.6 = [38 x i8] c"Total time: %.9g seconds to execute \0A\00"
@.str.7 = [44 x i8] c"foo() took %.9g seconds in avg to execute \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (...) @fill_arrays()
store i32 0, i32* %9
store i64 0, i64* @opterr
br label %15
15: ; preds = %49, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %11
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %50
20: ; preds = %15
%21 = load i32, i32* %11
switch i32 %21, label %49 [
i32 104, label %22
i32 100, label %24
i32 63, label %27
]
22: ; preds = %20
%23 = call i32 (...) @print_help()
store i32 0, i32* %3
br label %93
24: ; preds = %20
%25 = load i32, i32* @optarg
%26 = call i32 @atoi(i32 %25)
store i32 %26, i32* %9
br label %49
27: ; preds = %20
%28 = load i8, i8* @optopt
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 100
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = load i8, i8* @optopt
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8 signext %33)
br label %48
35: ; preds = %27
%36 = load i8, i8* @optopt
%37 = call i32 @isprint(i8 signext %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = load i8, i8* @optopt
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %41)
br label %47
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = load i8, i8* @optopt
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8 signext %45)
br label %47
47: ; preds = %43, %39
br label %48
48: ; preds = %47, %31
store i32 -1, i32* %3
br label %93
49: ; preds = %20, %24
br label %15
50: ; preds = %15
%51 = call i64 (...) @clock()
store i64 %51, i64* %6
store i32 0, i32* %12
br label %52
52: ; preds = %63, %50
%53 = load i32, i32* %12
%54 = icmp slt i32 %53, 1000000
br i1 %54, label %55, label %66
55: ; preds = %52
%56 = call i32 (...) @foo()
%57 = load i32, i32* %9
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i32, i32* %9
%61 = call i32 @usleep(i32 %60)
br label %62
62: ; preds = %59, %55
br label %63
63: ; preds = %62
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %52
66: ; preds = %52
%67 = call i64 (...) @clock()
%68 = load i64, i64* %6
%69 = sub nsw i64 %67, %68
store i64 %69, i64* %6
%70 = load i64, i64* %6
%71 = sitofp i64 %70 to double
%72 = load double, double* @CLOCKS_PER_SEC
%73 = fdiv double %71, %72
store double %73, double* %8
%74 = load i32, i32* %9
%75 = sitofp i32 %74 to double
%76 = fdiv double %75, 1.000000e+06
store double %76, double* %13
%77 = load i64, i64* %6
%78 = sitofp i64 %77 to double
%79 = load double, double* @CLOCKS_PER_SEC
%80 = fdiv double %78, %79
%81 = fdiv double %80, 1.000000e+06
store double %81, double* %7
%82 = call i64 (...) @check_arrays()
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %66
store i32 -1, i32* %3
br label %93
85: ; preds = %66
%86 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), double 1.000000e+06)
%87 = load double, double* %13
%88 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), double %87)
%89 = load double, double* %8
%90 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), double %89)
%91 = load double, double* %7
%92 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), double %91)
store i32 0, i32* %3
br label %93
93: ; preds = %85, %84, %48, %22
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@opterr = global i64 0
@.str = [4 x i8] c"hd:\00"
@optarg = global i32 0
@optopt = global i8 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Option -%c requires an argument.\0A\00"
@.str.2 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@.str.3 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [11 x i8] c"Loops: %d\0A\00"
@.str.5 = [38 x i8] c"Delay per function: %.9g in seconds \0A\00"
@.str.6 = [38 x i8] c"Total time: %.9g seconds to execute \0A\00"
@.str.7 = [44 x i8] c"foo() took %.9g seconds in avg to execute \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @fill_arrays()
store i64 0, i64* @opterr
br label %4
4: ; preds = %10, %2
%5 = phi i32 [ %12, %10 ], [ 0, %2 ]
br label %6
6: ; preds = %4, %6
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %7, label %6 [
i32 -1, label %28
i32 104, label %8
i32 100, label %10
i32 63, label %13
]
8: ; preds = %6
%9 = tail call i32 (...) @print_help()
br label %55
10: ; preds = %6
%11 = load i32, i32* @optarg
%12 = tail call i32 @atoi(i32 %11)
br label %4
13: ; preds = %6
%14 = load i8, i8* @optopt
%15 = icmp eq i8 %14, 100
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8 signext 100)
br label %55
19: ; preds = %13
%20 = tail call i32 @isprint(i8 signext %14)
%21 = icmp eq i32 %20, 0
%22 = load i32, i32* @stderr
%23 = load i8, i8* @optopt
br i1 %21, label %26, label %24
24: ; preds = %19
%25 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %23)
br label %55
26: ; preds = %19
%27 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8 signext %23)
br label %55
28: ; preds = %6
%29 = tail call i64 (...) @clock()
%30 = icmp eq i32 %5, 0
br label %39
31: ; preds = %44
%32 = tail call i64 (...) @clock()
%33 = sub nsw i64 %32, %29
%34 = sitofp i64 %33 to double
%35 = load double, double* @CLOCKS_PER_SEC
%36 = fdiv double %34, %35
%37 = tail call i64 (...) @check_arrays()
%38 = icmp eq i64 %37, 0
br i1 %38, label %47, label %55
39: ; preds = %28, %44
%40 = phi i32 [ 0, %28 ], [ %45, %44 ]
%41 = tail call i32 (...) @foo()
br i1 %30, label %44, label %42
42: ; preds = %39
%43 = tail call i32 @usleep(i32 %5)
br label %44
44: ; preds = %39, %42
%45 = add nuw nsw i32 %40, 1
%46 = icmp eq i32 %45, 1000000
br i1 %46, label %31, label %39
47: ; preds = %31
%48 = fdiv double %36, 1.000000e+06
%49 = sitofp i32 %5 to double
%50 = fdiv double %49, 1.000000e+06
%51 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), double 1.000000e+06)
%52 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), double %50)
%53 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), double %36)
%54 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), double %48)
br label %55
55: ; preds = %47, %31, %16, %26, %24, %8
%56 = phi i32 [ 0, %8 ], [ -1, %24 ], [ -1, %26 ], [ -1, %16 ], [ 0, %47 ], [ -1, %31 ]
ret i32 %56
}