#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_uint;
typedef int /*<<< orphan*/ cl_platform_id;
typedef int /*<<< orphan*/ cl_int;
typedef int /*<<< orphan*/ cl_device_id;

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_TYPE_ALL;
int /*<<< orphan*/ clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ *, scalar_t__ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ oclCheckStatus(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
cl_device_id oclGetFirstDevice(cl_platform_id platform) {
  cl_int status;
  cl_device_id device;
  cl_uint numDevices;
  status =
      clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, &device, &numDevices);
  oclCheckStatus(status, "clGetDeviceIDs failed.");
  if (numDevices == 0) {
    fprintf(stderr, "No Device available in OpenCL platform");
    exit(1);
  }
  return device;
}


x86 assembly (clang, -O0):
<oclGetFirstDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
lea    -0xc(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1030 <clGetDeviceIDs@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe8a(%rip),%rsi
call   1050 <oclCheckStatus@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11a5 <oclGetFirstDevice+0x65>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oclGetFirstDevice>:
sub    $0x18,%rsp
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    $0x1,%edx
call   1030 <clGetDeviceIDs@plt>
lea    0xe98(%rip),%rsi
mov    %eax,%edi
call   1050 <oclCheckStatus@plt>
cmpq   $0x0,0x10(%rsp)
je     1180 <oclGetFirstDevice+0x40>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
ret
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@CL_DEVICE_TYPE_ALL = global i32 0
@.str = [23 x i8] c"clGetDeviceIDs failed.\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"No Device available in OpenCL platform\00"
define i32 @oclGetFirstDevice(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* @CL_DEVICE_TYPE_ALL
%8 = call i32 @clGetDeviceIDs(i32 %6, i32 %7, i32 1, i32* %4, i64* %5)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call i32 @oclCheckStatus(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%11 = load i64, i64* %5
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
%18 = load i32, i32* %4
ret i32 %18
}

LLVM IR (-O2):
@CL_DEVICE_TYPE_ALL = global i32 0
@.str = [23 x i8] c"clGetDeviceIDs failed.\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"No Device available in OpenCL platform\00"
define i32 @oclGetFirstDevice(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = bitcast i32* %2 to i8*
%5 = bitcast i64* %3 to i8*
%6 = load i32, i32* @CL_DEVICE_TYPE_ALL
%7 = call i32 @clGetDeviceIDs(i32 %0, i32 %6, i32 1, i32* %2, i64* %3)
%8 = call i32 @oclCheckStatus(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%9 = load i64, i64* %3
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = load i32, i32* %2
ret i32 %16
}