#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 = 1000;
  const long num_steps = 100000;
  double step = 1.0 / ((double)num_steps);
  double sum[NUM_THREADS];
  for (int i = 0; i < NUM_THREADS; i++)
    sum[i] = 0;
  double pi = 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);
    }
    pi += sum[id];
  }
  printf("pi = %6.12f\n", pi);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f80,%rsp
movl   $0x3e8,-0x4(%rbp)
movq   $0x186a0,-0x10(%rbp)
movsd  0xeae(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3e8,-0x24(%rbp)
jge    1190 <main+0x60>
movslq -0x24(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1f80(%rbp,%rax,8)
ff ff
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1165 <main+0x35>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x3e8,%edi
call   1050 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
cmp    $0x186a0,%rax
jge    122e <main+0xfe>
cvtsi2sdl -0x38(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe2b(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe08(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movslq -0x34(%rbp),%rax
addsd  -0x1f80(%rbp,%rax,8),%xmm0
ff ff
movsd  %xmm0,-0x1f80(%rbp,%rax,8)
ff ff
mov    -0x38(%rbp),%eax
add    $0x3e8,%eax
mov    %eax,-0x38(%rbp)
jmp    11b2 <main+0x82>
movslq -0x34(%rbp),%rax
movsd  -0x1f80(%rbp,%rax,8),%xmm0
ff ff
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xdcf(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
add    $0x1f80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x1f48,%rsp
mov    %rsp,%rdi
mov    $0x1f40,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x3e8,%edi
call   1060 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
cmp    $0x186a0,%eax
jge    11d9 <main+0x99>
movslq %eax,%rcx
movsd  (%rsp,%rcx,8),%xmm1
movsd  0xe82(%rip),%xmm0
movsd  0xe82(%rip),%xmm2
movsd  0xe82(%rip),%xmm3
movsd  0xe82(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm5,%xmm5
cvtsi2sd %eax,%xmm5
addsd  %xmm0,%xmm5
mulsd  %xmm2,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm3,%xmm5
movapd %xmm4,%xmm6
divsd  %xmm5,%xmm6
addsd  %xmm6,%xmm1
lea    0x3e8(%rax),%edx
cmp    $0x182b8,%eax
mov    %edx,%eax
jl     11a0 <main+0x60>
movsd  %xmm1,(%rsp,%rcx,8)
jmp    11e0 <main+0xa0>
mov    %eax,%eax
movsd  (%rsp,%rax,8),%xmm1
xorpd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
lea    0xe31(%rip),%rdi
add    $0x1f48,%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 double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store i32 1000, i32* %1
store i64 100000, i64* %2
store double 1.000000e-05, double* %3
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca double, i64 1000
store i32 0, i32* %5
br label %12
12: ; preds = %19, %0
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 1000
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %11, i64 %17
store double 0.000000e+00, double* %18
br label %19
19: ; preds = %15
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %12
22: ; preds = %12
store double 0.000000e+00, double* %6
%23 = call i32 @omp_set_num_threads(i32 1000)
%24 = call i32 (...) @omp_get_thread_num()
store i32 %24, i32* %7
%25 = load i32, i32* %7
store i32 %25, i32* %8
br label %26
26: ; preds = %47, %22
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %28, 100000
br i1 %29, label %30, label %50
30: ; preds = %26
%31 = load i32, i32* %8
%32 = sitofp i32 %31 to double
%33 = fadd double %32, 5.000000e-01
%34 = load double, double* %3
%35 = fmul double %33, %34
store double %35, double* %9
%36 = load double, double* %3
%37 = fmul double 4.000000e+00, %36
%38 = load double, double* %9
%39 = load double, double* %9
%40 = call double @llvm.fmuladd.f64(double %38, double %39, double 1.000000e+00)
%41 = fdiv double %37, %40
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %11, i64 %43
%45 = load double, double* %44
%46 = fadd double %45, %41
store double %46, double* %44
br label %47
47: ; preds = %30
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1000
store i32 %49, i32* %8
br label %26
50: ; preds = %26
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %11, i64 %52
%54 = load double, double* %53
%55 = load double, double* %6
%56 = fadd double %55, %54
store double %56, double* %6
%57 = load double, double* %6
%58 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %57)
%59 = load i8*, i8** %4
ret void
}

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