#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 */
typedef int /*<<< orphan*/ acc_device_t;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ acc_device_default;
int acc_get_device_num(int /*<<< orphan*/);
int acc_get_num_devices(int /*<<< orphan*/);
int /*<<< orphan*/ acc_init(int /*<<< orphan*/);
int /*<<< orphan*/ acc_set_device_num(int, int /*<<< orphan*/);
int /*<<< orphan*/ acc_shutdown(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i;
  int num_devices;
  int devnum;
  acc_device_t devtype = acc_device_default;
  num_devices = acc_get_num_devices(devtype);
  if (num_devices == 0)
    abort();
  acc_init(devtype);
  if (num_devices != acc_get_num_devices(devtype))
    abort();
  for (i = 0; i < num_devices; i++) {
    acc_set_device_num(i, devtype);
    devnum = acc_get_device_num(devtype);
    if (devnum != i)
      abort();
  }
  acc_shutdown(devtype);
  if (num_devices != acc_get_num_devices(devtype))
    abort();
  for (i = 0; i < num_devices; i++) {
    acc_set_device_num(i, devtype);
    devnum = acc_get_device_num(devtype);
    if (devnum != i)
      abort();
  }
  acc_shutdown(devtype);
  acc_init(devtype);
  acc_set_device_num(0, devtype);
  devnum = acc_get_device_num(devtype);
  if (devnum != 0)
    abort();
  if (num_devices > 1) {
    acc_set_device_num(1, (acc_device_t)0);
    devnum = acc_get_device_num(devtype);
    if (devnum != 1)
      abort();
  }
  acc_shutdown(devtype);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1080 <acc_get_num_devices@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    119e <main+0x3e>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%edi
call   1060 <acc_init@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
call   1080 <acc_get_num_devices@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
je     11c8 <main+0x68>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1217 <main+0xb7>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1070 <acc_set_device_num@plt>
mov    -0x20(%rbp),%edi
call   1040 <acc_get_device_num@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1204 <main+0xa4>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1209 <main+0xa9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cf <main+0x6f>
mov    -0x20(%rbp),%edi
call   1050 <acc_shutdown@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
call   1080 <acc_get_num_devices@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
je     1241 <main+0xe1>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1290 <main+0x130>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1070 <acc_set_device_num@plt>
mov    -0x20(%rbp),%edi
call   1040 <acc_get_device_num@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     127d <main+0x11d>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1282 <main+0x122>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1248 <main+0xe8>
mov    -0x20(%rbp),%edi
call   1050 <acc_shutdown@plt>
mov    -0x20(%rbp),%edi
call   1060 <acc_init@plt>
mov    -0x20(%rbp),%esi
xor    %edi,%edi
call   1070 <acc_set_device_num@plt>
mov    -0x20(%rbp),%edi
call   1040 <acc_get_device_num@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12c6 <main+0x166>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x1,-0x18(%rbp)
jle    12fd <main+0x19d>
mov    $0x1,%edi
xor    %esi,%esi
call   1070 <acc_set_device_num@plt>
mov    -0x20(%rbp),%edi
call   1040 <acc_get_device_num@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     12f8 <main+0x198>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    12fd <main+0x19d>
mov    -0x20(%rbp),%edi
call   1050 <acc_shutdown@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e75(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <acc_get_num_devices@plt>
test   %eax,%eax
je     124a <main+0xea>
mov    %eax,%r14d
mov    %ebx,%edi
call   1060 <acc_init@plt>
mov    %ebx,%edi
call   1080 <acc_get_num_devices@plt>
cmp    %eax,%r14d
jne    124a <main+0xea>
test   %r14d,%r14d
jle    11c0 <main+0x60>
xor    %ebp,%ebp
nopl   (%rax)
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <acc_set_device_num@plt>
mov    %ebx,%edi
call   1040 <acc_get_device_num@plt>
cmp    %eax,%ebp
jne    124a <main+0xea>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    11a0 <main+0x40>
mov    %ebx,%edi
call   1050 <acc_shutdown@plt>
mov    %ebx,%edi
call   1080 <acc_get_num_devices@plt>
cmp    %eax,%r14d
jne    124a <main+0xea>
test   %r14d,%r14d
jle    11fc <main+0x9c>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <acc_set_device_num@plt>
mov    %ebx,%edi
call   1040 <acc_get_device_num@plt>
cmp    %eax,%ebp
jne    124a <main+0xea>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    11e0 <main+0x80>
mov    %ebx,%edi
call   1050 <acc_shutdown@plt>
mov    %ebx,%edi
call   1060 <acc_init@plt>
xor    %edi,%edi
mov    %ebx,%esi
call   1070 <acc_set_device_num@plt>
mov    %ebx,%edi
call   1040 <acc_get_device_num@plt>
test   %eax,%eax
jne    124a <main+0xea>
cmp    $0x2,%r14d
jl     123c <main+0xdc>
mov    $0x1,%edi
xor    %esi,%esi
call   1070 <acc_set_device_num@plt>
mov    %ebx,%edi
call   1040 <acc_get_device_num@plt>
cmp    $0x1,%eax
jne    124a <main+0xea>
mov    %ebx,%edi
call   1050 <acc_shutdown@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@acc_device_default = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @acc_device_default
store i32 %10, i32* %9
%11 = load i32, i32* %9
%12 = call i32 @acc_get_num_devices(i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @abort()
unreachable
17: ; preds = %2
%18 = load i32, i32* %9
%19 = call i32 @acc_init(i32 %18)
%20 = load i32, i32* %7
%21 = load i32, i32* %9
%22 = call i32 @acc_get_num_devices(i32 %21)
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %17
store i32 0, i32* %6
br label %27
27: ; preds = %43, %26
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = load i32, i32* %6
%33 = load i32, i32* %9
%34 = call i32 @acc_set_device_num(i32 %32, i32 %33)
%35 = load i32, i32* %9
%36 = call i32 @acc_get_device_num(i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = load i32, i32* %6
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %31
%41 = call i32 (...) @abort()
unreachable
42: ; preds = %31
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %27
46: ; preds = %27
%47 = load i32, i32* %9
%48 = call i32 @acc_shutdown(i32 %47)
%49 = load i32, i32* %7
%50 = load i32, i32* %9
%51 = call i32 @acc_get_num_devices(i32 %50)
%52 = icmp ne i32 %49, %51
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = call i32 (...) @abort()
unreachable
55: ; preds = %46
store i32 0, i32* %6
br label %56
56: ; preds = %72, %55
%57 = load i32, i32* %6
%58 = load i32, i32* %7
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %75
60: ; preds = %56
%61 = load i32, i32* %6
%62 = load i32, i32* %9
%63 = call i32 @acc_set_device_num(i32 %61, i32 %62)
%64 = load i32, i32* %9
%65 = call i32 @acc_get_device_num(i32 %64)
store i32 %65, i32* %8
%66 = load i32, i32* %8
%67 = load i32, i32* %6
%68 = icmp ne i32 %66, %67
br i1 %68, label %69, label %71
69: ; preds = %60
%70 = call i32 (...) @abort()
unreachable
71: ; preds = %60
br label %72
72: ; preds = %71
%73 = load i32, i32* %6
%74 = add nsw i32 %73, 1
store i32 %74, i32* %6
br label %56
75: ; preds = %56
%76 = load i32, i32* %9
%77 = call i32 @acc_shutdown(i32 %76)
%78 = load i32, i32* %9
%79 = call i32 @acc_init(i32 %78)
%80 = load i32, i32* %9
%81 = call i32 @acc_set_device_num(i32 0, i32 %80)
%82 = load i32, i32* %9
%83 = call i32 @acc_get_device_num(i32 %82)
store i32 %83, i32* %8
%84 = load i32, i32* %8
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %75
%87 = call i32 (...) @abort()
unreachable
88: ; preds = %75
%89 = load i32, i32* %7
%90 = icmp sgt i32 %89, 1
br i1 %90, label %91, label %100
91: ; preds = %88
%92 = call i32 @acc_set_device_num(i32 1, i32 0)
%93 = load i32, i32* %9
%94 = call i32 @acc_get_device_num(i32 %93)
store i32 %94, i32* %8
%95 = load i32, i32* %8
%96 = icmp ne i32 %95, 1
br i1 %96, label %97, label %99
97: ; preds = %91
%98 = call i32 (...) @abort()
unreachable
99: ; preds = %91
br label %100
100: ; preds = %99, %88
%101 = load i32, i32* %9
%102 = call i32 @acc_shutdown(i32 %101)
ret i32 0
}

LLVM IR (-O2):
@acc_device_default = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @acc_device_default
%4 = tail call i32 @acc_get_num_devices(i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %2
%9 = tail call i32 @acc_init(i32 %3)
%10 = tail call i32 @acc_get_num_devices(i32 %3)
%11 = icmp eq i32 %4, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = icmp sgt i32 %4, 0
br i1 %13, label %18, label %26
14: ; preds = %8
%15 = tail call i32 (...) @abort()
unreachable
16: ; preds = %18
%17 = icmp eq i32 %23, %4
br i1 %17, label %26, label %18
18: ; preds = %12, %16
%19 = phi i32 [ %23, %16 ], [ 0, %12 ]
%20 = tail call i32 @acc_set_device_num(i32 %19, i32 %3)
%21 = tail call i32 @acc_get_device_num(i32 %3)
%22 = icmp eq i32 %21, %19
%23 = add nuw nsw i32 %19, 1
br i1 %22, label %16, label %24
24: ; preds = %18
%25 = tail call i32 (...) @abort()
unreachable
26: ; preds = %16, %12
%27 = tail call i32 @acc_shutdown(i32 %3)
%28 = tail call i32 @acc_get_num_devices(i32 %3)
%29 = icmp eq i32 %4, %28
br i1 %29, label %30, label %31
30: ; preds = %26
br i1 %13, label %35, label %43
31: ; preds = %26
%32 = tail call i32 (...) @abort()
unreachable
33: ; preds = %35
%34 = icmp eq i32 %40, %4
br i1 %34, label %43, label %35
35: ; preds = %30, %33
%36 = phi i32 [ %40, %33 ], [ 0, %30 ]
%37 = tail call i32 @acc_set_device_num(i32 %36, i32 %3)
%38 = tail call i32 @acc_get_device_num(i32 %3)
%39 = icmp eq i32 %38, %36
%40 = add nuw nsw i32 %36, 1
br i1 %39, label %33, label %41
41: ; preds = %35
%42 = tail call i32 (...) @abort()
unreachable
43: ; preds = %33, %30
%44 = tail call i32 @acc_shutdown(i32 %3)
%45 = tail call i32 @acc_init(i32 %3)
%46 = tail call i32 @acc_set_device_num(i32 0, i32 %3)
%47 = tail call i32 @acc_get_device_num(i32 %3)
%48 = icmp eq i32 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %43
%50 = tail call i32 (...) @abort()
unreachable
51: ; preds = %43
%52 = icmp sgt i32 %4, 1
br i1 %52, label %53, label %59
53: ; preds = %51
%54 = tail call i32 @acc_set_device_num(i32 1, i32 0)
%55 = tail call i32 @acc_get_device_num(i32 %3)
%56 = icmp eq i32 %55, 1
br i1 %56, label %59, label %57
57: ; preds = %53
%58 = tail call i32 (...) @abort()
unreachable
59: ; preds = %53, %51
%60 = tail call i32 @acc_shutdown(i32 %3)
ret i32 0
}