#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 *);
int /*<<< orphan*/ printf(char *, double);
scalar_t__ 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.;
  clock_gettime(CLOCK_MONOTONIC, &t_init_wall);
  t_init_cpu = clock();
  for (i = 0; i < (20000000 * 8); i++) {
    res += sin(M_PI * (1 + 4 * i) / 2);
  }
  t_end_cpu = clock();
  clock_gettime(CLOCK_MONOTONIC, &t_end_wall);
  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    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    0x2e7b(%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    11d0 <main+0x90>
mov    0x2e52(%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>
cvtsi2sd %rax,%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1182 <main+0x42>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dd7(%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  0xddd(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x60(%rbp),%xmm0
lea    0xdcb(%rip),%rdi
call   1050 <printf@plt>
lea    0xdcd(%rip),%rdi
movsd  0xda7(%rip),%xmm0
call   1050 <printf@plt>
movsd  -0x38(%rbp),%xmm0
lea    0xdd4(%rip),%rdi
call   1050 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xdda(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2e8e(%rip),%r15
mov    (%r15),%edi
lea    0x30(%rsp),%rsi
call   1030 <clock_gettime@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    $0x5,%ebx
mov    0x2e6a(%rip),%r12
xchg   %ax,%ax
lea    -0x4(%rbx),%eax
imul   (%r12),%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1060 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    (%r12),%eax
imul   %ebx,%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1060 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
add    $0x8,%ebx
cmp    $0x2625a005,%ebx
jne    1180 <main+0x40>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
mov    (%r15),%edi
lea    0x20(%rsp),%rsi
call   1030 <clock_gettime@plt>
sub    %r14,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
mov    0x2dd5(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x20(%rsp),%xmm0
subpd  0x30(%rsp),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
divsd  0xdd7(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
lea    0xdd6(%rip),%rdi
movsd  (%rsp),%xmm0
call   1050 <printf@plt>
lea    0xdd3(%rip),%rdi
movsd  0xdb5(%rip),%xmm0
call   1050 <printf@plt>
lea    0xddf(%rip),%rdi
movaps 0x10(%rsp),%xmm0
call   1050 <printf@plt>
lea    0xde5(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %13
%14 = load i32, i32* @CLOCK_MONOTONIC
%15 = call i32 @clock_gettime(i32 %14, %struct.timespec* %6)
%16 = call i64 (...) @clock()
store i64 %16, i64* %10
store i32 0, i32* %12
br label %17
17: ; preds = %31, %2
%18 = load i32, i32* %12
%19 = icmp slt i32 %18, 160000000
br i1 %19, label %20, label %34
20: ; preds = %17
%21 = load i32, i32* @M_PI
%22 = load i32, i32* %12
%23 = mul nsw i32 4, %22
%24 = add nsw i32 1, %23
%25 = mul nsw i32 %21, %24
%26 = sdiv i32 %25, 2
%27 = call i64 @sin(i32 %26)
%28 = sitofp i64 %27 to double
%29 = load double, double* %13
%30 = fadd double %29, %28
store double %30, double* %13
br label %31
31: ; preds = %20
%32 = load i32, i32* %12
%33 = add nsw i32 %32, 1
store i32 %33, i32* %12
br label %17
34: ; preds = %17
%35 = call i64 (...) @clock()
store i64 %35, i64* %11
%36 = load i32, i32* @CLOCK_MONOTONIC
%37 = call i32 @clock_gettime(i32 %36, %struct.timespec* %7)
%38 = load i64, i64* %11
%39 = load i64, i64* %10
%40 = sub nsw i64 %38, %39
%41 = sitofp i64 %40 to double
%42 = load double, double* @CLOCKS_PER_SEC
%43 = fdiv double %41, %42
store double %43, double* %9
%44 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%45 = load double, double* %44
%46 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%47 = load double, double* %46
%48 = fsub double %45, %47
store double %48, double* %8
%49 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%50 = load double, double* %49
%51 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%52 = load double, double* %51
%53 = fsub double %50, %52
%54 = fdiv double %53, 1.000000e+09
%55 = load double, double* %8
%56 = fadd double %55, %54
store double %56, double* %8
%57 = load double, double* %13
%58 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %57)
%59 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double 1.600000e+08)
%60 = load double, double* %8
%61 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %60)
%62 = load double, double* %9
%63 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %62)
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>* %3 to i8*
%7 = bitcast <2 x double>* %5 to i8*
%8 = load i32, i32* @CLOCK_MONOTONIC
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %4)
%10 = call i64 (...) @clock()
br label %11
11: ; preds = %11, %2
%12 = phi double [ 0.000000e+00, %2 ], [ %29, %11 ]
%13 = phi i32 [ 0, %2 ], [ %30, %11 ]
%14 = load i32, i32* @M_PI
%15 = shl nuw nsw i32 %13, 2
%16 = or i32 %15, 1
%17 = mul nsw i32 %14, %16
%18 = sdiv i32 %17, 2
%19 = call i64 @sin(i32 %18)
%20 = sitofp i64 %19 to double
%21 = fadd double %12, %20
%22 = load i32, i32* @M_PI
%23 = shl i32 %13, 2
%24 = or i32 %23, 5
%25 = mul nsw i32 %22, %24
%26 = sdiv i32 %25, 2
%27 = call i64 @sin(i32 %26)
%28 = sitofp i64 %27 to double
%29 = fadd double %21, %28
%30 = add nuw nsw i32 %13, 2
%31 = icmp eq i32 %30, 160000000
br i1 %31, label %32, label %11
32: ; preds = %11
%33 = bitcast <2 x double>* %5 to %struct.timespec*
%34 = call i64 (...) @clock()
%35 = load i32, i32* @CLOCK_MONOTONIC
%36 = call i32 @clock_gettime(i32 %35, %struct.timespec* %33)
%37 = sub nsw i64 %34, %10
%38 = sitofp i64 %37 to double
%39 = load double, double* @CLOCKS_PER_SEC
%40 = fdiv double %38, %39
%41 = load <2 x double>, <2 x double>* %5
%42 = load <2 x double>, <2 x double>* %3
%43 = fsub <2 x double> %41, %42
%44 = extractelement <2 x double> %43, i64 1
%45 = fdiv double %44, 1.000000e+09
%46 = extractelement <2 x double> %43, i64 0
%47 = fadd double %46, %45
%48 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %29)
%49 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double 1.600000e+08)
%50 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %47)
%51 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %40)
ret i32 0
}