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

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_TYPE_GPU;
scalar_t__ CL_SUCCESS;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ assert(int, scalar_t__, char *);
int /*<<< orphan*/ clCreateCommandQueue(int /*<<< orphan*/, int /*<<< orphan*/,
                                        int /*<<< orphan*/, scalar_t__ *);
int /*<<< orphan*/ clCreateContext(int /*<<< orphan*/, int,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, scalar_t__ *);
scalar_t__ clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ clGetPlatformIDs(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ clReleaseCommandQueue(int /*<<< orphan*/);
scalar_t__ clReleaseContext(int /*<<< orphan*/);
int /*<<< orphan*/ execute(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  cl_int err;
  cl_platform_id platform;
  cl_device_id device;
  cl_context context;
  cl_command_queue queue;
  srand(time(NULL));
  err = clGetPlatformIDs(1, &platform, NULL);
  assert(err == CL_SUCCESS, err, "clGetPlatformIDs()");
  err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
  assert(err == CL_SUCCESS, err, "clGetDeviceIDs()");
  context = clCreateContext(0, 1, &device, NULL, NULL, &err);
  assert(err == CL_SUCCESS, err, "clCreateContext()");
  queue = clCreateCommandQueue(context, device, 0, &err);
  assert(err == CL_SUCCESS, err, "clCreateCommandQueue()");
  execute(device, context, queue);
  err = clReleaseCommandQueue(queue);
  assert(err == CL_SUCCESS, err, "clReleaseCommandQueue()");
  err = clReleaseContext(context);
  assert(err == CL_SUCCESS, err, "clReleaseContext()");
  exit(EXIT_SUCCESS);
}


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)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    $0x1,%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <clGetPlatformIDs@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x18(%rbp),%rsi
lea    0xdf3(%rip),%rdx
call   1090 <assert@plt>
mov    -0x1c(%rbp),%edi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <clGetDeviceIDs@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d90(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x18(%rbp),%rsi
lea    0xdbd(%rip),%rdx
call   1090 <assert@plt>
xor    %edi,%edi
mov    $0x1,%esi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x18(%rbp),%r9
mov    %r8,%rcx
call   1080 <clCreateContext@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d4b(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x18(%rbp),%rsi
lea    0xd89(%rip),%rdx
call   1090 <assert@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
xor    %edx,%edx
lea    -0x18(%rbp),%rcx
call   1040 <clCreateCommandQueue@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d11(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x18(%rbp),%rsi
lea    0xd61(%rip),%rdx
call   1090 <assert@plt>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1060 <execute@plt>
mov    -0x28(%rbp),%edi
call   10b0 <clReleaseCommandQueue@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2cd1(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x18(%rbp),%rsi
lea    0xd38(%rip),%rdx
call   1090 <assert@plt>
mov    -0x24(%rbp),%edi
call   10c0 <clReleaseContext@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2c9f(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x18(%rbp),%rsi
lea    0xd1e(%rip),%rdx
call   1090 <assert@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    0x14(%rsp),%rsi
mov    $0x1,%edi
xor    %edx,%edx
call   1050 <clGetPlatformIDs@plt>
mov    0x2df0(%rip),%r15
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
lea    0xe10(%rip),%rdx
mov    %rax,%rsi
call   1090 <assert@plt>
mov    0x14(%rsp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rbx
mov    $0x1,%edx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1030 <clGetDeviceIDs@plt>
mov    %rax,0x8(%rsp)
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
lea    0xde4(%rip),%rdx
mov    %rax,%rsi
call   1090 <assert@plt>
lea    0x8(%rsp),%r14
xor    %edi,%edi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   1080 <clCreateContext@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rsi
xor    %edi,%edi
cmp    (%r15),%rsi
sete   %dil
lea    0xdba(%rip),%rdx
call   1090 <assert@plt>
mov    0x10(%rsp),%esi
mov    %ebx,%edi
xor    %edx,%edx
mov    %r14,%rcx
call   1040 <clCreateCommandQueue@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rsi
xor    %edi,%edi
cmp    (%r15),%rsi
sete   %dil
lea    0xda0(%rip),%rdx
call   1090 <assert@plt>
mov    0x10(%rsp),%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <execute@plt>
mov    %ebp,%edi
call   10b0 <clReleaseCommandQueue@plt>
mov    %rax,0x8(%rsp)
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
lea    0xd89(%rip),%rdx
mov    %rax,%rsi
call   1090 <assert@plt>
mov    %ebx,%edi
call   10c0 <clReleaseContext@plt>
mov    %rax,0x8(%rsp)
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
lea    0xd7d(%rip),%rdx
mov    %rax,%rsi
call   1090 <assert@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@CL_SUCCESS = global i64 0
@.str = [19 x i8] c"clGetPlatformIDs()\00"
@CL_DEVICE_TYPE_GPU = global i32 0
@.str.1 = [17 x i8] c"clGetDeviceIDs()\00"
@.str.2 = [18 x i8] c"clCreateContext()\00"
@.str.3 = [23 x i8] c"clCreateCommandQueue()\00"
@.str.4 = [24 x i8] c"clReleaseCommandQueue()\00"
@.str.5 = [19 x i8] c"clReleaseContext()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @time(i32* null)
%12 = call i32 @srand(i32 %11)
%13 = call i64 @clGetPlatformIDs(i32 1, i32* %7, i32* null)
store i64 %13, i64* %6
%14 = load i64, i64* %6
%15 = load i64, i64* @CL_SUCCESS
%16 = icmp eq i64 %14, %15
%17 = zext i1 %16 to i32
%18 = load i64, i64* %6
%19 = call i32 @assert(i32 %17, i64 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %7
%21 = load i32, i32* @CL_DEVICE_TYPE_GPU
%22 = call i64 @clGetDeviceIDs(i32 %20, i32 %21, i32 1, i32* %8, i32* null)
store i64 %22, i64* %6
%23 = load i64, i64* %6
%24 = load i64, i64* @CL_SUCCESS
%25 = icmp eq i64 %23, %24
%26 = zext i1 %25 to i32
%27 = load i64, i64* %6
%28 = call i32 @assert(i32 %26, i64 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @clCreateContext(i32 0, i32 1, i32* %8, i32* null, i32* null, i64* %6)
store i32 %29, i32* %9
%30 = load i64, i64* %6
%31 = load i64, i64* @CL_SUCCESS
%32 = icmp eq i64 %30, %31
%33 = zext i1 %32 to i32
%34 = load i64, i64* %6
%35 = call i32 @assert(i32 %33, i64 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* %9
%37 = load i32, i32* %8
%38 = call i32 @clCreateCommandQueue(i32 %36, i32 %37, i32 0, i64* %6)
store i32 %38, i32* %10
%39 = load i64, i64* %6
%40 = load i64, i64* @CL_SUCCESS
%41 = icmp eq i64 %39, %40
%42 = zext i1 %41 to i32
%43 = load i64, i64* %6
%44 = call i32 @assert(i32 %42, i64 %43, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32, i32* %8
%46 = load i32, i32* %9
%47 = load i32, i32* %10
%48 = call i32 @execute(i32 %45, i32 %46, i32 %47)
%49 = load i32, i32* %10
%50 = call i64 @clReleaseCommandQueue(i32 %49)
store i64 %50, i64* %6
%51 = load i64, i64* %6
%52 = load i64, i64* @CL_SUCCESS
%53 = icmp eq i64 %51, %52
%54 = zext i1 %53 to i32
%55 = load i64, i64* %6
%56 = call i32 @assert(i32 %54, i64 %55, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%57 = load i32, i32* %9
%58 = call i64 @clReleaseContext(i32 %57)
store i64 %58, i64* %6
%59 = load i64, i64* %6
%60 = load i64, i64* @CL_SUCCESS
%61 = icmp eq i64 %59, %60
%62 = zext i1 %61 to i32
%63 = load i64, i64* %6
%64 = call i32 @assert(i32 %62, i64 %63, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%65 = load i32, i32* @EXIT_SUCCESS
%66 = call i32 @exit(i32 %65)
unreachable
}

LLVM IR (-O2):
@CL_SUCCESS = global i64 0
@.str = [19 x i8] c"clGetPlatformIDs()\00"
@CL_DEVICE_TYPE_GPU = global i32 0
@.str.1 = [17 x i8] c"clGetDeviceIDs()\00"
@.str.2 = [18 x i8] c"clCreateContext()\00"
@.str.3 = [23 x i8] c"clCreateCommandQueue()\00"
@.str.4 = [24 x i8] c"clReleaseCommandQueue()\00"
@.str.5 = [19 x i8] c"clReleaseContext()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i64* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 @time(i32* null)
%10 = tail call i32 @srand(i32 %9)
%11 = call i64 @clGetPlatformIDs(i32 1, i32* %4, i32* null)
%12 = load i64, i64* @CL_SUCCESS
%13 = icmp eq i64 %11, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14, i64 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = load i32, i32* @CL_DEVICE_TYPE_GPU
%18 = call i64 @clGetDeviceIDs(i32 %16, i32 %17, i32 1, i32* %5, i32* null)
store i64 %18, i64* %3
%19 = load i64, i64* @CL_SUCCESS
%20 = icmp eq i64 %18, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21, i64 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @clCreateContext(i32 0, i32 1, i32* %5, i32* null, i32* null, i64* %3)
%24 = load i64, i64* %3
%25 = load i64, i64* @CL_SUCCESS
%26 = icmp eq i64 %24, %25
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27, i64 %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* %5
%30 = call i32 @clCreateCommandQueue(i32 %23, i32 %29, i32 0, i64* %3)
%31 = load i64, i64* %3
%32 = load i64, i64* @CL_SUCCESS
%33 = icmp eq i64 %31, %32
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34, i64 %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* %5
%37 = call i32 @execute(i32 %36, i32 %23, i32 %30)
%38 = call i64 @clReleaseCommandQueue(i32 %30)
store i64 %38, i64* %3
%39 = load i64, i64* @CL_SUCCESS
%40 = icmp eq i64 %38, %39
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41, i64 %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%43 = call i64 @clReleaseContext(i32 %23)
store i64 %43, i64* %3
%44 = load i64, i64* @CL_SUCCESS
%45 = icmp eq i64 %43, %44
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46, i64 %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
}