#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 */
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 *, double);
int /*<<< orphan*/ sin(double);
int /*<<< orphan*/ stderr;
long strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  double 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);
  {
    struct timeval t;
    gettimeofday(&t, NULL);
    start = t.tv_sec + t.tv_usec / 1000000.0;
  };
  for (i = 0; i < n; i++, pm = -pm)
    x += pm * exp(sin((double)i));
  {
    struct timeval t;
    gettimeofday(&t, NULL);
    finish = t.tv_sec + t.tv_usec / 1000000.0;
  };
  elapsed = finish - start;
  printf("Elapsed time = %.14e seconds\n", elapsed);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe52(%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)
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  0xe05(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1265 <main+0xf5>
mov    -0x44(%rbp),%eax
mov    %eax,-0x6c(%rbp)
cvtsi2sdq -0x28(%rbp),%xmm0
call   1060 <sin@plt>
mov    %eax,%edi
call   1080 <exp@plt>
mov    %eax,%ecx
mov    -0x6c(%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    1210 <main+0xa0>
lea    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  -0x68(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  0xd7c(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xd6c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
cmp    $0x2,%edi
jne    122c <main+0xbc>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%r14
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  (%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
test   %r14,%r14
jle    11dd <main+0x6d>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
call   1060 <sin@plt>
mov    %eax,%edi
call   1080 <exp@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11c0 <main+0x50>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  0x8(%rsp),%xmm0
unpcklpd 0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
divpd  0xe00(%rip),%xmm0
unpcklpd 0x20(%rsp),%xmm1
addpd  %xmm1,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
subsd  %xmm1,%xmm0
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdd1(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <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 = [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 double
%7 = alloca double
%8 = alloca i64
%9 = alloca i64
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca %struct.timeval
%14 = 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
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @strtol(i8* %27, i32* null, i32 10)
store i64 %28, i64* %9
%29 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%31 = load double, double* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%33 = load double, double* %32
%34 = fdiv double %33, 1.000000e+06
%35 = fadd double %31, %34
store double %35, double* %6
store i64 0, i64* %8
br label %36
36: ; preds = %50, %24
%37 = load i64, i64* %8
%38 = load i64, i64* %9
%39 = icmp slt i64 %37, %38
br i1 %39, label %40, label %55
40: ; preds = %36
%41 = load i32, i32* %12
%42 = load i64, i64* %8
%43 = sitofp i64 %42 to double
%44 = call i32 @sin(double %43)
%45 = call i32 @exp(i32 %44)
%46 = mul nsw i32 %41, %45
%47 = sitofp i32 %46 to double
%48 = load double, double* %11
%49 = fadd double %48, %47
store double %49, double* %11
br label %50
50: ; preds = %40
%51 = load i64, i64* %8
%52 = add nsw i64 %51, 1
store i64 %52, i64* %8
%53 = load i32, i32* %12
%54 = sub nsw i32 0, %53
store i32 %54, i32* %12
br label %36
55: ; preds = %36
%56 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%58 = load double, double* %57
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%60 = load double, double* %59
%61 = fdiv double %60, 1.000000e+06
%62 = fadd double %58, %61
store double %62, double* %7
%63 = load double, double* %7
%64 = load double, double* %6
%65 = fsub double %63, %64
store double %65, double* %10
%66 = load double, double* %10
%67 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), double %66)
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 = [30 x i8] c"Elapsed time = %.14e seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @strtol(i8* nocapture %13, i32* null, i32 10)
%15 = bitcast %struct.timeval* %3 to i8*
%16 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%18 = load double, double* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%20 = load double, double* %19
%21 = icmp sgt i64 %14, 0
br i1 %21, label %22, label %29
22: ; preds = %11, %22
%23 = phi i64 [ %27, %22 ], [ 0, %11 ]
%24 = sitofp i64 %23 to double
%25 = tail call i32 @sin(double %24)
%26 = tail call i32 @exp(i32 %25)
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, %14
br i1 %28, label %29, label %22
29: ; preds = %22, %11
%30 = bitcast %struct.timeval* %4 to i8*
%31 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%33 = load double, double* %32
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%35 = load double, double* %34
%36 = insertelement <2 x double> poison, double %20, i64 1
%37 = insertelement <2 x double> %36, double %35, i64 0
%38 = fdiv <2 x double> %37, <double 1.000000e+06, double 1.000000e+06>
%39 = insertelement <2 x double> poison, double %18, i64 1
%40 = insertelement <2 x double> %39, double %33, i64 0
%41 = fadd <2 x double> %40, %38
%42 = shufflevector <2 x double> %41, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%43 = fsub <2 x double> %41, %42
%44 = extractelement <2 x double> %43, i64 0
%45 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), double %44)
ret i32 0
}