#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*/ acc_device_host;
int /*<<< orphan*/ acc_device_nvidia;
scalar_t__ acc_get_current_cuda_context();
scalar_t__ acc_get_num_devices(int /*<<< orphan*/);
int /*<<< orphan*/ acc_init(int /*<<< orphan*/);
int /*<<< orphan*/ acc_shutdown(int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (acc_get_num_devices(acc_device_nvidia) == 0)
    return 0;
  if (acc_get_current_cuda_context() != 0)
    abort();
  acc_init(acc_device_host);
  if (acc_get_current_cuda_context() != 0)
    abort();
  acc_shutdown(acc_device_host);
  if (acc_get_num_devices(acc_device_nvidia) == 0)
    return 0;
  if (acc_get_current_cuda_context() != 0)
    abort();
  acc_init(acc_device_nvidia);
  if (acc_get_current_cuda_context() == 0)
    abort();
  acc_shutdown(acc_device_nvidia);
  if (acc_get_current_cuda_context() != 0)
    abort();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1070 <acc_get_num_devices@plt>
cmp    $0x0,%rax
jne    118a <main+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    1265 <main+0x115>
mov    $0x0,%al
call   1060 <acc_get_current_cuda_context@plt>
cmp    $0x0,%rax
je     11a2 <main+0x52>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1050 <acc_init@plt>
mov    $0x0,%al
call   1060 <acc_get_current_cuda_context@plt>
cmp    $0x0,%rax
je     11c8 <main+0x78>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1040 <acc_shutdown@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1070 <acc_get_num_devices@plt>
cmp    $0x0,%rax
jne    11fa <main+0xaa>
movl   $0x0,-0x4(%rbp)
jmp    1265 <main+0x115>
mov    $0x0,%al
call   1060 <acc_get_current_cuda_context@plt>
cmp    $0x0,%rax
je     1212 <main+0xc2>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1050 <acc_init@plt>
mov    $0x0,%al
call   1060 <acc_get_current_cuda_context@plt>
cmp    $0x0,%rax
jne    1238 <main+0xe8>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1040 <acc_shutdown@plt>
mov    $0x0,%al
call   1060 <acc_get_current_cuda_context@plt>
cmp    $0x0,%rax
je     125e <main+0x10e>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%r14
mov    (%r14),%edi
call   1070 <acc_get_num_devices@plt>
test   %rax,%rax
je     11d6 <main+0x86>
xor    %eax,%eax
call   1060 <acc_get_current_cuda_context@plt>
test   %rax,%rax
jne    11e0 <main+0x90>
mov    0x2e65(%rip),%rbx
mov    (%rbx),%edi
call   1050 <acc_init@plt>
xor    %eax,%eax
call   1060 <acc_get_current_cuda_context@plt>
test   %rax,%rax
jne    11e0 <main+0x90>
mov    (%rbx),%edi
call   1040 <acc_shutdown@plt>
mov    (%r14),%edi
call   1070 <acc_get_num_devices@plt>
test   %rax,%rax
je     11d6 <main+0x86>
xor    %eax,%eax
call   1060 <acc_get_current_cuda_context@plt>
test   %rax,%rax
jne    11e0 <main+0x90>
mov    (%r14),%edi
call   1050 <acc_init@plt>
xor    %eax,%eax
call   1060 <acc_get_current_cuda_context@plt>
test   %rax,%rax
je     11e0 <main+0x90>
mov    (%r14),%edi
call   1040 <acc_shutdown@plt>
xor    %eax,%eax
call   1060 <acc_get_current_cuda_context@plt>
test   %rax,%rax
jne    11e0 <main+0x90>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@acc_device_nvidia = global i32 0
@acc_device_host = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* @acc_device_nvidia
%7 = call i64 @acc_get_num_devices(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %49
10: ; preds = %2
%11 = call i64 (...) @acc_get_current_cuda_context()
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (...) @abort()
unreachable
15: ; preds = %10
%16 = load i32, i32* @acc_device_host
%17 = call i32 @acc_init(i32 %16)
%18 = call i64 (...) @acc_get_current_cuda_context()
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %15
%23 = load i32, i32* @acc_device_host
%24 = call i32 @acc_shutdown(i32 %23)
%25 = load i32, i32* @acc_device_nvidia
%26 = call i64 @acc_get_num_devices(i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 0, i32* %3
br label %49
29: ; preds = %22
%30 = call i64 (...) @acc_get_current_cuda_context()
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %29
%35 = load i32, i32* @acc_device_nvidia
%36 = call i32 @acc_init(i32 %35)
%37 = call i64 (...) @acc_get_current_cuda_context()
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 (...) @abort()
unreachable
41: ; preds = %34
%42 = load i32, i32* @acc_device_nvidia
%43 = call i32 @acc_shutdown(i32 %42)
%44 = call i64 (...) @acc_get_current_cuda_context()
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (...) @abort()
unreachable
48: ; preds = %41
store i32 0, i32* %3
br label %49
49: ; preds = %48, %28, %9
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@acc_device_nvidia = global i32 0
@acc_device_host = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @acc_device_nvidia
%4 = tail call i64 @acc_get_num_devices(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %43, label %6
6: ; preds = %2
%7 = tail call i64 (...) @acc_get_current_cuda_context()
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 (...) @abort()
unreachable
11: ; preds = %6
%12 = load i32, i32* @acc_device_host
%13 = tail call i32 @acc_init(i32 %12)
%14 = tail call i64 (...) @acc_get_current_cuda_context()
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = tail call i32 (...) @abort()
unreachable
18: ; preds = %11
%19 = load i32, i32* @acc_device_host
%20 = tail call i32 @acc_shutdown(i32 %19)
%21 = load i32, i32* @acc_device_nvidia
%22 = tail call i64 @acc_get_num_devices(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %43, label %24
24: ; preds = %18
%25 = tail call i64 (...) @acc_get_current_cuda_context()
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i32 (...) @abort()
unreachable
29: ; preds = %24
%30 = load i32, i32* @acc_device_nvidia
%31 = tail call i32 @acc_init(i32 %30)
%32 = tail call i64 (...) @acc_get_current_cuda_context()
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = tail call i32 (...) @abort()
unreachable
36: ; preds = %29
%37 = load i32, i32* @acc_device_nvidia
%38 = tail call i32 @acc_shutdown(i32 %37)
%39 = tail call i64 (...) @acc_get_current_cuda_context()
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %36
%42 = tail call i32 (...) @abort()
unreachable
43: ; preds = %36, %18, %2
ret i32 0
}