#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();
void *omp_target_alloc(int, int);
int /*<<< orphan*/ omp_target_free(void *, int);
int main() {
  int d = omp_get_default_device();
  int id = omp_get_initial_device();
  int err;
  void *p;
  if (d < 0 || d >= omp_get_num_devices())
    d = id;
  p = omp_target_alloc(128 * sizeof(int), d);
  if (p == NULL)
    return 0;
#pragma omp target is_device_ptr(p) if (d >= 0) device(d >= 0 ? d : 0)
  {
    int i, *q = (int *)p;
    for (i = 0; i < 128; i++)
      q[i] = i + 7;
  }
#pragma omp target is_device_ptr(p) if (d >= 0) device(d >= 0 ? d : 0)         \
    map(from                                                                   \
        : err)
  {
    int i;
    err = 0;
    for (i = 0; i < 128; i++)
      if (((int *)p)[i] != i + 7)
        err = 1;
  }
  if (err)
    abort();
  omp_target_free(p, d);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <omp_get_default_device@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1060 <omp_get_initial_device@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11a7 <main+0x47>
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1070 <omp_get_num_devices@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jl     11ad <main+0x4d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    $0x200,%edi
call   1080 <omp_target_alloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d5 <main+0x75>
movl   $0x0,-0x4(%rbp)
jmp    1282 <main+0x122>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x80,-0x1c(%rbp)
jge    1210 <main+0xb0>
mov    -0x1c(%rbp),%edx
add    $0x7,%edx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e4 <main+0x84>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x80,-0x2c(%rbp)
jge    125e <main+0xfe>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x2c(%rbp),%ecx
add    $0x7,%ecx
cmp    %ecx,%eax
je     124b <main+0xeb>
movl   $0x1,-0x10(%rbp)
jmp    1250 <main+0xf0>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    121e <main+0xbe>
cmpl   $0x0,-0x10(%rbp)
je     126f <main+0x10f>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <omp_target_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <omp_get_default_device@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1060 <omp_get_initial_device@plt>
mov    %eax,%ebp
test   %r14d,%r14d
js     1188 <main+0x28>
xor    %eax,%eax
call   1070 <omp_get_num_devices@plt>
cmp    %eax,%r14d
jl     118b <main+0x2b>
mov    %ebp,%r14d
mov    $0x200,%edi
mov    %r14d,%esi
call   1080 <omp_target_alloc@plt>
test   %rax,%rax
je     13b0 <main+0x250>
movaps 0xe58(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe5e(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe63(%rip),%xmm0
movups %xmm0,0x20(%rax)
movaps 0xe68(%rip),%xmm0
movups %xmm0,0x30(%rax)
movaps 0xe6d(%rip),%xmm0
movups %xmm0,0x40(%rax)
movaps 0xe72(%rip),%xmm0
movups %xmm0,0x50(%rax)
movaps 0xe77(%rip),%xmm0
movups %xmm0,0x60(%rax)
movaps 0xe7c(%rip),%xmm0
movups %xmm0,0x70(%rax)
movaps 0xe81(%rip),%xmm0
movups %xmm0,0x80(%rax)
movaps 0xe83(%rip),%xmm0
movups %xmm0,0x90(%rax)
movaps 0xe85(%rip),%xmm0
movups %xmm0,0xa0(%rax)
movaps 0xe87(%rip),%xmm0
movups %xmm0,0xb0(%rax)
movaps 0xe89(%rip),%xmm0
movups %xmm0,0xc0(%rax)
movaps 0xe8b(%rip),%xmm0
movups %xmm0,0xd0(%rax)
movaps 0xe8d(%rip),%xmm0
movups %xmm0,0xe0(%rax)
movaps 0xe8f(%rip),%xmm0
movups %xmm0,0xf0(%rax)
movaps 0xe91(%rip),%xmm0
movups %xmm0,0x100(%rax)
movaps 0xe93(%rip),%xmm0
movups %xmm0,0x110(%rax)
movaps 0xe95(%rip),%xmm0
movups %xmm0,0x120(%rax)
movaps 0xe97(%rip),%xmm0
movups %xmm0,0x130(%rax)
movaps 0xe99(%rip),%xmm0
movups %xmm0,0x140(%rax)
movaps 0xe9b(%rip),%xmm0
movups %xmm0,0x150(%rax)
movaps 0xe9d(%rip),%xmm0
movups %xmm0,0x160(%rax)
movaps 0xe9f(%rip),%xmm0
movups %xmm0,0x170(%rax)
movaps 0xea1(%rip),%xmm0
movups %xmm0,0x180(%rax)
movaps 0xea3(%rip),%xmm0
movups %xmm0,0x190(%rax)
movaps 0xea5(%rip),%xmm0
movups %xmm0,0x1a0(%rax)
movaps 0xea7(%rip),%xmm0
movups %xmm0,0x1b0(%rax)
movaps 0xea9(%rip),%xmm0
movups %xmm0,0x1c0(%rax)
movaps 0xeab(%rip),%xmm0
movups %xmm0,0x1d0(%rax)
movaps 0xead(%rip),%xmm0
movups %xmm0,0x1e0(%rax)
movaps 0xeaf(%rip),%xmm0
movups %xmm0,0x1f0(%rax)
xor    %ecx,%ecx
mov    $0xa,%edx
mov    $0x1,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    -0x28(%rax,%rdx,4),%edi
mov    -0x24(%rax,%rdx,4),%ebp
lea    -0x3(%rdx),%rbx
xor    %rdi,%rbx
lea    -0x2(%rdx),%rdi
xor    %rbp,%rdi
or     %rbx,%rdi
mov    -0x20(%rax,%rdx,4),%ebp
lea    -0x1(%rdx),%rbx
xor    %rbp,%rbx
mov    -0x1c(%rax,%rdx,4),%ebp
xor    %rdx,%rbp
or     %rbx,%rbp
or     %rdi,%rbp
cmovne %esi,%ecx
add    $0x4,%rdx
cmp    $0x8a,%rdx
jne    1360 <main+0x200>
test   %ecx,%ecx
jne    13b7 <main+0x257>
mov    %rax,%rdi
mov    %r14d,%esi
call   1030 <omp_target_free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1040 <abort@plt>

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

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 (...) @omp_get_default_device()
%2 = tail call i32 (...) @omp_get_initial_device()
%3 = icmp slt i32 %1, 0
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = tail call i32 (...) @omp_get_num_devices()
%6 = icmp slt i32 %1, %5
br i1 %6, label %8, label %7
7: ; preds = %4, %0
br label %8
8: ; preds = %7, %4
%9 = phi i32 [ %2, %7 ], [ %1, %4 ]
%10 = tail call i8* @omp_target_alloc(i32 512, i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %115, label %12
12: ; preds = %8
%13 = bitcast i8* %10 to i32*
%14 = bitcast i8* %10 to <4 x i32>*
store <4 x i32> <i32 7, i32 8, i32 9, i32 10>, <4 x i32>* %14
%15 = getelementptr inbounds i8, i8* %10, i64 16
%16 = bitcast i8* %15 to <4 x i32>*
store <4 x i32> <i32 11, i32 12, i32 13, i32 14>, <4 x i32>* %16
%17 = getelementptr inbounds i8, i8* %10, i64 32
%18 = bitcast i8* %17 to <4 x i32>*
store <4 x i32> <i32 15, i32 16, i32 17, i32 18>, <4 x i32>* %18
%19 = getelementptr inbounds i8, i8* %10, i64 48
%20 = bitcast i8* %19 to <4 x i32>*
store <4 x i32> <i32 19, i32 20, i32 21, i32 22>, <4 x i32>* %20
%21 = getelementptr inbounds i8, i8* %10, i64 64
%22 = bitcast i8* %21 to <4 x i32>*
store <4 x i32> <i32 23, i32 24, i32 25, i32 26>, <4 x i32>* %22
%23 = getelementptr inbounds i8, i8* %10, i64 80
%24 = bitcast i8* %23 to <4 x i32>*
store <4 x i32> <i32 27, i32 28, i32 29, i32 30>, <4 x i32>* %24
%25 = getelementptr inbounds i8, i8* %10, i64 96
%26 = bitcast i8* %25 to <4 x i32>*
store <4 x i32> <i32 31, i32 32, i32 33, i32 34>, <4 x i32>* %26
%27 = getelementptr inbounds i8, i8* %10, i64 112
%28 = bitcast i8* %27 to <4 x i32>*
store <4 x i32> <i32 35, i32 36, i32 37, i32 38>, <4 x i32>* %28
%29 = getelementptr inbounds i8, i8* %10, i64 128
%30 = bitcast i8* %29 to <4 x i32>*
store <4 x i32> <i32 39, i32 40, i32 41, i32 42>, <4 x i32>* %30
%31 = getelementptr inbounds i8, i8* %10, i64 144
%32 = bitcast i8* %31 to <4 x i32>*
store <4 x i32> <i32 43, i32 44, i32 45, i32 46>, <4 x i32>* %32
%33 = getelementptr inbounds i8, i8* %10, i64 160
%34 = bitcast i8* %33 to <4 x i32>*
store <4 x i32> <i32 47, i32 48, i32 49, i32 50>, <4 x i32>* %34
%35 = getelementptr inbounds i8, i8* %10, i64 176
%36 = bitcast i8* %35 to <4 x i32>*
store <4 x i32> <i32 51, i32 52, i32 53, i32 54>, <4 x i32>* %36
%37 = getelementptr inbounds i8, i8* %10, i64 192
%38 = bitcast i8* %37 to <4 x i32>*
store <4 x i32> <i32 55, i32 56, i32 57, i32 58>, <4 x i32>* %38
%39 = getelementptr inbounds i8, i8* %10, i64 208
%40 = bitcast i8* %39 to <4 x i32>*
store <4 x i32> <i32 59, i32 60, i32 61, i32 62>, <4 x i32>* %40
%41 = getelementptr inbounds i8, i8* %10, i64 224
%42 = bitcast i8* %41 to <4 x i32>*
store <4 x i32> <i32 63, i32 64, i32 65, i32 66>, <4 x i32>* %42
%43 = getelementptr inbounds i8, i8* %10, i64 240
%44 = bitcast i8* %43 to <4 x i32>*
store <4 x i32> <i32 67, i32 68, i32 69, i32 70>, <4 x i32>* %44
%45 = getelementptr inbounds i8, i8* %10, i64 256
%46 = bitcast i8* %45 to <4 x i32>*
store <4 x i32> <i32 71, i32 72, i32 73, i32 74>, <4 x i32>* %46
%47 = getelementptr inbounds i8, i8* %10, i64 272
%48 = bitcast i8* %47 to <4 x i32>*
store <4 x i32> <i32 75, i32 76, i32 77, i32 78>, <4 x i32>* %48
%49 = getelementptr inbounds i8, i8* %10, i64 288
%50 = bitcast i8* %49 to <4 x i32>*
store <4 x i32> <i32 79, i32 80, i32 81, i32 82>, <4 x i32>* %50
%51 = getelementptr inbounds i8, i8* %10, i64 304
%52 = bitcast i8* %51 to <4 x i32>*
store <4 x i32> <i32 83, i32 84, i32 85, i32 86>, <4 x i32>* %52
%53 = getelementptr inbounds i8, i8* %10, i64 320
%54 = bitcast i8* %53 to <4 x i32>*
store <4 x i32> <i32 87, i32 88, i32 89, i32 90>, <4 x i32>* %54
%55 = getelementptr inbounds i8, i8* %10, i64 336
%56 = bitcast i8* %55 to <4 x i32>*
store <4 x i32> <i32 91, i32 92, i32 93, i32 94>, <4 x i32>* %56
%57 = getelementptr inbounds i8, i8* %10, i64 352
%58 = bitcast i8* %57 to <4 x i32>*
store <4 x i32> <i32 95, i32 96, i32 97, i32 98>, <4 x i32>* %58
%59 = getelementptr inbounds i8, i8* %10, i64 368
%60 = bitcast i8* %59 to <4 x i32>*
store <4 x i32> <i32 99, i32 100, i32 101, i32 102>, <4 x i32>* %60
%61 = getelementptr inbounds i8, i8* %10, i64 384
%62 = bitcast i8* %61 to <4 x i32>*
store <4 x i32> <i32 103, i32 104, i32 105, i32 106>, <4 x i32>* %62
%63 = getelementptr inbounds i8, i8* %10, i64 400
%64 = bitcast i8* %63 to <4 x i32>*
store <4 x i32> <i32 107, i32 108, i32 109, i32 110>, <4 x i32>* %64
%65 = getelementptr inbounds i8, i8* %10, i64 416
%66 = bitcast i8* %65 to <4 x i32>*
store <4 x i32> <i32 111, i32 112, i32 113, i32 114>, <4 x i32>* %66
%67 = getelementptr inbounds i8, i8* %10, i64 432
%68 = bitcast i8* %67 to <4 x i32>*
store <4 x i32> <i32 115, i32 116, i32 117, i32 118>, <4 x i32>* %68
%69 = getelementptr inbounds i8, i8* %10, i64 448
%70 = bitcast i8* %69 to <4 x i32>*
store <4 x i32> <i32 119, i32 120, i32 121, i32 122>, <4 x i32>* %70
%71 = getelementptr inbounds i8, i8* %10, i64 464
%72 = bitcast i8* %71 to <4 x i32>*
store <4 x i32> <i32 123, i32 124, i32 125, i32 126>, <4 x i32>* %72
%73 = getelementptr inbounds i8, i8* %10, i64 480
%74 = bitcast i8* %73 to <4 x i32>*
store <4 x i32> <i32 127, i32 128, i32 129, i32 130>, <4 x i32>* %74
%75 = getelementptr inbounds i8, i8* %10, i64 496
%76 = bitcast i8* %75 to <4 x i32>*
store <4 x i32> <i32 131, i32 132, i32 133, i32 134>, <4 x i32>* %76
br label %77
77: ; preds = %77, %12
%78 = phi i64 [ 0, %12 ], [ %107, %77 ]
%79 = phi i32 [ 0, %12 ], [ %106, %77 ]
%80 = getelementptr inbounds i32, i32* %13, i64 %78
%81 = load i32, i32* %80
%82 = add nuw nsw i64 %78, 7
%83 = zext i32 %81 to i64
%84 = icmp eq i64 %82, %83
%85 = or i64 %78, 1
%86 = getelementptr inbounds i32, i32* %13, i64 %85
%87 = load i32, i32* %86
%88 = add nuw nsw i64 %78, 8
%89 = zext i32 %87 to i64
%90 = icmp eq i64 %88, %89
%91 = or i64 %78, 2
%92 = getelementptr inbounds i32, i32* %13, i64 %91
%93 = load i32, i32* %92
%94 = add nuw nsw i64 %78, 9
%95 = zext i32 %93 to i64
%96 = icmp eq i64 %94, %95
%97 = or i64 %78, 3
%98 = getelementptr inbounds i32, i32* %13, i64 %97
%99 = load i32, i32* %98
%100 = add nuw nsw i64 %78, 10
%101 = zext i32 %99 to i64
%102 = icmp eq i64 %100, %101
%103 = select i1 %102, i1 %96, i1 false
%104 = select i1 %103, i1 %90, i1 false
%105 = select i1 %104, i1 %84, i1 false
%106 = select i1 %105, i32 %79, i32 1
%107 = add nuw nsw i64 %78, 4
%108 = icmp eq i64 %107, 128
br i1 %108, label %109, label %77
109: ; preds = %77
%110 = icmp eq i32 %106, 0
br i1 %110, label %113, label %111
111: ; preds = %109
%112 = tail call i32 (...) @abort()
unreachable
113: ; preds = %109
%114 = tail call i32 @omp_target_free(i8* %10, i32 %9)
br label %115
115: ; preds = %8, %113
ret i32 0
}