#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 scalar_t__ *width;
typedef size_t i;
typedef int /*<<< orphan*/ cl_uint;
typedef int /*<<< orphan*/ cl_program;
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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_TYPE_DEFAULT;
int /*<<< orphan*/ CL_MEM_READ_ONLY;
int /*<<< orphan*/ CL_MEM_WRITE_ONLY;
int /*<<< orphan*/ CL_TRUE;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ clBuildProgram(int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ **, 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*/ clCreateKernel(int /*<<< orphan*/, char *,
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ clCreateProgramWithSource(int /*<<< orphan*/, int,
                                             char const **, size_t const *,
                                             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, float *, int /*<<< orphan*/,
                                       int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ clEnqueueWriteBuffer(int /*<<< orphan*/,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/, int /*<<< orphan*/,
                                        int, float *, int /*<<< orphan*/,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ clFinish(int /*<<< orphan*/);
int /*<<< orphan*/ clFlush(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*/ clReleaseProgram(int /*<<< orphan*/);
int /*<<< orphan*/ clSetKernelArg(int /*<<< orphan*/, int, int, void *);
int /*<<< orphan*/ dumpGrid(float *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int /*<<< orphan*/ initGrid(float *, float *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printError(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int arg, char **argv) {
  int width;
  int numCycles;
  int i, j, n;
  float *u0, *u1;
  float inTemp;
  int cycle = 0;
  int numInit;
  int TILE_SIZE = 10;
  FILE *fp;
  FILE *kp;
  char *source_str;
  size_t source_size;
  fp = fopen(argv[1], "r");
  fscanf(fp, "%d", &numCycles);
  fscanf(fp, "%d", &width);
  fscanf(fp, "%d", &numInit);
  printf("# cycles %d width %d # initializations %d\n", numCycles, width,
         numInit);
  u0 = (float *)calloc(width * width, sizeof(float));
  u1 = (float *)calloc(width * width, sizeof(float));
  initGrid(u0, u1, width);
  for (n = 0; n < numInit; n++) {
    fscanf(fp, "%d%d%f", &i, &j, &inTemp);
    u1[(i) * (width) + j] = inTemp;
  }
  kp = fopen("kernel.cl", "r");
  if (!kp) {
    fprintf(stderr, "Failed to load kernel.\n");
    exit(1);
  }
  source_str = (char *)malloc((0x100000));
  source_size = fread(source_str, 1, (0x100000), fp);
  fclose(fp);
  fclose(fp);
  cl_platform_id platform_id = NULL;
  cl_device_id device_id = NULL;
  cl_uint ret_num_devices;
  cl_uint ret_num_platforms;
  cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
  printf("Getting IDs\n");
  ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id,
                       &ret_num_devices);
  printf("Creating Context\n");
  cl_context context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret);
  printf("Creating queue\n");
  cl_command_queue command_queue =
      clCreateCommandQueue(context, device_id, 0, &ret);
  printf("Allocating memory\n");
  int memory_size = width * width * sizeof(float);
  cl_mem device_u0 =
      clCreateBuffer(context, CL_MEM_WRITE_ONLY, memory_size, NULL, &ret);
  cl_mem device_u1 =
      clCreateBuffer(context, CL_MEM_READ_ONLY, memory_size, NULL, &ret);
  initGrid(u0, u1, width);
  printf("Copy from host to device\n");
  ret = clEnqueueWriteBuffer(command_queue, device_u1, CL_TRUE, 0, memory_size,
                             u1, 0, NULL, NULL);
  printf("\nCreating program");
  cl_program program =
      clCreateProgramWithSource(context, 1, (const char **)&source_str,
                                (const size_t *)&source_size, &ret);
  printError(ret);
  printf("\nBuilding program");
  ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
  printError(ret);
  printf("Create kernel\n");
  cl_kernel kernel = clCreateKernel(program, "updateGrid", &ret);
  size_t global_size = (width * width) / (TILE_SIZE * TILE_SIZE);
  size_t local_size = TILE_SIZE * TILE_SIZE;
  cl_mem temp = NULL;
  printf("Start loop.\n");
  for (cycle = 0; cycle < numCycles; cycle++) {
    ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&device_u0);
    ret = clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&device_u1);
    ret = clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&width);
    ret = clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&TILE_SIZE);
    ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_size,
                                 &local_size, 0, NULL, NULL);
    printError(ret);
    temp = device_u0;
    device_u0 = device_u1;
    device_u1 = temp;
  }
  int *C = (int *)malloc(sizeof(int) * TILE_SIZE);
  ret = clEnqueueReadBuffer(command_queue, device_u1, CL_TRUE, 0,
                            width * width * sizeof(int), u1, 0, NULL, NULL);
  dumpGrid(u1, width);
  ret = clFlush(command_queue);
  ret = clFinish(command_queue);
  ret = clReleaseKernel(kernel);
  ret = clReleaseProgram(program);
  ret = clReleaseMemObject(device_u0);
  ret = clReleaseMemObject(device_u1);
  ret = clReleaseCommandQueue(command_queue);
  ret = clReleaseContext(context);
  free(u0);
  free(u1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0xa,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcca(%rip),%rsi
call   11d0 <fopen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
lea    0xcb8(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1120 <fscanf@plt>
mov    -0x50(%rbp),%rdi
lea    0xca2(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1120 <fscanf@plt>
mov    -0x50(%rbp),%rdi
lea    0xc8c(%rip),%rsi
lea    -0x44(%rbp),%rdx
mov    $0x0,%al
call   1120 <fscanf@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x44(%rbp),%ecx
lea    0xc74(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0x14(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    $0x4,%esi
call   1130 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    $0x4,%esi
call   1130 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1170 <initGrid@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    142c <main+0x12c>
mov    -0x50(%rbp),%rdi
lea    0xc40(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x3c(%rbp),%r8
mov    $0x0,%al
call   1120 <fscanf@plt>
movss  -0x3c(%rbp),%xmm0
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    13d9 <main+0xd9>
lea    0xc04(%rip),%rdi
lea    0xbc6(%rip),%rsi
call   11d0 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    146d <main+0x16d>
mov    0x2b7b(%rip),%rax
mov    (%rax),%edi
lea    0xbe3(%rip),%rsi
call   1160 <fprintf@plt>
mov    $0x1,%edi
call   1200 <exit@plt>
mov    $0x100000,%edi
call   1190 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100000,%edx
call   1070 <fread@plt>
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%rdi
call   10d0 <fclose@plt>
mov    -0x50(%rbp),%rdi
call   10d0 <fclose@plt>
movq   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
mov    $0x1,%edi
lea    -0x70(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1100 <clGetPlatformIDs@plt>
mov    %eax,-0x84(%rbp)
lea    0xb82(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0x70(%rbp),%rdi
mov    0x2adf(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
lea    -0x78(%rbp),%rcx
lea    -0x7c(%rbp),%r8
call   10c0 <clGetDeviceIDs@plt>
mov    %eax,-0x84(%rbp)
lea    0xb5c(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x1,%esi
lea    -0x78(%rbp),%rdx
lea    -0x84(%rbp),%r9
mov    %r8,%rdi
mov    %r8,%rcx
call   1150 <clCreateContext@plt>
mov    %eax,-0x88(%rbp)
lea    0xb3a(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0x88(%rbp),%edi
mov    -0x78(%rbp),%rsi
xor    %edx,%edx
lea    -0x84(%rbp),%rcx
call   10f0 <clCreateCommandQueue@plt>
mov    %eax,-0x8c(%rbp)
lea    0xb1e(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,-0x90(%rbp)
mov    -0x88(%rbp),%edi
mov    0x2a4f(%rip),%rax
mov    (%rax),%esi
mov    -0x90(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x84(%rbp),%r8
call   10a0 <clCreateBuffer@plt>
mov    %rax,-0x98(%rbp)
mov    -0x88(%rbp),%edi
mov    0x2a03(%rip),%rax
mov    (%rax),%esi
mov    -0x90(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x84(%rbp),%r8
call   10a0 <clCreateBuffer@plt>
mov    %rax,-0xa0(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1170 <initGrid@plt>
lea    0xaa8(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0x8c(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    0x29da(%rip),%rax
mov    (%rax),%edx
mov    -0x90(%rbp),%r8d
mov    -0x38(%rbp),%r9
xor    %ecx,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1220 <clEnqueueWriteBuffer@plt>
mov    %eax,-0x84(%rbp)
lea    0xa6b(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0x88(%rbp),%edi
mov    $0x1,%esi
lea    -0x60(%rbp),%rdx
lea    -0x68(%rbp),%rcx
lea    -0x84(%rbp),%r8
call   1060 <clCreateProgramWithSource@plt>
mov    %eax,-0xa4(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
lea    0xa3f(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0xa4(%rbp),%edi
mov    $0x1,%esi
lea    -0x78(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rcx
mov    %r9,%r8
call   1030 <clBuildProgram@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
lea    0xa13(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0xa4(%rbp),%edi
lea    0xa0e(%rip),%rsi
lea    -0x84(%rbp),%rdx
call   11f0 <clCreateKernel@plt>
mov    %eax,-0xa8(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    -0x48(%rbp),%ecx
imul   -0x48(%rbp),%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0xb0(%rbp)
mov    -0x48(%rbp),%eax
imul   -0x48(%rbp),%eax
cltq
mov    %rax,-0xb8(%rbp)
movq   $0x0,-0xc0(%rbp)
lea    0x9cb(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    184d <main+0x54d>
mov    -0xa8(%rbp),%edi
lea    -0x98(%rbp),%rcx
xor    %esi,%esi
mov    $0x8,%edx
call   1210 <clSetKernelArg@plt>
mov    %eax,-0x84(%rbp)
mov    -0xa8(%rbp),%edi
lea    -0xa0(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1210 <clSetKernelArg@plt>
mov    %eax,-0x84(%rbp)
mov    -0xa8(%rbp),%edi
lea    -0x14(%rbp),%rcx
mov    $0x2,%esi
mov    $0x8,%edx
call   1210 <clSetKernelArg@plt>
mov    %eax,-0x84(%rbp)
mov    -0xa8(%rbp),%edi
lea    -0x48(%rbp),%rcx
mov    $0x3,%esi
mov    $0x8,%edx
call   1210 <clSetKernelArg@plt>
mov    %eax,-0x84(%rbp)
mov    -0x8c(%rbp),%edi
mov    -0xa8(%rbp),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xb0(%rbp),%r8
lea    -0xb8(%rbp),%r9
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   10e0 <clEnqueueNDRangeKernel@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
mov    -0x98(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0xc0(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1736 <main+0x436>
movslq -0x48(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1190 <malloc@plt>
mov    %rax,-0xc8(%rbp)
mov    -0x8c(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    0x2771(%rip),%rax
mov    (%rax),%edx
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%r8d
mov    -0x38(%rbp),%r9
xor    %ecx,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   11a0 <clEnqueueReadBuffer@plt>
mov    %eax,-0x84(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1140 <dumpGrid@plt>
mov    -0x8c(%rbp),%edi
call   1090 <clFlush@plt>
mov    %eax,-0x84(%rbp)
mov    -0x8c(%rbp),%edi
call   1050 <clFinish@plt>
mov    %eax,-0x84(%rbp)
mov    -0xa8(%rbp),%edi
call   1080 <clReleaseKernel@plt>
mov    %eax,-0x84(%rbp)
mov    -0xa4(%rbp),%edi
call   10b0 <clReleaseProgram@plt>
mov    %eax,-0x84(%rbp)
mov    -0x98(%rbp),%rdi
call   11c0 <clReleaseMemObject@plt>
mov    %eax,-0x84(%rbp)
mov    -0xa0(%rbp),%rdi
call   11c0 <clReleaseMemObject@plt>
mov    %eax,-0x84(%rbp)
mov    -0x8c(%rbp),%edi
call   1180 <clReleaseCommandQueue@plt>
mov    %eax,-0x84(%rbp)
mov    -0x88(%rbp),%edi
call   11b0 <clReleaseContext@plt>
mov    %eax,-0x84(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
movl   $0xa,0x24(%rsp)
mov    0x8(%rsi),%rdi
lea    0xcdc(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,%r15
lea    0xccf(%rip),%rbx
lea    0x2c(%rsp),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1130 <fscanf@plt>
lea    0x20(%rsp),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1130 <fscanf@plt>
lea    0x28(%rsp),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1130 <fscanf@plt>
mov    0x2c(%rsp),%esi
mov    0x20(%rsp),%edx
mov    0x28(%rsp),%ecx
lea    0xc89(%rip),%rdi
xor    %eax,%eax
call   1120 <printf@plt>
mov    0x20(%rsp),%edi
imul   %edi,%edi
mov    $0x4,%esi
call   1140 <calloc@plt>
mov    %rax,%rbx
mov    0x20(%rsp),%edi
imul   %edi,%edi
mov    $0x4,%esi
call   1140 <calloc@plt>
mov    %rax,%r14
mov    0x20(%rsp),%edx
mov    %rbx,0x70(%rsp)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1180 <initGrid@plt>
cmpl   $0x0,0x28(%rsp)
jle    1435 <main+0x125>
lea    0x64(%rsp),%r12
lea    0x60(%rsp),%r13
lea    0x5c(%rsp),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
lea    0xc46(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1130 <fscanf@plt>
movss  0x5c(%rsp),%xmm0
movslq 0x64(%rsp),%rax
movslq 0x20(%rsp),%rcx
imul   %rax,%rcx
movslq 0x60(%rsp),%rax
add    %rcx,%rax
movss  %xmm0,(%r14,%rax,4)
add    $0x1,%ebp
cmp    0x28(%rsp),%ebp
jl     13f0 <main+0xe0>
mov    %r14,0x68(%rsp)
lea    0xc06(%rip),%rdi
lea    0xbc8(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     1890 <main+0x580>
mov    $0x100000,%edi
call   11a0 <malloc@plt>
mov    %rax,0x98(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
mov    %r15,%rcx
call   1080 <fread@plt>
mov    %rax,0x90(%rsp)
mov    %r15,%rdi
call   10e0 <fclose@plt>
mov    %r15,%rdi
call   10e0 <fclose@plt>
movq   $0x0,0x78(%rsp)
movq   $0x0,0x48(%rsp)
lea    0x78(%rsp),%rsi
lea    0xa0(%rsp),%rdx
mov    $0x1,%edi
call   1110 <clGetPlatformIDs@plt>
mov    %eax,0x1c(%rsp)
lea    0xbcf(%rip),%rdi
call   1070 <puts@plt>
mov    0x78(%rsp),%rdi
mov    0x2aee(%rip),%rax
mov    (%rax),%esi
lea    0x48(%rsp),%rbx
lea    0xa4(%rsp),%r8
mov    $0x1,%edx
mov    %rbx,%rcx
call   10d0 <clGetDeviceIDs@plt>
mov    %eax,0x1c(%rsp)
lea    0xba3(%rip),%rdi
call   1070 <puts@plt>
xor    %r15d,%r15d
lea    0x1c(%rsp),%r9
xor    %edi,%edi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r9,%rbx
call   1160 <clCreateContext@plt>
mov    %eax,%r14d
lea    0xb86(%rip),%rdi
call   1070 <puts@plt>
mov    0x48(%rsp),%rsi
mov    %r14d,%edi
xor    %edx,%edx
mov    %rbx,%rcx
call   1100 <clCreateCommandQueue@plt>
mov    %eax,%r12d
lea    0xb74(%rip),%rdi
call   1070 <puts@plt>
mov    0x20(%rsp),%ebp
imul   %ebp,%ebp
shl    $0x2,%ebp
mov    0x2a7a(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   10b0 <clCreateBuffer@plt>
mov    %rax,0x40(%rsp)
mov    0x2a3d(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   10b0 <clCreateBuffer@plt>
mov    %rax,%rbx
mov    %rax,0x30(%rsp)
mov    0x20(%rsp),%edx
mov    0x70(%rsp),%rdi
mov    0x68(%rsp),%r13
mov    %r13,%rsi
call   1180 <initGrid@plt>
lea    0xb1d(%rip),%rdi
call   1070 <puts@plt>
mov    0x2a23(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r12d,0x3c(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    %ebp,%r8d
mov    %r13,%r9
call   1230 <clEnqueueWriteBuffer@plt>
mov    %eax,0x1c(%rsp)
lea    0xa70(%rip),%rdi
xor    %eax,%eax
call   1120 <printf@plt>
lea    0x98(%rsp),%rdx
lea    0x90(%rsp),%rcx
mov    %r14d,0x58(%rsp)
mov    %r14d,%edi
mov    $0x1,%esi
lea    0x1c(%rsp),%rbx
mov    %rbx,%r8
call   1060 <clCreateProgramWithSource@plt>
mov    %eax,%r14d
mov    0x1c(%rsp),%edi
call   11f0 <printError@plt>
lea    0xa3e(%rip),%rdi
xor    %eax,%eax
call   1120 <printf@plt>
mov    %r14d,%edi
mov    $0x1,%esi
lea    0x48(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
mov    %eax,0x1c(%rsp)
mov    %eax,%edi
call   11f0 <printError@plt>
lea    0xa7f(%rip),%rdi
call   1070 <puts@plt>
lea    0xa11(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1200 <clCreateKernel@plt>
mov    %eax,%ebx
mov    0x20(%rsp),%eax
imul   %eax,%eax
mov    0x24(%rsp),%ebp
mov    %ebp,%ecx
imul   %ecx,%ecx
xor    %edx,%edx
div    %ecx
mov    %rax,0x88(%rsp)
mov    %rcx,0x80(%rsp)
lea    0xa49(%rip),%rdi
call   1070 <puts@plt>
cmpl   $0x0,0x2c(%rsp)
jle    17b5 <main+0x4a5>
mov    %r14d,0x54(%rsp)
lea    0x24(%rsp),%r13
lea    0x88(%rsp),%r14
lea    0x80(%rsp),%rbp
mov    0x3c(%rsp),%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x8,%edx
lea    0x40(%rsp),%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x1c(%rsp)
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x8,%edx
lea    0x30(%rsp),%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x1c(%rsp)
mov    %ebx,%edi
mov    $0x2,%esi
mov    $0x8,%edx
lea    0x20(%rsp),%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x1c(%rsp)
mov    %ebx,%edi
mov    $0x3,%esi
mov    $0x8,%edx
mov    %r13,%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x1c(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r12d,%edi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %rbp,%r9
call   10f0 <clEnqueueNDRangeKernel@plt>
mov    %eax,0x1c(%rsp)
mov    %eax,%edi
call   11f0 <printError@plt>
mov    0x40(%rsp),%rax
mov    0x30(%rsp),%rcx
mov    %rcx,0x40(%rsp)
mov    %rax,0x30(%rsp)
add    $0x1,%r15d
cmp    0x2c(%rsp),%r15d
jl     16f0 <main+0x3e0>
mov    0x24(%rsp),%ebp
mov    0x68(%rsp),%r13
mov    0x54(%rsp),%r14d
shl    $0x2,%ebp
mov    %ebp,%edi
call   11a0 <malloc@plt>
mov    0x30(%rsp),%rsi
mov    0x281d(%rip),%rax
mov    (%rax),%edx
mov    0x20(%rsp),%r8d
imul   %r8d,%r8d
shl    $0x2,%r8d
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    0x3c(%rsp),%ebp
mov    %ebp,%edi
xor    %ecx,%ecx
mov    %r13,%r9
call   11b0 <clEnqueueReadBuffer@plt>
mov    %eax,0x1c(%rsp)
mov    0x20(%rsp),%esi
mov    %r13,%rdi
call   1150 <dumpGrid@plt>
mov    %ebp,%edi
call   10a0 <clFlush@plt>
mov    %eax,0x1c(%rsp)
mov    %ebp,%edi
call   1050 <clFinish@plt>
mov    %eax,0x1c(%rsp)
mov    %ebx,%edi
call   1090 <clReleaseKernel@plt>
mov    %eax,0x1c(%rsp)
mov    %r14d,%edi
call   10c0 <clReleaseProgram@plt>
mov    %eax,0x1c(%rsp)
mov    0x40(%rsp),%rdi
call   11d0 <clReleaseMemObject@plt>
mov    %eax,0x1c(%rsp)
mov    0x30(%rsp),%rdi
call   11d0 <clReleaseMemObject@plt>
mov    %eax,0x1c(%rsp)
mov    %ebp,%edi
call   1190 <clReleaseCommandQueue@plt>
mov    %eax,0x1c(%rsp)
mov    0x58(%rsp),%edi
call   11c0 <clReleaseContext@plt>
mov    %eax,0x1c(%rsp)
mov    0x70(%rsp),%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2739(%rip),%rax
mov    (%rax),%edi
lea    0x7b1(%rip),%rsi
call   1170 <fprintf@plt>
mov    $0x1,%edi
call   1210 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"# cycles %d width %d # initializations %d\0A\00"
@.str.3 = [7 x i8] c"%d%d%f\00"
@.str.4 = [10 x i8] c"kernel.cl\00"
@stderr = global i32 0
@.str.5 = [24 x i8] c"Failed to load kernel.\0A\00"
@.str.6 = [13 x i8] c"Getting IDs\0A\00"
@CL_DEVICE_TYPE_DEFAULT = global i32 0
@.str.7 = [18 x i8] c"Creating Context\0A\00"
@.str.8 = [16 x i8] c"Creating queue\0A\00"
@.str.9 = [19 x i8] c"Allocating memory\0A\00"
@CL_MEM_WRITE_ONLY = global i32 0
@CL_MEM_READ_ONLY = global i32 0
@.str.10 = [26 x i8] c"Copy from host to device\0A\00"
@CL_TRUE = global i32 0
@.str.11 = [18 x i8] c"\0ACreating program\00"
@.str.12 = [18 x i8] c"\0ABuilding program\00"
@.str.13 = [15 x i8] c"Create kernel\0A\00"
@.str.14 = [11 x i8] c"updateGrid\00"
@.str.15 = [13 x i8] c"Start loop.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca float*
%12 = alloca float*
%13 = alloca float
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i8*
%20 = alloca i64
%21 = alloca i32*
%22 = alloca i32*
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32*
%30 = alloca i32*
%31 = alloca i32
%32 = alloca i32
%33 = alloca i64
%34 = alloca i64
%35 = alloca i32*
%36 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %14
store i32 10, i32* %16
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %40, i32** %17
%41 = load i32*, i32** %17
%42 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%43 = load i32*, i32** %17
%44 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%45 = load i32*, i32** %17
%46 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%47 = load i32, i32* %7
%48 = load i32, i32* %6
%49 = load i32, i32* %15
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %6
%52 = load i32, i32* %6
%53 = mul nsw i32 %51, %52
%54 = call i64 @calloc(i32 %53, i32 4)
%55 = inttoptr i64 %54 to float*
store float* %55, float** %11
%56 = load i32, i32* %6
%57 = load i32, i32* %6
%58 = mul nsw i32 %56, %57
%59 = call i64 @calloc(i32 %58, i32 4)
%60 = inttoptr i64 %59 to float*
store float* %60, float** %12
%61 = load float*, float** %11
%62 = load float*, float** %12
%63 = load i32, i32* %6
%64 = call i32 @initGrid(float* %61, float* %62, i32 %63)
store i32 0, i32* %10
br label %65
65: ; preds = %81, %2
%66 = load i32, i32* %10
%67 = load i32, i32* %15
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %84
69: ; preds = %65
%70 = load i32*, i32** %17
%71 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %70, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %8, i32* %9, float* %13)
%72 = load float, float* %13
%73 = load float*, float** %12
%74 = load i32, i32* %8
%75 = load i32, i32* %6
%76 = mul nsw i32 %74, %75
%77 = load i32, i32* %9
%78 = add nsw i32 %76, %77
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds float, float* %73, i64 %79
store float %72, float* %80
br label %81
81: ; preds = %69
%82 = load i32, i32* %10
%83 = add nsw i32 %82, 1
store i32 %83, i32* %10
br label %65
84: ; preds = %65
%85 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %85, i32** %18
%86 = load i32*, i32** %18
%87 = icmp ne i32* %86, null
br i1 %87, label %92, label %88
88: ; preds = %84
%89 = load i32, i32* @stderr
%90 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %84
%93 = call i64 @malloc(i32 1048576)
%94 = inttoptr i64 %93 to i8*
store i8* %94, i8** %19
%95 = load i8*, i8** %19
%96 = load i32*, i32** %17
%97 = call i64 @fread(i8* %95, i32 1, i32 1048576, i32* %96)
store i64 %97, i64* %20
%98 = load i32*, i32** %17
%99 = call i32 @fclose(i32* %98)
%100 = load i32*, i32** %17
%101 = call i32 @fclose(i32* %100)
store i32* null, i32** %21
store i32* null, i32** %22
%102 = call i32 @clGetPlatformIDs(i32 1, i32** %21, i32* %24)
store i32 %102, i32* %25
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%104 = load i32*, i32** %21
%105 = load i32, i32* @CL_DEVICE_TYPE_DEFAULT
%106 = call i32 @clGetDeviceIDs(i32* %104, i32 %105, i32 1, i32** %22, i32* %23)
store i32 %106, i32* %25
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%108 = call i32 @clCreateContext(i32* null, i32 1, i32** %22, i32* null, i32* null, i32* %25)
store i32 %108, i32* %26
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%110 = load i32, i32* %26
%111 = load i32*, i32** %22
%112 = call i32 @clCreateCommandQueue(i32 %110, i32* %111, i32 0, i32* %25)
store i32 %112, i32* %27
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%114 = load i32, i32* %6
%115 = load i32, i32* %6
%116 = mul nsw i32 %114, %115
%117 = sext i32 %116 to i64
%118 = mul i64 %117, 4
%119 = trunc i64 %118 to i32
store i32 %119, i32* %28
%120 = load i32, i32* %26
%121 = load i32, i32* @CL_MEM_WRITE_ONLY
%122 = load i32, i32* %28
%123 = call i32* @clCreateBuffer(i32 %120, i32 %121, i32 %122, i32* null, i32* %25)
store i32* %123, i32** %29
%124 = load i32, i32* %26
%125 = load i32, i32* @CL_MEM_READ_ONLY
%126 = load i32, i32* %28
%127 = call i32* @clCreateBuffer(i32 %124, i32 %125, i32 %126, i32* null, i32* %25)
store i32* %127, i32** %30
%128 = load float*, float** %11
%129 = load float*, float** %12
%130 = load i32, i32* %6
%131 = call i32 @initGrid(float* %128, float* %129, i32 %130)
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
%133 = load i32, i32* %27
%134 = load i32*, i32** %30
%135 = load i32, i32* @CL_TRUE
%136 = load i32, i32* %28
%137 = load float*, float** %12
%138 = call i32 @clEnqueueWriteBuffer(i32 %133, i32* %134, i32 %135, i32 0, i32 %136, float* %137, i32 0, i32* null, i32* null)
store i32 %138, i32* %25
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
%140 = load i32, i32* %26
%141 = call i32 @clCreateProgramWithSource(i32 %140, i32 1, i8** %19, i64* %20, i32* %25)
store i32 %141, i32* %31
%142 = load i32, i32* %25
%143 = call i32 @printError(i32 %142)
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%145 = load i32, i32* %31
%146 = call i32 @clBuildProgram(i32 %145, i32 1, i32** %22, i32* null, i32* null, i32* null)
store i32 %146, i32* %25
%147 = load i32, i32* %25
%148 = call i32 @printError(i32 %147)
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
%150 = load i32, i32* %31
%151 = call i32 @clCreateKernel(i32 %150, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32* %25)
store i32 %151, i32* %32
%152 = load i32, i32* %6
%153 = load i32, i32* %6
%154 = mul nsw i32 %152, %153
%155 = load i32, i32* %16
%156 = load i32, i32* %16
%157 = mul nsw i32 %155, %156
%158 = sdiv i32 %154, %157
%159 = sext i32 %158 to i64
store i64 %159, i64* %33
%160 = load i32, i32* %16
%161 = load i32, i32* %16
%162 = mul nsw i32 %160, %161
%163 = sext i32 %162 to i64
store i64 %163, i64* %34
store i32* null, i32** %35
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
store i32 0, i32* %14
br label %165
165: ; preds = %190, %92
%166 = load i32, i32* %14
%167 = load i32, i32* %7
%168 = icmp slt i32 %166, %167
br i1 %168, label %169, label %193
169: ; preds = %165
%170 = load i32, i32* %32
%171 = bitcast i32** %29 to i8*
%172 = call i32 @clSetKernelArg(i32 %170, i32 0, i32 8, i8* %171)
store i32 %172, i32* %25
%173 = load i32, i32* %32
%174 = bitcast i32** %30 to i8*
%175 = call i32 @clSetKernelArg(i32 %173, i32 1, i32 8, i8* %174)
store i32 %175, i32* %25
%176 = load i32, i32* %32
%177 = bitcast i32* %6 to i8*
%178 = call i32 @clSetKernelArg(i32 %176, i32 2, i32 8, i8* %177)
store i32 %178, i32* %25
%179 = load i32, i32* %32
%180 = bitcast i32* %16 to i8*
%181 = call i32 @clSetKernelArg(i32 %179, i32 3, i32 8, i8* %180)
store i32 %181, i32* %25
%182 = load i32, i32* %27
%183 = load i32, i32* %32
%184 = call i32 @clEnqueueNDRangeKernel(i32 %182, i32 %183, i32 1, i32* null, i64* %33, i64* %34, i32 0, i32* null, i32* null)
store i32 %184, i32* %25
%185 = load i32, i32* %25
%186 = call i32 @printError(i32 %185)
%187 = load i32*, i32** %29
store i32* %187, i32** %35
%188 = load i32*, i32** %30
store i32* %188, i32** %29
%189 = load i32*, i32** %35
store i32* %189, i32** %30
br label %190
190: ; preds = %169
%191 = load i32, i32* %14
%192 = add nsw i32 %191, 1
store i32 %192, i32* %14
br label %165
193: ; preds = %165
%194 = load i32, i32* %16
%195 = sext i32 %194 to i64
%196 = mul i64 4, %195
%197 = trunc i64 %196 to i32
%198 = call i64 @malloc(i32 %197)
%199 = inttoptr i64 %198 to i32*
store i32* %199, i32** %36
%200 = load i32, i32* %27
%201 = load i32*, i32** %30
%202 = load i32, i32* @CL_TRUE
%203 = load i32, i32* %6
%204 = load i32, i32* %6
%205 = mul nsw i32 %203, %204
%206 = sext i32 %205 to i64
%207 = mul i64 %206, 4
%208 = trunc i64 %207 to i32
%209 = load float*, float** %12
%210 = call i32 @clEnqueueReadBuffer(i32 %200, i32* %201, i32 %202, i32 0, i32 %208, float* %209, i32 0, i32* null, i32* null)
store i32 %210, i32* %25
%211 = load float*, float** %12
%212 = load i32, i32* %6
%213 = call i32 @dumpGrid(float* %211, i32 %212)
%214 = load i32, i32* %27
%215 = call i32 @clFlush(i32 %214)
store i32 %215, i32* %25
%216 = load i32, i32* %27
%217 = call i32 @clFinish(i32 %216)
store i32 %217, i32* %25
%218 = load i32, i32* %32
%219 = call i32 @clReleaseKernel(i32 %218)
store i32 %219, i32* %25
%220 = load i32, i32* %31
%221 = call i32 @clReleaseProgram(i32 %220)
store i32 %221, i32* %25
%222 = load i32*, i32** %29
%223 = call i32 @clReleaseMemObject(i32* %222)
store i32 %223, i32* %25
%224 = load i32*, i32** %30
%225 = call i32 @clReleaseMemObject(i32* %224)
store i32 %225, i32* %25
%226 = load i32, i32* %27
%227 = call i32 @clReleaseCommandQueue(i32 %226)
store i32 %227, i32* %25
%228 = load i32, i32* %26
%229 = call i32 @clReleaseContext(i32 %228)
store i32 %229, i32* %25
%230 = load float*, float** %11
%231 = call i32 @free(float* %230)
%232 = load float*, float** %12
%233 = call i32 @free(float* %232)
%234 = load i32, i32* %3
ret i32 %234
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"# cycles %d width %d # initializations %d\0A\00"
@.str.3 = [7 x i8] c"%d%d%f\00"
@.str.4 = [10 x i8] c"kernel.cl\00"
@stderr = global i32 0
@.str.5 = [24 x i8] c"Failed to load kernel.\0A\00"
@CL_DEVICE_TYPE_DEFAULT = global i32 0
@CL_MEM_WRITE_ONLY = global i32 0
@CL_MEM_READ_ONLY = global i32 0
@CL_TRUE = global i32 0
@.str.11 = [18 x i8] c"\0ACreating program\00"
@.str.12 = [18 x i8] c"\0ABuilding program\00"
@.str.14 = [11 x i8] c"updateGrid\00"
@str = [12 x i8] c"Getting IDs\00"
@str.16 = [17 x i8] c"Creating Context\00"
@str.17 = [15 x i8] c"Creating queue\00"
@str.18 = [18 x i8] c"Allocating memory\00"
@str.19 = [25 x i8] c"Copy from host to device\00"
@str.20 = [14 x i8] c"Create kernel\00"
@str.21 = [12 x i8] c"Start loop.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i64
%20 = alloca i64
%21 = bitcast i32* %3 to i8*
%22 = bitcast i32* %4 to i8*
%23 = bitcast i32* %5 to i8*
%24 = bitcast i32* %6 to i8*
%25 = bitcast float* %7 to i8*
%26 = bitcast i32* %8 to i8*
%27 = bitcast i32* %9 to i8*
store i32 10, i32* %9
%28 = bitcast i8** %10 to i8*
%29 = bitcast i64* %11 to i8*
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = tail call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%33 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%34 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%35 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = load i32, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
%40 = load i32, i32* %3
%41 = mul nsw i32 %40, %40
%42 = call i64 @calloc(i32 %41, i32 4)
%43 = inttoptr i64 %42 to float*
%44 = load i32, i32* %3
%45 = mul nsw i32 %44, %44
%46 = call i64 @calloc(i32 %45, i32 4)
%47 = inttoptr i64 %46 to float*
%48 = load i32, i32* %3
%49 = call i32 @initGrid(float* %43, float* %47, i32 %48)
%50 = load i32, i32* %8
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %66
52: ; preds = %2, %52
%53 = phi i32 [ %63, %52 ], [ 0, %2 ]
%54 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %5, i32* %6, float* %7)
%55 = load float, float* %7
%56 = load i32, i32* %5
%57 = load i32, i32* %3
%58 = mul nsw i32 %57, %56
%59 = load i32, i32* %6
%60 = add nsw i32 %58, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds float, float* %47, i64 %61
store float %55, float* %62
%63 = add nuw nsw i32 %53, 1
%64 = load i32, i32* %8
%65 = icmp slt i32 %63, %64
br i1 %65, label %52, label %66
66: ; preds = %52, %2
%67 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %66
%74 = call i64 @malloc(i32 1048576)
%75 = inttoptr i64 %74 to i8*
store i8* %75, i8** %10
%76 = call i64 @fread(i8* %75, i32 1, i32 1048576, i32* %32)
store i64 %76, i64* %11
%77 = call i32 @fclose(i32* %32)
%78 = call i32 @fclose(i32* %32)
%79 = bitcast i32** %12 to i8*
store i32* null, i32** %12
%80 = bitcast i32** %13 to i8*
store i32* null, i32** %13
%81 = bitcast i32* %14 to i8*
%82 = bitcast i32* %15 to i8*
%83 = bitcast i32* %16 to i8*
%84 = call i32 @clGetPlatformIDs(i32 1, i32** %12, i32* %15)
store i32 %84, i32* %16
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%86 = load i32*, i32** %12
%87 = load i32, i32* @CL_DEVICE_TYPE_DEFAULT
%88 = call i32 @clGetDeviceIDs(i32* %86, i32 %87, i32 1, i32** %13, i32* %14)
store i32 %88, i32* %16
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.16, i64 0, i64 0))
%90 = call i32 @clCreateContext(i32* null, i32 1, i32** %13, i32* null, i32* null, i32* %16)
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.17, i64 0, i64 0))
%92 = load i32*, i32** %13
%93 = call i32 @clCreateCommandQueue(i32 %90, i32* %92, i32 0, i32* %16)
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.18, i64 0, i64 0))
%95 = load i32, i32* %3
%96 = shl i32 %95, 2
%97 = mul i32 %96, %95
%98 = bitcast i32** %17 to i8*
%99 = load i32, i32* @CL_MEM_WRITE_ONLY
%100 = call i32* @clCreateBuffer(i32 %90, i32 %99, i32 %97, i32* null, i32* %16)
store i32* %100, i32** %17
%101 = bitcast i32** %18 to i8*
%102 = load i32, i32* @CL_MEM_READ_ONLY
%103 = call i32* @clCreateBuffer(i32 %90, i32 %102, i32 %97, i32* null, i32* %16)
store i32* %103, i32** %18
%104 = load i32, i32* %3
%105 = call i32 @initGrid(float* %43, float* %47, i32 %104)
%106 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.19, i64 0, i64 0))
%107 = load i32, i32* @CL_TRUE
%108 = call i32 @clEnqueueWriteBuffer(i32 %93, i32* %103, i32 %107, i32 0, i32 %97, float* %47, i32 0, i32* null, i32* null)
store i32 %108, i32* %16
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
%110 = call i32 @clCreateProgramWithSource(i32 %90, i32 1, i8** %10, i64* %11, i32* %16)
%111 = load i32, i32* %16
%112 = call i32 @printError(i32 %111)
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%114 = call i32 @clBuildProgram(i32 %110, i32 1, i32** %13, i32* null, i32* null, i32* null)
store i32 %114, i32* %16
%115 = call i32 @printError(i32 %114)
%116 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.20, i64 0, i64 0))
%117 = call i32 @clCreateKernel(i32 %110, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32* %16)
%118 = bitcast i64* %19 to i8*
%119 = load i32, i32* %3
%120 = mul nsw i32 %119, %119
%121 = load i32, i32* %9
%122 = mul nsw i32 %121, %121
%123 = udiv i32 %120, %122
%124 = zext i32 %123 to i64
store i64 %124, i64* %19
%125 = bitcast i64* %20 to i8*
%126 = zext i32 %122 to i64
store i64 %126, i64* %20
%127 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.21, i64 0, i64 0))
%128 = load i32, i32* %4
%129 = icmp sgt i32 %128, 0
br i1 %129, label %130, label %145
130: ; preds = %73, %130
%131 = phi i32 [ %140, %130 ], [ 0, %73 ]
%132 = call i32 @clSetKernelArg(i32 %117, i32 0, i32 8, i8* %98)
store i32 %132, i32* %16
%133 = call i32 @clSetKernelArg(i32 %117, i32 1, i32 8, i8* %101)
store i32 %133, i32* %16
%134 = call i32 @clSetKernelArg(i32 %117, i32 2, i32 8, i8* %21)
store i32 %134, i32* %16
%135 = call i32 @clSetKernelArg(i32 %117, i32 3, i32 8, i8* %27)
store i32 %135, i32* %16
%136 = call i32 @clEnqueueNDRangeKernel(i32 %93, i32 %117, i32 1, i32* null, i64* %19, i64* %20, i32 0, i32* null, i32* null)
store i32 %136, i32* %16
%137 = call i32 @printError(i32 %136)
%138 = load i32*, i32** %17
%139 = load i32*, i32** %18
store i32* %139, i32** %17
store i32* %138, i32** %18
%140 = add nuw nsw i32 %131, 1
%141 = load i32, i32* %4
%142 = icmp slt i32 %140, %141
br i1 %142, label %130, label %143
143: ; preds = %130
%144 = load i32, i32* %9
br label %145
145: ; preds = %143, %73
%146 = phi i32 [ %144, %143 ], [ %121, %73 ]
%147 = shl i32 %146, 2
%148 = call i64 @malloc(i32 %147)
%149 = load i32*, i32** %18
%150 = load i32, i32* @CL_TRUE
%151 = load i32, i32* %3
%152 = shl i32 %151, 2
%153 = mul i32 %152, %151
%154 = call i32 @clEnqueueReadBuffer(i32 %93, i32* %149, i32 %150, i32 0, i32 %153, float* %47, i32 0, i32* null, i32* null)
store i32 %154, i32* %16
%155 = load i32, i32* %3
%156 = call i32 @dumpGrid(float* %47, i32 %155)
%157 = call i32 @clFlush(i32 %93)
store i32 %157, i32* %16
%158 = call i32 @clFinish(i32 %93)
store i32 %158, i32* %16
%159 = call i32 @clReleaseKernel(i32 %117)
store i32 %159, i32* %16
%160 = call i32 @clReleaseProgram(i32 %110)
store i32 %160, i32* %16
%161 = load i32*, i32** %17
%162 = call i32 @clReleaseMemObject(i32* %161)
store i32 %162, i32* %16
%163 = load i32*, i32** %18
%164 = call i32 @clReleaseMemObject(i32* %163)
store i32 %164, i32* %16
%165 = call i32 @clReleaseCommandQueue(i32 %93)
store i32 %165, i32* %16
%166 = call i32 @clReleaseContext(i32 %90)
store i32 %166, i32* %16
%167 = call i32 @free(float* %43)
%168 = call i32 @free(float* %47)
ret i32 0
}