#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 scalar_t__ cl_device_id;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ loclPrintAvailableDevices();
scalar_t__ loclSelectDevice(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
cl_device_id loclGetArgSelectedDevice(int argc, char *argv[]) {
  printf("\nInitializing OpenCL\n");
  int preferred_device = -1;
  if (argc < 2) {
    loclPrintAvailableDevices();
    exit(EXIT_FAILURE);
  } else
    preferred_device = atoi(argv[1]);
  cl_device_id device_selected = loclSelectDevice(preferred_device, stdout);
  if (device_selected == (cl_device_id)-1) {
    if (preferred_device == -1)
      fprintf(stderr, "No OpenCL device selected\n");
    else
      fprintf(stderr, "OpenCL with index %d does not exist\n",
              preferred_device);
    exit(EXIT_FAILURE);
  }
  return device_selected;
}


x86 assembly (clang, -O0):
<loclGetArgSelectedDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    11a1 <loclGetArgSelectedDevice+0x41>
mov    $0x0,%al
call   1050 <loclPrintAvailableDevices@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
call   1070 <loclSelectDevice@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    121f <loclGetArgSelectedDevice+0xbf>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f7 <loclGetArgSelectedDevice+0x97>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1211 <loclGetArgSelectedDevice+0xb1>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loclGetArgSelectedDevice>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebp
jle    11a1 <loclGetArgSelectedDevice+0x41>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1070 <loclSelectDevice@plt>
cmp    $0xffffffffffffffff,%rax
je     11aa <loclGetArgSelectedDevice+0x4a>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1050 <loclPrintAvailableDevices@plt>
jmp    11d8 <loclGetArgSelectedDevice+0x78>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
cmp    $0xffffffff,%ebx
jne    11c8 <loclGetArgSelectedDevice+0x68>
lea    0xe41(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d8 <loclGetArgSelectedDevice+0x78>
lea    0xe4c(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"\0AInitializing OpenCL\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"No OpenCL device selected\0A\00"
@.str.2 = [37 x i8] c"OpenCL with index %d does not exist\0A\00"
define i64 @loclGetArgSelectedDevice(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 (...) @loclPrintAvailableDevices()
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %5
br label %19
19: ; preds = %14
%20 = load i32, i32* %5
%21 = load i32, i32* @stdout
%22 = call i64 @loclSelectDevice(i32 %20, i32 %21)
store i64 %22, i64* %6
%23 = load i64, i64* %6
%24 = icmp eq i64 %23, -1
br i1 %24, label %25, label %38
25: ; preds = %19
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %35
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i32, i32* %5
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %31, %28
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %19
%39 = load i64, i64* %6
ret i64 %39
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"No OpenCL device selected\0A\00"
@.str.2 = [37 x i8] c"OpenCL with index %d does not exist\0A\00"
@str = [21 x i8] c"\0AInitializing OpenCL\00"
define i64 @loclGetArgSelectedDevice(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 (...) @loclPrintAvailableDevices()
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = load i32, i32* @stdout
%14 = tail call i64 @loclSelectDevice(i32 %12, i32 %13)
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %26
16: ; preds = %9
%17 = icmp eq i32 %12, -1
%18 = load i32, i32* @stderr
br i1 %17, label %19, label %21
19: ; preds = %16
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %23
21: ; preds = %16
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %9
ret i64 %14
}