#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_READ_WRITE;
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, ...);
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("update_grid.cl", "r");
  if (!kp) {
    fprintf(stderr, "Failed to load kernel.\n");
    exit(1);
  }
  printf("test\n");
  source_str = (char *)malloc((0x100000));
  source_size = fread(source_str, 1, (0x100000), 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_READ_WRITE, memory_size, NULL, &ret);
  printError(ret);
  cl_mem device_u1 =
      clCreateBuffer(context, CL_MEM_READ_WRITE, memory_size, NULL, &ret);
  printError(ret);
  cl_mem device_width =
      clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(int), NULL, &ret);
  printError(ret);
  initGrid(u0, u1, width);
  printf("Copy from host to device\n");
  ret = clEnqueueWriteBuffer(command_queue, device_u0, CL_TRUE, 0, memory_size,
                             u0, 0, NULL, NULL);
  printError(ret);
  ret = clEnqueueWriteBuffer(command_queue, device_u1, CL_TRUE, 0, memory_size,
                             u1, 0, NULL, NULL);
  printError(ret);
  ret = clEnqueueWriteBuffer(command_queue, device_width, CL_TRUE, 0,
                             sizeof(int), &width, 0, NULL, NULL);
  printError(ret);
  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, "update_grid", &ret);
  printError(ret);
  size_t global_size =
      (((width * width) / (TILE_SIZE * TILE_SIZE)) + 1) * 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 = 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    $0xf0,%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    0xbe8(%rip),%rsi
