#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 omp_get_default_device();
int omp_get_initial_device();
int omp_get_num_devices();
int omp_target_is_present(int *, int);
int main() {
  int d = omp_get_default_device();
  int id = omp_get_initial_device();
  if (d < 0 || d >= omp_get_num_devices())
    d = id;
  int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int *b = a;
  int shared_mem = 0;
#pragma omp target map(alloc : shared_mem)
  shared_mem = 1;
  if (omp_target_is_present(b, d) != shared_mem)
    abort();
#pragma omp target enter data map(to : a)
  if (omp_target_is_present(b, d) == 0)
    abort();
#pragma omp target enter data map(alloc : b[:0])
  if (omp_target_is_present(b, d) == 0)
    abort();
#pragma omp target exit data map(release : b[:0])
  if (omp_target_is_present(b, d) == 0)
    abort();
#pragma omp target exit data map(release : b[:0])
  if (omp_target_is_present(b, d) != shared_mem)
    abort();
#pragma omp target enter data map(to : a)
  if (omp_target_is_present(b, d) == 0)
    abort();
#pragma omp target enter data map(always, to : b[:0])
  if (omp_target_is_present(b, d) == 0)
    abort();
#pragma omp target exit data map(delete : b[:0])
  if (omp_target_is_present(b, d) != shared_mem)
    abort();
#pragma omp target exit data map(from : b[:0])
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <omp_get_default_device@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <omp_get_initial_device@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11a7 <main+0x47>
mov    -0x8(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    $0x0,%al
call   1080 <omp_get_num_devices@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
cmp    %ecx,%eax
jl     11ad <main+0x4d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe48(%rip),%rsi
mov    $0x28,%edx
call   1060 <memcpy@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <omp_target_is_present@plt>
cmp    -0x4c(%rbp),%eax
je     11f4 <main+0x94>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <omp_target_is_present@plt>
cmp    $0x0,%eax
jne    1210 <main+0xb0>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <omp_target_is_present@plt>
cmp    $0x0,%eax
jne    122c <main+0xcc>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <omp_target_is_present@plt>
cmp    $0x0,%eax
jne    1248 <main+0xe8>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <omp_target_is_present@plt>
cmp    -0x4c(%rbp),%eax
je     1264 <main+0x104>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <omp_target_is_present@plt>
cmp    $0x0,%eax
jne    1280 <main+0x120>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <omp_target_is_present@plt>
cmp    $0x0,%eax
jne    129c <main+0x13c>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <omp_target_is_present@plt>
cmp    -0x4c(%rbp),%eax
je     12b8 <main+0x158>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   1040 <omp_get_default_device@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <omp_get_initial_device@plt>
mov    %eax,%ebp
test   %ebx,%ebx
js     1177 <main+0x27>
xor    %eax,%eax
call   1070 <omp_get_num_devices@plt>
cmp    %eax,%ebx
jl     1179 <main+0x29>
mov    %ebp,%ebx
mov    0xea0(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xe84(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe68(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    %ebx,%esi
call   1050 <omp_target_is_present@plt>
cmp    $0x1,%eax
jne    1218 <main+0xc8>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1050 <omp_target_is_present@plt>
test   %eax,%eax
je     1218 <main+0xc8>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1050 <omp_target_is_present@plt>
test   %eax,%eax
je     1218 <main+0xc8>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1050 <omp_target_is_present@plt>
test   %eax,%eax
je     1218 <main+0xc8>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1050 <omp_target_is_present@plt>
cmp    $0x1,%eax
jne    1218 <main+0xc8>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1050 <omp_target_is_present@plt>
test   %eax,%eax
je     1218 <main+0xc8>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1050 <omp_target_is_present@plt>
test   %eax,%eax
je     1218 <main+0xc8>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1050 <omp_target_is_present@plt>
cmp    $0x1,%eax
jne    1218 <main+0xc8>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@__const.main.a = [10 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i32]
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (...) @omp_get_default_device()
store i32 %7, i32* %2
%8 = call i32 (...) @omp_get_initial_device()
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 (...) @omp_get_num_devices()
%14 = icmp sge i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11, %0
%16 = load i32, i32* %3
store i32 %16, i32* %2
br label %17
17: ; preds = %15, %11
%18 = bitcast [10 x i32]* %4 to i8*
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 0
store i32* %19, i32** %5
store i32 0, i32* %6
store i32 1, i32* %6
%20 = load i32*, i32** %5
%21 = load i32, i32* %2
%22 = call i32 @omp_target_is_present(i32* %20, i32 %21)
%23 = load i32, i32* %6
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %17
%28 = load i32*, i32** %5
%29 = load i32, i32* %2
%30 = call i32 @omp_target_is_present(i32* %28, i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %27
%35 = load i32*, i32** %5
%36 = load i32, i32* %2
%37 = call i32 @omp_target_is_present(i32* %35, i32 %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 (...) @abort()
unreachable
41: ; preds = %34
%42 = load i32*, i32** %5
%43 = load i32, i32* %2
%44 = call i32 @omp_target_is_present(i32* %42, i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (...) @abort()
unreachable
48: ; preds = %41
%49 = load i32*, i32** %5
%50 = load i32, i32* %2
%51 = call i32 @omp_target_is_present(i32* %49, i32 %50)
%52 = load i32, i32* %6
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 (...) @abort()
unreachable
56: ; preds = %48
%57 = load i32*, i32** %5
%58 = load i32, i32* %2
%59 = call i32 @omp_target_is_present(i32* %57, i32 %58)
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = call i32 (...) @abort()
unreachable
63: ; preds = %56
%64 = load i32*, i32** %5
%65 = load i32, i32* %2
%66 = call i32 @omp_target_is_present(i32* %64, i32 %65)
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %63
%69 = call i32 (...) @abort()
unreachable
70: ; preds = %63
%71 = load i32*, i32** %5
%72 = load i32, i32* %2
%73 = call i32 @omp_target_is_present(i32* %71, i32 %72)
%74 = load i32, i32* %6
%75 = icmp ne i32 %73, %74
br i1 %75, label %76, label %78
76: ; preds = %70
%77 = call i32 (...) @abort()
unreachable
78: ; preds = %70
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [10 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
define i32 @main() {
%1 = alloca [10 x i32]
%2 = tail call i32 (...) @omp_get_default_device()
%3 = tail call i32 (...) @omp_get_initial_device()
%4 = icmp slt i32 %2, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = tail call i32 (...) @omp_get_num_devices()
%7 = icmp slt i32 %2, %6
br i1 %7, label %9, label %8
8: ; preds = %5, %0
br label %9
9: ; preds = %8, %5
%10 = phi i32 [ %3, %8 ], [ %2, %5 ]
%11 = bitcast [10 x i32]* %1 to i8*
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%13 = call i32 @omp_target_is_present(i32* %12, i32 %10)
%14 = icmp eq i32 %13, 1
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = call i32 (...) @abort()
unreachable
17: ; preds = %9
%18 = call i32 @omp_target_is_present(i32* %12, i32 %10)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %17
%23 = call i32 @omp_target_is_present(i32* %12, i32 %10)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %22
%28 = call i32 @omp_target_is_present(i32* %12, i32 %10)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %27
%33 = call i32 @omp_target_is_present(i32* %12, i32 %10)
%34 = icmp eq i32 %33, 1
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = call i32 (...) @abort()
unreachable
37: ; preds = %32
%38 = call i32 @omp_target_is_present(i32* %12, i32 %10)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 (...) @abort()
unreachable
42: ; preds = %37
%43 = call i32 @omp_target_is_present(i32* %12, i32 %10)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 (...) @abort()
unreachable
47: ; preds = %42
%48 = call i32 @omp_target_is_present(i32* %12, i32 %10)
%49 = icmp eq i32 %48, 1
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = call i32 (...) @abort()
unreachable
52: ; preds = %47
ret i32 0
}