#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, 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_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);
  cl_mem temp = NULL;
  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;
  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    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    -0x84(%rbp),%edi
call   11e0 <printError@plt>
mov    -0x88(%rbp),%edi
mov    0x2a18(%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    0x29c1(%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>
movq   $0x0,-0xb0(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1170 <initGrid@plt>
lea    0xa51(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0x8c(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    0x2983(%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    0xa14(%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,-0xb4(%rbp)
mov    -0x84(%rbp),%edi
call   11e0 <printError@plt>
lea    0x9e8(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0xb4(%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    0x9bc(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
mov    -0xb4(%rbp),%edi
lea    0x9b7(%rip),%rsi
lea    -0x84(%rbp),%rdx
call   11f0 <clCreateKernel@plt>
mov    %eax,-0xb8(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    -0x48(%rbp),%ecx
imul   -0x48(%rbp),%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0xc0(%rbp)
mov    -0x48(%rbp),%eax
imul   -0x48(%rbp),%eax
cltq
mov    %rax,-0xc8(%rbp)
lea    0x97f(%rip),%rdi
mov    $0x0,%al
call   1110 <printf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    187a <main+0x57a>
mov    -0xb8(%rbp),%edi
lea    -0x98(%rbp),%rcx
xor    %esi,%esi
mov    $0x8,%edx
call   1210 <clSetKernelArg@plt>
mov    %eax,-0x84(%rbp)
mov    -0xb8(%rbp),%edi
lea    -0xa0(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1210 <clSetKernelArg@plt>
mov    %eax,-0x84(%rbp)
mov    -0xb8(%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    -0xb8(%rbp),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xc0(%rbp),%r8
lea    -0xc8(%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,-0xb0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0xb0(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1782 <main+0x482>
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    0x2744(%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    -0xb8(%rbp),%edi
call   1080 <clReleaseKernel@plt>
mov    %eax,-0x84(%rbp)
mov    -0xb4(%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    $0xa8,%rsp
mov    0x8(%rsi),%rdi
lea    0xce4(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,%r15
lea    0xcd7(%rip),%rbx
lea    0x2c(%rsp),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1130 <fscanf@plt>
lea    0x24(%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    0x24(%rsp),%edx
mov    0x28(%rsp),%ecx
lea    0xc91(%rip),%rdi
xor    %eax,%eax
call   1120 <printf@plt>
mov    0x24(%rsp),%edi
imul   %edi,%edi
mov    $0x4,%esi
call   1140 <calloc@plt>
mov    %rax,%rbx
mov    0x24(%rsp),%edi
imul   %edi,%edi
mov    $0x4,%esi
call   1140 <calloc@plt>
mov    %rax,%r14
mov    0x24(%rsp),%edx
mov    %rbx,0x70(%rsp)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1180 <initGrid@plt>
cmpl   $0x0,0x28(%rsp)
jle    1425 <main+0x115>
lea    0x64(%rsp),%r12
lea    0x60(%rsp),%r13
lea    0x5c(%rsp),%rbp
xor    %ebx,%ebx
nop
mov    %r15,%rdi
lea    0xc56(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   1130 <fscanf@plt>
movss  0x5c(%rsp),%xmm0
movslq 0x64(%rsp),%rax
movslq 0x24(%rsp),%rcx
imul   %rax,%rcx
movslq 0x60(%rsp),%rax
add    %rcx,%rax
movss  %xmm0,(%r14,%rax,4)
add    $0x1,%ebx
cmp    0x28(%rsp),%ebx
jl     13e0 <main+0xd0>
mov    %r14,0x68(%rsp)
lea    0xc16(%rip),%rdi
lea    0xbd8(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     188d <main+0x57d>
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,0x20(%rsp)
lea    0xbdf(%rip),%rdi
call   1070 <puts@plt>
mov    0x78(%rsp),%rdi
mov    0x2afe(%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,0x20(%rsp)
lea    0xbb3(%rip),%rdi
call   1070 <puts@plt>
xor    %r13d,%r13d
lea    0x20(%rsp),%r15
xor    %edi,%edi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r15,%r9
call   1160 <clCreateContext@plt>
mov    %eax,%r12d
lea    0xb96(%rip),%rdi
call   1070 <puts@plt>
mov    0x48(%rsp),%rsi
mov    %r12d,%edi
xor    %edx,%edx
mov    %r15,%rcx
call   1100 <clCreateCommandQueue@plt>
mov    %eax,%r14d
lea    0xb84(%rip),%rdi
call   1070 <puts@plt>
mov    0x24(%rsp),%ebx
imul   %ebx,%ebx
shl    $0x2,%ebx
mov    0x2a8a(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r12d,%edi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   10b0 <clCreateBuffer@plt>
mov    %rax,0x40(%rsp)
mov    0x20(%rsp),%edi
call   11f0 <printError@plt>
mov    0x0(%rbp),%esi
mov    %r12d,%edi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r15,%rbp
call   10b0 <clCreateBuffer@plt>
mov    %rax,%r15
mov    %rax,0x30(%rsp)
mov    0x20(%rsp),%edi
call   11f0 <printError@plt>
mov    0x2a1d(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
call   10b0 <clCreateBuffer@plt>
mov    0x20(%rsp),%edi
call   11f0 <printError@plt>
mov    0x24(%rsp),%edx
mov    0x70(%rsp),%rdi
mov    0x68(%rsp),%rbp
mov    %rbp,%rsi
call   1180 <initGrid@plt>
lea    0xaf9(%rip),%rdi
call   1070 <puts@plt>
mov    0x29ff(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r14d,0x3c(%rsp)
mov    %r14d,%edi
mov    %r15,%rsi
xor    %ecx,%ecx
mov    %ebx,%r8d
mov    %rbp,%r9
call   1230 <clEnqueueWriteBuffer@plt>
mov    %eax,0x20(%rsp)
lea    0xa4c(%rip),%rdi
xor    %eax,%eax
call   1120 <printf@plt>
lea    0x98(%rsp),%rdx
lea    0x90(%rsp),%rcx
mov    %r12d,0x58(%rsp)
mov    %r12d,%edi
mov    $0x1,%esi
lea    0x20(%rsp),%rbp
mov    %rbp,%r8
call   1060 <clCreateProgramWithSource@plt>
mov    %eax,%ebx
mov    0x20(%rsp),%edi
call   11f0 <printError@plt>
lea    0xa1b(%rip),%rdi
xor    %eax,%eax
call   1120 <printf@plt>
mov    %ebx,%edi
mov    $0x1,%esi
lea    0x48(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
mov    %eax,0x20(%rsp)
mov    %eax,%edi
call   11f0 <printError@plt>
lea    0xa5d(%rip),%rdi
call   1070 <puts@plt>
lea    0x9ef(%rip),%rsi
mov    %ebx,0x54(%rsp)
mov    %ebx,%edi
mov    %rbp,%rdx
call   1200 <clCreateKernel@plt>
mov    %eax,%ebx
mov    0x24(%rsp),%eax
imul   %eax,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
mov    %rax,0x88(%rsp)
movq   $0x64,0x80(%rsp)
lea    0xa22(%rip),%rdi
call   1070 <puts@plt>
cmpl   $0x0,0x2c(%rsp)
jle    17ac <main+0x49c>
lea    0x30(%rsp),%rbp
lea    0x24(%rsp),%r15
lea    0x88(%rsp),%r14
lea    0x80(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x8,%edx
lea    0x40(%rsp),%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x20(%rsp)
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %rbp,%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x20(%rsp)
mov    %ebx,%edi
mov    $0x2,%esi
mov    $0x8,%edx
mov    %r15,%rcx
call   1220 <clSetKernelArg@plt>
mov    %eax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    0x3c(%rsp),%edi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r12,%r9
call   10f0 <clEnqueueNDRangeKernel@plt>
mov    %eax,0x20(%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,%r13d
cmp    0x2c(%rsp),%r13d
jl     1710 <main+0x400>
mov    $0x28,%edi
call   11a0 <malloc@plt>
mov    0x30(%rsp),%rsi
mov    0x2826(%rip),%rax
mov    (%rax),%edx
mov    0x24(%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    0x68(%rsp),%r14
mov    %r14,%r9
call   11b0 <clEnqueueReadBuffer@plt>
mov    %eax,0x20(%rsp)
mov    0x24(%rsp),%esi
mov    %r14,%rdi
call   1150 <dumpGrid@plt>
mov    %ebp,%edi
call   10a0 <clFlush@plt>
mov    %eax,0x20(%rsp)
mov    %ebp,%edi
call   1050 <clFinish@plt>
mov    %eax,0x20(%rsp)
mov    %ebx,%edi
call   1090 <clReleaseKernel@plt>
mov    %eax,0x20(%rsp)
mov    0x54(%rsp),%edi
call   10c0 <clReleaseProgram@plt>
mov    %eax,0x20(%rsp)
mov    0x40(%rsp),%rdi
call   11d0 <clReleaseMemObject@plt>
mov    %eax,0x20(%rsp)
mov    0x30(%rsp),%rdi
call   11d0 <clReleaseMemObject@plt>
mov    %eax,0x20(%rsp)
mov    %ebp,%edi
call   1190 <clReleaseCommandQueue@plt>
mov    %eax,0x20(%rsp)
mov    0x58(%rsp),%edi
call   11c0 <clReleaseContext@plt>
mov    %eax,0x20(%rsp)
mov    0x70(%rsp),%rdi
call   1040 <free@plt>
mov    %r14,%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    0x273c(%rip),%rax
mov    (%rax),%edi
lea    0x7b4(%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_READ_WRITE = 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 i32
%34 = alloca i32
%35 = alloca i64
%36 = alloca i64
%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 ([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* %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 i64 @malloc(i32 1048576)
%95 = inttoptr i64 %94 to i8*
store i8* %95, i8** %19
%96 = load i8*, i8** %19
%97 = load i32*, i32** %17
%98 = call i64 @fread(i8* %96, i32 1, i32 1048576, i32* %97)
store i64 %98, i64* %20
%99 = load i32*, i32** %17
%100 = call i32 @fclose(i32* %99)
%101 = load i32*, i32** %17
%102 = call i32 @fclose(i32* %101)
store i32* null, i32** %21
store i32* null, i32** %22
%103 = call i32 @clGetPlatformIDs(i32 1, i32** %21, i32* %24)
store i32 %103, i32* %25
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%105 = load i32*, i32** %21
%106 = load i32, i32* @CL_DEVICE_TYPE_DEFAULT
%107 = call i32 @clGetDeviceIDs(i32* %105, i32 %106, i32 1, i32** %22, i32* %23)
store i32 %107, i32* %25
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%109 = call i32 @clCreateContext(i32* null, i32 1, i32** %22, i32* null, i32* null, i32* %25)
store i32 %109, i32* %26
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%111 = load i32, i32* %26
%112 = load i32*, i32** %22
%113 = call i32 @clCreateCommandQueue(i32 %111, i32* %112, i32 0, i32* %25)
store i32 %113, i32* %27
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%115 = load i32, i32* %6
%116 = load i32, i32* %6
%117 = mul nsw i32 %115, %116
%118 = sext i32 %117 to i64
%119 = mul i64 %118, 4
%120 = trunc i64 %119 to i32
store i32 %120, i32* %28
%121 = load i32, i32* %26
%122 = load i32, i32* @CL_MEM_READ_WRITE
%123 = load i32, i32* %28
%124 = call i32* @clCreateBuffer(i32 %121, i32 %122, i32 %123, i32* null, i32* %25)
store i32* %124, i32** %29
%125 = load i32, i32* %25
%126 = call i32 @printError(i32 %125)
%127 = load i32, i32* %26
%128 = load i32, i32* @CL_MEM_READ_WRITE
%129 = load i32, i32* %28
%130 = call i32* @clCreateBuffer(i32 %127, i32 %128, i32 %129, i32* null, i32* %25)
store i32* %130, i32** %30
%131 = load i32, i32* %25
%132 = call i32 @printError(i32 %131)
%133 = load i32, i32* %26
%134 = load i32, i32* @CL_MEM_READ_ONLY
%135 = call i32* @clCreateBuffer(i32 %133, i32 %134, i32 4, i32* null, i32* %25)
store i32* %135, i32** %31
%136 = load i32, i32* %25
%137 = call i32 @printError(i32 %136)
store i32* null, i32** %32
%138 = load float*, float** %11
%139 = load float*, float** %12
%140 = load i32, i32* %6
%141 = call i32 @initGrid(float* %138, float* %139, i32 %140)
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
%143 = load i32, i32* %27
%144 = load i32*, i32** %30
%145 = load i32, i32* @CL_TRUE
%146 = load i32, i32* %28
%147 = load float*, float** %12
%148 = call i32 @clEnqueueWriteBuffer(i32 %143, i32* %144, i32 %145, i32 0, i32 %146, float* %147, i32 0, i32* null, i32* null)
store i32 %148, i32* %25
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
%150 = load i32, i32* %26
%151 = call i32 @clCreateProgramWithSource(i32 %150, i32 1, i8** %19, i64* %20, i32* %25)
store i32 %151, i32* %33
%152 = load i32, i32* %25
%153 = call i32 @printError(i32 %152)
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%155 = load i32, i32* %33
%156 = call i32 @clBuildProgram(i32 %155, i32 1, i32** %22, i32* null, i32* null, i32* null)
store i32 %156, i32* %25
%157 = load i32, i32* %25
%158 = call i32 @printError(i32 %157)
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
%160 = load i32, i32* %33
%161 = call i32 @clCreateKernel(i32 %160, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32* %25)
store i32 %161, i32* %34
%162 = load i32, i32* %6
%163 = load i32, i32* %6
%164 = mul nsw i32 %162, %163
%165 = load i32, i32* %16
%166 = load i32, i32* %16
%167 = mul nsw i32 %165, %166
%168 = sdiv i32 %164, %167
%169 = sext i32 %168 to i64
store i64 %169, i64* %35
%170 = load i32, i32* %16
%171 = load i32, i32* %16
%172 = mul nsw i32 %170, %171
%173 = sext i32 %172 to i64
store i64 %173, i64* %36
%174 = 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 %175
175: ; preds = %197, %93
%176 = load i32, i32* %14
%177 = load i32, i32* %7
%178 = icmp slt i32 %176, %177
br i1 %178, label %179, label %200
179: ; preds = %175
%180 = load i32, i32* %34
%181 = bitcast i32** %29 to i8*
%182 = call i32 @clSetKernelArg(i32 %180, i32 0, i32 8, i8* %181)
store i32 %182, i32* %25
%183 = load i32, i32* %34
%184 = bitcast i32** %30 to i8*
%185 = call i32 @clSetKernelArg(i32 %183, i32 1, i32 8, i8* %184)
store i32 %185, i32* %25
%186 = load i32, i32* %34
%187 = bitcast i32* %6 to i8*
%188 = call i32 @clSetKernelArg(i32 %186, i32 2, i32 8, i8* %187)
store i32 %188, i32* %25
%189 = load i32, i32* %27
%190 = load i32, i32* %34
%191 = call i32 @clEnqueueNDRangeKernel(i32 %189, i32 %190, i32 1, i32* null, i64* %35, i64* %36, i32 0, i32* null, i32* null)
store i32 %191, i32* %25
%192 = load i32, i32* %25
%193 = call i32 @printError(i32 %192)
%194 = load i32*, i32** %29
store i32* %194, i32** %32
%195 = load i32*, i32** %30
store i32* %195, i32** %29
%196 = load i32*, i32** %32
store i32* %196, i32** %30
br label %197
197: ; preds = %179
%198 = load i32, i32* %14
%199 = add nsw i32 %198, 1
store i32 %199, i32* %14
br label %175
200: ; preds = %175
%201 = load i32, i32* %16
%202 = sext i32 %201 to i64
%203 = mul i64 4, %202
%204 = trunc i64 %203 to i32
%205 = call i64 @malloc(i32 %204)
%206 = inttoptr i64 %205 to i32*
store i32* %206, i32** %37
%207 = load i32, i32* %27
%208 = load i32*, i32** %30
%209 = load i32, i32* @CL_TRUE
%210 = load i32, i32* %6
%211 = load i32, i32* %6
%212 = mul nsw i32 %210, %211
%213 = sext i32 %212 to i64
%214 = mul i64 %213, 4
%215 = trunc i64 %214 to i32
%216 = load float*, float** %12
%217 = call i32 @clEnqueueReadBuffer(i32 %207, i32* %208, i32 %209, i32 0, i32 %215, float* %216, i32 0, i32* null, i32* null)
store i32 %217, i32* %25
%218 = load float*, float** %12
%219 = load i32, i32* %6
%220 = call i32 @dumpGrid(float* %218, i32 %219)
%221 = load i32, i32* %27
%222 = call i32 @clFlush(i32 %221)
store i32 %222, i32* %25
%223 = load i32, i32* %27
%224 = call i32 @clFinish(i32 %223)
store i32 %224, i32* %25
%225 = load i32, i32* %34
%226 = call i32 @clReleaseKernel(i32 %225)
store i32 %226, i32* %25
%227 = load i32, i32* %33
%228 = call i32 @clReleaseProgram(i32 %227)
store i32 %228, i32* %25
%229 = load i32*, i32** %29
%230 = call i32 @clReleaseMemObject(i32* %229)
store i32 %230, i32* %25
%231 = load i32*, i32** %30
%232 = call i32 @clReleaseMemObject(i32* %231)
store i32 %232, i32* %25
%233 = load i32, i32* %27
%234 = call i32 @clReleaseCommandQueue(i32 %233)
store i32 %234, i32* %25
%235 = load i32, i32* %26
%236 = call i32 @clReleaseContext(i32 %235)
store i32 %236, i32* %25
%237 = load float*, float** %11
%238 = call i32 @free(float* %237)
%239 = load float*, float** %12
%240 = call i32 @free(float* %239)
%241 = load i32, i32* %3
ret i32 %241
}

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_READ_WRITE = 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 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 ([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))
%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 i64 @malloc(i32 1048576)
%73 = inttoptr i64 %72 to i8*
store i8* %73, i8** %9
%74 = call i64 @fread(i8* %73, i32 1, i32 1048576, i32* %30)
store i64 %74, i64* %10
%75 = call i32 @fclose(i32* %30)
%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, 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.16, 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.17, 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.18, 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.19, i64 0, i64 0))
%113 = load i32, i32* @CL_TRUE
%114 = call i32 @clEnqueueWriteBuffer(i32 %91, i32* %103, i32 %113, i32 0, i32 %95, float* %45, i32 0, i32* null, i32* null)
store i32 %114, i32* %15
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
%116 = call i32 @clCreateProgramWithSource(i32 %88, i32 1, i8** %9, i64* %10, i32* %15)
%117 = load i32, i32* %15
%118 = call i32 @printError(i32 %117)
%119 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%120 = call i32 @clBuildProgram(i32 %116, i32 1, i32** %12, i32* null, i32* null, i32* null)
store i32 %120, i32* %15
%121 = call i32 @printError(i32 %120)
%122 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.20, i64 0, i64 0))
%123 = call i32 @clCreateKernel(i32 %116, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32* %15)
%124 = bitcast i64* %18 to i8*
%125 = load i32, i32* %3
%126 = mul nsw i32 %125, %125
%127 = udiv i32 %126, 100
%128 = zext i32 %127 to i64
store i64 %128, i64* %18
%129 = bitcast i64* %19 to i8*
store i64 100, i64* %19
%130 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.21, i64 0, i64 0))
%131 = load i32, i32* %4
%132 = icmp sgt i32 %131, 0
br i1 %132, label %133, label %145
133: ; preds = %71, %133
%134 = phi i32 [ %142, %133 ], [ 0, %71 ]
%135 = call i32 @clSetKernelArg(i32 %123, i32 0, i32 8, i8* %96)
store i32 %135, i32* %15
%136 = call i32 @clSetKernelArg(i32 %123, i32 1, i32 8, i8* %101)
store i32 %136, i32* %15
%137 = call i32 @clSetKernelArg(i32 %123, i32 2, i32 8, i8* %20)
store i32 %137, i32* %15
%138 = call i32 @clEnqueueNDRangeKernel(i32 %91, i32 %123, i32 1, i32* null, i64* %18, i64* %19, i32 0, i32* null, i32* null)
store i32 %138, i32* %15
%139 = call i32 @printError(i32 %138)
%140 = load i32*, i32** %16
%141 = load i32*, i32** %17
store i32* %141, i32** %16
store i32* %140, i32** %17
%142 = add nuw nsw i32 %134, 1
%143 = load i32, i32* %4
%144 = icmp slt i32 %142, %143
br i1 %144, label %133, label %145
145: ; preds = %133, %71
%146 = call i64 @malloc(i32 40)
%147 = load i32*, i32** %17
%148 = load i32, i32* @CL_TRUE
%149 = load i32, i32* %3
%150 = shl i32 %149, 2
%151 = mul i32 %150, %149
%152 = call i32 @clEnqueueReadBuffer(i32 %91, i32* %147, i32 %148, i32 0, i32 %151, float* %45, i32 0, i32* null, i32* null)
store i32 %152, i32* %15
%153 = load i32, i32* %3
%154 = call i32 @dumpGrid(float* %45, i32 %153)
%155 = call i32 @clFlush(i32 %91)
store i32 %155, i32* %15
%156 = call i32 @clFinish(i32 %91)
store i32 %156, i32* %15
%157 = call i32 @clReleaseKernel(i32 %123)
store i32 %157, i32* %15
%158 = call i32 @clReleaseProgram(i32 %116)
store i32 %158, i32* %15
%159 = load i32*, i32** %16
%160 = call i32 @clReleaseMemObject(i32* %159)
store i32 %160, i32* %15
%161 = load i32*, i32** %17
%162 = call i32 @clReleaseMemObject(i32* %161)
store i32 %162, i32* %15
%163 = call i32 @clReleaseCommandQueue(i32 %91)
store i32 %163, i32* %15
%164 = call i32 @clReleaseContext(i32 %88)
store i32 %164, i32* %15
%165 = call i32 @free(float* %41)
%166 = call i32 @free(float* %45)
ret i32 0
}