#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 Sum_array(int, int *);
int /*<<< orphan*/ fill_rand(int, int *);
int omp_get_thread_num();
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int A[100000], sum;
  int flag = 0;
#pragma omp parallel num_threads(8)
  {
    int tid = omp_get_thread_num();
    if (tid < 4) {
      fill_rand(tid, A);
#pragma omp flush
      flag = 1;
#pragma omp flush(flag)
    } else {
#pragma omp flush(flag)
      while (flag != 1) {
#pragma omp flush(flag)
      }
#pragma omp flush
      sum = Sum_array(tid, A);
    }
  }
  printf("the sum is %d \n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61aa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x61a98(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x61a9c(%rbp)
cmpl   $0x4,-0x61a9c(%rbp)
jge    119e <main+0x5e>
mov    -0x61a9c(%rbp),%edi
lea    -0x61a90(%rbp),%rsi
call   1060 <fill_rand@plt>
movl   $0x1,-0x61a98(%rbp)
jmp    11cd <main+0x8d>
jmp    11a3 <main+0x63>
cmpl   $0x1,-0x61a98(%rbp)
je     11b5 <main+0x75>
jmp    11a3 <main+0x63>
mov    -0x61a9c(%rbp),%edi
lea    -0x61a90(%rbp),%rsi
call   1040 <Sum_array@plt>
mov    %eax,-0x61a94(%rbp)
mov    -0x61a94(%rbp),%esi
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x61aa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x61a88,%rsp
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
cmp    $0x4,%eax
jge    1170 <main+0x40>
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <fill_rand@plt>
lea    0xeac(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x61a88,%rsp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
jmp    1170 <main+0x40>

LLVM IR (-O0):
@.str = [16 x i8] c"the sum is %d \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100000 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = call i32 (...) @omp_get_thread_num()
store i32 %10, i32* %9
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* %9
%15 = getelementptr inbounds [100000 x i32], [100000 x i32]* %6, i64 0, i64 0
%16 = call i32 @fill_rand(i32 %14, i32* %15)
store i32 1, i32* %8
br label %26
17: ; preds = %2
br label %18
18: ; preds = %21, %17
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %18
br label %18
22: ; preds = %18
%23 = load i32, i32* %9
%24 = getelementptr inbounds [100000 x i32], [100000 x i32]* %6, i64 0, i64 0
%25 = call i32 @Sum_array(i32 %23, i32* %24)
store i32 %25, i32* %7
br label %26
26: ; preds = %22, %13
%27 = load i32, i32* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"the sum is %d \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100000 x i32]
%4 = bitcast [100000 x i32]* %3 to i8*
%5 = tail call i32 (...) @omp_get_thread_num()
%6 = icmp slt i32 %5, 4
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 0
%9 = call i32 @fill_rand(i32 %5, i32* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 undef)
ret i32 0
11: ; preds = %2, %11
br label %11
}