#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 */

/* 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*/ printf(char *, double);
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;
  if (argc != 2) {
    fprintf(stderr, "usage:  %s <n>\n", argv[0]);
    exit(0);
  }
  n = strtol(argv[1], NULL, 10);
  printf("CLOCKS_PER_SEC = %ld\n", (long)CLOCKS_PER_SEC);
  start = clock();
  for (i = 0; i < n; i++, pm = -pm)
    x += pm * exp(sin((double)i));
  finish = clock();
  elapsed = finish - start;
  elapsed = elapsed / CLOCKS_PER_SEC;
  printf("Elapsed time = %.14e seconds\n", elapsed);
  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)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c2 <main+0x52>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4a(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e05(%rip),%rax
cvttsd2si (%rax),%rax
cvtsi2sd %rax,%xmm0
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1261 <main+0xf1>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
cvtsi2sdq -0x28(%rbp),%xmm0
call   1060 <sin@plt>
mov    %eax,%edi
call   1080 <exp@plt>
mov    %eax,%ecx
mov    -0x48(%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    120c <main+0x9c>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    0x2d5e(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xd87(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    121e <main+0xae>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    0x2e50(%rip),%r15
cvttsd2si (%r15),%rcx
mov    %rax,%r12
cvtsi2sd %rcx,%xmm0
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
test   %r12,%r12
jle    11ed <main+0x7d>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
call   1060 <sin@plt>
mov    %eax,%edi
call   1080 <exp@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11d0 <main+0x60>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdcf(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"usage: %s <n>\0A\00"
@.str.1 = [22 x i8] c"CLOCKS_PER_SEC = %ld\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [30 x i8] c"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
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
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strtol(i8* %25, i32* null, i32 10)
store i64 %26, i64* %9
%27 = load double, double* @CLOCKS_PER_SEC
%28 = fptosi double %27 to i64
%29 = sitofp i64 %28 to double
%30 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), double %29)
%31 = call i64 (...) @clock()
store i64 %31, i64* %6
store i64 0, i64* %8
br label %32
32: ; preds = %46, %22
%33 = load i64, i64* %8
%34 = load i64, i64* %9
%35 = icmp slt i64 %33, %34
br i1 %35, label %36, label %51
36: ; preds = %32
%37 = load i32, i32* %12
%38 = load i64, i64* %8
%39 = sitofp i64 %38 to double
%40 = call i32 @sin(double %39)
%41 = call i32 @exp(i32 %40)
%42 = mul nsw i32 %37, %41
%43 = sitofp i32 %42 to double
%44 = load double, double* %11
%45 = fadd double %44, %43
store double %45, double* %11
br label %46
46: ; preds = %36
%47 = load i64, i64* %8
%48 = add nsw i64 %47, 1
store i64 %48, i64* %8
%49 = load i32, i32* %12
%50 = sub nsw i32 0, %49
store i32 %50, i32* %12
br label %32
51: ; preds = %32
%52 = call i64 (...) @clock()
store i64 %52, i64* %7
%53 = load i64, i64* %7
%54 = load i64, i64* %6
%55 = sub nsw i64 %53, %54
%56 = sitofp i64 %55 to double
store double %56, double* %10
%57 = load double, double* %10
%58 = load double, double* @CLOCKS_PER_SEC
%59 = fdiv double %57, %58
store double %59, double* %10
%60 = load double, double* %10
%61 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), double %60)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"usage: %s <n>\0A\00"
@.str.1 = [22 x i8] c"CLOCKS_PER_SEC = %ld\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [30 x i8] c"Elapsed time = %.14e seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strtol(i8* nocapture %11, i32* null, i32 10)
%13 = load double, double* @CLOCKS_PER_SEC
%14 = fptosi double %13 to i64
%15 = sitofp i64 %14 to double
%16 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), double %15)
%17 = tail call i64 (...) @clock()
%18 = icmp sgt i64 %12, 0
br i1 %18, label %19, label %26
19: ; preds = %9, %19
%20 = phi i64 [ %24, %19 ], [ 0, %9 ]
%21 = sitofp i64 %20 to double
%22 = tail call i32 @sin(double %21)
%23 = tail call i32 @exp(i32 %22)
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, %12
br i1 %25, label %26, label %19
26: ; preds = %19, %9
%27 = tail call i64 (...) @clock()
%28 = sub nsw i64 %27, %17
%29 = sitofp i64 %28 to double
%30 = load double, double* @CLOCKS_PER_SEC
%31 = fdiv double %29, %30
%32 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), double %31)
ret i32 0
}