#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 timespec {
  double tv_sec;
  double tv_nsec;
};
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ CLOCK_MONOTONIC;
int M_PI;
scalar_t__ clock();
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
double *malloc(int);
int /*<<< orphan*/ printf(char *, double);
double sin(int);
main(int argc, char *argv[]) {
  struct timespec t_init_wall, t_end_wall;
  double elapsed_wall, elapsed_cpu;
  clock_t t_init_cpu, t_end_cpu;
  int i;
  double res = 0;
  double *a = malloc(sizeof(double) * (20000000 * 8));
  clock_gettime(CLOCK_MONOTONIC, &t_init_wall);
  t_init_cpu = clock();
#pragma omp parallel for shared(a)
  for (i = 0; i < (20000000 * 8); i++) {
    a[i] = sin(M_PI * (1 + 4 * i) / 2);
  }
  t_end_cpu = clock();
  clock_gettime(CLOCK_MONOTONIC, &t_end_wall);
  for (i = 0; i < (20000000 * 8); i++) {
    res += a[i];
  }
  elapsed_cpu = (double)(t_end_cpu - t_init_cpu) / CLOCKS_PER_SEC;
  elapsed_wall = (t_end_wall.tv_sec - t_init_wall.tv_sec);
  elapsed_wall += (t_end_wall.tv_nsec - t_init_wall.tv_nsec) / 1000000000.0;
  printf("Result:  %g \n", res);
  printf("Total number of operations: %g\n", (double)(20000000 * 8));
  printf("Total wall-time: %g s\n", elapsed_wall);
  printf("Total cpu-time:  %g s\n", elapsed_cpu);
  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,-0x60(%rbp)
mov    $0x4c4b4000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x9896800,-0x54(%rbp)
jge    11ec <main+0x9c>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    -0x54(%rbp),%ecx
shl    $0x2,%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1060 <sin@plt>
mov    -0x68(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11a0 <main+0x50>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <clock_gettime@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x9896800,-0x54(%rbp)
jge    1242 <main+0xf2>
mov    -0x68(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1210 <main+0xc0>
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d82(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xd88(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x60(%rbp),%xmm0
lea    0xd76(%rip),%rdi
call   1050 <printf@plt>
lea    0xd78(%rip),%rdi
movsd  0xd52(%rip),%xmm0
call   1050 <printf@plt>
movsd  -0x38(%rbp),%xmm0
lea    0xd7f(%rip),%rdi
call   1050 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xd85(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    $0x4c4b4000,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    0x2e6f(%rip),%r12
mov    (%r12),%edi
lea    0x30(%rsp),%rsi
call   1030 <clock_gettime@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    0x2e56(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbx),%eax
imul   (%r15),%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1060 <sin@plt>
lea    0x5(%rbx),%eax
imul   (%r15),%eax
movsd  %xmm0,0x0(%r13,%rbx,2)
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1060 <sin@plt>
movsd  %xmm0,0x8(%r13,%rbx,2)
add    $0x8,%rbx
cmp    $0x2625a000,%rbx
jne    11a0 <main+0x50>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r15
mov    (%r12),%edi
lea    0x20(%rsp),%rsi
call   1030 <clock_gettime@plt>
xorpd  %xmm0,%xmm0
mov    $0x7,%eax
cs nopw 0x0(%rax,%rax,1)
addsd  -0x38(%r13,%rax,8),%xmm0
addsd  -0x30(%r13,%rax,8),%xmm0
addsd  -0x28(%r13,%rax,8),%xmm0
addsd  -0x20(%r13,%rax,8),%xmm0
addsd  -0x18(%r13,%rax,8),%xmm0
addsd  -0x10(%r13,%rax,8),%xmm0
addsd  -0x8(%r13,%rax,8),%xmm0
addsd  0x0(%r13,%rax,8),%xmm0
add    $0x8,%rax
cmp    $0x9896807,%rax
jne    1210 <main+0xc0>
sub    %r14,%r15
cvtsi2sd %r15,%xmm1
mov    0x2d75(%rip),%rax
divsd  (%rax),%xmm1
movsd  %xmm1,0x8(%rsp)
movapd 0x20(%rsp),%xmm1
subpd  0x30(%rsp),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
divsd  0xd77(%rip),%xmm2
addsd  %xmm1,%xmm2
movapd %xmm2,0x10(%rsp)
lea    0xd76(%rip),%rdi
call   1050 <printf@plt>
lea    0xd78(%rip),%rdi
movsd  0xd5a(%rip),%xmm0
call   1050 <printf@plt>
lea    0xd84(%rip),%rdi
movaps 0x10(%rsp),%xmm0
call   1050 <printf@plt>
lea    0xd8a(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { double, double }
@CLOCK_MONOTONIC = global i32 0
@M_PI = global i32 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [14 x i8] c"Result: %g \0A\00"
@.str.1 = [32 x i8] c"Total number of operations: %g\0A\00"
@.str.2 = [23 x i8] c"Total wall-time: %g s\0A\00"
@.str.3 = [23 x i8] c"Total cpu-time: %g s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = alloca double
%9 = alloca double
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca double
%14 = alloca double*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %13
%15 = call double* @malloc(i32 1280000000)
store double* %15, double** %14
%16 = load i32, i32* @CLOCK_MONOTONIC
%17 = call i32 @clock_gettime(i32 %16, %struct.timespec* %6)
%18 = call i64 (...) @clock()
store i64 %18, i64* %10
store i32 0, i32* %12
br label %19
19: ; preds = %34, %2
%20 = load i32, i32* %12
%21 = icmp slt i32 %20, 160000000
br i1 %21, label %22, label %37
22: ; preds = %19
%23 = load i32, i32* @M_PI
%24 = load i32, i32* %12
%25 = mul nsw i32 4, %24
%26 = add nsw i32 1, %25
%27 = mul nsw i32 %23, %26
%28 = sdiv i32 %27, 2
%29 = call double @sin(i32 %28)
%30 = load double*, double** %14
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double %29, double* %33
br label %34
34: ; preds = %22
%35 = load i32, i32* %12
%36 = add nsw i32 %35, 1
store i32 %36, i32* %12
br label %19
37: ; preds = %19
%38 = call i64 (...) @clock()
store i64 %38, i64* %11
%39 = load i32, i32* @CLOCK_MONOTONIC
%40 = call i32 @clock_gettime(i32 %39, %struct.timespec* %7)
store i32 0, i32* %12
br label %41
41: ; preds = %52, %37
%42 = load i32, i32* %12
%43 = icmp slt i32 %42, 160000000
br i1 %43, label %44, label %55
44: ; preds = %41
%45 = load double*, double** %14
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = load double, double* %13
%51 = fadd double %50, %49
store double %51, double* %13
br label %52
52: ; preds = %44
%53 = load i32, i32* %12
%54 = add nsw i32 %53, 1
store i32 %54, i32* %12
br label %41
55: ; preds = %41
%56 = load i64, i64* %11
%57 = load i64, i64* %10
%58 = sub nsw i64 %56, %57
%59 = sitofp i64 %58 to double
%60 = load double, double* @CLOCKS_PER_SEC
%61 = fdiv double %59, %60
store double %61, double* %9
%62 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%63 = load double, double* %62
%64 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%65 = load double, double* %64
%66 = fsub double %63, %65
store double %66, double* %8
%67 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%68 = load double, double* %67
%69 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%70 = load double, double* %69
%71 = fsub double %68, %70
%72 = fdiv double %71, 1.000000e+09
%73 = load double, double* %8
%74 = fadd double %73, %72
store double %74, double* %8
%75 = load double, double* %13
%76 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %75)
%77 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double 1.600000e+08)
%78 = load double, double* %8
%79 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %78)
%80 = load double, double* %9
%81 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %80)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { double, double }
@CLOCK_MONOTONIC = global i32 0
@M_PI = global i32 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [14 x i8] c"Result: %g \0A\00"
@.str.1 = [32 x i8] c"Total number of operations: %g\0A\00"
@.str.2 = [23 x i8] c"Total wall-time: %g s\0A\00"
@.str.3 = [23 x i8] c"Total cpu-time: %g s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca <2 x double>
%4 = bitcast <2 x double>* %3 to %struct.timespec*
%5 = alloca <2 x double>
%6 = bitcast <2 x double>* %5 to %struct.timespec*
%7 = bitcast <2 x double>* %3 to i8*
%8 = bitcast <2 x double>* %5 to i8*
%9 = tail call double* @malloc(i32 1280000000)
%10 = load i32, i32* @CLOCK_MONOTONIC
%11 = call i32 @clock_gettime(i32 %10, %struct.timespec* %4)
%12 = call i64 (...) @clock()
br label %13
13: ; preds = %13, %2
%14 = phi i64 [ 0, %2 ], [ %32, %13 ]
%15 = load i32, i32* @M_PI
%16 = trunc i64 %14 to i32
%17 = shl i32 %16, 2
%18 = or i32 %17, 1
%19 = mul nsw i32 %15, %18
%20 = sdiv i32 %19, 2
%21 = call double @sin(i32 %20)
%22 = getelementptr inbounds double, double* %9, i64 %14
store double %21, double* %22
%23 = or i64 %14, 1
%24 = load i32, i32* @M_PI
%25 = trunc i64 %23 to i32
%26 = shl i32 %25, 2
%27 = or i32 %26, 1
%28 = mul nsw i32 %24, %27
%29 = sdiv i32 %28, 2
%30 = call double @sin(i32 %29)
%31 = getelementptr inbounds double, double* %9, i64 %23
store double %30, double* %31
%32 = add nuw nsw i64 %14, 2
%33 = icmp eq i64 %32, 160000000
br i1 %33, label %34, label %13
34: ; preds = %13
%35 = call i64 (...) @clock()
%36 = load i32, i32* @CLOCK_MONOTONIC
%37 = call i32 @clock_gettime(i32 %36, %struct.timespec* %6)
br label %38
38: ; preds = %38, %34
%39 = phi i64 [ 0, %34 ], [ %72, %38 ]
%40 = phi double [ 0.000000e+00, %34 ], [ %71, %38 ]
%41 = getelementptr inbounds double, double* %9, i64 %39
%42 = load double, double* %41
%43 = fadd double %40, %42
%44 = or i64 %39, 1
%45 = getelementptr inbounds double, double* %9, i64 %44
%46 = load double, double* %45
%47 = fadd double %43, %46
%48 = or i64 %39, 2
%49 = getelementptr inbounds double, double* %9, i64 %48
%50 = load double, double* %49
%51 = fadd double %47, %50
%52 = or i64 %39, 3
%53 = getelementptr inbounds double, double* %9, i64 %52
%54 = load double, double* %53
%55 = fadd double %51, %54
%56 = or i64 %39, 4
%57 = getelementptr inbounds double, double* %9, i64 %56
%58 = load double, double* %57
%59 = fadd double %55, %58
%60 = or i64 %39, 5
%61 = getelementptr inbounds double, double* %9, i64 %60
%62 = load double, double* %61
%63 = fadd double %59, %62
%64 = or i64 %39, 6
%65 = getelementptr inbounds double, double* %9, i64 %64
%66 = load double, double* %65
%67 = fadd double %63, %66
%68 = or i64 %39, 7
%69 = getelementptr inbounds double, double* %9, i64 %68
%70 = load double, double* %69
%71 = fadd double %67, %70
%72 = add nuw nsw i64 %39, 8
%73 = icmp eq i64 %72, 160000000
br i1 %73, label %74, label %38
74: ; preds = %38
%75 = sub nsw i64 %35, %12
%76 = sitofp i64 %75 to double
%77 = load double, double* @CLOCKS_PER_SEC
%78 = fdiv double %76, %77
%79 = load <2 x double>, <2 x double>* %5
%80 = load <2 x double>, <2 x double>* %3
%81 = fsub <2 x double> %79, %80
%82 = extractelement <2 x double> %81, i64 1
%83 = fdiv double %82, 1.000000e+09
%84 = extractelement <2 x double> %81, i64 0
%85 = fadd double %84, %83
%86 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %71)
%87 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double 1.600000e+08)
%88 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %85)
%89 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %78)
ret i32 0
}