#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, ...);
int main() {
  int i, TID, n = 9;
  int a[n];
  for (i = 0; i < n; i++)
    a[i] = i;
#pragma omp parallel for default(none) ordered schedule(runtime) private(      \
    i, TID) shared(n, a)
  for (i = 0; i < n; i++) {
    TID = 0;
    printf("Thread %d updates a[%d]\n", TID, i);
    a[i] += i;
#pragma omp ordered
    { printf("Thread %d prints value of a[%d] = %d\n", TID, i, a[i]); }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x9,-0x10(%rbp)
mov    -0x10(%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,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    117c <main+0x6c>
mov    -0x28(%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    1154 <main+0x44>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e4 <main+0xd4>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%edx
movslq -0x8(%rbp),%rcx
add    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1183 <main+0x73>
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   %r14
push   %rbx
push   %rax
lea    0xee5(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee9(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2,%edx
mov    $0x4,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x6,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
mov    $0x8,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x5,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0xa,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x6,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x6,%edx
mov    $0xc,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x7,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x7,%edx
mov    $0xe,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
mov    $0x10,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Thread %d updates a[%d]\0A\00"
@.str.1 = [38 x i8] c"Thread %d prints value of a[%d] = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
store i32 9, i32* %4
%7 = load i32, i32* %4
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %5
%10 = alloca i32, i64 %8
store i64 %8, i64* %6
store i32 0, i32* %2
br label %11
11: ; preds = %20, %0
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i32, i32* %2
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %10, i64 %18
store i32 %16, i32* %19
br label %20
20: ; preds = %15
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %11
23: ; preds = %11
store i32 0, i32* %2
br label %24
24: ; preds = %45, %23
%25 = load i32, i32* %2
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %48
28: ; preds = %24
store i32 0, i32* %3
%29 = load i32, i32* %3
%30 = load i32, i32* %2
%31 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30)
%32 = load i32, i32* %2
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %10, i64 %34
%36 = load i32, i32* %35
%37 = add nsw i32 %36, %32
store i32 %37, i32* %35
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = load i32, i32* %2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %10, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39, i32 %43)
br label %45
45: ; preds = %28
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
br label %24
48: ; preds = %24
store i32 0, i32* %1
%49 = load i8*, i8** %5
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str = [25 x i8] c"Thread %d updates a[%d]\0A\00"
@.str.1 = [38 x i8] c"Thread %d prints value of a[%d] = %d\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%2 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0, i32 0)
%3 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 1)
%4 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 1, i32 2)
%5 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 2)
%6 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 2, i32 4)
%7 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 3)
%8 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 3, i32 6)
%9 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 4)
%10 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 4, i32 8)
%11 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 5)
%12 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 5, i32 10)
%13 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 6)
%14 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 6, i32 12)
%15 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 7)
%16 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 7, i32 14)
%17 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 8)
%18 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 8, i32 16)
ret i32 0
}