#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 big_calc1(int);
int big_calc2(int, int *);
int big_calc3(int, int *);
int big_calc4(int);
int omp_get_thread_num();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int A[4] = {1, 1, 1, 1};
  int B[4] = {2, 2, 2, 2};
  int C[4] = {3, 3, 3, 3};
  int i, id;
#pragma omp parallel shared(A, B, C) private(id)
  {
    id = omp_get_thread_num();
    printf("[%d] Hello!\n", id);
    A[id] = big_calc1(id);
#pragma omp barrier
#pragma omp for
    for (i = 0; i < 4; ++i) {
      C[i] = big_calc2(i, A);
    }
#pragma omp for nowait
    for (i = 0; i < 4; ++i) {
      B[i] = big_calc3(i, C);
    }
    A[id] = big_calc4(id);
  }
  printf("Done!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe84(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe81(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe7e(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe7b(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%edi
call   1070 <big_calc1@plt>
mov    %eax,%ecx
movslq -0x48(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    1213 <main+0xb3>
mov    -0x44(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <big_calc2@plt>
mov    %eax,%ecx
movslq -0x44(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11e5 <main+0x85>
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    1248 <main+0xe8>
mov    -0x44(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1080 <big_calc3@plt>
mov    %eax,%ecx
movslq -0x44(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    121a <main+0xba>
mov    -0x48(%rbp),%edi
call   1050 <big_calc4@plt>
mov    %eax,%ecx
movslq -0x48(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xe82(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %eax,%ebx
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1080 <big_calc1@plt>
movslq %ebx,%r14
mov    %eax,0x10(%rsp,%r14,4)
lea    0x10(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <big_calc2@plt>
mov    %eax,(%rsp)
mov    $0x1,%edi
mov    %rbx,%rsi
call   1070 <big_calc2@plt>
mov    %eax,0x4(%rsp)
mov    $0x2,%edi
mov    %rbx,%rsi
call   1070 <big_calc2@plt>
mov    %eax,0x8(%rsp)
mov    $0x3,%edi
mov    %rbx,%rsi
call   1070 <big_calc2@plt>
mov    %eax,0xc(%rsp)
mov    %rsp,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <big_calc3@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1090 <big_calc3@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
call   1090 <big_calc3@plt>
mov    $0x3,%edi
mov    %rbx,%rsi
call   1090 <big_calc3@plt>
mov    %r14d,%edi
call   1060 <big_calc4@plt>
mov    %eax,0x10(%rsp,%r14,4)
lea    0xde5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@__const.main.A = [4 x i32] [i32 1, i32 1, i32 1, i32 1]
@.str = [13 x i8] c"[%d] Hello!\0A\00"
@str = [6 x i8] c"Done!\00"
define i32 @main() {
%1 = alloca [4 x i32]
%2 = alloca [4 x i32]
%3 = bitcast [4 x i32]* %1 to i8*
%4 = bitcast [4 x i32]* %2 to i8*
%5 = tail call i32 (...) @omp_get_thread_num()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @big_calc1(i32 %5)
%8 = sext i32 %5 to i64
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 %8
store i32 %7, i32* %9
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%11 = call i32 @big_calc2(i32 0, i32* %10)
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
store i32 %11, i32* %12
%13 = call i32 @big_calc2(i32 1, i32* %10)
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
store i32 %13, i32* %14
%15 = call i32 @big_calc2(i32 2, i32* %10)
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
store i32 %15, i32* %16
%17 = call i32 @big_calc2(i32 3, i32* %10)
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
store i32 %17, i32* %18
%19 = call i32 @big_calc3(i32 0, i32* %12)
%20 = call i32 @big_calc3(i32 1, i32* %12)
%21 = call i32 @big_calc3(i32 2, i32* %12)
%22 = call i32 @big_calc3(i32 3, i32* %12)
%23 = call i32 @big_calc4(i32 %5)
store i32 %23, i32* %9
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}