call   1160 <fprintf@plt>
mov    $0x1,%edi
call   1200 <exit@plt>
lea    0xbea(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@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>
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    0xb88(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0x70(%rbp),%rdi
mov    0x2ada(%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    0xb62(%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    0xb40(%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    0xb24(%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    0x2a4a(%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    -0x84(%rbp),%edi
call   11e0 <printError@plt>
mov    -0x88(%rbp),%edi
mov    0x2a13(%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    -0x84(%rbp),%edi
call   11e0 <printError@plt>
mov    -0x88(%rbp),%edi
mov    0x29bc(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x84(%rbp),%r8
call   10a0 <clCreateBuffer@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1170 <initGrid@plt>
lea    0xa62(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0x8c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    0x2989(%rip),%rax
mov    (%rax),%edx
mov    -0x90(%rbp),%r8d
mov    -0x30(%rbp),%r9
xor    %ecx,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    $0x0,%al
call   1220 <clEnqueueWriteBuffer@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
mov    -0x8c(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    0x2933(%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)
mov    $0x0,%al
call   1220 <clEnqueueWriteBuffer@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
mov    -0x8c(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    0x28dd(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
mov    $0x4,%r8d
lea    -0x14(%rbp),%r9
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    $0x0,%al
call   1220 <clEnqueueWriteBuffer@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
lea    0x96d(%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,-0xac(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
lea    0x941(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0xac(%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    0x915(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0xac(%rbp),%edi
lea    0x910(%rip),%rsi
lea    -0x84(%rbp),%rdx
call   11f0 <clCreateKernel@plt>
mov    %eax,-0xb0(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    -0x48(%rbp),%ecx
imul   -0x48(%rbp),%ecx
cltd
idiv   %ecx
add    $0x1,%eax
imul   -0x48(%rbp),%eax
imul   -0x48(%rbp),%eax
cltq
mov    %rax,-0xb8(%rbp)
mov    -0x48(%rbp),%eax
imul   -0x48(%rbp),%eax
cltq
mov    %rax,-0xc0(%rbp)
movq   $0x0,-0xc8(%rbp)
lea    0x8b8(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    194d <main+0x64d>
mov    -0xb0(%rbp),%edi
lea    -0x98(%rbp),%rcx
xor    %esi,%esi
mov    $0x8,%edx
call   1210 <clSetKernelArg@plt>
mov    %eax,-0x84(%rbp)
mov    -0xb0(%rbp),%edi
lea    -0xa0(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1210 <clSetKernelArg@plt>
mov    %eax,-0x84(%rbp)
mov    -0xb0(%rbp),%edi
lea    -0x14(%rbp),%rcx
mov    $0x2,%esi
mov    $0x8,%edx
call   1210 <clSetKernelArg@plt>
mov    %eax,-0x84(%rbp)
mov    -0x8c(%rbp),%edi
mov    -0xb0(%rbp),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xb8(%rbp),%r8
lea    -0xc0(%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,-0xc8(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0xc8(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1855 <main+0x555>
movslq -0x48(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1190 <malloc@plt>
mov    %rax,-0xd0(%rbp)
mov    -0x8c(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    0x2671(%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    -0xb0(%rbp),%edi
call   1080 <clReleaseKernel@plt>
mov    %eax,-0x84(%rbp)
mov    -0xac(%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    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    0x8(%rsi),%rdi
lea    0xce4(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,%r15
lea    0xcd7(%rip),%rbx
lea    0x34(%rsp),%rdx
mov    %rax,%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>
lea    0x30(%rsp),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1130 <fscanf@plt>
mov    0x34(%rsp),%esi
mov    0x28(%rsp),%edx
mov    0x30(%rsp),%ecx
lea    0xc91(%rip),%rdi
xor    %eax,%eax
call   1120 <printf@plt>
mov    0x28(%rsp),%edi
imul   %edi,%edi
mov    $0x4,%esi
call   1140 <calloc@plt>
mov    %rax,%rbx
mov    0x28(%rsp),%edi
imul   %edi,%edi
mov    $0x4,%esi
call   1140 <calloc@plt>
mov    %rax,%r14
mov    0x28(%rsp),%edx
mov    %rbx,0x78(%rsp)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1180 <initGrid@plt>
cmpl   $0x0,0x30(%rsp)
jle    1425 <main+0x115>
lea    0x6c(%rsp),%r12
lea    0x68(%rsp),%r13
lea    0x64(%rsp),%rbx
xor    %ebp,%ebp
nop
mov    %r15,%rdi
lea    0xc56(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1130 <fscanf@plt>
movss  0x64(%rsp),%xmm0
movslq 0x6c(%rsp),%rax
movslq 0x28(%rsp),%rcx
imul   %rax,%rcx
movslq 0x68(%rsp),%rax
add    %rcx,%rax
movss  %xmm0,(%r14,%rax,4)
add    $0x1,%ebp
cmp    0x30(%rsp),%ebp
jl     13e0 <main+0xd0>
mov    %r14,0x70(%rsp)
lea    0xc16(%rip),%rdi
lea    0xbd8(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     193b <main+0x62b>
lea    0xc51(%rip),%rdi
call   1070 <puts@plt>
mov    $0x100000,%edi
call   11a0 <malloc@plt>
mov    %rax,0xa8(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
mov    %r15,%rcx
call   1080 <fread@plt>
mov    %rax,0xa0(%rsp)
mov    %r15,%rdi
call   10e0 <fclose@plt>
movq   $0x0,0x80(%rsp)
movq   $0x0,0x58(%rsp)
lea    0x80(%rsp),%rsi
lea    0xb0(%rsp),%rdx
mov    $0x1,%edi
call   1110 <clGetPlatformIDs@plt>
mov    %eax,0x24(%rsp)
lea    0xbe0(%rip),%rdi
call   1070 <puts@plt>
mov    0x80(%rsp),%rdi
mov    0x2af1(%rip),%rax
mov    (%rax),%esi
lea    0x58(%rsp),%rbx
lea    0xb4(%rsp),%r8
mov    $0x1,%edx
mov    %rbx,%rcx
call   10d0 <clGetDeviceIDs@plt>
mov    %eax,0x24(%rsp)
lea    0xbb1(%rip),%rdi
call   1070 <puts@plt>
xor    %ebp,%ebp
lea    0x24(%rsp),%r12
xor    %edi,%edi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r12,%r9
call   1160 <clCreateContext@plt>
mov    %eax,%r14d
lea    0xb95(%rip),%rdi
call   1070 <puts@plt>
mov    0x58(%rsp),%rsi
mov    %r14d,%edi
xor    %edx,%edx
mov    %r12,%rcx
call   1100 <clCreateCommandQueue@plt>
mov    %eax,0x2c(%rsp)
lea    0xb82(%rip),%rdi
call   1070 <puts@plt>
mov    0x28(%rsp),%ebx
imul   %ebx,%ebx
shl    $0x2,%ebx
mov    0x2a7d(%rip),%r15
mov    (%r15),%esi
mov    %r14d,%edi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10b0 <clCreateBuffer@plt>
mov    %rax,0x88(%rsp)
mov    %rax,0x40(%rsp)
mov    0x24(%rsp),%edi
call   11f0 <printError@plt>
mov    (%r15),%esi
mov    %r14d,%edi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10b0 <clCreateBuffer@plt>
mov    %rax,0x48(%rsp)
mov    %rax,0x38(%rsp)
mov    0x24(%rsp),%edi
call   11f0 <printError@plt>
mov    0x2a09(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10b0 <clCreateBuffer@plt>
mov    %rax,0x50(%rsp)
mov    0x24(%rsp),%edi
call   11f0 <printError@plt>
mov    0x28(%rsp),%edx
mov    0x78(%rsp),%r15
mov    %r15,%rdi
mov    0x70(%rsp),%r13
mov    %r13,%rsi
call   1180 <initGrid@plt>
lea    0xae8(%rip),%rdi
call   1070 <puts@plt>
mov    0x29e3(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    0x2c(%rsp),%r12d
mov    %r12d,%edi
mov    0x88(%rsp),%rsi
xor    %ecx,%ecx
mov    %ebx,%r8d
mov    %r15,%r9
xor    %eax,%eax
call   1230 <clEnqueueWriteBuffer@plt>
mov    %eax,0x24(%rsp)
mov    %eax,%edi
call   11f0 <printError@plt>
mov    0x29a1(%rip),%r15
mov    (%r15),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r12d,%edi
mov    0x48(%rsp),%rsi
xor    %ecx,%ecx
mov    %ebx,%r8d
mov    %r13,%r9
xor    %eax,%eax
call   1230 <clEnqueueWriteBuffer@plt>
mov    %eax,0x24(%rsp)
mov    %eax,%edi
call   11f0 <printError@plt>
mov    (%r15),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
lea    0x28(%rsp),%r9
mov    %r12d,%edi
mov    0x50(%rsp),%rsi
xor    %ecx,%ecx
mov    $0x4,%r8d
xor    %eax,%eax
call   1230 <clEnqueueWriteBuffer@plt>
mov    %eax,0x24(%rsp)
mov    %eax,%edi
call   11f0 <printError@plt>
lea    0x9b3(%rip),%rdi
xor    %eax,%eax
call   1120 <printf@plt>
lea    0xa8(%rsp),%rdx
lea    0xa0(%rsp),%rcx
mov    %r14d,0x50(%rsp)
mov    %r14d,%edi
mov    $0x1,%esi
lea    0x24(%rsp),%r14
mov    %r14,%r8
call   1060 <clCreateProgramWithSource@plt>
mov    %eax,%ebx
mov    0x24(%rsp),%edi
call   11f0 <printError@plt>
lea    0x982(%rip),%rdi
xor    %eax,%eax
call   1120 <printf@plt>
mov    %ebx,%edi
mov    $0x1,%esi
lea    0x58(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
mov    %eax,0x24(%rsp)
mov    %eax,%edi
call   11f0 <printError@plt>
lea    0x9ca(%rip),%rdi
call   1070 <puts@plt>
lea    0x956(%rip),%rsi
mov    %ebx,0x48(%rsp)
mov    %ebx,%edi
mov    %r14,%rdx
call   1200 <clCreateKernel@plt>
mov    %eax,%ebx
mov    0x24(%rsp),%edi
call   11f0 <printError@plt>
mov    0x28(%rsp),%eax
imul   %eax,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
imul   $0x64,%eax,%eax
add    $0x64,%eax
cltq
mov    %rax,0x98(%rsp)
movq   $0x64,0x90(%rsp)
lea    0x97e(%rip),%rdi
call   1070 <puts@plt>
cmpl   $0x0,0x34(%rsp)
jle    185a <main+0x54a>
lea    0x38(%rsp),%r15
lea    0x28(%rsp),%r13
lea    0x98(%rsp),%r14
lea    0x90(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x8,%edx
lea    0x40(%rsp),%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x24(%rsp)
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r15,%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x24(%rsp)
mov    %ebx,%edi
mov    $0x2,%esi
mov    $0x8,%edx
mov    %r13,%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x24(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    0x2c(%rsp),%edi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r12,%r9
call   10f0 <clEnqueueNDRangeKernel@plt>
mov    %eax,0x24(%rsp)
mov    %eax,%edi
call   11f0 <printError@plt>
mov    0x40(%rsp),%rax
mov    0x38(%rsp),%rcx
mov    %rcx,0x40(%rsp)
mov    %rax,0x38(%rsp)
add    $0x1,%ebp
cmp    0x34(%rsp),%ebp
jl     17c0 <main+0x4b0>
mov    $0x28,%edi
call   11a0 <malloc@plt>
mov    0x38(%rsp),%rsi
mov    0x2778(%rip),%rax
mov    (%rax),%edx
mov    0x28(%rsp),%r8d
imul   %r8d,%r8d
shl    $0x2,%r8d
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    0x2c(%rsp),%ebp
mov    %ebp,%edi
xor    %ecx,%ecx
mov    0x70(%rsp),%r14
mov    %r14,%r9
call   11b0 <clEnqueueReadBuffer@plt>
mov    %eax,0x24(%rsp)
mov    0x28(%rsp),%esi
mov    %r14,%rdi
call   1150 <dumpGrid@plt>
mov    %ebp,%edi
call   10a0 <clFlush@plt>
mov    %eax,0x24(%rsp)
mov    %ebp,%edi
call   1050 <clFinish@plt>
mov    %eax,0x24(%rsp)
mov    %ebx,%edi
call   1090 <clReleaseKernel@plt>
mov    %eax,0x24(%rsp)
mov    0x48(%rsp),%edi
call   10c0 <clReleaseProgram@plt>
mov    %eax,0x24(%rsp)
mov    0x40(%rsp),%rdi
call   11d0 <clReleaseMemObject@plt>
mov    %eax,0x24(%rsp)
mov    0x38(%rsp),%rdi
call   11d0 <clReleaseMemObject@plt>
mov    %eax,0x24(%rsp)
mov    %ebp,%edi
call   1190 <clReleaseCommandQueue@plt>
mov    %eax,0x24(%rsp)
mov    0x50(%rsp),%edi
call   11c0 <clReleaseContext@plt>
mov    %eax,0x24(%rsp)
mov    0x78(%rsp),%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x268e(%rip),%rax
mov    (%rax),%edi
lea    0x70b(%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 = [15 x i8] c"update_grid.cl\00"
@stderr = global i32 0
@.str.5 = [24 x i8] c"Failed to load kernel.\0A\00"
@.str.6 = [6 x i8] c"test\0A\00"
@.str.7 = [13 x i8] c"Getting IDs\0A\00"
@CL_DEVICE_TYPE_DEFAULT = global i32 0
@.str.8 = [18 x i8] c"Creating Context\0A\00"
@.str.9 = [16 x i8] c"Creating queue\0A\00"
@.str.10 = [19 x i8] c"Allocating memory\0A\00"
@CL_MEM_READ_WRITE = global i32 0
@CL_MEM_READ_ONLY = global i32 0
@.str.11 = [26 x i8] c"Copy from host to device\0A\00"
@CL_TRUE = global i32 0
@.str.12 = [18 x i8] c"\0ACreating program\00"
@.str.13 = [18 x i8] c"\0ABuilding program\00"
@.str.14 = [15 x i8] c"Create kernel\0A\00"
@.str.15 = [12 x i8] c"update_grid\00"
@.str.16 = [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 i32
%34 = alloca i64
%35 = alloca i64
%36 = alloca i32*
%37 = 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
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %41, i32** %17
%42 = load i32*, i32** %17
%43 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%44 = load i32*, i32** %17
%45 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%46 = load i32*, i32** %17
%47 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%48 = load i32, i32* %7
%49 = load i32, i32* %6
%50 = load i32, i32* %15
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %49, i32 %50)
%52 = load i32, i32* %6
%53 = load i32, i32* %6
%54 = mul nsw i32 %52, %53
%55 = call i64 @calloc(i32 %54, i32 4)
%56 = inttoptr i64 %55 to float*
store float* %56, float** %11
%57 = load i32, i32* %6
%58 = load i32, i32* %6
%59 = mul nsw i32 %57, %58
%60 = call i64 @calloc(i32 %59, i32 4)
%61 = inttoptr i64 %60 to float*
store float* %61, float** %12
%62 = load float*, float** %11
%63 = load float*, float** %12
%64 = load i32, i32* %6
%65 = call i32 @initGrid(float* %62, float* %63, i32 %64)
store i32 0, i32* %10
br label %66
66: ; preds = %82, %2
%67 = load i32, i32* %10
%68 = load i32, i32* %15
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %85
70: ; preds = %66
%71 = load i32*, i32** %17
%72 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %8, i32* %9, float* %13)
%73 = load float, float* %13
%74 = load float*, float** %12
%75 = load i32, i32* %8
%76 = load i32, i32* %6
%77 = mul nsw i32 %75, %76
%78 = load i32, i32* %9
%79 = add nsw i32 %77, %78
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds float, float* %74, i64 %80
store float %73, float* %81
br label %82
82: ; preds = %70
%83 = load i32, i32* %10
%84 = add nsw i32 %83, 1
store i32 %84, i32* %10
br label %66
85: ; preds = %66
%86 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %86, i32** %18
%87 = load i32*, i32** %18
%88 = icmp ne i32* %87, null
br i1 %88, label %93, label %89
89: ; preds = %85
%90 = load i32, i32* @stderr
%91 = call i32 @fprintf(i32 %90, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%92 = call i32 @exit(i32 1)
unreachable
93: ; preds = %85
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%95 = call i64 @malloc(i32 1048576)
%96 = inttoptr i64 %95 to i8*
store i8* %96, i8** %19
%97 = load i8*, i8** %19
%98 = load i32*, i32** %17
%99 = call i64 @fread(i8* %97, i32 1, i32 1048576, i32* %98)
store i64 %99, i64* %20
%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.7, 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.8, 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.9, 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.10, 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_READ_WRITE
%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* %25
%125 = call i32 @printError(i32 %124)
%126 = load i32, i32* %26
%127 = load i32, i32* @CL_MEM_READ_WRITE
%128 = load i32, i32* %28
%129 = call i32* @clCreateBuffer(i32 %126, i32 %127, i32 %128, i32* null, i32* %25)
store i32* %129, i32** %30
%130 = load i32, i32* %25
%131 = call i32 @printError(i32 %130)
%132 = load i32, i32* %26
%133 = load i32, i32* @CL_MEM_READ_ONLY
%134 = call i32* @clCreateBuffer(i32 %132, i32 %133, i32 4, i32* null, i32* %25)
store i32* %134, i32** %31
%135 = load i32, i32* %25
%136 = call i32 @printError(i32 %135)
%137 = load float*, float** %11
%138 = load float*, float** %12
%139 = load i32, i32* %6
%140 = call i32 @initGrid(float* %137, float* %138, i32 %139)
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0))
%142 = load i32, i32* %27
%143 = load i32*, i32** %29
%144 = load i32, i32* @CL_TRUE
%145 = load i32, i32* %28
%146 = load float*, float** %11
%147 = call i32 (i32, i32*, i32, i32, i32, ...) @clEnqueueWriteBuffer(i32 %142, i32* %143, i32 %144, i32 0, i32 %145, float* %146, i32 0, i8* null, i8* null)
store i32 %147, i32* %25
%148 = load i32, i32* %25
%149 = call i32 @printError(i32 %148)
%150 = load i32, i32* %27
%151 = load i32*, i32** %30
%152 = load i32, i32* @CL_TRUE
%153 = load i32, i32* %28
%154 = load float*, float** %12
%155 = call i32 (i32, i32*, i32, i32, i32, ...) @clEnqueueWriteBuffer(i32 %150, i32* %151, i32 %152, i32 0, i32 %153, float* %154, i32 0, i8* null, i8* null)
store i32 %155, i32* %25
%156 = load i32, i32* %25
%157 = call i32 @printError(i32 %156)
%158 = load i32, i32* %27
%159 = load i32*, i32** %31
%160 = load i32, i32* @CL_TRUE
%161 = call i32 (i32, i32*, i32, i32, i32, ...) @clEnqueueWriteBuffer(i32 %158, i32* %159, i32 %160, i32 0, i32 4, i32* %6, i32 0, i8* null, i8* null)
store i32 %161, i32* %25
%162 = load i32, i32* %25
%163 = call i32 @printError(i32 %162)
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%165 = load i32, i32* %26
%166 = call i32 @clCreateProgramWithSource(i32 %165, i32 1, i8** %19, i64* %20, i32* %25)
store i32 %166, i32* %32
%167 = load i32, i32* %25
%168 = call i32 @printError(i32 %167)
%169 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0))
%170 = load i32, i32* %32
%171 = call i32 @clBuildProgram(i32 %170, i32 1, i32** %22, i32* null, i32* null, i32* null)
store i32 %171, i32* %25
%172 = load i32, i32* %25
%173 = call i32 @printError(i32 %172)
%174 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.14, i64 0, i64 0))
%175 = load i32, i32* %32
%176 = call i32 @clCreateKernel(i32 %175, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0), i32* %25)
store i32 %176, i32* %33
%177 = load i32, i32* %25
%178 = call i32 @printError(i32 %177)
%179 = load i32, i32* %6
%180 = load i32, i32* %6
%181 = mul nsw i32 %179, %180
%182 = load i32, i32* %16
%183 = load i32, i32* %16
%184 = mul nsw i32 %182, %183
%185 = sdiv i32 %181, %184
%186 = add nsw i32 %185, 1
%187 = load i32, i32* %16
%188 = mul nsw i32 %186, %187
%189 = load i32, i32* %16
%190 = mul nsw i32 %188, %189
%191 = sext i32 %190 to i64
store i64 %191, i64* %34
%192 = load i32, i32* %16
%193 = load i32, i32* %16
%194 = mul nsw i32 %192, %193
%195 = sext i32 %194 to i64
store i64 %195, i64* %35
store i32* null, i32** %36
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* %14
br label %197
197: ; preds = %219, %93
%198 = load i32, i32* %14
%199 = load i32, i32* %7
%200 = icmp slt i32 %198, %199
br i1 %200, label %201, label %222
201: ; preds = %197
%202 = load i32, i32* %33
%203 = bitcast i32** %29 to i8*
%204 = call i32 @clSetKernelArg(i32 %202, i32 0, i32 8, i8* %203)
store i32 %204, i32* %25
%205 = load i32, i32* %33
%206 = bitcast i32** %30 to i8*
%207 = call i32 @clSetKernelArg(i32 %205, i32 1, i32 8, i8* %206)
store i32 %207, i32* %25
%208 = load i32, i32* %33
%209 = bitcast i32* %6 to i8*
%210 = call i32 @clSetKernelArg(i32 %208, i32 2, i32 8, i8* %209)
store i32 %210, i32* %25
%211 = load i32, i32* %27
%212 = load i32, i32* %33
%213 = call i32 @clEnqueueNDRangeKernel(i32 %211, i32 %212, i32 1, i32* null, i64* %34, i64* %35, i32 0, i32* null, i32* null)
store i32 %213, i32* %25
%214 = load i32, i32* %25
%215 = call i32 @printError(i32 %214)
%216 = load i32*, i32** %29
store i32* %216, i32** %36
%217 = load i32*, i32** %30
store i32* %217, i32** %29
%218 = load i32*, i32** %36
store i32* %218, i32** %30
br label %219
219: ; preds = %201
%220 = load i32, i32* %14
%221 = add nsw i32 %220, 1
store i32 %221, i32* %14
br label %197
222: ; preds = %197
%223 = load i32, i32* %16
%224 = sext i32 %223 to i64
%225 = mul i64 4, %224
%226 = trunc i64 %225 to i32
%227 = call i64 @malloc(i32 %226)
%228 = inttoptr i64 %227 to i32*
store i32* %228, i32** %37
%229 = load i32, i32* %27
%230 = load i32*, i32** %30
%231 = load i32, i32* @CL_TRUE
%232 = load i32, i32* %6
%233 = load i32, i32* %6
%234 = mul nsw i32 %232, %233
%235 = sext i32 %234 to i64
%236 = mul i64 %235, 4
%237 = trunc i64 %236 to i32
%238 = load float*, float** %12
%239 = call i32 @clEnqueueReadBuffer(i32 %229, i32* %230, i32 %231, i32 0, i32 %237, float* %238, i32 0, i32* null, i32* null)
store i32 %239, i32* %25
%240 = load float*, float** %12
%241 = load i32, i32* %6
%242 = call i32 @dumpGrid(float* %240, i32 %241)
%243 = load i32, i32* %27
%244 = call i32 @clFlush(i32 %243)
store i32 %244, i32* %25
%245 = load i32, i32* %27
%246 = call i32 @clFinish(i32 %245)
store i32 %246, i32* %25
%247 = load i32, i32* %33
%248 = call i32 @clReleaseKernel(i32 %247)
store i32 %248, i32* %25
%249 = load i32, i32* %32
%250 = call i32 @clReleaseProgram(i32 %249)
store i32 %250, i32* %25
%251 = load i32*, i32** %29
%252 = call i32 @clReleaseMemObject(i32* %251)
store i32 %252, i32* %25
%253 = load i32*, i32** %30
%254 = call i32 @clReleaseMemObject(i32* %253)
store i32 %254, i32* %25
%255 = load i32, i32* %27
%256 = call i32 @clReleaseCommandQueue(i32 %255)
store i32 %256, i32* %25
%257 = load i32, i32* %26
%258 = call i32 @clReleaseContext(i32 %257)
store i32 %258, i32* %25
%259 = load float*, float** %11
%260 = call i32 @free(float* %259)
%261 = load float*, float** %12
%262 = call i32 @free(float* %261)
%263 = load i32, i32* %3
ret i32 %263
}

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