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

/* Variables and functions */
int /*<<< orphan*/ CL_PROGRAM_BUILD_LOG;
scalar_t__ CL_SUCCESS;
scalar_t__ clBuildProgram(int /*<<< orphan*/, int, int /*<<< orphan*/ *,
                          char const *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ clCreateProgramWithSource(int /*<<< orphan*/, int,
                                             char const **, size_t const *,
                                             scalar_t__ *);
int /*<<< orphan*/ clGetProgramBuildInfo(int /*<<< orphan*/, int /*<<< orphan*/,
                                         int /*<<< orphan*/, size_t, char *,
                                         size_t *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ oclCheckStatus(scalar_t__, char *);
char *oclGetProgramSrcFromFile(char const *, size_t *);
int /*<<< orphan*/ stderr;
cl_program oclCreateProgramFromSource(cl_context context, cl_device_id device,
                                      const char *filename,
                                      const char *options) {
  size_t sourceSize;
  char *source = oclGetProgramSrcFromFile(filename, &sourceSize);
  cl_int status;
  cl_program program = clCreateProgramWithSource(
      context, 1, (const char **)&source, (const size_t *)&sourceSize, &status);
  oclCheckStatus(status, "clCreateProgramWithSource failed.");
  status = clBuildProgram(program, 1, &device, options, NULL, NULL);
  if (status != CL_SUCCESS) {
    size_t nb_bytes;
    clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL,
                          &nb_bytes);
    char *p = malloc(nb_bytes + 1);
    clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, nb_bytes + 1,
                          p, &nb_bytes);
    fprintf(stderr, "Program '%s' build error\nCompilation Log:\n%s\n",
            filename, p);
    free(p);
    oclCheckStatus(status, "clBuildProgram failed.");
  }
  return program;
}


