#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, double);
int main() {
  double sum = 0, pi;
  double step = 1.0 / (double)4000;
#pragma omp parallel for reduction(+ : sum) check
  for (int i = 0; i < 4000; ++i) {
    double x = (i + 0.5) * step;
    sum = sum + 4.0 / (1.0 + x * x);
  }
  pi = step * sum;
  printf("PI: %f\n", pi);
  return pi;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xed1(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xfa0,-0x24(%rbp)
jge    11a5 <main+0x95>
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xec3(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm2
movsd  0xe92(%rip),%xmm1
addsd  %xmm1,%xmm2
movsd  0xe7e(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113b <main+0x2b>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
cvttsd2si -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xorpd  %xmm0,%xmm0
mov    $0x1,%eax
movsd  0xede(%rip),%xmm4
movsd  0xede(%rip),%xmm1
movsd  0xede(%rip),%xmm2
movsd  0xede(%rip),%xmm3
movsd  0xedd(%rip),%xmm8
xorpd  %xmm5,%xmm5
nopw   0x0(%rax,%rax,1)
movapd %xmm5,%xmm6
addsd  %xmm4,%xmm6
mulsd  %xmm1,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm2,%xmm6
movapd %xmm3,%xmm7
divsd  %xmm6,%xmm7
addsd  %xmm0,%xmm7
xorps  %xmm6,%xmm6
cvtsi2sd %eax,%xmm6
addsd  %xmm4,%xmm6
mulsd  %xmm1,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm2,%xmm6
movapd %xmm3,%xmm0
divsd  %xmm6,%xmm0
addsd  %xmm7,%xmm0
addsd  %xmm8,%xmm5
add    $0x2,%eax
cmp    $0xfa1,%eax
jne    1150 <main+0x40>
mulsd  0xe5e(%rip),%xmm0
movsd  %xmm0,(%rsp)
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
cvttsd2si (%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"PI: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 2.500000e-04, double* %4
store i32 0, i32* %5
br label %7
7: ; preds = %22, %0
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 4000
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i32, i32* %5
%12 = sitofp i32 %11 to double
%13 = fadd double %12, 5.000000e-01
%14 = load double, double* %4
%15 = fmul double %13, %14
store double %15, double* %6
%16 = load double, double* %2
%17 = load double, double* %6
%18 = load double, double* %6
%19 = call double @llvm.fmuladd.f64(double %17, double %18, double 1.000000e+00)
%20 = fdiv double 4.000000e+00, %19
%21 = fadd double %16, %20
store double %21, double* %2
br label %22
22: ; preds = %10
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %7
25: ; preds = %7
%26 = load double, double* %4
%27 = load double, double* %2
%28 = fmul double %26, %27
store double %28, double* %3
%29 = load double, double* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %29)
%31 = load double, double* %3
%32 = fptosi double %31 to i32
ret i32 %32
}

LLVM IR (-O2):
@.str = [8 x i8] c"PI: %f\0A\00"
define i32 @main() {
br label %5
1: ; preds = %5
%2 = fmul double %20, 2.500000e-04
%3 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %2)
%4 = fptosi double %2 to i32
ret i32 %4
5: ; preds = %5, %0
%6 = phi double [ 0.000000e+00, %0 ], [ %20, %5 ]
%7 = phi i32 [ 0, %0 ], [ %21, %5 ]
%8 = sitofp i32 %7 to double
%9 = fadd double %8, 5.000000e-01
%10 = fmul double %9, 2.500000e-04
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double 1.000000e+00)
%12 = fdiv double 4.000000e+00, %11
%13 = fadd double %6, %12
%14 = or i32 %7, 1
%15 = sitofp i32 %14 to double
%16 = fadd double %15, 5.000000e-01
%17 = fmul double %16, 2.500000e-04
%18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double 1.000000e+00)
%19 = fdiv double 4.000000e+00, %18
%20 = fadd double %13, %19
%21 = add nuw nsw i32 %7, 2
%22 = icmp eq i32 %21, 4000
br i1 %22, label %1, label %5
}