#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_num_procs();
int omp_get_num_threads();
double omp_get_wtime();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, double, ...);
int main(int argc, const char *argv[]) {
  static long num_steps = 10000000000;
  int i, nthreads;
  double pi;
  double step;
  double x;
  double sum = 0.0;
  step = (1.0 / (double)num_steps);
  omp_set_num_threads(4);
  double wtime;
  wtime = omp_get_wtime();
#pragma omp parallel for reduction(+ : sum) private(x)
  for (i = 0; i <= num_steps; i++) {
    if (i == 0)
      printf("\n Nombre de proc=%d, Nombre de threads=%d\n",
             omp_get_num_procs(), omp_get_num_threads());
    x = (double)((double)i + 0.5) * step;
    sum += 4.0 / (1.0 + x * x);
  }
  pi = step * sum;
  wtime = omp_get_wtime() - wtime;
  printf(" Elapsed wall clock time = %f with %ld steps\n", wtime, num_steps);
  printf(" \n Calcul Serie Pi = %f\n", pi);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdq 0x2ed1(%rip),%xmm1
movsd  0xe81(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x4,%edi
call   1070 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    0x2e98(%rip),%rax
jg     1245 <main+0xf5>
cmpl   $0x0,-0x14(%rbp)
jne    11ec <main+0x9c>
mov    $0x0,%al
call   1060 <omp_get_num_procs@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
movsd  -0x48(%rbp),%xmm0
mov    %eax,%esi
lea    0xe33(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe17(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xde3(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xddf(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a5 <main+0x55>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    0x2dd7(%rip),%rsi
lea    0xdcb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xde6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x4,%edi
call   1070 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
lea    0xe95(%rip),%rbx
xor    %ebp,%ebp
nopl   (%rax)
sub    $0x1,%ebp
jae    1170 <main+0x20>
xor    %eax,%eax
call   1060 <omp_get_num_procs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
mov    %rbx,%rdi
movsd  (%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1170 <main+0x20>

LLVM IR (-O0):
@main.num_steps = internal global i64 10000000000
@.str = [43 x i8] c"\0A Nombre de proc=%d, Nombre de threads=%d\0A\00"
@.str.1 = [46 x i8] c" Elapsed wall clock time = %f with %ld steps\0A\00"
@.str.2 = [25 x i8] c" \0A Calcul Serie Pi = %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %11
%13 = load i64, i64* @main.num_steps
%14 = sitofp i64 %13 to double
%15 = fdiv double 1.000000e+00, %14
store double %15, double* %9
%16 = call i32 @omp_set_num_threads(i32 4)
%17 = call double (...) @omp_get_wtime()
store double %17, double* %12
store i32 0, i32* %6
br label %18
18: ; preds = %43, %2
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = load i64, i64* @main.num_steps
%22 = icmp sle i64 %20, %21
br i1 %22, label %23, label %46
23: ; preds = %18
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = call i32 (...) @omp_get_num_procs()
%28 = sitofp i32 %27 to double
%29 = call i32 (...) @omp_get_num_threads()
%30 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %28, i32 %29)
br label %31
31: ; preds = %26, %23
%32 = load i32, i32* %6
%33 = sitofp i32 %32 to double
%34 = fadd double %33, 5.000000e-01
%35 = load double, double* %9
%36 = fmul double %34, %35
store double %36, double* %10
%37 = load double, double* %10
%38 = load double, double* %10
%39 = call double @llvm.fmuladd.f64(double %37, double %38, double 1.000000e+00)
%40 = fdiv double 4.000000e+00, %39
%41 = load double, double* %11
%42 = fadd double %41, %40
store double %42, double* %11
br label %43
43: ; preds = %31
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %18
46: ; preds = %18
%47 = load double, double* %9
%48 = load double, double* %11
%49 = fmul double %47, %48
store double %49, double* %8
%50 = call double (...) @omp_get_wtime()
%51 = load double, double* %12
%52 = fsub double %50, %51
store double %52, double* %12
%53 = load double, double* %12
%54 = load i64, i64* @main.num_steps
%55 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), double %53, i64 %54)
%56 = load double, double* %8
%57 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), double %56)
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [43 x i8] c"\0A Nombre de proc=%d, Nombre de threads=%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @omp_set_num_threads(i32 4)
%4 = tail call double (...) @omp_get_wtime()
br label %5
5: ; preds = %13, %2
%6 = phi i32 [ 0, %2 ], [ %14, %13 ]
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i32 (...) @omp_get_num_procs()
%10 = sitofp i32 %9 to double
%11 = tail call i32 (...) @omp_get_num_threads()
%12 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %10, i32 %11)
br label %13
13: ; preds = %8, %5
%14 = add nuw nsw i32 %6, 1
br label %5
}