x86 assembly (clang, -O0):
<oclCreateProgramFromSource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <oclGetProgramSrcFromFile@plt>
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
lea    -0x28(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1050 <clCreateProgramWithSource@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   10a0 <oclCheckStatus@plt>
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
lea    -0x8(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1030 <clBuildProgram@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%rax
je     1293 <oclCreateProgramFromSource+0x113>
mov    -0x34(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x40(%rbp),%r9
mov    %r8,%rcx
call   1070 <clGetProgramBuildInfo@plt>
mov    -0x40(%rbp),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
mov    -0x40(%rbp),%rcx
add    $0x1,%rcx
mov    -0x48(%rbp),%r8
lea    -0x40(%rbp),%r9
call   1070 <clGetProgramBuildInfo@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xdad(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   10a0 <oclCheckStatus@plt>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oclCreateProgramFromSource>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %edi,%ebp
mov    %esi,0x4(%rsp)
lea    0x20(%rsp),%rbx
mov    %rdx,%rdi
mov    %rbx,%rsi
call   1090 <oclGetProgramSrcFromFile@plt>
mov    %rax,0x18(%rsp)
lea    0x18(%rsp),%rdx
lea    0x8(%rsp),%r8
mov    %ebp,%edi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1050 <clCreateProgramWithSource@plt>
mov    %eax,%r12d
mov    0x8(%rsp),%rdi
lea    0xe29(%rip),%rsi
call   10a0 <oclCheckStatus@plt>
lea    0x4(%rsp),%rdx
mov    %r12d,%edi
mov    $0x1,%esi
mov    %r15,%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
mov    %rax,0x8(%rsp)
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%rax
je     1291 <oclCreateProgramFromSource+0x111>
mov    0x4(%rsp),%esi
mov    0x2dd1(%rip),%r13
mov    0x0(%r13),%edx
lea    0x10(%rsp),%r15
mov    %r12d,%edi
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r15,%r9
call   1070 <clGetProgramBuildInfo@plt>
mov    0x10(%rsp),%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    0x4(%rsp),%esi
mov    0x0(%r13),%edx
mov    %r12d,%edi
mov    %rbx,%rcx
mov    %rax,%r8
mov    %r15,%r9
call   1070 <clGetProgramBuildInfo@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
call   1060 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
lea    0xdc4(%rip),%rsi
call   10a0 <oclCheckStatus@plt>
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"clCreateProgramWithSource failed.\00"
@CL_SUCCESS = global i64 0
@CL_PROGRAM_BUILD_LOG = global i32 0
@stderr = global i32 0
@.str.1 = [46 x i8] c"Program '%s' build error\0ACompilation Log:\0A%s\0A\00"
@.str.2 = [23 x i8] c"clBuildProgram failed.\00"
define i32 @oclCreateProgramFromSource(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
%14 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%15 = load i8*, i8** %7
%16 = call i8* @oclGetProgramSrcFromFile(i8* %15, i64* %9)
store i8* %16, i8** %10
%17 = load i32, i32* %5
%18 = call i32 @clCreateProgramWithSource(i32 %17, i32 1, i8** %10, i64* %9, i64* %11)
store i32 %18, i32* %12
%19 = load i64, i64* %11
%20 = call i32 @oclCheckStatus(i64 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %12
%22 = load i8*, i8** %8
%23 = call i64 @clBuildProgram(i32 %21, i32 1, i32* %6, i8* %22, i32* null, i32* null)
store i64 %23, i64* %11
%24 = load i64, i64* %11
%25 = load i64, i64* @CL_SUCCESS
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %50
27: ; preds = %4
%28 = load i32, i32* %12
%29 = load i32, i32* %6
%30 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%31 = call i32 @clGetProgramBuildInfo(i32 %28, i32 %29, i32 %30, i64 0, i8* null, i64* %13)
%32 = load i64, i64* %13
%33 = add i64 %32, 1
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %14
%35 = load i32, i32* %12
%36 = load i32, i32* %6
%37 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%38 = load i64, i64* %13
%39 = add i64 %38, 1
%40 = load i8*, i8** %14
%41 = call i32 @clGetProgramBuildInfo(i32 %35, i32 %36, i32 %37, i64 %39, i8* %40, i64* %13)
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %7
%44 = load i8*, i8** %14
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %43, i8* %44)
%46 = load i8*, i8** %14
%47 = call i32 @free(i8* %46)
%48 = load i64, i64* %11
%49 = call i32 @oclCheckStatus(i64 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %27, %4
%51 = load i32, i32* %12
ret i32 %51
}

LLVM IR (-O2):
@.str = [34 x i8] c"clCreateProgramWithSource failed.\00"
@CL_SUCCESS = global i64 0
@CL_PROGRAM_BUILD_LOG = global i32 0
@stderr = global i32 0
@.str.1 = [46 x i8] c"Program '%s' build error\0ACompilation Log:\0A%s\0A\00"
@.str.2 = [23 x i8] c"clBuildProgram failed.\00"
define i32 @oclCreateProgramFromSource(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i32 %1, i32* %5
%10 = bitcast i64* %6 to i8*
%11 = bitcast i8** %7 to i8*
%12 = call i8* @oclGetProgramSrcFromFile(i8* %2, i64* %6)
store i8* %12, i8** %7
%13 = bitcast i64* %8 to i8*
%14 = call i32 @clCreateProgramWithSource(i32 %0, i32 1, i8** %7, i64* %6, i64* %8)
%15 = load i64, i64* %8
%16 = call i32 @oclCheckStatus(i64 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%17 = call i64 @clBuildProgram(i32 %14, i32 1, i32* %5, i8* %3, i32* null, i32* null)
store i64 %17, i64* %8
%18 = load i64, i64* @CL_SUCCESS
%19 = icmp eq i64 %17, %18
br i1 %19, label %36, label %20
20: ; preds = %4
%21 = bitcast i64* %9 to i8*
%22 = load i32, i32* %5
%23 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%24 = call i32 @clGetProgramBuildInfo(i32 %14, i32 %22, i32 %23, i64 0, i8* null, i64* %9)
%25 = load i64, i64* %9
%26 = add i64 %25, 1
%27 = call i8* @malloc(i64 %26)
%28 = load i32, i32* %5
%29 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%30 = call i32 @clGetProgramBuildInfo(i32 %14, i32 %28, i32 %29, i64 %26, i8* %27, i64* %9)
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %27)
%33 = call i32 @free(i8* %27)
%34 = load i64, i64* %8
%35 = call i32 @oclCheckStatus(i64 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %20, %4
ret i32 %14
}