#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 omp_is_initial_device();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int isHost = -1;
#pragma omp target map(from : isHost)
  { isHost = omp_is_initial_device(); }
  if (isHost < 0) {
    printf("Runtime error, isHost=%d\n", isHost);
  }
  printf("Target region executed on the %s\n", isHost ? "host" : "device");
  return isHost;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
mov    $0x0,%al
call   1040 <omp_is_initial_device@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    115b <main+0x3b>
mov    -0x8(%rbp),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%ecx
lea    0xedc(%rip),%rsi
lea    0xed0(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <omp_is_initial_device@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    113e <main+0x1e>
lea    0xecb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebx,%ebx
lea    0xefa(%rip),%rax
lea    0xeee(%rip),%rsi
cmove  %rax,%rsi
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Runtime error, isHost=%d\0A\00"
@.str.1 = [34 x i8] c"Target region executed on the %s\0A\00"
@.str.2 = [5 x i8] c"host\00"
@.str.3 = [7 x i8] c"device\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
%3 = call i32 (...) @omp_is_initial_device()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %6, %0
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
@.str = [26 x i8] c"Runtime error, isHost=%d\0A\00"
@.str.1 = [34 x i8] c"Target region executed on the %s\0A\00"
@.str.2 = [5 x i8] c"host\00"
@.str.3 = [7 x i8] c"device\00"
define i32 @main() {
%1 = tail call i32 (...) @omp_is_initial_device()
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %5
5: ; preds = %3, %0
%6 = icmp eq i32 %1, 0
%7 = select i1 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %7)
ret i32 %1
}