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

/* Variables and functions */
int /*<<< orphan*/ CL_CONTEXT_PLATFORM;
int /*<<< orphan*/ clCreateContext(int /*<<< orphan*/ *, int,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ oclCheckStatus(int /*<<< orphan*/, char *);
cl_context oclCreateContext(cl_platform_id platform, cl_device_id device) {
  cl_context context;
  cl_int status;
  cl_context_properties context_prop[3] = {CL_CONTEXT_PLATFORM,
                                           (cl_context_properties)platform, 0};
  context = clCreateContext(context_prop, 1, &device, NULL, NULL, &status);
  oclCheckStatus(status, "clCreateContext failed.");
  return context;
}


x86 assembly (clang, -O0):
<oclCreateContext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x1c(%rbp),%rdi
mov    $0x1,%esi
lea    -0x8(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x10(%rbp),%r9
mov    %r8,%rcx
call   1030 <clCreateContext@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe8e(%rip),%rsi
call   1040 <oclCheckStatus@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oclCreateContext>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,0x10(%rsp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %edi,0x18(%rsp)
movl   $0x0,0x1c(%rsp)
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%r9
mov    $0x1,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <clCreateContext@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
lea    0xe93(%rip),%rsi
call   1040 <oclCheckStatus@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@CL_CONTEXT_PLATFORM = global i32 0
@.str = [24 x i8] c"clCreateContext failed.\00"
define i32 @oclCreateContext(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [3 x i32]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%9 = load i32, i32* @CL_CONTEXT_PLATFORM
store i32 %9, i32* %8
%10 = getelementptr inbounds i32, i32* %8, i64 1
%11 = load i32, i32* %3
store i32 %11, i32* %10
%12 = getelementptr inbounds i32, i32* %10, i64 1
store i32 0, i32* %12
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%14 = call i32 @clCreateContext(i32* %13, i32 1, i32* %4, i32* null, i32* null, i32* %6)
store i32 %14, i32* %5
%15 = load i32, i32* %6
%16 = call i32 @oclCheckStatus(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %5
ret i32 %17
}

LLVM IR (-O2):
@CL_CONTEXT_PLATFORM = global i32 0
@.str = [24 x i8] c"clCreateContext failed.\00"
define i32 @oclCreateContext(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [3 x i32]
store i32 %1, i32* %3
%6 = bitcast i32* %4 to i8*
%7 = bitcast [3 x i32]* %5 to i8*
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%9 = load i32, i32* @CL_CONTEXT_PLATFORM
store i32 %9, i32* %8
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
store i32 %0, i32* %10
%11 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
store i32 0, i32* %11
%12 = call i32 @clCreateContext(i32* %8, i32 1, i32* %3, i32* null, i32* null, i32* %4)
%13 = load i32, i32* %4
%14 = call i32 @oclCheckStatus(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
ret i32 %12
}