#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*/ region_device;
typedef int /*<<< orphan*/ image_device;
typedef int /*<<< orphan*/ data_device;
typedef int /*<<< orphan*/ cl_uchar;
typedef int /*<<< orphan*/ cl_platform_id;
typedef int /*<<< orphan*/ cl_mem;
typedef int /*<<< orphan*/ cl_kernel;
typedef int /*<<< orphan*/ 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;
int /*<<< orphan*/ CL_FALSE;
int /*<<< orphan*/ CL_MEM_READ_ONLY;
int /*<<< orphan*/ CL_TRUE;
int /*<<< orphan*/ buildKernel(char *, char *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ clCreateBuffer(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clCreateCommandQueue(int /*<<< orphan*/, int /*<<< orphan*/,
                                        int /*<<< orphan*/,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ clCreateContext(int /*<<< orphan*/ *, int,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clEnqueueNDRangeKernel(
    int /*<<< orphan*/, int /*<<< orphan*/, int, int /*<<< orphan*/ *, size_t *,
    size_t *, int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clEnqueueReadBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                                       int /*<<< orphan*/, int /*<<< orphan*/,
                                       int, unsigned char *, int /*<<< orphan*/,
                                       int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ clEnqueueWriteBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                                        int /*<<< orphan*/, int /*<<< orphan*/,
                                        int, unsigned char *,
                                        int /*<<< orphan*/,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ clError(char *, int /*<<< orphan*/);
int /*<<< orphan*/ clFinish(int /*<<< orphan*/);
int /*<<< orphan*/ clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clGetPlatformIDs(int, int /*<<< orphan*/ *,
                                    int /*<<< orphan*/ *);
int /*<<< orphan*/ clReleaseCommandQueue(int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseContext(int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseKernel(int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseMemObject(int /*<<< orphan*/);
int /*<<< orphan*/ clSetKernelArg(int /*<<< orphan*/, int, int, void *);
int /*<<< orphan*/ free(size_t *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printDeviceInfo(int /*<<< orphan*/);
int /*<<< orphan*/ printPlatformInfo(int /*<<< orphan*/);
unsigned char *raycast_gpu(unsigned char *data, unsigned char *region) {
  cl_platform_id platform;
  cl_device_id device;
  cl_context context;
  cl_command_queue queue;
  cl_kernel kernel;
  cl_int err;
  char *source;
  int i;
  unsigned char *image =
      (unsigned char *)malloc(sizeof(unsigned char) * 64 * 64);
  clGetPlatformIDs(1, &platform, NULL);
  clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
  context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
  printPlatformInfo(platform);
  printDeviceInfo(device);
  queue = clCreateCommandQueue(context, device, 0, &err);
  kernel = buildKernel("raycast.cl", "raycast", NULL, context, device);
  cl_mem data_device =
      clCreateBuffer(context, CL_MEM_READ_ONLY,
                     512 * 512 * 512 * sizeof(cl_uchar), NULL, &err);
  cl_mem region_device =
      clCreateBuffer(context, CL_MEM_READ_ONLY,
                     512 * 512 * 512 * sizeof(cl_uchar), NULL, &err);
  cl_mem image_device = clCreateBuffer(context, CL_MEM_READ_ONLY,
                                       64 * 64 * sizeof(cl_uchar), NULL, &err);
  clError("Error allocating memory", err);
  clEnqueueWriteBuffer(queue, data_device, CL_FALSE, 0,
                       512 * 512 * 512 * sizeof(cl_uchar), data, 0, NULL, NULL);
  clEnqueueWriteBuffer(queue, region_device, CL_FALSE, 0,
                       512 * 512 * 512 * sizeof(cl_uchar), region, 0, NULL,
                       NULL);
  err = clSetKernelArg(kernel, 0, sizeof(data_device), (void *)&data_device);
  err =
      clSetKernelArg(kernel, 1, sizeof(region_device), (void *)&region_device);
  err = clSetKernelArg(kernel, 2, sizeof(image_device), (void *)&image_device);
  clError("Error setting arguments", err);
  size_t *global = (size_t *)malloc(sizeof(size_t) * 2);
  size_t *local = (size_t *)malloc(sizeof(size_t) * 2);
  global[0] = 64;
  global[1] = 64;
  local[0] = 4;
  local[1] = 4;
  clEnqueueNDRangeKernel(queue, kernel, 2, NULL, global, local, 0, NULL, NULL);
  free(global);
  free(local);
  clFinish(queue);
  err = clEnqueueReadBuffer(queue, image_device, CL_TRUE, 0,
                            64 * 64 * sizeof(cl_uchar), image, 0, NULL, NULL);
  clFinish(queue);
  clReleaseMemObject(data_device);
  clReleaseMemObject(region_device);
  clReleaseKernel(kernel);
  clReleaseCommandQueue(queue);
  clReleaseContext(context);
  return image;
}


x86 assembly (clang, -O0):
<raycast_gpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1000,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <clGetPlatformIDs@plt>
mov    -0x14(%rbp),%edi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
lea    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <clGetDeviceIDs@plt>
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x1,%esi
lea    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%r9
mov    %r8,%rdi
mov    %r8,%rcx
call   10c0 <clCreateContext@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1130 <printPlatformInfo@plt>
mov    -0x18(%rbp),%edi
call   10d0 <printDeviceInfo@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
lea    -0x28(%rbp),%rcx
call   10a0 <clCreateCommandQueue@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xd1c(%rip),%rdi
lea    0xd20(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1140 <buildKernel@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2cc7(%rip),%rax
mov    (%rax),%esi
mov    $0x20000000,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,-0x44(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2ca6(%rip),%rax
mov    (%rax),%esi
mov    $0x20000000,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,-0x48(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2c85(%rip),%rax
mov    (%rax),%esi
mov    $0x4000,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%esi
lea    0xcaf(%rip),%rdi
call   1040 <clError@plt>
mov    -0x20(%rbp),%edi
mov    -0x44(%rbp),%esi
mov    0x2c72(%rip),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%r9
xor    %ecx,%ecx
mov    $0x20000000,%r8d
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1160 <clEnqueueWriteBuffer@plt>
mov    -0x20(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2c37(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%r9
xor    %ecx,%ecx
mov    $0x20000000,%r8d
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1160 <clEnqueueWriteBuffer@plt>
mov    -0x24(%rbp),%edi
lea    -0x44(%rbp),%rcx
xor    %esi,%esi
mov    $0x4,%edx
call   1150 <clSetKernelArg@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x48(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1150 <clSetKernelArg@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x4c(%rbp),%rcx
mov    $0x2,%esi
mov    $0x4,%edx
call   1150 <clSetKernelArg@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xbfa(%rip),%rdi
call   1040 <clError@plt>
mov    $0x10,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    $0x10,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rax
movq   $0x40,(%rax)
mov    -0x58(%rbp),%rax
movq   $0x40,0x8(%rax)
mov    -0x60(%rbp),%rax
movq   $0x4,(%rax)
mov    -0x60(%rbp),%rax
movq   $0x4,0x8(%rax)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x58(%rbp),%r8
mov    -0x60(%rbp),%r9
mov    $0x2,%edx
xor    %eax,%eax
mov    %eax,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1090 <clEnqueueNDRangeKernel@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%edi
call   1050 <clFinish@plt>
mov    -0x20(%rbp),%edi
mov    -0x4c(%rbp),%esi
mov    0x2b02(%rip),%rax
mov    (%rax),%edx
mov    -0x40(%rbp),%r9
xor    %ecx,%ecx
mov    $0x4000,%r8d
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1100 <clEnqueueReadBuffer@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <clFinish@plt>
mov    -0x44(%rbp),%edi
call   1120 <clReleaseMemObject@plt>
mov    -0x48(%rbp),%edi
call   1120 <clReleaseMemObject@plt>
mov    -0x24(%rbp),%edi
call   1060 <clReleaseKernel@plt>
mov    -0x20(%rbp),%edi
call   10e0 <clReleaseCommandQueue@plt>
mov    -0x1c(%rbp),%edi
call   1110 <clReleaseContext@plt>
mov    -0x40(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raycast_gpu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,0x48(%rsp)
mov    %rdi,0x40(%rsp)
mov    $0x1000,%edi
call   10f0 <malloc@plt>
mov    %rax,0x50(%rsp)
lea    0x34(%rsp),%rsi
mov    $0x1,%edi
xor    %edx,%edx
call   10b0 <clGetPlatformIDs@plt>
mov    0x34(%rsp),%edi
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
lea    0x24(%rsp),%rbx
mov    $0x1,%edx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1080 <clGetDeviceIDs@plt>
lea    0x20(%rsp),%r14
xor    %edi,%edi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   10c0 <clCreateContext@plt>
mov    %eax,%ebp
mov    0x34(%rsp),%edi
call   1130 <printPlatformInfo@plt>
mov    0x24(%rsp),%edi
call   10d0 <printDeviceInfo@plt>
mov    0x24(%rsp),%esi
mov    %ebp,%edi
xor    %edx,%edx
mov    %r14,%rcx
call   10a0 <clCreateCommandQueue@plt>
mov    %eax,%r15d
mov    0x24(%rsp),%r8d
lea    0xd47(%rip),%rdi
lea    0xd4b(%rip),%rsi
xor    %edx,%edx
mov    %ebp,%ecx
call   1140 <buildKernel@plt>
mov    %eax,0x38(%rsp)
mov    0x2cc4(%rip),%rbx
mov    (%rbx),%esi
mov    %ebp,%edi
mov    $0x20000000,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,%r13d
mov    %eax,0x30(%rsp)
mov    (%rbx),%esi
mov    %ebp,%edi
mov    %ebp,0x3c(%rsp)
mov    $0x20000000,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,%r12d
mov    %eax,0x2c(%rsp)
mov    (%rbx),%esi
mov    %ebp,%edi
mov    $0x4000,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,0x28(%rsp)
mov    0x20(%rsp),%esi
lea    0xce5(%rip),%rdi
call   1040 <clError@plt>
mov    0x2c7e(%rip),%rbx
mov    (%rbx),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r15d,%edi
mov    %r13d,%esi
xor    %ecx,%ecx
mov    $0x20000000,%r8d
mov    0x40(%rsp),%r9
call   1160 <clEnqueueWriteBuffer@plt>
mov    (%rbx),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r15d,%edi
mov    %r12d,%esi
xor    %ecx,%ecx
mov    $0x20000000,%r8d
mov    0x48(%rsp),%r9
call   1160 <clEnqueueWriteBuffer@plt>
lea    0x30(%rsp),%rcx
mov    0x38(%rsp),%r14d
mov    %r14d,%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1150 <clSetKernelArg@plt>
mov    %eax,0x20(%rsp)
lea    0x2c(%rsp),%rcx
mov    %r14d,%edi
mov    $0x1,%esi
mov    $0x4,%edx
call   1150 <clSetKernelArg@plt>
mov    %eax,0x20(%rsp)
lea    0x28(%rsp),%rcx
mov    %r14d,%edi
mov    $0x2,%esi
mov    $0x4,%edx
call   1150 <clSetKernelArg@plt>
mov    %eax,0x20(%rsp)
lea    0xc45(%rip),%rdi
mov    %eax,%esi
call   1040 <clError@plt>
mov    $0x10,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbp
mov    $0x10,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
movaps 0xbc2(%rip),%xmm0
movups %xmm0,0x0(%rbp)
movaps 0xbc7(%rip),%xmm0
movups %xmm0,(%rax)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r15d,%edi
mov    %r14d,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    %rax,%r9
call   1090 <clEnqueueNDRangeKernel@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1050 <clFinish@plt>
mov    0x28(%rsp),%esi
mov    0x2b4a(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r15d,%edi
xor    %ecx,%ecx
mov    $0x4000,%r8d
mov    0x50(%rsp),%rbx
mov    %rbx,%r9
call   1100 <clEnqueueReadBuffer@plt>
mov    %eax,0x20(%rsp)
mov    %r15d,%edi
call   1050 <clFinish@plt>
mov    0x30(%rsp),%edi
call   1120 <clReleaseMemObject@plt>
mov    0x2c(%rsp),%edi
call   1120 <clReleaseMemObject@plt>
mov    %r14d,%edi
call   1060 <clReleaseKernel@plt>
mov    %r15d,%edi
call   10e0 <clReleaseCommandQueue@plt>
mov    0x3c(%rsp),%edi
call   1110 <clReleaseContext@plt>
mov    %rbx,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CL_DEVICE_TYPE_GPU = global i32 0
@.str = [11 x i8] c"raycast.cl\00"
@.str.1 = [8 x i8] c"raycast\00"
@CL_MEM_READ_ONLY = global i32 0
@.str.2 = [24 x i8] c"Error allocating memory\00"
@CL_FALSE = global i32 0
@.str.3 = [24 x i8] c"Error setting arguments\00"
@CL_TRUE = global i32 0
define i8* @raycast_gpu(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i64*
%18 = alloca i64*
store i8* %0, i8** %3
store i8* %1, i8** %4
%19 = call i64 @malloc(i32 4096)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %13
%21 = call i32 @clGetPlatformIDs(i32 1, i32* %5, i32* null)
%22 = load i32, i32* %5
%23 = load i32, i32* @CL_DEVICE_TYPE_GPU
%24 = call i32 @clGetDeviceIDs(i32 %22, i32 %23, i32 1, i32* %6, i32* null)
%25 = call i32 @clCreateContext(i32* null, i32 1, i32* %6, i32* null, i32* null, i32* %10)
store i32 %25, i32* %7
%26 = load i32, i32* %5
%27 = call i32 @printPlatformInfo(i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @printDeviceInfo(i32 %28)
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = call i32 @clCreateCommandQueue(i32 %30, i32 %31, i32 0, i32* %10)
store i32 %32, i32* %8
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = call i32 @buildKernel(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* null, i32 %33, i32 %34)
store i32 %35, i32* %9
%36 = load i32, i32* %7
%37 = load i32, i32* @CL_MEM_READ_ONLY
%38 = call i32 @clCreateBuffer(i32 %36, i32 %37, i32 536870912, i32* null, i32* %10)
store i32 %38, i32* %14
%39 = load i32, i32* %7
%40 = load i32, i32* @CL_MEM_READ_ONLY
%41 = call i32 @clCreateBuffer(i32 %39, i32 %40, i32 536870912, i32* null, i32* %10)
store i32 %41, i32* %15
%42 = load i32, i32* %7
%43 = load i32, i32* @CL_MEM_READ_ONLY
%44 = call i32 @clCreateBuffer(i32 %42, i32 %43, i32 16384, i32* null, i32* %10)
store i32 %44, i32* %16
%45 = load i32, i32* %10
%46 = call i32 @clError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %8
%48 = load i32, i32* %14
%49 = load i32, i32* @CL_FALSE
%50 = load i8*, i8** %3
%51 = call i32 @clEnqueueWriteBuffer(i32 %47, i32 %48, i32 %49, i32 0, i32 536870912, i8* %50, i32 0, i32* null, i32* null)
%52 = load i32, i32* %8
%53 = load i32, i32* %15
%54 = load i32, i32* @CL_FALSE
%55 = load i8*, i8** %4
%56 = call i32 @clEnqueueWriteBuffer(i32 %52, i32 %53, i32 %54, i32 0, i32 536870912, i8* %55, i32 0, i32* null, i32* null)
%57 = load i32, i32* %9
%58 = bitcast i32* %14 to i8*
%59 = call i32 @clSetKernelArg(i32 %57, i32 0, i32 4, i8* %58)
store i32 %59, i32* %10
%60 = load i32, i32* %9
%61 = bitcast i32* %15 to i8*
%62 = call i32 @clSetKernelArg(i32 %60, i32 1, i32 4, i8* %61)
store i32 %62, i32* %10
%63 = load i32, i32* %9
%64 = bitcast i32* %16 to i8*
%65 = call i32 @clSetKernelArg(i32 %63, i32 2, i32 4, i8* %64)
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = call i32 @clError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %66)
%68 = call i64 @malloc(i32 16)
%69 = inttoptr i64 %68 to i64*
store i64* %69, i64** %17
%70 = call i64 @malloc(i32 16)
%71 = inttoptr i64 %70 to i64*
store i64* %71, i64** %18
%72 = load i64*, i64** %17
%73 = getelementptr inbounds i64, i64* %72, i64 0
store i64 64, i64* %73
%74 = load i64*, i64** %17
%75 = getelementptr inbounds i64, i64* %74, i64 1
store i64 64, i64* %75
%76 = load i64*, i64** %18
%77 = getelementptr inbounds i64, i64* %76, i64 0
store i64 4, i64* %77
%78 = load i64*, i64** %18
%79 = getelementptr inbounds i64, i64* %78, i64 1
store i64 4, i64* %79
%80 = load i32, i32* %8
%81 = load i32, i32* %9
%82 = load i64*, i64** %17
%83 = load i64*, i64** %18
%84 = call i32 @clEnqueueNDRangeKernel(i32 %80, i32 %81, i32 2, i32* null, i64* %82, i64* %83, i32 0, i32* null, i32* null)
%85 = load i64*, i64** %17
%86 = call i32 @free(i64* %85)
%87 = load i64*, i64** %18
%88 = call i32 @free(i64* %87)
%89 = load i32, i32* %8
%90 = call i32 @clFinish(i32 %89)
%91 = load i32, i32* %8
%92 = load i32, i32* %16
%93 = load i32, i32* @CL_TRUE
%94 = load i8*, i8** %13
%95 = call i32 @clEnqueueReadBuffer(i32 %91, i32 %92, i32 %93, i32 0, i32 16384, i8* %94, i32 0, i32* null, i32* null)
store i32 %95, i32* %10
%96 = load i32, i32* %8
%97 = call i32 @clFinish(i32 %96)
%98 = load i32, i32* %14
%99 = call i32 @clReleaseMemObject(i32 %98)
%100 = load i32, i32* %15
%101 = call i32 @clReleaseMemObject(i32 %100)
%102 = load i32, i32* %9
%103 = call i32 @clReleaseKernel(i32 %102)
%104 = load i32, i32* %8
%105 = call i32 @clReleaseCommandQueue(i32 %104)
%106 = load i32, i32* %7
%107 = call i32 @clReleaseContext(i32 %106)
%108 = load i8*, i8** %13
ret i8* %108
}

LLVM IR (-O2):
@CL_DEVICE_TYPE_GPU = global i32 0
@.str = [11 x i8] c"raycast.cl\00"
@.str.1 = [8 x i8] c"raycast\00"
@CL_MEM_READ_ONLY = global i32 0
@.str.2 = [24 x i8] c"Error allocating memory\00"
@CL_FALSE = global i32 0
@.str.3 = [24 x i8] c"Error setting arguments\00"
@CL_TRUE = global i32 0
define i8* @raycast_gpu(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = tail call i64 @malloc(i32 4096)
%13 = inttoptr i64 %12 to i8*
%14 = call i32 @clGetPlatformIDs(i32 1, i32* %3, i32* null)
%15 = load i32, i32* %3
%16 = load i32, i32* @CL_DEVICE_TYPE_GPU
%17 = call i32 @clGetDeviceIDs(i32 %15, i32 %16, i32 1, i32* %4, i32* null)
%18 = call i32 @clCreateContext(i32* null, i32 1, i32* %4, i32* null, i32* null, i32* %5)
%19 = load i32, i32* %3
%20 = call i32 @printPlatformInfo(i32 %19)
%21 = load i32, i32* %4
%22 = call i32 @printDeviceInfo(i32 %21)
%23 = load i32, i32* %4
%24 = call i32 @clCreateCommandQueue(i32 %18, i32 %23, i32 0, i32* %5)
%25 = load i32, i32* %4
%26 = call i32 @buildKernel(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* null, i32 %18, i32 %25)
%27 = bitcast i32* %6 to i8*
%28 = load i32, i32* @CL_MEM_READ_ONLY
%29 = call i32 @clCreateBuffer(i32 %18, i32 %28, i32 536870912, i32* null, i32* %5)
store i32 %29, i32* %6
%30 = bitcast i32* %7 to i8*
%31 = load i32, i32* @CL_MEM_READ_ONLY
%32 = call i32 @clCreateBuffer(i32 %18, i32 %31, i32 536870912, i32* null, i32* %5)
store i32 %32, i32* %7
%33 = bitcast i32* %8 to i8*
%34 = load i32, i32* @CL_MEM_READ_ONLY
%35 = call i32 @clCreateBuffer(i32 %18, i32 %34, i32 16384, i32* null, i32* %5)
store i32 %35, i32* %8
%36 = load i32, i32* %5
%37 = call i32 @clError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* @CL_FALSE
%39 = call i32 @clEnqueueWriteBuffer(i32 %24, i32 %29, i32 %38, i32 0, i32 536870912, i8* %0, i32 0, i32* null, i32* null)
%40 = load i32, i32* @CL_FALSE
%41 = call i32 @clEnqueueWriteBuffer(i32 %24, i32 %32, i32 %40, i32 0, i32 536870912, i8* %1, i32 0, i32* null, i32* null)
%42 = call i32 @clSetKernelArg(i32 %26, i32 0, i32 4, i8* %27)
store i32 %42, i32* %5
%43 = call i32 @clSetKernelArg(i32 %26, i32 1, i32 4, i8* %30)
store i32 %43, i32* %5
%44 = call i32 @clSetKernelArg(i32 %26, i32 2, i32 4, i8* %33)
store i32 %44, i32* %5
%45 = call i32 @clError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = call i64 @malloc(i32 16)
%47 = inttoptr i64 %46 to i64*
%48 = call i64 @malloc(i32 16)
%49 = inttoptr i64 %48 to i64*
%50 = inttoptr i64 %46 to <2 x i64>*
store <2 x i64> <i64 64, i64 64>, <2 x i64>* %50
%51 = inttoptr i64 %48 to <2 x i64>*
store <2 x i64> <i64 4, i64 4>, <2 x i64>* %51
%52 = call i32 @clEnqueueNDRangeKernel(i32 %24, i32 %26, i32 2, i32* null, i64* %47, i64* %49, i32 0, i32* null, i32* null)
%53 = call i32 @free(i64* %47)
%54 = call i32 @free(i64* %49)
%55 = call i32 @clFinish(i32 %24)
%56 = load i32, i32* %8
%57 = load i32, i32* @CL_TRUE
%58 = call i32 @clEnqueueReadBuffer(i32 %24, i32 %56, i32 %57, i32 0, i32 16384, i8* %13, i32 0, i32* null, i32* null)
store i32 %58, i32* %5
%59 = call i32 @clFinish(i32 %24)
%60 = load i32, i32* %6
%61 = call i32 @clReleaseMemObject(i32 %60)
%62 = load i32, i32* %7
%63 = call i32 @clReleaseMemObject(i32 %62)
%64 = call i32 @clReleaseKernel(i32 %26)
%65 = call i32 @clReleaseCommandQueue(i32 %24)
%66 = call i32 @clReleaseContext(i32 %18)
ret i8* %13
}