#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 /*<<< orphan*/ abort();
long atol(int /*<<< orphan*/);
scalar_t__ clock();
int /*<<< orphan*/ foo(long);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char **argv) {
  int c;
  long iter;
  clock_t start, end;
  double cpu_time_used;
  while ((c = getopt(argc, argv, "i:")) != -1)
    switch (c) {
    case 'i':
      iter = atol(optarg);
      break;
    default:
      abort();
    }
  start = clock();
  foo(iter);
  end = clock();
  cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
  printf("Time in foo: %f seconds\n", cpu_time_used);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7c(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11c9 <main+0x69>
mov    -0x14(%rbp),%eax
sub    $0x69,%eax
jne    11bd <main+0x5d>
jmp    11a6 <main+0x46>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1070 <atol@plt>
mov    %rax,-0x20(%rbp)
jmp    11c4 <main+0x64>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1176 <main+0x16>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <foo@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2de4(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xdf2(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe8c(%rip),%r15
mov    0x2e7d(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    $0x69,%eax
jne    11a0 <main+0x40>
mov    (%r12),%edi
call   1070 <atol@plt>
mov    %rax,%r14
jmp    1180 <main+0x20>
cmp    $0xffffffff,%eax
jne    11e8 <main+0x88>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <foo@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e13(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe2b(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"i:\00"
@optarg = global i32 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [25 x i8] c"Time in foo: %f seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %11
11: ; preds = %23, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %21 [
i32 105, label %18
]
18: ; preds = %16
%19 = load i32, i32* @optarg
%20 = call i64 @atol(i32 %19)
store i64 %20, i64* %7
br label %23
21: ; preds = %16
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %18
br label %11
24: ; preds = %11
%25 = call i64 (...) @clock()
store i64 %25, i64* %8
%26 = load i64, i64* %7
%27 = call i32 @foo(i64 %26)
%28 = call i64 (...) @clock()
store i64 %28, i64* %9
%29 = load i64, i64* %9
%30 = load i64, i64* %8
%31 = sub nsw i64 %29, %30
%32 = sitofp i64 %31 to double
%33 = load double, double* @CLOCKS_PER_SEC
%34 = fdiv double %32, %33
store double %34, double* %10
%35 = load double, double* %10
%36 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"i:\00"
@optarg = global i32 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [25 x i8] c"Time in foo: %f seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %6, %2
%4 = phi i64 [ undef, %2 ], [ %8, %6 ]
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %9 [
i32 -1, label %11
i32 105, label %6
]
6: ; preds = %3
%7 = load i32, i32* @optarg
%8 = tail call i64 @atol(i32 %7)
br label %3
9: ; preds = %3
%10 = tail call i32 (...) @abort()
unreachable
11: ; preds = %3
%12 = tail call i64 (...) @clock()
%13 = tail call i32 @foo(i64 %4)
%14 = tail call i64 (...) @clock()
%15 = sub nsw i64 %14, %12
%16 = sitofp i64 %15 to double
%17 = load double, double* @CLOCKS_PER_SEC
%18 = fdiv double %16, %17
%19 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %18)
ret i32 0
}