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

/* Variables and functions */
int CLOCKS_PER_SEC;
double clock();
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sscanf(char *, char *, double *);
int main(int argc, char **argv) {
  clock_t ticks = 1 * CLOCKS_PER_SEC;
  if (argc == 2) {
    double seconds = 1;
    sscanf(argv[1], "%lg", &seconds);
    ticks = seconds * CLOCKS_PER_SEC;
  }
  printf("Starting timing for %lg seconds...\n",
         ticks / (double)CLOCKS_PER_SEC);
  double foo = 0;
  while (clock() < ticks) {
    for (int i = 0; i < 1000000; i++) {
      foo += 1;
    }
  }
  printf("All done spinning! %g\n", foo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
shl    $0x0,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11a3 <main+0x73>
movsd  0xe93(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe87(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <sscanf@plt>
movsd  -0x20(%rbp),%xmm0
mov    0x2e52(%rip),%rax
cvtsi2sdl (%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2e39(%rip),%rax
cvtsi2sdl (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    121d <main+0xed>
movl   $0x0,-0x2c(%rbp)
cmpl   $0xf4240,-0x2c(%rbp)
jge    1218 <main+0xe8>
movsd  0xe00(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11eb <main+0xbb>
jmp    11cb <main+0x9b>
movsd  -0x28(%rbp),%xmm0
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2eac(%rip),%rbx
cmp    $0x2,%edi
jne    1175 <main+0x45>
movabs $0x3ff0000000000000,%rax
mov    %rax,0x10(%rsp)
mov    0x8(%rsi),%rdi
lea    0xead(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1050 <sscanf@plt>
cvtsi2sdl (%rbx),%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm1,%xmm0
jmp    117d <main+0x4d>
cvtsi2sdl (%rbx),%xmm1
movapd %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
xorpd  %xmm2,%xmm2
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    11f8 <main+0xc8>
xorpd  %xmm2,%xmm2
movsd  0xe42(%rip),%xmm0
xchg   %ax,%ax
addsd  %xmm0,%xmm2
add    $0x1,%ebx
cmp    $0xf4240,%ebx
jne    11c0 <main+0x90>
xor    %ebx,%ebx
xor    %eax,%eax
movsd  %xmm2,0x18(%rsp)
call   1030 <clock@plt>
movsd  0x18(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movsd  0xe0a(%rip),%xmm0
ja     11c0 <main+0x90>
lea    0xe31(%rip),%rdi
movapd %xmm2,%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global i32 0
@.str = [4 x i8] c"%lg\00"
@.str.1 = [36 x i8] c"Starting timing for %lg seconds...\0A\00"
@.str.2 = [23 x i8] c"All done spinning! %g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @CLOCKS_PER_SEC
%11 = mul nsw i32 1, %10
%12 = sitofp i32 %11 to double
store double %12, double* %6
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %24
15: ; preds = %2
store double 1.000000e+00, double* %7
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %7)
%20 = load double, double* %7
%21 = load i32, i32* @CLOCKS_PER_SEC
%22 = sitofp i32 %21 to double
%23 = fmul double %20, %22
store double %23, double* %6
br label %24
24: ; preds = %15, %2
%25 = load double, double* %6
%26 = load i32, i32* @CLOCKS_PER_SEC
%27 = sitofp i32 %26 to double
%28 = fdiv double %25, %27
%29 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %28)
store double 0.000000e+00, double* %8
br label %30
30: ; preds = %44, %24
%31 = call double (...) @clock()
%32 = load double, double* %6
%33 = fcmp olt double %31, %32
br i1 %33, label %34, label %45
34: ; preds = %30
store i32 0, i32* %9
br label %35
35: ; preds = %41, %34
%36 = load i32, i32* %9
%37 = icmp slt i32 %36, 1000000
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load double, double* %8
%40 = fadd double %39, 1.000000e+00
store double %40, double* %8
br label %41
41: ; preds = %38
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %35
44: ; preds = %35
br label %30
45: ; preds = %30
%46 = load double, double* %8
%47 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %46)
ret i32 0
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i32 0
@.str = [4 x i8] c"%lg\00"
@.str.1 = [36 x i8] c"Starting timing for %lg seconds...\0A\00"
@.str.2 = [23 x i8] c"All done spinning! %g\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = load i32, i32* @CLOCKS_PER_SEC
%5 = sitofp i32 %4 to double
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = bitcast double* %3 to i8*
store double 1.000000e+00, double* %3
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %3)
%12 = load double, double* %3
%13 = load i32, i32* @CLOCKS_PER_SEC
%14 = sitofp i32 %13 to double
%15 = fmul double %12, %14
br label %16
16: ; preds = %7, %2
%17 = phi double [ %14, %7 ], [ %5, %2 ]
%18 = phi double [ %15, %7 ], [ %5, %2 ]
%19 = fdiv double %18, %17
%20 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %19)
%21 = call double (...) @clock()
%22 = fcmp olt double %21, %18
br i1 %22, label %26, label %34
23: ; preds = %26
%24 = call double (...) @clock()
%25 = fcmp olt double %24, %18
br i1 %25, label %32, label %34
26: ; preds = %16, %32
%27 = phi i32 [ %33, %32 ], [ 0, %16 ]
%28 = phi double [ %29, %32 ], [ 0.000000e+00, %16 ]
%29 = fadd double %28, 1.000000e+00
%30 = add nuw nsw i32 %27, 1
%31 = icmp eq i32 %30, 1000000
br i1 %31, label %23, label %32
32: ; preds = %26, %23
%33 = phi i32 [ %30, %26 ], [ 0, %23 ]
br label %26
34: ; preds = %23, %16
%35 = phi double [ 0.000000e+00, %16 ], [ %29, %23 ]
%36 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %35)
ret i32 0
}