#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*/ printf(char *, double, ...);
int main() {
  int ix;
  double Scale, LScale, ssq, Lssq;
#pragma omp parallel
  {
#pragma omp single
    printf("Number of threads is %d\n", 1);
  }
  Scale = 2.0;
  ssq = 1.0;
  printf("Before parallel region: Scale = %f ssq = %f\n", Scale, ssq);
#pragma omp parallel default(none) private(ix, LScale, Lssq) shared(Scale, ssq)
  {
    int TID = 0;
    Lssq = 2.0 * TID;
#pragma omp for
    for (ix = 1; ix < 10; ix++) {
      LScale = TID + ix;
    }
    printf("Thread %d computed LScale = %f\n", TID, LScale);
#pragma omp critical
    {
      printf("Thread %d entered critical region\n", TID);
      if (Scale < LScale) {
        ssq = (Scale / LScale) * ssq + Lssq;
        Scale = LScale;
        printf("\tThread %d: Reset Scale to %f\n", TID, Scale);
      } else {
        ssq = ssq + (LScale / Scale) * Lssq;
      }
      printf("\tThread %d: New value of ssq = %f\n", TID, ssq);
    }
  }
  printf("After parallel region: Scale = %f ssq = %f\n", Scale, ssq);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeea(%rip),%rdi
movsd  0xeda(%rip),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xec3(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xec9(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xe85(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    11b2 <main+0xa2>
mov    -0x2c(%rbp),%eax
add    -0x8(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118b <main+0x7b>
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xe93(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
cvtsi2sdl -0x2c(%rbp),%xmm0
lea    0xea0(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1239 <main+0x129>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    0xe6c(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    125a <main+0x14a>
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe4d(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe58(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf08(%rip),%rdi
movsd  0xee0(%rip),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xf0b(%rip),%rdi
movsd  0xed2(%rip),%xmm0
movsd  0xec2(%rip),%xmm1
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xf1a(%rip),%rdi
movsd  0xebc(%rip),%xmm1
xorps  %xmm0,%xmm0
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xf21(%rip),%rdi
xorps  %xmm0,%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xf33(%rip),%rdi
xorps  %xmm0,%xmm0
movsd  0xe8f(%rip),%xmm1
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xf39(%rip),%rdi
movsd  0xe81(%rip),%xmm1
xorps  %xmm0,%xmm0
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xf43(%rip),%rdi
movsd  0xe60(%rip),%xmm0
movsd  0xe60(%rip),%xmm1
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Number of threads is %d\0A\00"
@.str.1 = [45 x i8] c"Before parallel region: Scale = %f ssq = %f\0A\00"
@.str.2 = [32 x i8] c"Thread %d computed LScale = %f\0A\00"
@.str.3 = [35 x i8] c"Thread %d entered critical region\0A\00"
@.str.4 = [31 x i8] c"\09Thread %d: Reset Scale to %f\0A\00"
@.str.5 = [35 x i8] c"\09Thread %d: New value of ssq = %f\0A\00"
@.str.6 = [44 x i8] c"After parallel region: Scale = %f ssq = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double 1.000000e+00)
store double 2.000000e+00, double* %3
store double 1.000000e+00, double* %5
%9 = load double, double* %3
%10 = load double, double* %5
%11 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), double %9, double %10)
store i32 0, i32* %7
%12 = load i32, i32* %7
%13 = sitofp i32 %12 to double
%14 = fmul double 2.000000e+00, %13
store double %14, double* %6
store i32 1, i32* %2
br label %15
15: ; preds = %23, %0
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 10
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %7
%20 = load i32, i32* %2
%21 = add nsw i32 %19, %20
%22 = sitofp i32 %21 to double
store double %22, double* %4
br label %23
23: ; preds = %18
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %15
26: ; preds = %15
%27 = load i32, i32* %7
%28 = sitofp i32 %27 to double
%29 = load double, double* %4
%30 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), double %28, double %29)
%31 = load i32, i32* %7
%32 = sitofp i32 %31 to double
%33 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), double %32)
%34 = load double, double* %3
%35 = load double, double* %4
%36 = fcmp olt double %34, %35
br i1 %36, label %37, label %49
37: ; preds = %26
%38 = load double, double* %3
%39 = load double, double* %4
%40 = fdiv double %38, %39
%41 = load double, double* %5
%42 = load double, double* %6
%43 = call double @llvm.fmuladd.f64(double %40, double %41, double %42)
store double %43, double* %5
%44 = load double, double* %4
store double %44, double* %3
%45 = load i32, i32* %7
%46 = sitofp i32 %45 to double
%47 = load double, double* %3
%48 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), double %46, double %47)
br label %56
49: ; preds = %26
%50 = load double, double* %5
%51 = load double, double* %4
%52 = load double, double* %3
%53 = fdiv double %51, %52
%54 = load double, double* %6
%55 = call double @llvm.fmuladd.f64(double %53, double %54, double %50)
store double %55, double* %5
br label %56
56: ; preds = %49, %37
%57 = load i32, i32* %7
%58 = sitofp i32 %57 to double
%59 = load double, double* %5
%60 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), double %58, double %59)
%61 = load double, double* %3
%62 = load double, double* %5
%63 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), double %61, double %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Number of threads is %d\0A\00"
@.str.1 = [45 x i8] c"Before parallel region: Scale = %f ssq = %f\0A\00"
@.str.2 = [32 x i8] c"Thread %d computed LScale = %f\0A\00"
@.str.3 = [35 x i8] c"Thread %d entered critical region\0A\00"
@.str.4 = [31 x i8] c"\09Thread %d: Reset Scale to %f\0A\00"
@.str.5 = [35 x i8] c"\09Thread %d: New value of ssq = %f\0A\00"
@.str.6 = [44 x i8] c"After parallel region: Scale = %f ssq = %f\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double 1.000000e+00)
%2 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), double 2.000000e+00, double 1.000000e+00)
%3 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), double 0.000000e+00, double 9.000000e+00)
%4 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), double 0.000000e+00)
%5 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), double 0.000000e+00, double 9.000000e+00)
%6 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), double 0.000000e+00, double 0x3FCC71C71C71C71C)
%7 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), double 9.000000e+00, double 0x3FCC71C71C71C71C)
ret i32 0
}