#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*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, double);
int main(int argc, char *argv[]) {
  long i;
  double pi = 0;
  double tstart, tstop, time;
  {
    static struct timeval tv;
    gettimeofday(&tv, NULL);
    tstart = ((tv.tv_sec) + (tv.tv_usec) * 1.0e-6);
  };
#pragma omp parallel for reduction(+ : pi)
  for (i = 0; i < 1000000000; i++) {
    pi += 1.0 / (i * 4.0 + 1.0);
    pi -= 1.0 / (i * 4.0 + 3.0);
  }
  pi = pi * 4.0;
  {
    static struct timeval tv;
    gettimeofday(&tv, NULL);
    tstop = ((tv.tv_sec) + (tv.tv_usec) * 1.0e-6);
  };
  time = tstop - tstart;
  printf("Pi = %.*f\n", 10, pi);
  printf("Time: %.*f\n", 2, tstop - tstart);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0x2ef3(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  0x2ee2(%rip),%xmm1
movsd  0x2ee2(%rip),%xmm0
movsd  0xe9a(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x3b9aca00,-0x18(%rbp)
3b
jge    1206 <main+0xe6>
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xe71(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe6d(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe61(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  0xe3d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe41(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe2d(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    117b <main+0x5b>
movsd  0xdfa(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0x2e29(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  0x2e18(%rip),%xmm1
movsd  0x2e18(%rip),%xmm0
movsd  0xdc0(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xdb8(%rip),%rdi
mov    $0xa,%esi
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
lea    0xda8(%rip),%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0x2f0c(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  0x2efb(%rip),%xmm0
movaps %xmm0,(%rsp)
xorpd  %xmm6,%xmm6
movsd  0x2ef3(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0xea6(%rip),%xmm0
movsd  0xea6(%rip),%xmm1
movsd  0xea6(%rip),%xmm2
nopw   0x0(%rax,%rax,1)
xorps  %xmm3,%xmm3
cvtsi2sd %rbx,%xmm3
mulsd  %xmm0,%xmm3
movapd %xmm3,%xmm4
addsd  %xmm1,%xmm4
movapd %xmm1,%xmm5
divsd  %xmm4,%xmm5
addsd  %xmm5,%xmm6
addsd  %xmm2,%xmm3
movapd %xmm1,%xmm4
divsd  %xmm3,%xmm4
subsd  %xmm4,%xmm6
add    $0x1,%rbx
cmp    $0x3b9aca00,%rbx
jne    1170 <main+0x50>
mulsd  0xe4b(%rip),%xmm6
movsd  %xmm6,0x18(%rsp)
lea    0x2e86(%rip),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  0x2e7f(%rip),%xmm1
unpcklpd 0x20(%rsp),%xmm1
movsd  0x2e69(%rip),%xmm0
unpcklpd (%rsp),%xmm0
mulpd  0xe34(%rip),%xmm1
addpd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
lea    0xe34(%rip),%rdi
mov    $0xa,%esi
movsd  0x18(%rsp),%xmm0
call   1030 <printf@plt>
movapd (%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
lea    0xe13(%rip),%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@main.tv = internal global %struct.timeval zeroinitializer
@main.tv.1 = internal global %struct.timeval zeroinitializer
@.str = [11 x i8] c"Pi = %.*f\0A\00"
@.str.2 = [12 x i8] c"Time: %.*f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %7
%11 = call i32 @gettimeofday(%struct.timeval* @main.tv, i32* null)
%12 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @main.tv, i32 0, i32 0)
%13 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @main.tv, i32 0, i32 1)
%14 = call double @llvm.fmuladd.f64(double %13, double 0x3EB0C6F7A0B5ED8D, double %12)
store double %14, double* %8
store i64 0, i64* %6
br label %15
15: ; preds = %31, %2
%16 = load i64, i64* %6
%17 = icmp slt i64 %16, 1000000000
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = load i64, i64* %6
%20 = sitofp i64 %19 to double
%21 = call double @llvm.fmuladd.f64(double %20, double 4.000000e+00, double 1.000000e+00)
%22 = fdiv double 1.000000e+00, %21
%23 = load double, double* %7
%24 = fadd double %23, %22
store double %24, double* %7
%25 = load i64, i64* %6
%26 = sitofp i64 %25 to double
%27 = call double @llvm.fmuladd.f64(double %26, double 4.000000e+00, double 3.000000e+00)
%28 = fdiv double 1.000000e+00, %27
%29 = load double, double* %7
%30 = fsub double %29, %28
store double %30, double* %7
br label %31
31: ; preds = %18
%32 = load i64, i64* %6
%33 = add nsw i64 %32, 1
store i64 %33, i64* %6
br label %15
34: ; preds = %15
%35 = load double, double* %7
%36 = fmul double %35, 4.000000e+00
store double %36, double* %7
%37 = call i32 @gettimeofday(%struct.timeval* @main.tv.1, i32* null)
%38 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @main.tv.1, i32 0, i32 0)
%39 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @main.tv.1, i32 0, i32 1)
%40 = call double @llvm.fmuladd.f64(double %39, double 0x3EB0C6F7A0B5ED8D, double %38)
store double %40, double* %9
%41 = load double, double* %9
%42 = load double, double* %8
%43 = fsub double %41, %42
store double %43, double* %10
%44 = load double, double* %7
%45 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 10, double %44)
%46 = load double, double* %9
%47 = load double, double* %8
%48 = fsub double %46, %47
%49 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 2, double %48)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@main.tv = internal global %struct.timeval zeroinitializer
@main.tv.1 = internal global %struct.timeval zeroinitializer
@.str = [11 x i8] c"Pi = %.*f\0A\00"
@.str.2 = [12 x i8] c"Time: %.*f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @gettimeofday(%struct.timeval* @main.tv, i32* null)
%4 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @main.tv, i64 0, i32 0)
%5 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @main.tv, i64 0, i32 1)
br label %6
6: ; preds = %2, %6
%7 = phi i64 [ 0, %2 ], [ %16, %6 ]
%8 = phi double [ 0.000000e+00, %2 ], [ %15, %6 ]
%9 = sitofp i64 %7 to double
%10 = tail call double @llvm.fmuladd.f64(double %9, double 4.000000e+00, double 1.000000e+00)
%11 = fdiv double 1.000000e+00, %10
%12 = fadd double %8, %11
%13 = tail call double @llvm.fmuladd.f64(double %9, double 4.000000e+00, double 3.000000e+00)
%14 = fdiv double 1.000000e+00, %13
%15 = fsub double %12, %14
%16 = add nuw nsw i64 %7, 1
%17 = icmp eq i64 %16, 1000000000
br i1 %17, label %18, label %6
18: ; preds = %6
%19 = fmul double %15, 4.000000e+00
%20 = tail call i32 @gettimeofday(%struct.timeval* @main.tv.1, i32* null)
%21 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @main.tv.1, i64 0, i32 0)
%22 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @main.tv.1, i64 0, i32 1)
%23 = insertelement <2 x double> poison, double %5, i64 1
%24 = insertelement <2 x double> %23, double %22, i64 0
%25 = insertelement <2 x double> poison, double %4, i64 1
%26 = insertelement <2 x double> %25, double %21, i64 0
%27 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %24, <2 x double> <double 0x3EB0C6F7A0B5ED8D, double 0x3EB0C6F7A0B5ED8D>, <2 x double> %26)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 10, double %19)
%29 = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%30 = fsub <2 x double> %27, %29
%31 = extractelement <2 x double> %30, i64 0
%32 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 2, double %31)
ret i32 0
}