#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 /*<<< orphan*/ omp_get_num_devices();
int omp_is_initial_device();
int /*<<< orphan*/ omp_set_default_device(int /*<<< orphan*/);
int main() {
  int res;
  int default_device = omp_get_default_device();
#pragma omp target map(from : res)
  res = omp_is_initial_device();
  if (res)
    abort();
  omp_set_default_device(omp_get_num_devices());
#pragma omp target map(from : res)
  res = omp_is_initial_device();
  if (!res)
    abort();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <omp_get_default_device@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <omp_is_initial_device@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1184 <main+0x34>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   1060 <omp_get_num_devices@plt>
mov    %eax,%edi
call   1050 <omp_set_default_device@plt>
mov    $0x0,%al
call   1070 <omp_is_initial_device@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11ad <main+0x5d>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1040 <omp_get_default_device@plt>
xor    %eax,%eax
call   1070 <omp_is_initial_device@plt>
test   %eax,%eax
jne    1180 <main+0x30>
xor    %eax,%eax
call   1060 <omp_get_num_devices@plt>
mov    %eax,%edi
call   1050 <omp_set_default_device@plt>
xor    %eax,%eax
call   1070 <omp_is_initial_device@plt>
test   %eax,%eax
je     1180 <main+0x30>
xor    %eax,%eax
pop    %rcx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @omp_get_default_device()
store i32 %4, i32* %3
%5 = call i32 (...) @omp_is_initial_device()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (...) @abort()
unreachable
10: ; preds = %0
%11 = call i32 (...) @omp_get_num_devices()
%12 = call i32 @omp_set_default_device(i32 %11)
%13 = call i32 (...) @omp_is_initial_device()
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 (...) @omp_get_default_device()
%2 = tail call i32 (...) @omp_is_initial_device()
%3 = icmp eq i32 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 (...) @abort()
unreachable
6: ; preds = %0
%7 = tail call i32 (...) @omp_get_num_devices()
%8 = tail call i32 @omp_set_default_device(i32 %7)
%9 = tail call i32 (...) @omp_is_initial_device()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %6
ret i32 0
}