#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 */
double fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void do_work(void) {
  int i;
  int n = 1000000;
  double PI25DT = 3.141592653589793238462643;
  double pi, h, area, x;
  h = 1.0 / (double)n;
  area = 0.0;
#pragma omp parallel for private(x) reduction(+ : area)
  for (i = 1; i <= n; i++) {
    x = h * ((double)i - 0.5);
    area += (4.0 / (1.0 + x * x));
  }
  pi = h * area;
  printf("pi (by using #pragma omp parallel for) is approximately %.16f, Error "
         "is %.16f\n",
         pi, fabs(pi - PI25DT));
#pragma omp parallel
  {
#pragma omp barrier
    fprintf(stdout, "In a barrier\n");
#pragma omp barrier
  }
#pragma omp parallel
  {
#pragma omp critical(foo)
    printf("critical foo\n");
#pragma omp critical(bar)
    printf("critical bar\n");
#pragma omp critical(foo)
    printf("critical foo (again)\n");
#pragma omp critical
    printf("critical unnamed\n");
  }
  h = 1.0 / (double)n;
  area = 0.0;
#pragma omp parallel sections private(i, x) reduction(+ : area)
  {
#pragma omp section
    for (i = 1; i < n / 2; i++) {
      x = h * ((double)i - 0.5);
      area += (4.0 / (1.0 + x * x));
    }
#pragma omp section
    for (i = n / 2; i <= n; i++) {
      x = h * ((double)i - 0.5);
      area += (4.0 / (1.0 + x * x));
    }
  }
  pi = h * area;
  printf("pi (by using #pragma omp parallel sections) is approximately %.16f, "
         "Error is %.16f\n",
         pi, fabs(pi - PI25DT));
}


