#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 *, int, ...);
int main() {
  int i, n = 25;
  int sum, a[n];
  int ref = 0 + (n - 1) * n / 2;
  for (i = 0; i < n; i++)
    a[i] = i;
#pragma omp parallel
  {
#pragma omp single
    printf("Number of threads is %d\n", 1);
  }
  sum = 0;
  printf("Value of sum prior to parallel region: %d\n", sum);
#pragma omp parallel for default(none) shared(n, a) reduction(+ : sum)
  for (i = 0; i < n; i++)
    sum += a[i];
  printf("Value of sum after parallel region: %d\n", sum);
  printf("Check results: sum = %d (should be %d)\n", sum, ref);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x19,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
imul   -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x0,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1194 <main+0x84>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%edx
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116c <main+0x5c>
lea    0xe65(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f1 <main+0xe1>
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c6 <main+0xb6>
mov    -0x10(%rbp),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf09(%rip),%rdi
mov    $0x12c,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf1e(%rip),%rdi
mov    $0x12c,%esi
mov    $0x12c,%edx
xor    %eax,%eax
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 = [43 x i8] c"Value of sum prior to parallel region: %d\0A\00"
@.str.2 = [40 x i8] c"Value of sum after parallel region: %d\0A\00"
@.str.3 = [40 x i8] c"Check results: sum = %d (should be %d)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
store i32 25, i32* %3
%8 = load i32, i32* %3
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i32, i64 %9
store i64 %9, i64* %6
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 1
%14 = load i32, i32* %3
%15 = mul nsw i32 %13, %14
%16 = sdiv i32 %15, 2
%17 = add nsw i32 0, %16
store i32 %17, i32* %7
store i32 0, i32* %2
br label %18
18: ; preds = %27, %0
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i32, i32* %2
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %11, i64 %25
store i32 %23, i32* %26
br label %27
27: ; preds = %22
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %18
30: ; preds = %18
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 0, i32* %4
%32 = load i32, i32* %4
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %32)
store i32 0, i32* %2
br label %34
34: ; preds = %45, %30
%35 = load i32, i32* %2
%36 = load i32, i32* %3
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %11, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %4
%44 = add nsw i32 %43, %42
store i32 %44, i32* %4
br label %45
45: ; preds = %38
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
br label %34
48: ; preds = %34
%49 = load i32, i32* %4
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %4
%52 = load i32, i32* %7
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %51, i32 %52)
store i32 0, i32* %1
%54 = load i8*, i8** %5
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@.str = [25 x i8] c"Number of threads is %d\0A\00"
@.str.1 = [43 x i8] c"Value of sum prior to parallel region: %d\0A\00"
@.str.2 = [40 x i8] c"Value of sum after parallel region: %d\0A\00"
@.str.3 = [40 x i8] c"Check results: sum = %d (should be %d)\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 1)
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 0)
%3 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 300)
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 300, i32 300)
ret i32 0
}