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

/* Variables and functions */
int /*<<< orphan*/ clGetPlatformIDs(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_platform_id oclGetFirstPlatform() {
  cl_int status;
  cl_uint numPlatforms;
  cl_platform_id platforms[1];
  status = clGetPlatformIDs(1, platforms, &numPlatforms);
  oclCheckStatus(status, "clGetPlatformIDs failed.");
  if (numPlatforms == 0) {
    fprintf(stderr, "No OpenCL platform available");
    exit(1);
  }
  return platforms[0];
}


x86 assembly (clang, -O0):
<oclGetFirstPlatform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x14(%rbp),%rsi
mov    $0x1,%edi
lea    -0x10(%rbp),%rdx
call   1030 <clGetPlatformIDs@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe99(%rip),%rsi
call   1050 <oclCheckStatus@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1196 <oclGetFirstPlatform+0x56>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oclGetFirstPlatform>:
sub    $0x18,%rsp
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    $0x1,%edi
call   1030 <clGetPlatformIDs@plt>
lea    0xea1(%rip),%rsi
mov    %eax,%edi
call   1050 <oclCheckStatus@plt>
cmpq   $0x0,0x10(%rsp)
je     1177 <oclGetFirstPlatform+0x37>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
ret
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

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