#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 */
double Sum_array(int, double *);
int /*<<< orphan*/ fill_rand(int, double *);
scalar_t__ malloc(int);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double, double);
int main() {
  double *A, sum, runtime;
  int flag = 0, flg_temp;
  A = (double *)malloc(10000 * sizeof(double));
  runtime = omp_get_wtime();
#pragma omp parallel sections
  {
#pragma omp section
    {
      fill_rand(10000, A);
#pragma omp flush
#pragma atomic write
      flag = 1;
#pragma omp flush(flag)
    }
#pragma omp section
    {
#pragma omp flush(flag)
      while (1) {
#pragma omp flush(flag)
#pragma atomic read
        flg_temp = flag;
        if (flg_temp == 1)
          break;
      }
#pragma omp flush
      sum = Sum_array(10000, A);
    }
  }
  runtime = omp_get_wtime() - runtime;
  printf(" In %f seconds, The sum is %f \n", runtime, sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x13880,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x2710,%edi
call   1070 <fill_rand@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    11aa <main+0x5a>
jmp    11af <main+0x5f>
jmp    1195 <main+0x45>
mov    -0x10(%rbp),%rsi
mov    $0x2710,%edi
call   1040 <Sum_array@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x13880,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x2710,%edi
mov    %rbx,%rsi
call   1070 <fill_rand@plt>
mov    $0x2710,%edi
mov    %rbx,%rsi
call   1040 <Sum_array@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
lea    0xe5e(%rip),%rdi
movsd  (%rsp),%xmm1
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c" In %f seconds, The sum is %f \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%7 = call i64 @malloc(i32 80000)
%8 = inttoptr i64 %7 to double*
store double* %8, double** %2
%9 = call double (...) @omp_get_wtime()
store double %9, double* %4
%10 = load double*, double** %2
%11 = call i32 @fill_rand(i32 10000, double* %10)
store i32 1, i32* %5
br label %12
12: ; preds = %0, %17
%13 = load i32, i32* %5
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %12
br label %18
17: ; preds = %12
br label %12
18: ; preds = %16
%19 = load double*, double** %2
%20 = call double @Sum_array(i32 10000, double* %19)
store double %20, double* %3
%21 = call double (...) @omp_get_wtime()
%22 = load double, double* %4
%23 = fsub double %21, %22
store double %23, double* %4
%24 = load double, double* %4
%25 = load double, double* %3
%26 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %24, double %25)
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [32 x i8] c" In %f seconds, The sum is %f \0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 80000)
%2 = inttoptr i64 %1 to double*
%3 = tail call double (...) @omp_get_wtime()
%4 = tail call i32 @fill_rand(i32 10000, double* %2)
%5 = tail call double @Sum_array(i32 10000, double* %2)
%6 = tail call double (...) @omp_get_wtime()
%7 = fsub double %6, %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %7, double %5)
ret i32 0
}