#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*/ abort();
int /*<<< orphan*/ usleep(int);
int main() {
  int x = 0, y = 0, z = 0, err;
  int shared_mem = 0;
#pragma omp target map(to : shared_mem)
  shared_mem = 1;
#pragma omp parallel
#pragma omp single
  {
#pragma omp task depend(in : x)
    {
      usleep(5000);
      x = 1;
    }
#pragma omp task depend(in : x)
    {
      usleep(6000);
      y = 2;
    }
#pragma omp task depend(out : z)
    {
      usleep(7000);
      z = 3;
    }
#pragma omp target enter data map(to : x, y, z) depend(inout : x, z) nowait
#pragma omp task depend(inout : x, z)
    {
      x++;
      y++;
      z++;
    }
#pragma omp target update to(x, y) depend(inout : x) nowait
#pragma omp target enter data map(always, to : z) depend(inout : z) nowait
#pragma omp target map(alloc : x, y, z) map(from : err) depend(inout : x, z)
    {
      err = x != 2 || y != 3 || z != 4;
      x = 5;
      y = 6;
      z = 7;
    }
#pragma omp task depend(in : x)
    {
      usleep(5000);
      if (!shared_mem)
        x = 1;
    }
#pragma omp task depend(in : x)
    {
      usleep(6000);
      if (!shared_mem)
        y = 2;
    }
#pragma omp task depend(out : z)
    {
      usleep(3000);
      if (!shared_mem)
        z = 3;
    }
#pragma omp target exit data map(release : z) depend(inout : z) nowait
#pragma omp target exit data map(from : x, y) depend(inout : x) nowait
#pragma omp target exit data map(from : z) depend(inout : z) nowait
#pragma omp taskwait
    if (err || x != 5 || y != 6 || z != 7)
      abort();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x18(%rbp)
mov    $0x1388,%edi
call   1040 <usleep@plt>
movl   $0x1,-0x8(%rbp)
mov    $0x1770,%edi
call   1040 <usleep@plt>
movl   $0x2,-0xc(%rbp)
mov    $0x1b58,%edi
call   1040 <usleep@plt>
movl   $0x3,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x1,%al
cmpl   $0x2,-0x8(%rbp)
mov    %al,-0x19(%rbp)
jne    11c8 <main+0xa8>
mov    $0x1,%al
cmpl   $0x3,-0xc(%rbp)
mov    %al,-0x19(%rbp)
jne    11c8 <main+0xa8>
cmpl   $0x4,-0x10(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x6,-0xc(%rbp)
movl   $0x7,-0x10(%rbp)
mov    $0x1388,%edi
call   1040 <usleep@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1203 <main+0xe3>
movl   $0x1,-0x8(%rbp)
mov    $0x1770,%edi
call   1040 <usleep@plt>
cmpl   $0x0,-0x18(%rbp)
jne    121e <main+0xfe>
movl   $0x2,-0xc(%rbp)
mov    $0xbb8,%edi
call   1040 <usleep@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1239 <main+0x119>
movl   $0x3,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1261 <main+0x141>
cmpl   $0x5,-0x8(%rbp)
jne    1261 <main+0x141>
cmpl   $0x6,-0xc(%rbp)
jne    1261 <main+0x141>
cmpl   $0x7,-0x10(%rbp)
je     1268 <main+0x148>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x1388,%edi
call   1030 <usleep@plt>
mov    $0x1770,%edi
call   1030 <usleep@plt>
mov    $0x1b58,%edi
call   1030 <usleep@plt>
mov    $0x1388,%edi
call   1030 <usleep@plt>
mov    $0x1770,%edi
call   1030 <usleep@plt>
mov    $0xbb8,%edi
call   1030 <usleep@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %6
store i32 1, i32* %6
%7 = call i32 @usleep(i32 5000)
store i32 1, i32* %2
%8 = call i32 @usleep(i32 6000)
store i32 2, i32* %3
%9 = call i32 @usleep(i32 7000)
store i32 3, i32* %4
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 1
store i32 %11, i32* %2
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 2
br i1 %17, label %24, label %18
18: ; preds = %0
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 3
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 4
br label %24
24: ; preds = %21, %18, %0
%25 = phi i1 [ true, %18 ], [ true, %0 ], [ %23, %21 ]
%26 = zext i1 %25 to i32
store i32 %26, i32* %5
store i32 5, i32* %2
store i32 6, i32* %3
store i32 7, i32* %4
%27 = call i32 @usleep(i32 5000)
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %24
store i32 1, i32* %2
br label %31
31: ; preds = %30, %24
%32 = call i32 @usleep(i32 6000)
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %31
store i32 2, i32* %3
br label %36
36: ; preds = %35, %31
%37 = call i32 @usleep(i32 3000)
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %36
store i32 3, i32* %4
br label %41
41: ; preds = %40, %36
%42 = load i32, i32* %5
%43 = icmp ne i32 %42, 0
br i1 %43, label %53, label %44
44: ; preds = %41
%45 = load i32, i32* %2
%46 = icmp ne i32 %45, 5
br i1 %46, label %53, label %47
47: ; preds = %44
%48 = load i32, i32* %3
%49 = icmp ne i32 %48, 6
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = load i32, i32* %4
%52 = icmp ne i32 %51, 7
br i1 %52, label %53, label %55
53: ; preds = %50, %47, %44, %41
%54 = call i32 (...) @abort()
unreachable
55: ; preds = %50
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 @usleep(i32 5000)
%2 = tail call i32 @usleep(i32 6000)
%3 = tail call i32 @usleep(i32 7000)
%4 = tail call i32 @usleep(i32 5000)
%5 = tail call i32 @usleep(i32 6000)
%6 = tail call i32 @usleep(i32 3000)
ret i32 0
}