#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 omp_get_thread_num();
int /*<<< orphan*/ omp_set_num_threads(int const);
int /*<<< orphan*/ printf(char *, double);
void main() {
  const int NUM_THREADS = 4;
  const long num_steps = 1000000;
  double step = 1.0 / ((double)num_steps);
  double sum[NUM_THREADS];
  for (int i = 0; i < NUM_THREADS; i++)
    sum[i] = 0;
  omp_set_num_threads(NUM_THREADS);
#pragma omp parallel
  {
    int id = omp_get_thread_num();
    for (int i = id; i < num_steps; i += NUM_THREADS) {
      double x = (i + 0.5) * step;
      sum[id] += 4.0 * step / (1.0 + x * x);
    }
  }
  double pi = 0;
  for (int i = 0; i < NUM_THREADS; i++)
    pi += sum[i];
  printf("pi = %6.12f\n", pi);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x4,-0x4(%rbp)
movq   $0xf4240,-0x10(%rbp)
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1187 <main+0x57>
movslq -0x24(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp,%rax,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <main+0x32>
mov    $0x4,%edi
call   1050 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    $0xf4240,%rax
jge    1215 <main+0xe5>
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  0xe5a(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe3c(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe19(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movslq -0x28(%rbp),%rax
addsd  -0x70(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x70(%rbp,%rax,8)
mov    -0x2c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a1 <main+0x71>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    1250 <main+0x120>
movslq -0x44(%rbp),%rax
movsd  -0x70(%rbp,%rax,8),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1224 <main+0xf4>
movsd  -0x40(%rbp),%xmm0
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
xorpd  %xmm0,%xmm0
movapd %xmm0,0x10(%rsp)
movapd %xmm0,(%rsp)
mov    $0x4,%edi
call   1050 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
xorpd  %xmm0,%xmm0
cmp    $0xf423f,%eax
jg     11df <main+0xaf>
movslq %eax,%rcx
movsd  (%rsp,%rcx,8),%xmm0
movsd  0xe8d(%rip),%xmm1
movsd  0xe8d(%rip),%xmm2
movsd  0xe8d(%rip),%xmm3
movsd  0xe8d(%rip),%xmm4
nopl   0x0(%rax,%rax,1)
xorps  %xmm5,%xmm5
cvtsi2sd %eax,%xmm5
addsd  %xmm1,%xmm5
mulsd  %xmm2,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm3,%xmm5
movapd %xmm4,%xmm6
divsd  %xmm5,%xmm6
addsd  %xmm6,%xmm0
lea    0x4(%rax),%edx
cmp    $0xf423c,%eax
mov    %edx,%eax
jl     1190 <main+0x60>
movsd  %xmm0,(%rsp,%rcx,8)
xorpd  %xmm0,%xmm0
addsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
lea    0xe3a(%rip),%rdi
add    $0x28,%rsp
jmp    1040 <printf@plt>

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

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