#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 timeval {
  double tv_sec;
  double tv_usec;
};

/* Variables and functions */
double CLOCKS_PER_SEC;
long clock();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int exp(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sin(double);
int /*<<< orphan*/ stderr;
long strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  long start, finish;
  long i, n;
  double elapsed;
  double x = 0;
  int pm = 1;
  double gstart, gfinish, gelapsed;
  char c;
  if (argc != 2) {
    fprintf(stderr, "usage:  %s <n>\n", argv[0]);
    exit(0);
  }
  n = strtol(argv[1], NULL, 10);
  start = clock();
  {
    struct timeval t;
    gettimeofday(&t, NULL);
    gstart = t.tv_sec + t.tv_usec / 1000000.0;
  };
  printf("Hit enter to start...");
  scanf("%c", &c);
  for (i = 0; i < n; i++, pm = -pm)
    x += pm * exp(sin((double)i));
  finish = clock();
  {
    struct timeval t;
    gettimeofday(&t, NULL);
    gfinish = t.tv_sec + t.tv_usec / 1000000.0;
  };
  elapsed = finish - start;
  elapsed = elapsed / CLOCKS_PER_SEC;
  printf("Clock elapsed time = %.14e seconds\n", elapsed);
  gelapsed = gfinish - gstart;
  printf("Wall clock elapsed time = %.14e seconds\n", gelapsed);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e5 <main+0x55>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2f(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
lea    -0x78(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x78(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm1
movsd  0xdd7(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde3(%rip),%rdi
lea    -0x61(%rbp),%rsi
call   10a0 <scanf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    12b7 <main+0x127>
mov    -0x44(%rbp),%eax
mov    %eax,-0x8c(%rbp)
cvtsi2sdq -0x28(%rbp),%xmm0
call   1070 <sin@plt>
mov    %eax,%edi
call   1090 <exp@plt>
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    125c <main+0xcc>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
lea    -0x88(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x80(%rbp),%xmm1
movsd  0xd19(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    0x2cd6(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xd0a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x58(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
lea    0xd0c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
cmp    $0x2,%edi
jne    12c1 <main+0x131>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movsd  0x10(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0x18(%rsp),%xmm0
movapd %xmm0,0x30(%rsp)
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe3f(%rip),%rdi
lea    0xf(%rsp),%rsi
call   10a0 <scanf@plt>
test   %r15,%r15
jle    122d <main+0x9d>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
call   1070 <sin@plt>
mov    %eax,%edi
call   1090 <exp@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1210 <main+0x80>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movsd  0x18(%rsp),%xmm2
unpcklpd 0x30(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
divpd  0xda3(%rip),%xmm2
unpcklpd 0x20(%rsp),%xmm1
sub    %r14,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
addpd  %xmm1,%xmm2
movapd %xmm2,0x20(%rsp)
mov    0x2d69(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdaf(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movapd 0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
lea    0xdaf(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd3c(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, double }
@stderr = global i32 0
@.str = [16 x i8] c"usage: %s <n>\0A\00"
@.str.1 = [22 x i8] c"Hit enter to start...\00"
@.str.2 = [3 x i8] c"%c\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [36 x i8] c"Clock elapsed time = %.14e seconds\0A\00"
@.str.4 = [41 x i8] c"Wall clock elapsed time = %.14e seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca i8
%17 = alloca %struct.timeval
%18 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %11
store i32 1, i32* %12
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %28
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i64 @strtol(i8* %31, i32* null, i32 10)
store i64 %32, i64* %9
%33 = call i64 (...) @clock()
store i64 %33, i64* %6
%34 = call i32 @gettimeofday(%struct.timeval* %17, i32* null)
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%36 = load double, double* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
%38 = load double, double* %37
%39 = fdiv double %38, 1.000000e+06
%40 = fadd double %36, %39
store double %40, double* %13
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %16)
store i64 0, i64* %8
br label %43
43: ; preds = %57, %28
%44 = load i64, i64* %8
%45 = load i64, i64* %9
%46 = icmp slt i64 %44, %45
br i1 %46, label %47, label %62
47: ; preds = %43
%48 = load i32, i32* %12
%49 = load i64, i64* %8
%50 = sitofp i64 %49 to double
%51 = call i32 @sin(double %50)
%52 = call i32 @exp(i32 %51)
%53 = mul nsw i32 %48, %52
%54 = sitofp i32 %53 to double
%55 = load double, double* %11
%56 = fadd double %55, %54
store double %56, double* %11
br label %57
57: ; preds = %47
%58 = load i64, i64* %8
%59 = add nsw i64 %58, 1
store i64 %59, i64* %8
%60 = load i32, i32* %12
%61 = sub nsw i32 0, %60
store i32 %61, i32* %12
br label %43
62: ; preds = %43
%63 = call i64 (...) @clock()
store i64 %63, i64* %7
%64 = call i32 @gettimeofday(%struct.timeval* %18, i32* null)
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%66 = load double, double* %65
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%68 = load double, double* %67
%69 = fdiv double %68, 1.000000e+06
%70 = fadd double %66, %69
store double %70, double* %14
%71 = load i64, i64* %7
%72 = load i64, i64* %6
%73 = sub nsw i64 %71, %72
%74 = sitofp i64 %73 to double
store double %74, double* %10
%75 = load double, double* %10
%76 = load double, double* @CLOCKS_PER_SEC
%77 = fdiv double %75, %76
store double %77, double* %10
%78 = load double, double* %10
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %78)
%80 = load double, double* %14
%81 = load double, double* %13
%82 = fsub double %80, %81
store double %82, double* %15
%83 = load double, double* %15
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), double %83)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@stderr = global i32 0
@.str = [16 x i8] c"usage: %s <n>\0A\00"
@.str.1 = [22 x i8] c"Hit enter to start...\00"
@.str.2 = [3 x i8] c"%c\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [36 x i8] c"Clock elapsed time = %.14e seconds\0A\00"
@.str.4 = [41 x i8] c"Wall clock elapsed time = %.14e seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = icmp eq i32 %0, 2
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strtol(i8* nocapture %14, i32* null, i32 10)
%16 = tail call i64 (...) @clock()
%17 = bitcast %struct.timeval* %4 to i8*
%18 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%20 = load double, double* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%22 = load double, double* %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%25 = icmp sgt i64 %15, 0
br i1 %25, label %26, label %33
26: ; preds = %12, %26
%27 = phi i64 [ %31, %26 ], [ 0, %12 ]
%28 = sitofp i64 %27 to double
%29 = call i32 @sin(double %28)
%30 = call i32 @exp(i32 %29)
%31 = add nuw nsw i64 %27, 1
%32 = icmp eq i64 %31, %15
br i1 %32, label %33, label %26
33: ; preds = %26, %12
%34 = call i64 (...) @clock()
%35 = bitcast %struct.timeval* %5 to i8*
%36 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%38 = load double, double* %37
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%40 = load double, double* %39
%41 = insertelement <2 x double> poison, double %22, i64 1
%42 = insertelement <2 x double> %41, double %40, i64 0
%43 = fdiv <2 x double> %42, <double 1.000000e+06, double 1.000000e+06>
%44 = insertelement <2 x double> poison, double %20, i64 1
%45 = insertelement <2 x double> %44, double %38, i64 0
%46 = fadd <2 x double> %45, %43
%47 = sub nsw i64 %34, %16
%48 = sitofp i64 %47 to double
%49 = load double, double* @CLOCKS_PER_SEC
%50 = fdiv double %48, %49
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %50)
%52 = shufflevector <2 x double> %46, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%53 = fsub <2 x double> %46, %52
%54 = extractelement <2 x double> %53, i64 0
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), double %54)
ret i32 0
}