x86 assembly (clang, -O0):
<do_work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0xf4240,-0x8(%rbp)
movsd  0xed1(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xeb7(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11ca <do_work+0xaa>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xe99(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe5e(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe62(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1161 <do_work+0x41>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movaps 0xe31(%rip),%xmm2
pand   %xmm2,%xmm1
lea    0xe36(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xda5(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    12ee <do_work+0x1ce>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xd75(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xd3a(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xd3e(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1273 <do_work+0x153>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1365 <do_work+0x245>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xcfe(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xcc3(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xcc7(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12fc <do_work+0x1dc>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movaps 0xc96(%rip),%xmm2
pand   %xmm2,%xmm1
lea    0xd3c(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_work>:
push   %rax
movsd  0xec7(%rip),%xmm1
xorpd  %xmm0,%xmm0
mov    $0x2,%eax
movsd  0xebe(%rip),%xmm5
movsd  0xebe(%rip),%xmm6
movsd  0xebe(%rip),%xmm7
movapd %xmm1,%xmm2
xchg   %ax,%ax
movapd %xmm2,%xmm3
addsd  %xmm5,%xmm3
mulsd  %xmm6,%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
movapd %xmm7,%xmm4
divsd  %xmm3,%xmm4
addsd  %xmm0,%xmm4
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
addsd  %xmm5,%xmm3
mulsd  %xmm6,%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
movapd %xmm7,%xmm0
divsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
addsd  0xe75(%rip),%xmm2
add    $0x2,%eax
cmp    $0xf4242,%eax
jne    1160 <do_work+0x30>
mulsd  0xe53(%rip),%xmm0
movsd  0xe63(%rip),%xmm1
addsd  %xmm0,%xmm1
andpd  0xe6f(%rip),%xmm1
lea    0xe78(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xeb0(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xf06(%rip),%rdi
call   1030 <puts@plt>
lea    0xf07(%rip),%rdi
call   1030 <puts@plt>
lea    0xf08(%rip),%rdi
call   1030 <puts@plt>
lea    0xf11(%rip),%rdi
call   1030 <puts@plt>
movsd  0xdf3(%rip),%xmm8
movsd  0xde3(%rip),%xmm7
movsd  0xdd3(%rip),%xmm6
movsd  0xdc3(%rip),%xmm5
movsd  0xdb3(%rip),%xmm0
xorpd  %xmm3,%xmm3
mov    $0x2,%eax
movapd %xmm0,%xmm2
nopw   0x0(%rax,%rax,1)
movapd %xmm2,%xmm4
addsd  %xmm5,%xmm4
mulsd  %xmm6,%xmm4
mulsd  %xmm4,%xmm4
addsd  %xmm0,%xmm4
movapd %xmm7,%xmm1
divsd  %xmm4,%xmm1
addsd  %xmm3,%xmm1
cmp    $0x7a120,%eax
je     12b8 <do_work+0x188>
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
addsd  %xmm5,%xmm3
mulsd  %xmm6,%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm0,%xmm3
movapd %xmm7,%xmm4
divsd  %xmm3,%xmm4
addsd  %xmm4,%xmm1
addsd  %xmm8,%xmm2
add    $0x2,%eax
movapd %xmm1,%xmm3
jmp    1260 <do_work+0x130>
movsd  0xd70(%rip),%xmm2
mov    $0x7a121,%eax
movsd  0xd33(%rip),%xmm3
nopl   (%rax)
movapd %xmm2,%xmm4
addsd  %xmm5,%xmm4
mulsd  %xmm6,%xmm4
mulsd  %xmm4,%xmm4
addsd  %xmm3,%xmm4
movapd %xmm7,%xmm0
divsd  %xmm4,%xmm0
addsd  %xmm1,%xmm0
cmp    $0xf4241,%eax
je     1328 <do_work+0x1f8>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  %xmm5,%xmm1
mulsd  %xmm6,%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm3,%xmm1
movapd %xmm7,%xmm4
divsd  %xmm1,%xmm4
addsd  %xmm4,%xmm0
addsd  %xmm8,%xmm2
add    $0x2,%eax
movapd %xmm0,%xmm1
jmp    12d0 <do_work+0x1a0>
mulsd  0xce0(%rip),%xmm0
movsd  0xcf0(%rip),%xmm1
addsd  %xmm0,%xmm1
andpd  0xcfc(%rip),%xmm1
lea    0xd62(%rip),%rdi
mov    $0x2,%al
pop    %rcx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [79 x i8] c"pi (by using #pragma omp parallel for) is approximately %.16f, Error is %.16f\0A\00"
@stdout = global i32 0
@.str.1 = [14 x i8] c"In a barrier\0A\00"
@.str.2 = [14 x i8] c"critical foo\0A\00"
@.str.3 = [14 x i8] c"critical bar\0A\00"
@.str.4 = [22 x i8] c"critical foo (again)\0A\00"
@.str.5 = [18 x i8] c"critical unnamed\0A\00"
@.str.6 = [84 x i8] c"pi (by using #pragma omp parallel sections) is approximately %.16f, Error is %.16f\0A\00"
define void @do_work() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 1000000, i32* %2
store double 0x400921FB54442D18, double* %3
%8 = load i32, i32* %2
%9 = sitofp i32 %8 to double
%10 = fdiv double 1.000000e+00, %9
store double %10, double* %5
store double 0.000000e+00, double* %6
store i32 1, i32* %1
br label %11
11: ; preds = %27, %0
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load double, double* %5
%17 = load i32, i32* %1
%18 = sitofp i32 %17 to double
%19 = fsub double %18, 5.000000e-01
%20 = fmul double %16, %19
store double %20, double* %7
%21 = load double, double* %7
%22 = load double, double* %7
%23 = call double @llvm.fmuladd.f64(double %21, double %22, double 1.000000e+00)
%24 = fdiv double 4.000000e+00, %23
%25 = load double, double* %6
%26 = fadd double %25, %24
store double %26, double* %6
br label %27
27: ; preds = %15
%28 = load i32, i32* %1
%29 = add nsw i32 %28, 1
store i32 %29, i32* %1
br label %11
30: ; preds = %11
%31 = load double, double* %5
%32 = load double, double* %6
%33 = fmul double %31, %32
store double %33, double* %4
%34 = load double, double* %4
%35 = load double, double* %4
%36 = load double, double* %3
%37 = fsub double %35, %36
%38 = call double @llvm.fabs.f64(double %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), double %34, double %38)
%40 = load i32, i32* @stdout
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%46 = load i32, i32* %2
%47 = sitofp i32 %46 to double
%48 = fdiv double 1.000000e+00, %47
store double %48, double* %5
store double 0.000000e+00, double* %6
store i32 1, i32* %1
br label %49
49: ; preds = %66, %30
%50 = load i32, i32* %1
%51 = load i32, i32* %2
%52 = sdiv i32 %51, 2
%53 = icmp slt i32 %50, %52
br i1 %53, label %54, label %69
54: ; preds = %49
%55 = load double, double* %5
%56 = load i32, i32* %1
%57 = sitofp i32 %56 to double
%58 = fsub double %57, 5.000000e-01
%59 = fmul double %55, %58
store double %59, double* %7
%60 = load double, double* %7
%61 = load double, double* %7
%62 = call double @llvm.fmuladd.f64(double %60, double %61, double 1.000000e+00)
%63 = fdiv double 4.000000e+00, %62
%64 = load double, double* %6
%65 = fadd double %64, %63
store double %65, double* %6
br label %66
66: ; preds = %54
%67 = load i32, i32* %1
%68 = add nsw i32 %67, 1
store i32 %68, i32* %1
br label %49
69: ; preds = %49
%70 = load i32, i32* %2
%71 = sdiv i32 %70, 2
store i32 %71, i32* %1
br label %72
72: ; preds = %88, %69
%73 = load i32, i32* %1
%74 = load i32, i32* %2
%75 = icmp sle i32 %73, %74
br i1 %75, label %76, label %91
76: ; preds = %72
%77 = load double, double* %5
%78 = load i32, i32* %1
%79 = sitofp i32 %78 to double
%80 = fsub double %79, 5.000000e-01
%81 = fmul double %77, %80
store double %81, double* %7
%82 = load double, double* %7
%83 = load double, double* %7
%84 = call double @llvm.fmuladd.f64(double %82, double %83, double 1.000000e+00)
%85 = fdiv double 4.000000e+00, %84
%86 = load double, double* %6
%87 = fadd double %86, %85
store double %87, double* %6
br label %88
88: ; preds = %76
%89 = load i32, i32* %1
%90 = add nsw i32 %89, 1
store i32 %90, i32* %1
br label %72
91: ; preds = %72
%92 = load double, double* %5
%93 = load double, double* %6
%94 = fmul double %92, %93
store double %94, double* %4
%95 = load double, double* %4
%96 = load double, double* %4
%97 = load double, double* %3
%98 = fsub double %96, %97
%99 = call double @llvm.fabs.f64(double %98)
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.6, i64 0, i64 0), double %95, double %99)
ret void
}

LLVM IR (-O2):
@.str = [79 x i8] c"pi (by using #pragma omp parallel for) is approximately %.16f, Error is %.16f\0A\00"
@stdout = global i32 0
@.str.1 = [14 x i8] c"In a barrier\0A\00"
@.str.6 = [84 x i8] c"pi (by using #pragma omp parallel sections) is approximately %.16f, Error is %.16f\0A\00"
@str = [13 x i8] c"critical foo\00"
@str.7 = [13 x i8] c"critical bar\00"
@str.8 = [21 x i8] c"critical foo (again)\00"
@str.9 = [17 x i8] c"critical unnamed\00"
define void @do_work() {
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, 0x3EB0C6F7A0B5ED8D
%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, 0x3EB0C6F7A0B5ED8D
%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, 1000001
br i1 %18, label %19, label %1
19: ; preds = %1
%20 = fmul double %16, 0x3EB0C6F7A0B5ED8D
%21 = fadd double %20, 0xC00921FB54442D18
%22 = tail call double @llvm.fabs.f64(double %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), double %20, double %22)
%24 = load i32, i32* @stdout
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.8, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
br label %30
30: ; preds = %41, %19
%31 = phi double [ 0.000000e+00, %19 ], [ %47, %41 ]
%32 = phi i32 [ 1, %19 ], [ %48, %41 ]
%33 = sitofp i32 %32 to double
%34 = fadd double %33, -5.000000e-01
%35 = fmul double %34, 0x3EB0C6F7A0B5ED8D
%36 = tail call double @llvm.fmuladd.f64(double %35, double %35, double 1.000000e+00)
%37 = fdiv double 4.000000e+00, %36
%38 = fadd double %31, %37
%39 = add nuw nsw i32 %32, 1
%40 = icmp eq i32 %39, 500000
br i1 %40, label %49, label %41
41: ; preds = %30
%42 = sitofp i32 %39 to double
%43 = fadd double %42, -5.000000e-01
%44 = fmul double %43, 0x3EB0C6F7A0B5ED8D
%45 = tail call double @llvm.fmuladd.f64(double %44, double %44, double 1.000000e+00)
%46 = fdiv double 4.000000e+00, %45
%47 = fadd double %38, %46
%48 = add nuw nsw i32 %32, 2
br label %30
49: ; preds = %30, %60
%50 = phi double [ %66, %60 ], [ %38, %30 ]
%51 = phi i32 [ %67, %60 ], [ 500000, %30 ]
%52 = sitofp i32 %51 to double
%53 = fadd double %52, -5.000000e-01
%54 = fmul double %53, 0x3EB0C6F7A0B5ED8D
%55 = tail call double @llvm.fmuladd.f64(double %54, double %54, double 1.000000e+00)
%56 = fdiv double 4.000000e+00, %55
%57 = fadd double %50, %56
%58 = or i32 %51, 1
%59 = icmp eq i32 %58, 1000001
br i1 %59, label %68, label %60
60: ; preds = %49
%61 = sitofp i32 %58 to double
%62 = fadd double %61, -5.000000e-01
%63 = fmul double %62, 0x3EB0C6F7A0B5ED8D
%64 = tail call double @llvm.fmuladd.f64(double %63, double %63, double 1.000000e+00)
%65 = fdiv double 4.000000e+00, %64
%66 = fadd double %57, %65
%67 = add nuw nsw i32 %51, 2
br label %49
68: ; preds = %49
%69 = fmul double %57, 0x3EB0C6F7A0B5ED8D
%70 = fadd double %69, 0xC00921FB54442D18
%71 = tail call double @llvm.fabs.f64(double %70)
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @.str.6, i64 0, i64 0), double %69, double %71)
ret void
}