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

/* Variables and functions */
int /*<<< orphan*/ CL_PROGRAM_BUILD_LOG;
int /*<<< orphan*/ CL_SUCCESS;
int /*<<< orphan*/ clBuildProgram(int /*<<< orphan*/ *, int,
                                  int /*<<< orphan*/ *, char *,
                                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *clCreateProgramWithSource(int /*<<< orphan*/, int,
                                              char const **, size_t *,
                                              int /*<<< orphan*/ *);
int /*<<< orphan*/ clGetProgramBuildInfo(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/, int /*<<< orphan*/,
                                         int, char *, size_t *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
cl_program load_program(cl_context ctx, cl_device_id gpu, cl_int *errcode_ret) {
  extern char _binary____tests_opencl_test_kernel_cl_start;
  extern char _binary____tests_opencl_test_kernel_cl_size;
  const char *strings[] = {&_binary____tests_opencl_test_kernel_cl_start};
  size_t lengths[] = {(size_t)&_binary____tests_opencl_test_kernel_cl_size};
  cl_program pgm = clCreateProgramWithSource(
      ctx, (sizeof(strings) / sizeof(*strings)), strings, lengths, errcode_ret);
  if (*errcode_ret != CL_SUCCESS)
    return NULL;
  *errcode_ret = clBuildProgram(pgm, 1, &gpu, "-Werror", NULL, NULL);
  if (*errcode_ret != CL_SUCCESS) {
    size_t logsize;
    *errcode_ret = clGetProgramBuildInfo(pgm, gpu, CL_PROGRAM_BUILD_LOG, 0,
                                         NULL, &logsize);
    if (*errcode_ret != CL_SUCCESS)
      return NULL;
    char buildlog[logsize + 1];
    *errcode_ret = clGetProgramBuildInfo(pgm, gpu, CL_PROGRAM_BUILD_LOG,
                                         sizeof(buildlog), buildlog, &logsize);
    if (*errcode_ret != CL_SUCCESS)
      return NULL;
    fprintf(stderr, "\n\n--Build Log:\n%s\n", buildlog);
  }
  return pgm;
}


x86 assembly (clang, -O0):
<load_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2c9f(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c9c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x1,%esi
call   1040 <clCreateProgramWithSource@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
je     11a7 <load_program+0x67>
movq   $0x0,-0x8(%rbp)
jmp    12ef <load_program+0x1af>
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
lea    -0x10(%rbp),%rdx
lea    0xe45(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1030 <clBuildProgram@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%eax
je     12e7 <load_program+0x1a7>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x38(%rbp),%r9
call   1060 <clGetProgramBuildInfo@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%eax
je     122f <load_program+0xef>
movq   $0x0,-0x8(%rbp)
jmp    12ef <load_program+0x1af>
mov    -0x38(%rbp),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rsp,%rdx
mov    %rdx,-0x40(%rbp)
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r8
sub    %rcx,%r8
mov    %r8,-0x58(%rbp)
mov    %r8,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    0x2d80(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%ecx
lea    -0x38(%rbp),%r9
call   1060 <clGetProgramBuildInfo@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2d46(%rip),%rcx
cmp    (%rcx),%eax
je     12a6 <load_program+0x166>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    12c6 <load_program+0x186>
mov    -0x58(%rbp),%rdx
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4c(%rbp),%eax
test   %eax,%eax
je     12e2 <load_program+0x1a2>
jmp    12dd <load_program+0x19d>
jmp    12ef <load_program+0x1af>
jmp    12e7 <load_program+0x1a7>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_program>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %esi,-0x2c(%rbp)
mov    0x2e7a(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2e4f(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x50(%rbp),%rdx
lea    -0x48(%rbp),%rcx
mov    $0x1,%esi
mov    %rbx,%r8
call   1040 <clCreateProgramWithSource@plt>
mov    %rax,%r14
mov    (%rbx),%eax
mov    0x2e3a(%rip),%r12
cmp    (%r12),%eax
jne    1247 <load_program+0x107>
lea    0xe61(%rip),%rcx
lea    -0x2c(%rbp),%rdx
mov    %r14,%rdi
mov    $0x1,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
mov    %eax,(%rbx)
cmp    (%r12),%eax
je     124a <load_program+0x10a>
mov    -0x2c(%rbp),%esi
mov    0x2e1c(%rip),%r13
mov    0x0(%r13),%edx
lea    -0x38(%rbp),%r9
mov    %r14,%rdi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <clGetProgramBuildInfo@plt>
mov    %eax,(%rbx)
cmp    (%r12),%eax
jne    1247 <load_program+0x107>
mov    %rsp,-0x40(%rbp)
mov    -0x38(%rbp),%rax
lea    0x1(%rax),%ecx
mov    %rsp,%r15
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%esi
mov    0x0(%r13),%edx
lea    -0x38(%rbp),%r9
mov    %r14,%rdi
mov    %r15,%r8
call   1060 <clGetProgramBuildInfo@plt>
mov    %eax,(%rbx)
mov    -0x40(%rbp),%rbx
cmp    (%r12),%eax
jne    1244 <load_program+0x104>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rsp
jmp    124a <load_program+0x10a>
mov    %rbx,%rsp
xor    %r14d,%r14d
mov    %r14,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_binary____tests_opencl_test_kernel_cl_start = external global i8
@__const.load_program.strings = [1 x i8*] [i8* @_binary____tests_opencl_test_kernel_cl_start]
@_binary____tests_opencl_test_kernel_cl_size = external global i8
@__const.load_program.lengths = [1 x i64] [i64 ptrtoint (i8* @_binary____tests_opencl_test_kernel_cl_size to i64)]
@CL_SUCCESS = global i32 0
@.str = [8 x i8] c"-Werror\00"
@CL_PROGRAM_BUILD_LOG = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"\0A\0A--Build Log:\0A%s\0A\00"
define i32* @load_program(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [1 x i8*]
%9 = alloca [1 x i64]
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%15 = bitcast [1 x i8*]* %8 to i8*
%16 = bitcast [1 x i64]* %9 to i8*
%17 = load i32, i32* %5
%18 = getelementptr inbounds [1 x i8*], [1 x i8*]* %8, i64 0, i64 0
%19 = getelementptr inbounds [1 x i64], [1 x i64]* %9, i64 0, i64 0
%20 = load i32*, i32** %7
%21 = call i32* @clCreateProgramWithSource(i32 %17, i32 1, i8** %18, i64* %19, i32* %20)
store i32* %21, i32** %10
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = load i32, i32* @CL_SUCCESS
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %3
store i32* null, i32** %4
br label %71
27: ; preds = %3
%28 = load i32*, i32** %10
%29 = call i32 @clBuildProgram(i32* %28, i32 1, i32* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* null, i32* null)
%30 = load i32*, i32** %7
store i32 %29, i32* %30
%31 = load i32*, i32** %7
%32 = load i32, i32* %31
%33 = load i32, i32* @CL_SUCCESS
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %69
35: ; preds = %27
%36 = load i32*, i32** %10
%37 = load i32, i32* %6
%38 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%39 = call i32 @clGetProgramBuildInfo(i32* %36, i32 %37, i32 %38, i32 0, i8* null, i64* %11)
%40 = load i32*, i32** %7
store i32 %39, i32* %40
%41 = load i32*, i32** %7
%42 = load i32, i32* %41
%43 = load i32, i32* @CL_SUCCESS
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %35
store i32* null, i32** %4
br label %71
46: ; preds = %35
%47 = load i64, i64* %11
%48 = add i64 %47, 1
%49 = call i8* @llvm.stacksave()
store i8* %49, i8** %12
%50 = alloca i8, i64 %48
store i64 %48, i64* %13
%51 = load i32*, i32** %10
%52 = load i32, i32* %6
%53 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%54 = trunc i64 %48 to i32
%55 = call i32 @clGetProgramBuildInfo(i32* %51, i32 %52, i32 %53, i32 %54, i8* %50, i64* %11)
%56 = load i32*, i32** %7
store i32 %55, i32* %56
%57 = load i32*, i32** %7
%58 = load i32, i32* %57
%59 = load i32, i32* @CL_SUCCESS
%60 = icmp ne i32 %58, %59
br i1 %60, label %61, label %62
61: ; preds = %46
store i32* null, i32** %4
store i32 1, i32* %14
br label %65
62: ; preds = %46
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %50)
store i32 0, i32* %14
br label %65
65: ; preds = %62, %61
%66 = load i8*, i8** %12
%67 = load i32, i32* %14
switch i32 %67, label %73 [
i32 0, label %68
i32 1, label %71
]
68: ; preds = %65
br label %69
69: ; preds = %68, %27
%70 = load i32*, i32** %10
store i32* %70, i32** %4
br label %71
71: ; preds = %69, %65, %45, %26
%72 = load i32*, i32** %4
ret i32* %72
73: ; preds = %65
unreachable
}

LLVM IR (-O2):
@_binary____tests_opencl_test_kernel_cl_start = external global i8
@_binary____tests_opencl_test_kernel_cl_size = external global i8
@CL_SUCCESS = global i32 0
@.str = [8 x i8] c"-Werror\00"
@CL_PROGRAM_BUILD_LOG = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"\0A\0A--Build Log:\0A%s\0A\00"
define i32* @load_program(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca [1 x i8*]
%6 = alloca [1 x i64]
%7 = alloca i64
store i32 %1, i32* %4
%8 = bitcast [1 x i8*]* %5 to i8*
%9 = bitcast [1 x i8*]* %5 to i64*
store i64 ptrtoint (i8* @_binary____tests_opencl_test_kernel_cl_start to i64), i64* %9
%10 = bitcast [1 x i64]* %6 to i8*
%11 = getelementptr inbounds [1 x i64], [1 x i64]* %6, i64 0, i64 0
store i64 ptrtoint (i8* @_binary____tests_opencl_test_kernel_cl_size to i64), i64* %11
%12 = getelementptr inbounds [1 x i8*], [1 x i8*]* %5, i64 0, i64 0
%13 = call i32* @clCreateProgramWithSource(i32 %0, i32 1, i8** %12, i64* %11, i32* %2)
%14 = load i32, i32* %2
%15 = load i32, i32* @CL_SUCCESS
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %44
17: ; preds = %3
%18 = call i32 @clBuildProgram(i32* %13, i32 1, i32* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* null, i32* null)
store i32 %18, i32* %2
%19 = load i32, i32* @CL_SUCCESS
%20 = icmp eq i32 %18, %19
br i1 %20, label %44, label %21
21: ; preds = %17
%22 = bitcast i64* %7 to i8*
%23 = load i32, i32* %4
%24 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%25 = call i32 @clGetProgramBuildInfo(i32* %13, i32 %23, i32 %24, i32 0, i8* null, i64* %7)
store i32 %25, i32* %2
%26 = load i32, i32* @CL_SUCCESS
%27 = icmp eq i32 %25, %26
br i1 %27, label %29, label %28
28: ; preds = %21
br label %44
29: ; preds = %21
%30 = load i64, i64* %7
%31 = add i64 %30, 1
%32 = call i8* @llvm.stacksave()
%33 = alloca i8, i64 %31
%34 = load i32, i32* %4
%35 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%36 = trunc i64 %31 to i32
%37 = call i32 @clGetProgramBuildInfo(i32* %13, i32 %34, i32 %35, i32 %36, i8* %33, i64* %7)
store i32 %37, i32* %2
%38 = load i32, i32* @CL_SUCCESS
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %33)
br label %44
43: ; preds = %29
br label %44
44: ; preds = %17, %40, %43, %28, %3
%45 = phi i32* [ null, %43 ], [ null, %3 ], [ null, %28 ], [ %13, %40 ], [ %13, %17 ]
ret i32* %45
}