#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*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, double);
int main() {
  long i, numdiv = 200000000;
  double x, dx, pi, sum = 0.0;
  dx = 1.0 / (double)numdiv;
  omp_set_num_threads(4);
#pragma omp parallel for reduction(+ : sum) private(x)
  for (i = 0; i < numdiv; i++) {
    x = ((double)i + 0.5) * dx;
    sum = sum + 4.0 / (1.0 + x * x);
  }
  pi = sum * dx;
  printf("PI = %16.14f\n", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xbebc200,-0x18(%rbp)
0b
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xeb3(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x4,%edi
call   1040 <omp_set_num_threads@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11d7 <main+0xb7>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm2
movsd  0xe53(%rip),%xmm1
addsd  %xmm1,%xmm2
movsd  0xe4f(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1168 <main+0x48>
movsd  -0x38(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x4,%edi
call   1040 <omp_set_num_threads@plt>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
movsd  0xec7(%rip),%xmm1
movsd  0xec7(%rip),%xmm2
movsd  0xec7(%rip),%xmm3
movsd  0xec7(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm5,%xmm5
cvtsi2sd %rax,%xmm5
addsd  %xmm1,%xmm5
mulsd  %xmm2,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm3,%xmm5
movapd %xmm4,%xmm6
divsd  %xmm5,%xmm6
addsd  %xmm0,%xmm6
lea    0x1(%rax),%rcx
xorps  %xmm5,%xmm5
cvtsi2sd %rcx,%xmm5
addsd  %xmm1,%xmm5
mulsd  %xmm2,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm3,%xmm5
movapd %xmm4,%xmm0
divsd  %xmm5,%xmm0
addsd  %xmm6,%xmm0
add    $0x2,%rax
cmp    $0xbebc200,%rax
jne    1160 <main+0x40>
mulsd  0xe48(%rip),%xmm0
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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