#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 timezone {
  int dummy;
};
struct timeval {
  int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char const *argv[]) {
  struct timeval TimeValue_Start;
  struct timezone TimeZone_Start;
  struct timeval TimeValue_Final;
  struct timezone TimeZone_Final;
  long time_start, time_end;
  double time_overhead;
  double pi, x;
  int i, n;
  pi = 0.0;
  n = 1000;
  gettimeofday(&TimeValue_Start, &TimeZone_Start);
#pragma omp parallel for private(x) reduction(+ : pi)
  for (i = 0; i < n; i++) {
    x = (double)i / n;
    pi += 4 / (1 + x * x);
  }
  gettimeofday(&TimeValue_Final, &TimeZone_Final);
  time_start = TimeValue_Start.tv_sec * 1000000 + TimeValue_Start.tv_sec;
  time_end = TimeValue_Final.tv_sec * 1000000 + TimeValue_Final.tv_sec;
  time_overhead = (time_end - time_start);
  printf("Time in seconds: %lf %lf\n", time_overhead);
  pi = pi / n;
  printf("Pi is %lf\n", pi);
  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,-0x50(%rbp)
movl   $0x3e8,-0x60(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <gettimeofday@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x60(%rbp),%eax
jge    11b6 <main+0x96>
cvtsi2sdl -0x5c(%rbp),%xmm0
cvtsi2sdl -0x60(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe7a(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe66(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1159 <main+0x39>
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <gettimeofday@plt>
imul   $0xf4240,-0x18(%rbp),%eax
add    -0x18(%rbp),%eax
cltq
mov    %rax,-0x38(%rbp)
imul   $0xf4240,-0x28(%rbp),%eax
add    -0x28(%rbp),%eax
cltq
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
lea    0xe0f(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x60(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
lea    0xe05(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1040 <gettimeofday@plt>
xorpd  %xmm7,%xmm7
mov    $0x1,%eax
movsd  0xebc(%rip),%xmm0
movsd  0xebc(%rip),%xmm1
movsd  0xebc(%rip),%xmm2
movsd  0xebc(%rip),%xmm3
xorpd  %xmm4,%xmm4
movapd %xmm4,%xmm5
divsd  %xmm0,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm1,%xmm5
movapd %xmm2,%xmm6
divsd  %xmm5,%xmm6
addsd  %xmm7,%xmm6
xorps  %xmm5,%xmm5
cvtsi2sd %eax,%xmm5
divsd  %xmm0,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm1,%xmm5
movapd %xmm2,%xmm7
divsd  %xmm5,%xmm7
addsd  %xmm6,%xmm7
addsd  %xmm3,%xmm4
add    $0x2,%eax
cmp    $0x3e9,%eax
jne    1160 <main+0x40>
mov    %rsp,%rdi
lea    0x18(%rsp),%rsi
movsd  %xmm7,0x10(%rsp)
call   1040 <gettimeofday@plt>
movslq 0x8(%rsp),%rax
imul   $0xf4241,%rax,%rax
movslq (%rsp),%rcx
imul   $0xf4241,%rcx,%rcx
sub    %rax,%rcx
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
movsd  0x10(%rsp),%xmm0
divsd  0xe08(%rip),%xmm0
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
@.str = [26 x i8] c"Time in seconds: %lf %lf\0A\00"
@.str.1 = [11 x i8] c"Pi is %lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timezone
%8 = alloca %struct.timeval
%9 = alloca %struct.timezone
%10 = alloca i64
%11 = alloca i64
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %13
store i32 1000, i32* %16
%17 = call i32 @gettimeofday(%struct.timeval* %6, %struct.timezone* %7)
store i32 0, i32* %15
br label %18
18: ; preds = %34, %2
%19 = load i32, i32* %15
%20 = load i32, i32* %16
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = load i32, i32* %15
%24 = sitofp i32 %23 to double
%25 = load i32, i32* %16
%26 = sitofp i32 %25 to double
%27 = fdiv double %24, %26
store double %27, double* %14
%28 = load double, double* %14
%29 = load double, double* %14
%30 = call double @llvm.fmuladd.f64(double %28, double %29, double 1.000000e+00)
%31 = fdiv double 4.000000e+00, %30
%32 = load double, double* %13
%33 = fadd double %32, %31
store double %33, double* %13
br label %34
34: ; preds = %22
%35 = load i32, i32* %15
%36 = add nsw i32 %35, 1
store i32 %36, i32* %15
br label %18
37: ; preds = %18
%38 = call i32 @gettimeofday(%struct.timeval* %8, %struct.timezone* %9)
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%40 = load i32, i32* %39
%41 = mul nsw i32 %40, 1000000
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%43 = load i32, i32* %42
%44 = add nsw i32 %41, %43
%45 = sext i32 %44 to i64
store i64 %45, i64* %10
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%47 = load i32, i32* %46
%48 = mul nsw i32 %47, 1000000
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%50 = load i32, i32* %49
%51 = add nsw i32 %48, %50
%52 = sext i32 %51 to i64
store i64 %52, i64* %11
%53 = load i64, i64* %11
%54 = load i64, i64* %10
%55 = sub nsw i64 %53, %54
%56 = sitofp i64 %55 to double
store double %56, double* %12
%57 = load double, double* %12
%58 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %57)
%59 = load double, double* %13
%60 = load i32, i32* %16
%61 = sitofp i32 %60 to double
%62 = fdiv double %59, %61
store double %62, double* %13
%63 = load double, double* %13
%64 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %63)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
@.str = [26 x i8] c"Time in seconds: %lf %lf\0A\00"
@.str.1 = [11 x i8] c"Pi is %lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timezone
%5 = alloca %struct.timeval
%6 = alloca %struct.timezone
%7 = bitcast %struct.timeval* %3 to i8*
%8 = bitcast %struct.timezone* %4 to i8*
%9 = bitcast %struct.timeval* %5 to i8*
%10 = bitcast %struct.timezone* %6 to i8*
%11 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
br label %12
12: ; preds = %12, %2
%13 = phi double [ 0.000000e+00, %2 ], [ %25, %12 ]
%14 = phi i32 [ 0, %2 ], [ %26, %12 ]
%15 = sitofp i32 %14 to double
%16 = fdiv double %15, 1.000000e+03
%17 = tail call double @llvm.fmuladd.f64(double %16, double %16, double 1.000000e+00)
%18 = fdiv double 4.000000e+00, %17
%19 = fadd double %13, %18
%20 = or i32 %14, 1
%21 = sitofp i32 %20 to double
%22 = fdiv double %21, 1.000000e+03
%23 = tail call double @llvm.fmuladd.f64(double %22, double %22, double 1.000000e+00)
%24 = fdiv double 4.000000e+00, %23
%25 = fadd double %19, %24
%26 = add nuw nsw i32 %14, 2
%27 = icmp eq i32 %26, 1000
br i1 %27, label %28, label %12
28: ; preds = %12
%29 = call i32 @gettimeofday(%struct.timeval* %5, %struct.timezone* %6)
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%31 = load i32, i32* %30
%32 = mul nsw i32 %31, 1000001
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%35 = load i32, i32* %34
%36 = mul nsw i32 %35, 1000001
%37 = sext i32 %36 to i64
%38 = sub nsw i64 %37, %33
%39 = sitofp i64 %38 to double
%40 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %39)
%41 = fdiv double %25, 1.000000e+03
%42 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %41)
ret i32 0
}