#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 const);
int main() {
  const int num_steps = 100000;
  double x, sum = 0.0;
  const double step = 1.0 / (double)num_steps;
  int i;
#pragma omp parallel for reduction(+ : sum) private(x)
  for (i = 1; i <= num_steps; i++) {
    x = (double)(i - 0.5) * step;
    sum += 4.0 / (1.0 + x * x);
  }
  const double pi = step * sum;
  printf("The value if pi is %f\n", pi);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x186a0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeca(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x186a0,-0x24(%rbp)
jg     11af <main+0x9f>
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xebc(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe98(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe75(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1142 <main+0x32>
movsd  0xe49(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

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

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