#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ kernel_code;
typedef int cl_uint;
typedef int /*<<< orphan*/ cl_program;
typedef int /*<<< orphan*/ cl_platform_id;
typedef unsigned int cl_mem;
typedef int /*<<< orphan*/ cl_kernel;
typedef int /*<<< orphan*/ cl_event;
typedef int /*<<< orphan*/ cl_device_id;
typedef int /*<<< orphan*/ cl_context_properties;
typedef int /*<<< orphan*/ cl_context;
typedef int /*<<< orphan*/ cl_command_queue;

/* Variables and functions */
int /*<<< orphan*/ CL_CONTEXT_PLATFORM;
int /*<<< orphan*/ CL_DEVICE_TYPE_ACCELERATOR;
int /*<<< orphan*/ CL_MEM_USE_HOST_PTR;
int /*<<< orphan*/ CL_PLATFORM_NAME;
int /*<<< orphan*/ CL_TRUE;
int /*<<< orphan*/ clBuildProgram(int /*<<< orphan*/, int, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/, int /*<<< orphan*/,
                                  int /*<<< orphan*/);
unsigned int clCreateBuffer(int /*<<< orphan*/, int /*<<< orphan*/, size_t,
                            float *, int *);
int /*<<< orphan*/ clCreateCommandQueue(int /*<<< orphan*/, int /*<<< orphan*/,
                                        int /*<<< orphan*/, int *);
int /*<<< orphan*/ clCreateContext(int /*<<< orphan*/ *, int,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   int /*<<< orphan*/, int *);
int /*<<< orphan*/ clCreateKernel(int /*<<< orphan*/, char *, int *);
int /*<<< orphan*/ clCreateProgramWithSource(int /*<<< orphan*/, int,
                                             char const **, size_t *, int *);
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*/, unsigned int,
                                       int /*<<< orphan*/, int /*<<< orphan*/,
                                       size_t, float *, int /*<<< orphan*/,
                                       int /*<<< orphan*/,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ clGetPlatformIDs(int, int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ clGetPlatformInfo(int /*<<< orphan*/, int /*<<< orphan*/,
                                     int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseCommandQueue(int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseContext(int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseEvent(int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseKernel(int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseMemObject(unsigned int);
int /*<<< orphan*/ clReleaseProgram(int /*<<< orphan*/);
int /*<<< orphan*/ clSetKernelArg(int /*<<< orphan*/, int, int, unsigned int *);
int clWaitForEvents(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int main() {
  int i, j;
  int err;
  char buffer[256];
  unsigned int n = 1024;
  cl_uint nplatforms;
  cl_platform_id *platforms;
  cl_platform_id platform;
  clGetPlatformIDs(0, 0, &nplatforms);
  platforms = (cl_platform_id *)malloc(nplatforms * sizeof(cl_platform_id));
  clGetPlatformIDs(nplatforms, platforms, 0);
  for (i = 0; i < nplatforms; i++) {
    platform = platforms[i];
    clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 256, buffer, 0);
    if (!strcmp(buffer, "coprthr-e"))
      break;
  }
  if (i < nplatforms)
    platform = platforms[i];
  else
    exit(1);
  cl_uint ndevices;
  cl_device_id *devices;
  cl_device_id dev;
  clGetDeviceIDs(platform, CL_DEVICE_TYPE_ACCELERATOR, 0, 0, &ndevices);
  devices = (cl_device_id *)malloc(ndevices * sizeof(cl_device_id));
  clGetDeviceIDs(platform, CL_DEVICE_TYPE_ACCELERATOR, ndevices, devices, 0);
  if (ndevices)
    dev = devices[0];
  else
    exit(1);
  cl_context_properties ctxprop[3] = {
      (cl_context_properties)CL_CONTEXT_PLATFORM,
      (cl_context_properties)platform, (cl_context_properties)0};
  cl_context ctx = clCreateContext(ctxprop, 1, &dev, 0, 0, &err);
  cl_command_queue cmdq = clCreateCommandQueue(ctx, dev, 0, &err);
  size_t aa_sz = n * n * sizeof(float);
  size_t b_sz = n * sizeof(float);
  size_t c_sz = n * sizeof(float);
  float *aa = (float *)malloc(n * n * sizeof(float));
  float *b = (float *)malloc(n * sizeof(float));
  float *c = (float *)malloc(n * sizeof(float));
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      aa[i * n + j] = 1.1f * i * j;
  for (i = 0; i < n; i++)
    b[i] = 2.2f * i;
  for (i = 0; i < n; i++)
    c[i] = 0.0f;
  cl_mem aa_buf = clCreateBuffer(ctx, CL_MEM_USE_HOST_PTR, aa_sz, aa, &err);
  cl_mem b_buf = clCreateBuffer(ctx, CL_MEM_USE_HOST_PTR, b_sz, b, &err);
  cl_mem c_buf = clCreateBuffer(ctx, CL_MEM_USE_HOST_PTR, c_sz, c, &err);
  const char kernel_code[] =
      "__kernel void matvecmult_kern(\n"
      "   uint n,__global float* aa,__global float* b,__global float* c )\n"
      "{\n"
      "   int i = get_global_id(0);\n"
      "   int j;\n"
      "   float tmp = 0.0f;\n"
      "   for(j=0;j<n;j++) tmp += aa[i*n+j] * b[j];\n"
      "   c[i] = aa[i*n+i];\n"
      "}\n";
  const char *src[1] = {kernel_code};
  size_t src_sz = sizeof(kernel_code);
  cl_program prg =
      clCreateProgramWithSource(ctx, 1, (const char **)&src, &src_sz, &err);
  clBuildProgram(prg, 1, &dev, 0, 0, 0);
  cl_kernel krn = clCreateKernel(prg, "matvecmult_kern", &err);
  clSetKernelArg(krn, 0, sizeof(cl_uint), &n);
  clSetKernelArg(krn, 1, sizeof(cl_mem), &aa_buf);
  clSetKernelArg(krn, 2, sizeof(cl_mem), &b_buf);
  clSetKernelArg(krn, 3, sizeof(cl_mem), &c_buf);
  size_t gtdsz[] = {n};
  size_t ltdsz[] = {16};
  cl_event ev[10];
  clEnqueueNDRangeKernel(cmdq, krn, 1, 0, gtdsz, ltdsz, 0, 0, &ev[0]);
  clEnqueueReadBuffer(cmdq, c_buf, CL_TRUE, 0, c_sz, c, 0, 0, &ev[1]);
  err = clWaitForEvents(2, ev);
  for (i = 0; i < n; i++)
    printf("c[%d] %f\n", i, c[i]);
  printf("clWaitForEvents returned %d\n", err);
  clReleaseEvent(ev[1]);
  clReleaseEvent(ev[0]);
  clReleaseKernel(krn);
  clReleaseProgram(prg);
  clReleaseMemObject(aa_buf);
  clReleaseMemObject(b_buf);
  clReleaseMemObject(c_buf);
  clReleaseCommandQueue(cmdq);
  clReleaseContext(ctx);
  free(aa);
  free(b);
  free(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2e0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x400,-0x114(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x118(%rbp),%rdx
call   10c0 <clGetPlatformIDs@plt>
movslq -0x118(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1130 <malloc@plt>
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%edi
mov    -0x120(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10c0 <clGetPlatformIDs@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x118(%rbp),%eax
jge    1376 <main+0xe6>
mov    -0x120(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x124(%rbp)
mov    -0x120(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    0x2ca4(%rip),%rax
mov    (%rax),%esi
lea    -0x110(%rbp),%rcx
mov    $0x100,%edx
xor    %r8d,%r8d
call   10e0 <clGetPlatformInfo@plt>
lea    -0x110(%rbp),%rdi
lea    0xcb8(%rip),%rsi
call   1100 <strcmp@plt>
cmp    $0x0,%eax
jne    1363 <main+0xd3>
jmp    1376 <main+0xe6>
jmp    1368 <main+0xd8>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12f4 <main+0x64>
mov    -0x8(%rbp),%eax
cmp    -0x118(%rbp),%eax
jge    139e <main+0x10e>
mov    -0x120(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x124(%rbp)
jmp    13a8 <main+0x118>
mov    $0x1,%edi
call   11a0 <exit@plt>
mov    -0x124(%rbp),%edi
mov    0x2c0b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x128(%rbp),%r8
call   1090 <clGetDeviceIDs@plt>
movslq -0x128(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1130 <malloc@plt>
mov    %rax,-0x130(%rbp)
mov    -0x124(%rbp),%edi
mov    0x2bd1(%rip),%rax
mov    (%rax),%esi
mov    -0x128(%rbp),%edx
mov    -0x130(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <clGetDeviceIDs@plt>
cmpl   $0x0,-0x128(%rbp)
je     1429 <main+0x199>
mov    -0x130(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
jmp    1433 <main+0x1a3>
mov    $0x1,%edi
call   11a0 <exit@plt>
mov    0x2b8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x140(%rbp)
mov    -0x124(%rbp),%eax
mov    %eax,-0x13c(%rbp)
movl   $0x0,-0x138(%rbp)
lea    -0x140(%rbp),%rdi
mov    $0x1,%esi
lea    -0x134(%rbp),%rdx
xor    %r8d,%r8d
lea    -0x10(%rbp),%r9
mov    %r8d,%ecx
call   10f0 <clCreateContext@plt>
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%edi
mov    -0x134(%rbp),%esi
xor    %edx,%edx
lea    -0x10(%rbp),%rcx
call   10b0 <clCreateCommandQueue@plt>
mov    %eax,-0x148(%rbp)
mov    -0x114(%rbp),%eax
imul   -0x114(%rbp),%eax
mov    %eax,%eax
shl    $0x2,%rax
mov    %rax,-0x150(%rbp)
mov    -0x114(%rbp),%eax
shl    $0x2,%rax
mov    %rax,-0x158(%rbp)
mov    -0x114(%rbp),%eax
shl    $0x2,%rax
mov    %rax,-0x160(%rbp)
mov    -0x114(%rbp),%eax
imul   -0x114(%rbp),%eax
mov    %eax,%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1130 <malloc@plt>
mov    %rax,-0x168(%rbp)
mov    -0x114(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1130 <malloc@plt>
mov    %rax,-0x170(%rbp)
mov    -0x114(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1130 <malloc@plt>
mov    %rax,-0x178(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x114(%rbp),%eax
jae    15ac <main+0x31c>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x114(%rbp),%eax
jae    1599 <main+0x309>
cvtsi2ssl -0x8(%rbp),%xmm1
movss  0xaa1(%rip),%xmm0
mulss  %xmm1,%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
mulss  %xmm1,%xmm0
mov    -0x168(%rbp),%rax
mov    -0x8(%rbp),%ecx
imul   -0x114(%rbp),%ecx
add    -0xc(%rbp),%ecx
mov    %ecx,%ecx
movss  %xmm0,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1547 <main+0x2b7>
jmp    159e <main+0x30e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1531 <main+0x2a1>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x114(%rbp),%eax
jae    15f1 <main+0x361>
cvtsi2ssl -0x8(%rbp),%xmm1
movss  0xa31(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    -0x170(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    15b3 <main+0x323>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x114(%rbp),%eax
jae    1628 <main+0x398>
mov    -0x178(%rbp),%rax
movslq -0x8(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    15f8 <main+0x368>
mov    -0x144(%rbp),%edi
mov    0x29ab(%rip),%rax
mov    (%rax),%esi
mov    -0x150(%rbp),%rdx
mov    -0x168(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,-0x17c(%rbp)
mov    -0x144(%rbp),%edi
mov    0x297f(%rip),%rax
mov    (%rax),%esi
mov    -0x158(%rbp),%rdx
mov    -0x170(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,-0x180(%rbp)
mov    -0x144(%rbp),%edi
mov    0x2953(%rip),%rax
mov    (%rax),%esi
mov    -0x160(%rbp),%rdx
mov    -0x178(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,-0x184(%rbp)
lea    -0x270(%rbp),%rdi
lea    0x996(%rip),%rsi
mov    $0xe5,%edx
call   1110 <memcpy@plt>
lea    -0x270(%rbp),%rax
mov    %rax,-0x278(%rbp)
movq   $0xe5,-0x280(%rbp)
mov    -0x144(%rbp),%edi
lea    -0x278(%rbp),%rdx
mov    $0x1,%esi
lea    -0x280(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1050 <clCreateProgramWithSource@plt>
mov    %eax,-0x284(%rbp)
mov    -0x284(%rbp),%edi
mov    $0x1,%esi
lea    -0x134(%rbp),%rdx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1030 <clBuildProgram@plt>
mov    -0x284(%rbp),%edi
lea    0x8e0(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1190 <clCreateKernel@plt>
mov    %eax,-0x288(%rbp)
mov    -0x288(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
lea    -0x114(%rbp),%rcx
call   11b0 <clSetKernelArg@plt>
mov    -0x288(%rbp),%edi
mov    $0x1,%esi
mov    $0x4,%edx
lea    -0x17c(%rbp),%rcx
call   11b0 <clSetKernelArg@plt>
mov    -0x288(%rbp),%edi
mov    $0x2,%esi
mov    $0x4,%edx
lea    -0x180(%rbp),%rcx
call   11b0 <clSetKernelArg@plt>
mov    -0x288(%rbp),%edi
mov    $0x3,%esi
mov    $0x4,%edx
lea    -0x184(%rbp),%rcx
call   11b0 <clSetKernelArg@plt>
mov    -0x114(%rbp),%eax
mov    %rax,-0x290(%rbp)
mov    0x976(%rip),%rax
mov    %rax,-0x298(%rbp)
mov    -0x148(%rbp),%edi
mov    -0x288(%rbp),%esi
lea    -0x290(%rbp),%r8
lea    -0x298(%rbp),%r9
lea    -0x2c0(%rbp),%rax
mov    $0x1,%edx
xor    %ecx,%ecx
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   10a0 <clEnqueueNDRangeKernel@plt>
mov    -0x148(%rbp),%edi
mov    -0x184(%rbp),%esi
mov    0x27cb(%rip),%rax
mov    (%rax),%edx
mov    -0x160(%rbp),%r8
mov    -0x178(%rbp),%r9
lea    -0x2c0(%rbp),%rax
add    $0x4,%rax
xor    %ecx,%ecx
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1140 <clEnqueueReadBuffer@plt>
lea    -0x2c0(%rbp),%rsi
mov    $0x2,%edi
call   1180 <clWaitForEvents@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x114(%rbp),%eax
jae    18b0 <main+0x620>
mov    -0x8(%rbp),%esi
mov    -0x178(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x787(%rip),%rdi
mov    $0x1,%al
call   10d0 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    186e <main+0x5de>
mov    -0x10(%rbp),%esi
lea    0x772(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    -0x2bc(%rbp),%edi
call   1170 <clReleaseEvent@plt>
mov    -0x2c0(%rbp),%edi
call   1170 <clReleaseEvent@plt>
mov    -0x288(%rbp),%edi
call   1060 <clReleaseKernel@plt>
mov    -0x284(%rbp),%edi
call   1080 <clReleaseProgram@plt>
mov    -0x17c(%rbp),%edi
call   1160 <clReleaseMemObject@plt>
mov    -0x180(%rbp),%edi
call   1160 <clReleaseMemObject@plt>
mov    -0x184(%rbp),%edi
call   1160 <clReleaseMemObject@plt>
mov    -0x148(%rbp),%edi
call   1120 <clReleaseCommandQueue@plt>
mov    -0x144(%rbp),%edi
call   1150 <clReleaseContext@plt>
mov    -0x168(%rbp),%rdi
call   1040 <free@plt>
mov    -0x170(%rbp),%rdi
call   1040 <free@plt>
mov    -0x178(%rbp),%rdi
call   1040 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x2e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x278,%rsp
movl   $0x400,0x8(%rsp)
xor    %ebp,%ebp
lea    0x4(%rsp),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   10c0 <clGetPlatformIDs@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1130 <malloc@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%edi
mov    %rax,%rsi
xor    %edx,%edx
call   10c0 <clGetPlatformIDs@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1346 <main+0xb6>
xor    %ebp,%ebp
mov    0x2ce9(%rip),%r15
lea    0x90(%rsp),%r14
movabs $0x2d72687472706f63,%r12
68 72 2d
nopl   0x0(%rax)
mov    (%rbx,%rbp,4),%edi
mov    (%r15),%esi
mov    $0x100,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   10f0 <clGetPlatformInfo@plt>
mov    0x90(%rsp),%rax
xor    %r12,%rax
movzwl 0x98(%rsp),%ecx
xor    $0x65,%rcx
or     %rax,%rcx
je     1342 <main+0xb2>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
cmp    %rax,%rbp
jl     1300 <main+0x70>
jmp    1346 <main+0xb6>
mov    0x4(%rsp),%eax
cmp    %eax,%ebp
jge    17d4 <main+0x544>
mov    %ebp,%eax
mov    (%rbx,%rax,4),%r14d
mov    0x2c65(%rip),%r15
mov    (%r15),%esi
xor    %ebx,%ebx
lea    0x14(%rsp),%r8
mov    %r14d,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1090 <clGetDeviceIDs@plt>
mov    0x14(%rsp),%edi
shl    $0x2,%edi
call   1130 <malloc@plt>
mov    %rax,%rbp
mov    (%r15),%esi
mov    0x14(%rsp),%edx
mov    %r14d,%edi
mov    %rax,%rcx
xor    %r8d,%r8d
call   1090 <clGetDeviceIDs@plt>
cmpl   $0x0,0x14(%rsp)
je     17d4 <main+0x544>
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x2c1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    %r14d,0x30(%rsp)
movl   $0x0,0x34(%rsp)
lea    0x2c(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0x18(%rsp),%rbp
mov    $0x1,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rbp,%r9
call   1100 <clCreateContext@plt>
mov    %eax,%r15d
mov    0x10(%rsp),%esi
mov    %eax,%edi
xor    %edx,%edx
mov    %rbp,%rcx
call   10b0 <clCreateCommandQueue@plt>
mov    %eax,0x1c(%rsp)
mov    $0x400000,%edi
call   1130 <malloc@plt>
mov    %rax,%r13
mov    $0x1000,%edi
call   1130 <malloc@plt>
mov    %rax,%rbp
mov    $0x1000,%edi
call   1130 <malloc@plt>
mov    %rax,%r12
mov    %r13,%rax
add    $0x10,%rax
movss  0xbd1(%rip),%xmm0
movdqa 0xbd9(%rip),%xmm1
movdqa 0xbe1(%rip),%xmm2
nop
xorps  %xmm3,%xmm3
cvtsi2ss %ebx,%xmm3
mulss  %xmm0,%xmm3
shufps $0x0,%xmm3,%xmm3
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movd   %ecx,%xmm4
lea    0x1(%rcx),%edx
pshufd $0x50,%xmm4,%xmm5
por    %xmm1,%xmm5
movd   %edx,%xmm6
pshufd $0x0,%xmm4,%xmm7
punpckldq %xmm6,%xmm4
punpcklqdq %xmm5,%xmm4
por    %xmm2,%xmm7
cvtdq2ps %xmm4,%xmm4
cvtdq2ps %xmm7,%xmm5
mulps  %xmm3,%xmm4
mulps  %xmm3,%xmm5
movups %xmm4,-0x10(%rax,%rcx,4)
movups %xmm5,(%rax,%rcx,4)
add    $0x8,%rcx
cmp    $0x400,%rcx
jne    1460 <main+0x1d0>
add    $0x1,%ebx
add    $0x1000,%rax
cmp    $0x400,%ebx
jne    1440 <main+0x1b0>
movdqa 0xb70(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xb73(%rip),%xmm1
movaps 0xb7c(%rip),%xmm2
movdqa 0xb84(%rip),%xmm3
movdqa 0xb8c(%rip),%xmm4
movdqa 0xb94(%rip),%xmm5
nopl   0x0(%rax)
movdqa %xmm0,%xmm6
paddd  %xmm1,%xmm6
cvtdq2ps %xmm0,%xmm7
cvtdq2ps %xmm6,%xmm6
mulps  %xmm2,%xmm7
mulps  %xmm2,%xmm6
movups %xmm7,-0x30(%rbp,%rax,4)
movups %xmm6,-0x20(%rbp,%rax,4)
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
movdqa %xmm0,%xmm7
paddd  %xmm4,%xmm7
cvtdq2ps %xmm6,%xmm6
cvtdq2ps %xmm7,%xmm7
mulps  %xmm2,%xmm6
mulps  %xmm2,%xmm7
movups %xmm6,-0x10(%rbp,%rax,4)
movups %xmm7,0x0(%rbp,%rax,4)
paddd  %xmm5,%xmm0
add    $0x10,%rax
cmp    $0x40c,%rax
jne    14f0 <main+0x260>
mov    $0x1000,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10e0 <memset@plt>
mov    0x2a86(%rip),%rbx
mov    (%rbx),%esi
lea    0x18(%rsp),%r14
mov    $0x400000,%edx
mov    %r15d,%edi
mov    %r13,0x38(%rsp)
mov    %r13,%rcx
mov    %r14,%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,0x24(%rsp)
mov    (%rbx),%esi
mov    $0x1000,%edx
mov    %r15d,%edi
mov    %rbp,%rcx
mov    %r14,%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,0x20(%rsp)
mov    (%rbx),%esi
mov    $0x1000,%edx
mov    %r15d,%edi
mov    %r12,%rcx
mov    %r14,%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,0xc(%rsp)
lea    0xb2a(%rip),%rsi
lea    0x190(%rsp),%rbx
mov    $0xe5,%edx
mov    %rbx,%rdi
call   1110 <memcpy@plt>
mov    %rbx,0x58(%rsp)
movq   $0xe5,0x50(%rsp)
lea    0x58(%rsp),%rdx
lea    0x50(%rsp),%rcx
mov    %r15d,0x28(%rsp)
mov    %r15d,%edi
mov    $0x1,%esi
mov    %r14,%r8
call   1050 <clCreateProgramWithSource@plt>
mov    %eax,%r13d
lea    0x10(%rsp),%rdx
mov    %eax,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
lea    0xa7f(%rip),%rsi
mov    %r13d,%edi
mov    %r14,%rdx
call   1190 <clCreateKernel@plt>
mov    %eax,%r14d
lea    0x8(%rsp),%rcx
mov    %eax,%edi
xor    %esi,%esi
mov    $0x4,%edx
call   11b0 <clSetKernelArg@plt>
lea    0x24(%rsp),%rcx
mov    %r14d,%edi
mov    $0x1,%esi
mov    $0x4,%edx
call   11b0 <clSetKernelArg@plt>
lea    0x20(%rsp),%rcx
mov    %r14d,%edi
mov    $0x2,%esi
mov    $0x4,%edx
call   11b0 <clSetKernelArg@plt>
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x3,%esi
mov    $0x4,%edx
call   11b0 <clSetKernelArg@plt>
mov    0x8(%rsp),%eax
mov    %rax,0x48(%rsp)
movq   $0x10,0x40(%rsp)
sub    $0x8,%rsp
lea    0x68(%rsp),%r15
lea    0x50(%rsp),%r8
lea    0x48(%rsp),%r9
mov    0x24(%rsp),%ebx
mov    %ebx,%edi
mov    %r14d,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
push   %r15
push   $0x0
push   $0x0
call   10a0 <clEnqueueNDRangeKernel@plt>
add    $0x20,%rsp
mov    0xc(%rsp),%esi
mov    0x2918(%rip),%rax
mov    (%rax),%edx
lea    0x64(%rsp),%rax
sub    $0x8,%rsp
mov    $0x1000,%r8d
mov    %ebx,%edi
xor    %ecx,%ecx
mov    %r12,%r9
push   %rax
push   $0x0
push   $0x0
call   1140 <clEnqueueReadBuffer@plt>
add    $0x20,%rsp
mov    $0x2,%edi
mov    %r15,%rsi
call   1180 <clWaitForEvents@plt>
mov    %eax,0x18(%rsp)
cmpl   $0x0,0x8(%rsp)
je     1747 <main+0x4b7>
xor    %ebx,%ebx
lea    0x993(%rip),%r15
nopw   0x0(%rax,%rax,1)
movss  (%r12,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   10d0 <printf@plt>
add    $0x1,%rbx
mov    0x8(%rsp),%eax
cmp    %rax,%rbx
jb     1720 <main+0x490>
mov    0x18(%rsp),%eax
lea    0x966(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10d0 <printf@plt>
mov    0x64(%rsp),%edi
call   1170 <clReleaseEvent@plt>
mov    0x60(%rsp),%edi
call   1170 <clReleaseEvent@plt>
mov    %r14d,%edi
call   1060 <clReleaseKernel@plt>
mov    %r13d,%edi
call   1080 <clReleaseProgram@plt>
mov    0x24(%rsp),%edi
call   1160 <clReleaseMemObject@plt>
mov    0x20(%rsp),%edi
call   1160 <clReleaseMemObject@plt>
mov    0xc(%rsp),%edi
call   1160 <clReleaseMemObject@plt>
mov    0x1c(%rsp),%edi
call   1120 <clReleaseCommandQueue@plt>
mov    0x28(%rsp),%edi
call   1150 <clReleaseContext@plt>
mov    0x38(%rsp),%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x278,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   11a0 <exit@plt>

LLVM IR (-O0):
@CL_PLATFORM_NAME = global i32 0
@.str = [10 x i8] c"coprthr-e\00"
@CL_DEVICE_TYPE_ACCELERATOR = global i32 0
@CL_CONTEXT_PLATFORM = global i32 0
@CL_MEM_USE_HOST_PTR = global i32 0
@__const.main.kernel_code = [229 x i8] c"__kernel void matvecmult_kern(\0A uint n,__global float* aa,__global float* b,__global float* c )\0A{\0A int i = get_global_id(0);\0A int j;\0A float tmp = 0.0f;\0A for(j=0;j<n;j++) tmp += aa[i*n+j] * b[j];\0A c[i] = aa[i*n+i];\0A}\0A\00"
@.str.1 = [16 x i8] c"matvecmult_kern\00"
@__const.main.ltdsz = [1 x i64] [i64 16]
@CL_TRUE = global i32 0
@.str.2 = [10 x i8] c"c[%d] %f\0A\00"
@.str.3 = [29 x i8] c"clWaitForEvents returned %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca [3 x i32]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca float*
%20 = alloca float*
%21 = alloca float*
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca [229 x i8]
%26 = alloca [1 x i8*]
%27 = alloca i64
%28 = alloca i32
%29 = alloca i32
%30 = alloca [1 x i64]
%31 = alloca [1 x i64]
%32 = alloca [10 x i32]
store i32 0, i32* %1
store i32 1024, i32* %6
%33 = call i32 @clGetPlatformIDs(i32 0, i32* null, i32* %7)
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 4
%37 = trunc i64 %36 to i32
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i32*
store i32* %39, i32** %8
%40 = load i32, i32* %7
%41 = load i32*, i32** %8
%42 = call i32 @clGetPlatformIDs(i32 %40, i32* %41, i32* null)
store i32 0, i32* %2
br label %43
43: ; preds = %66, %0
%44 = load i32, i32* %2
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %69
47: ; preds = %43
%48 = load i32*, i32** %8
%49 = load i32, i32* %2
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
%52 = load i32, i32* %51
store i32 %52, i32* %9
%53 = load i32*, i32** %8
%54 = load i32, i32* %2
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = load i32, i32* @CL_PLATFORM_NAME
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%60 = call i32 @clGetPlatformInfo(i32 %57, i32 %58, i32 256, i8* %59, i32 0)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%62 = call i32 @strcmp(i8* %61, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%63 = icmp ne i32 %62, 0
br i1 %63, label %65, label %64
64: ; preds = %47
br label %69
65: ; preds = %47
br label %66
66: ; preds = %65
%67 = load i32, i32* %2
%68 = add nsw i32 %67, 1
store i32 %68, i32* %2
br label %43
69: ; preds = %64, %43
%70 = load i32, i32* %2
%71 = load i32, i32* %7
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %79
73: ; preds = %69
%74 = load i32*, i32** %8
%75 = load i32, i32* %2
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %74, i64 %76
%78 = load i32, i32* %77
store i32 %78, i32* %9
br label %81
79: ; preds = %69
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %73
%82 = load i32, i32* %9
%83 = load i32, i32* @CL_DEVICE_TYPE_ACCELERATOR
%84 = call i32 @clGetDeviceIDs(i32 %82, i32 %83, i32 0, i32* null, i32* %10)
%85 = load i32, i32* %10
%86 = sext i32 %85 to i64
%87 = mul i64 %86, 4
%88 = trunc i64 %87 to i32
%89 = call i64 @malloc(i32 %88)
%90 = inttoptr i64 %89 to i32*
store i32* %90, i32** %11
%91 = load i32, i32* %9
%92 = load i32, i32* @CL_DEVICE_TYPE_ACCELERATOR
%93 = load i32, i32* %10
%94 = load i32*, i32** %11
%95 = call i32 @clGetDeviceIDs(i32 %91, i32 %92, i32 %93, i32* %94, i32* null)
%96 = load i32, i32* %10
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %102
98: ; preds = %81
%99 = load i32*, i32** %11
%100 = getelementptr inbounds i32, i32* %99, i64 0
%101 = load i32, i32* %100
store i32 %101, i32* %12
br label %104
102: ; preds = %81
%103 = call i32 @exit(i32 1)
unreachable
104: ; preds = %98
%105 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
%106 = load i32, i32* @CL_CONTEXT_PLATFORM
store i32 %106, i32* %105
%107 = getelementptr inbounds i32, i32* %105, i64 1
%108 = load i32, i32* %9
store i32 %108, i32* %107
%109 = getelementptr inbounds i32, i32* %107, i64 1
store i32 0, i32* %109
%110 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
%111 = call i32 @clCreateContext(i32* %110, i32 1, i32* %12, i32 0, i32 0, i32* %4)
store i32 %111, i32* %14
%112 = load i32, i32* %14
%113 = load i32, i32* %12
%114 = call i32 @clCreateCommandQueue(i32 %112, i32 %113, i32 0, i32* %4)
store i32 %114, i32* %15
%115 = load i32, i32* %6
%116 = load i32, i32* %6
%117 = mul i32 %115, %116
%118 = zext i32 %117 to i64
%119 = mul i64 %118, 4
store i64 %119, i64* %16
%120 = load i32, i32* %6
%121 = zext i32 %120 to i64
%122 = mul i64 %121, 4
store i64 %122, i64* %17
%123 = load i32, i32* %6
%124 = zext i32 %123 to i64
%125 = mul i64 %124, 4
store i64 %125, i64* %18
%126 = load i32, i32* %6
%127 = load i32, i32* %6
%128 = mul i32 %126, %127
%129 = zext i32 %128 to i64
%130 = mul i64 %129, 4
%131 = trunc i64 %130 to i32
%132 = call i64 @malloc(i32 %131)
%133 = inttoptr i64 %132 to float*
store float* %133, float** %19
%134 = load i32, i32* %6
%135 = zext i32 %134 to i64
%136 = mul i64 %135, 4
%137 = trunc i64 %136 to i32
%138 = call i64 @malloc(i32 %137)
%139 = inttoptr i64 %138 to float*
store float* %139, float** %20
%140 = load i32, i32* %6
%141 = zext i32 %140 to i64
%142 = mul i64 %141, 4
%143 = trunc i64 %142 to i32
%144 = call i64 @malloc(i32 %143)
%145 = inttoptr i64 %144 to float*
store float* %145, float** %21
store i32 0, i32* %2
br label %146
146: ; preds = %174, %104
%147 = load i32, i32* %2
%148 = load i32, i32* %6
%149 = icmp ult i32 %147, %148
br i1 %149, label %150, label %177
150: ; preds = %146
store i32 0, i32* %3
br label %151
151: ; preds = %170, %150
%152 = load i32, i32* %3
%153 = load i32, i32* %6
%154 = icmp ult i32 %152, %153
br i1 %154, label %155, label %173
155: ; preds = %151
%156 = load i32, i32* %2
%157 = sitofp i32 %156 to float
%158 = fmul float 0x3FF19999A0000000, %157
%159 = load i32, i32* %3
%160 = sitofp i32 %159 to float
%161 = fmul float %158, %160
%162 = load float*, float** %19
%163 = load i32, i32* %2
%164 = load i32, i32* %6
%165 = mul i32 %163, %164
%166 = load i32, i32* %3
%167 = add i32 %165, %166
%168 = zext i32 %167 to i64
%169 = getelementptr inbounds float, float* %162, i64 %168
store float %161, float* %169
br label %170
170: ; preds = %155
%171 = load i32, i32* %3
%172 = add nsw i32 %171, 1
store i32 %172, i32* %3
br label %151
173: ; preds = %151
br label %174
174: ; preds = %173
%175 = load i32, i32* %2
%176 = add nsw i32 %175, 1
store i32 %176, i32* %2
br label %146
177: ; preds = %146
store i32 0, i32* %2
br label %178
178: ; preds = %190, %177
%179 = load i32, i32* %2
%180 = load i32, i32* %6
%181 = icmp ult i32 %179, %180
br i1 %181, label %182, label %193
182: ; preds = %178
%183 = load i32, i32* %2
%184 = sitofp i32 %183 to float
%185 = fmul float 0x40019999A0000000, %184
%186 = load float*, float** %20
%187 = load i32, i32* %2
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds float, float* %186, i64 %188
store float %185, float* %189
br label %190
190: ; preds = %182
%191 = load i32, i32* %2
%192 = add nsw i32 %191, 1
store i32 %192, i32* %2
br label %178
193: ; preds = %178
store i32 0, i32* %2
br label %194
194: ; preds = %203, %193
%195 = load i32, i32* %2
%196 = load i32, i32* %6
%197 = icmp ult i32 %195, %196
br i1 %197, label %198, label %206
198: ; preds = %194
%199 = load float*, float** %21
%200 = load i32, i32* %2
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds float, float* %199, i64 %201
store float 0.000000e+00, float* %202
br label %203
203: ; preds = %198
%204 = load i32, i32* %2
%205 = add nsw i32 %204, 1
store i32 %205, i32* %2
br label %194
206: ; preds = %194
%207 = load i32, i32* %14
%208 = load i32, i32* @CL_MEM_USE_HOST_PTR
%209 = load i64, i64* %16
%210 = load float*, float** %19
%211 = call i32 @clCreateBuffer(i32 %207, i32 %208, i64 %209, float* %210, i32* %4)
store i32 %211, i32* %22
%212 = load i32, i32* %14
%213 = load i32, i32* @CL_MEM_USE_HOST_PTR
%214 = load i64, i64* %17
%215 = load float*, float** %20
%216 = call i32 @clCreateBuffer(i32 %212, i32 %213, i64 %214, float* %215, i32* %4)
store i32 %216, i32* %23
%217 = load i32, i32* %14
%218 = load i32, i32* @CL_MEM_USE_HOST_PTR
%219 = load i64, i64* %18
%220 = load float*, float** %21
%221 = call i32 @clCreateBuffer(i32 %217, i32 %218, i64 %219, float* %220, i32* %4)
store i32 %221, i32* %24
%222 = bitcast [229 x i8]* %25 to i8*
%223 = getelementptr inbounds [1 x i8*], [1 x i8*]* %26, i64 0, i64 0
%224 = getelementptr inbounds [229 x i8], [229 x i8]* %25, i64 0, i64 0
store i8* %224, i8** %223
store i64 229, i64* %27
%225 = load i32, i32* %14
%226 = bitcast [1 x i8*]* %26 to i8**
%227 = call i32 @clCreateProgramWithSource(i32 %225, i32 1, i8** %226, i64* %27, i32* %4)
store i32 %227, i32* %28
%228 = load i32, i32* %28
%229 = call i32 @clBuildProgram(i32 %228, i32 1, i32* %12, i32 0, i32 0, i32 0)
%230 = load i32, i32* %28
%231 = call i32 @clCreateKernel(i32 %230, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %4)
store i32 %231, i32* %29
%232 = load i32, i32* %29
%233 = call i32 @clSetKernelArg(i32 %232, i32 0, i32 4, i32* %6)
%234 = load i32, i32* %29
%235 = call i32 @clSetKernelArg(i32 %234, i32 1, i32 4, i32* %22)
%236 = load i32, i32* %29
%237 = call i32 @clSetKernelArg(i32 %236, i32 2, i32 4, i32* %23)
%238 = load i32, i32* %29
%239 = call i32 @clSetKernelArg(i32 %238, i32 3, i32 4, i32* %24)
%240 = getelementptr inbounds [1 x i64], [1 x i64]* %30, i64 0, i64 0
%241 = load i32, i32* %6
%242 = zext i32 %241 to i64
store i64 %242, i64* %240
%243 = bitcast [1 x i64]* %31 to i8*
%244 = load i32, i32* %15
%245 = load i32, i32* %29
%246 = getelementptr inbounds [1 x i64], [1 x i64]* %30, i64 0, i64 0
%247 = getelementptr inbounds [1 x i64], [1 x i64]* %31, i64 0, i64 0
%248 = getelementptr inbounds [10 x i32], [10 x i32]* %32, i64 0, i64 0
%249 = call i32 @clEnqueueNDRangeKernel(i32 %244, i32 %245, i32 1, i32 0, i64* %246, i64* %247, i32 0, i32 0, i32* %248)
%250 = load i32, i32* %15
%251 = load i32, i32* %24
%252 = load i32, i32* @CL_TRUE
%253 = load i64, i64* %18
%254 = load float*, float** %21
%255 = getelementptr inbounds [10 x i32], [10 x i32]* %32, i64 0, i64 1
%256 = call i32 @clEnqueueReadBuffer(i32 %250, i32 %251, i32 %252, i32 0, i64 %253, float* %254, i32 0, i32 0, i32* %255)
%257 = getelementptr inbounds [10 x i32], [10 x i32]* %32, i64 0, i64 0
%258 = call i32 @clWaitForEvents(i32 2, i32* %257)
store i32 %258, i32* %4
store i32 0, i32* %2
br label %259
259: ; preds = %272, %206
%260 = load i32, i32* %2
%261 = load i32, i32* %6
%262 = icmp ult i32 %260, %261
br i1 %262, label %263, label %275
263: ; preds = %259
%264 = load i32, i32* %2
%265 = load float*, float** %21
%266 = load i32, i32* %2
%267 = sext i32 %266 to i64
%268 = getelementptr inbounds float, float* %265, i64 %267
%269 = load float, float* %268
%270 = fpext float %269 to double
%271 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %264, double %270)
br label %272
272: ; preds = %263
%273 = load i32, i32* %2
%274 = add nsw i32 %273, 1
store i32 %274, i32* %2
br label %259
275: ; preds = %259
%276 = load i32, i32* %4
%277 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %276)
%278 = getelementptr inbounds [10 x i32], [10 x i32]* %32, i64 0, i64 1
%279 = load i32, i32* %278
%280 = call i32 @clReleaseEvent(i32 %279)
%281 = getelementptr inbounds [10 x i32], [10 x i32]* %32, i64 0, i64 0
%282 = load i32, i32* %281
%283 = call i32 @clReleaseEvent(i32 %282)
%284 = load i32, i32* %29
%285 = call i32 @clReleaseKernel(i32 %284)
%286 = load i32, i32* %28
%287 = call i32 @clReleaseProgram(i32 %286)
%288 = load i32, i32* %22
%289 = call i32 @clReleaseMemObject(i32 %288)
%290 = load i32, i32* %23
%291 = call i32 @clReleaseMemObject(i32 %290)
%292 = load i32, i32* %24
%293 = call i32 @clReleaseMemObject(i32 %292)
%294 = load i32, i32* %15
%295 = call i32 @clReleaseCommandQueue(i32 %294)
%296 = load i32, i32* %14
%297 = call i32 @clReleaseContext(i32 %296)
%298 = load float*, float** %19
%299 = call i32 @free(float* %298)
%300 = load float*, float** %20
%301 = call i32 @free(float* %300)
%302 = load float*, float** %21
%303 = call i32 @free(float* %302)
%304 = load i32, i32* %1
ret i32 %304
}

LLVM IR (-O2):
@CL_PLATFORM_NAME = global i32 0
@.str = [10 x i8] c"coprthr-e\00"
@CL_DEVICE_TYPE_ACCELERATOR = global i32 0
@CL_CONTEXT_PLATFORM = global i32 0
@CL_MEM_USE_HOST_PTR = global i32 0
@__const.main.kernel_code = [229 x i8] c"__kernel void matvecmult_kern(\0A uint n,__global float* aa,__global float* b,__global float* c )\0A{\0A int i = get_global_id(0);\0A int j;\0A float tmp = 0.0f;\0A for(j=0;j<n;j++) tmp += aa[i*n+j] * b[j];\0A c[i] = aa[i*n+i];\0A}\0A\00"
@.str.1 = [16 x i8] c"matvecmult_kern\00"
@CL_TRUE = global i32 0
@.str.2 = [10 x i8] c"c[%d] %f\0A\00"
@.str.3 = [29 x i8] c"clWaitForEvents returned %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [3 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [229 x i8]
%12 = alloca [1 x i8*]
%13 = alloca i64
%14 = alloca [1 x i64]
%15 = alloca [1 x i64]
%16 = alloca [10 x i32]
%17 = bitcast i32* %1 to i8*
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = bitcast i32* %3 to i8*
store i32 1024, i32* %3
%20 = bitcast i32* %4 to i8*
%21 = call i32 @clGetPlatformIDs(i32 0, i32* null, i32* %4)
%22 = load i32, i32* %4
%23 = shl i32 %22, 2
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i32*
%26 = load i32, i32* %4
%27 = call i32 @clGetPlatformIDs(i32 %26, i32* %25, i32* null)
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %49
30: ; preds = %0, %40
%31 = phi i64 [ %41, %40 ], [ 0, %0 ]
%32 = getelementptr inbounds i32, i32* %25, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* @CL_PLATFORM_NAME
%35 = call i32 @clGetPlatformInfo(i32 %33, i32 %34, i32 256, i8* %18, i32 0)
%36 = call i32 @bcmp(i8* dereferenceable(10) %18, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 10)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = load i32, i32* %4
br label %45
40: ; preds = %30
%41 = add nuw nsw i64 %31, 1
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = icmp slt i64 %41, %43
br i1 %44, label %30, label %45
45: ; preds = %40, %38
%46 = phi i32 [ %39, %38 ], [ %42, %40 ]
%47 = phi i64 [ %31, %38 ], [ %41, %40 ]
%48 = trunc i64 %47 to i32
br label %49
49: ; preds = %45, %0
%50 = phi i32 [ %28, %0 ], [ %46, %45 ]
%51 = phi i32 [ 0, %0 ], [ %48, %45 ]
%52 = icmp slt i32 %51, %50
br i1 %52, label %53, label %70
53: ; preds = %49
%54 = zext i32 %51 to i64
%55 = getelementptr inbounds i32, i32* %25, i64 %54
%56 = load i32, i32* %55
%57 = bitcast i32* %5 to i8*
%58 = bitcast i32* %6 to i8*
%59 = load i32, i32* @CL_DEVICE_TYPE_ACCELERATOR
%60 = call i32 @clGetDeviceIDs(i32 %56, i32 %59, i32 0, i32* null, i32* %5)
%61 = load i32, i32* %5
%62 = shl i32 %61, 2
%63 = call i64 @malloc(i32 %62)
%64 = inttoptr i64 %63 to i32*
%65 = load i32, i32* @CL_DEVICE_TYPE_ACCELERATOR
%66 = load i32, i32* %5
%67 = call i32 @clGetDeviceIDs(i32 %56, i32 %65, i32 %66, i32* %64, i32* null)
%68 = load i32, i32* %5
%69 = icmp eq i32 %68, 0
br i1 %69, label %89, label %72
70: ; preds = %49
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %53
%73 = load i32, i32* %64
store i32 %73, i32* %6
%74 = bitcast [3 x i32]* %7 to i8*
%75 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%76 = load i32, i32* @CL_CONTEXT_PLATFORM
store i32 %76, i32* %75
%77 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 1
store i32 %56, i32* %77
%78 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 2
store i32 0, i32* %78
%79 = call i32 @clCreateContext(i32* %75, i32 1, i32* %6, i32 0, i32 0, i32* %1)
%80 = load i32, i32* %6
%81 = call i32 @clCreateCommandQueue(i32 %79, i32 %80, i32 0, i32* %1)
%82 = call i64 @malloc(i32 4194304)
%83 = inttoptr i64 %82 to float*
%84 = call i64 @malloc(i32 4096)
%85 = inttoptr i64 %84 to float*
%86 = call i64 @malloc(i32 4096)
%87 = inttoptr i64 %86 to float*
%88 = inttoptr i64 %86 to i8*
br label %91
89: ; preds = %53
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %72, %126
%92 = phi i32 [ %127, %126 ], [ 0, %72 ]
%93 = sitofp i32 %92 to float
%94 = fmul float %93, 0x3FF19999A0000000
%95 = shl i32 %92, 10
%96 = insertelement <4 x float> poison, float %94, i64 0
%97 = shufflevector <4 x float> %96, <4 x float> poison, <4 x i32> zeroinitializer
%98 = insertelement <4 x float> poison, float %94, i64 0
%99 = shufflevector <4 x float> %98, <4 x float> poison, <4 x i32> zeroinitializer
br label %100
100: ; preds = %100, %91
%101 = phi i64 [ 0, %91 ], [ %124, %100 ]
%102 = trunc i64 %101 to i32
%103 = or i32 %102, 1
%104 = insertelement <2 x i32> poison, i32 %102, i64 0
%105 = shufflevector <2 x i32> %104, <2 x i32> poison, <2 x i32> zeroinitializer
%106 = or <2 x i32> %105, <i32 2, i32 3>
%107 = insertelement <4 x i32> poison, i32 %102, i64 0
%108 = insertelement <4 x i32> %107, i32 %103, i64 1
%109 = shufflevector <2 x i32> %106, <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
%110 = shufflevector <4 x i32> %108, <4 x i32> %109, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
%111 = insertelement <4 x i32> poison, i32 %102, i64 0
%112 = shufflevector <4 x i32> %111, <4 x i32> poison, <4 x i32> zeroinitializer
%113 = or <4 x i32> %112, <i32 4, i32 5, i32 6, i32 7>
%114 = sitofp <4 x i32> %110 to <4 x float>
%115 = sitofp <4 x i32> %113 to <4 x float>
%116 = fmul <4 x float> %97, %114
%117 = fmul <4 x float> %99, %115
%118 = add i32 %95, %102
%119 = zext i32 %118 to i64
%120 = getelementptr inbounds float, float* %83, i64 %119
%121 = bitcast float* %120 to <4 x float>*
store <4 x float> %116, <4 x float>* %121
%122 = getelementptr inbounds float, float* %120, i64 4
%123 = bitcast float* %122 to <4 x float>*
store <4 x float> %117, <4 x float>* %123
%124 = add nuw i64 %101, 8
%125 = icmp eq i64 %124, 1024
br i1 %125, label %126, label %100
126: ; preds = %100
%127 = add nuw nsw i32 %92, 1
%128 = icmp eq i32 %127, 1024
br i1 %128, label %129, label %91
129: ; preds = %126, %129
%130 = phi i64 [ %152, %129 ], [ 0, %126 ]
%131 = phi <4 x i32> [ %153, %129 ], [ <i32 0, i32 1, i32 2, i32 3>, %126 ]
%132 = add <4 x i32> %131, <i32 4, i32 4, i32 4, i32 4>
%133 = sitofp <4 x i32> %131 to <4 x float>
%134 = sitofp <4 x i32> %132 to <4 x float>
%135 = fmul <4 x float> %133, <float 0x40019999A0000000, float 0x40019999A0000000, float 0x40019999A0000000, float 0x40019999A0000000>
%136 = fmul <4 x float> %134, <float 0x40019999A0000000, float 0x40019999A0000000, float 0x40019999A0000000, float 0x40019999A0000000>
%137 = getelementptr inbounds float, float* %85, i64 %130
%138 = bitcast float* %137 to <4 x float>*
store <4 x float> %135, <4 x float>* %138
%139 = getelementptr inbounds float, float* %137, i64 4
%140 = bitcast float* %139 to <4 x float>*
store <4 x float> %136, <4 x float>* %140
%141 = or i64 %130, 8
%142 = add <4 x i32> %131, <i32 8, i32 8, i32 8, i32 8>
%143 = add <4 x i32> %131, <i32 12, i32 12, i32 12, i32 12>
%144 = sitofp <4 x i32> %142 to <4 x float>
%145 = sitofp <4 x i32> %143 to <4 x float>
%146 = fmul <4 x float> %144, <float 0x40019999A0000000, float 0x40019999A0000000, float 0x40019999A0000000, float 0x40019999A0000000>
%147 = fmul <4 x float> %145, <float 0x40019999A0000000, float 0x40019999A0000000, float 0x40019999A0000000, float 0x40019999A0000000>
%148 = getelementptr inbounds float, float* %85, i64 %141
%149 = bitcast float* %148 to <4 x float>*
store <4 x float> %146, <4 x float>* %149
%150 = getelementptr inbounds float, float* %148, i64 4
%151 = bitcast float* %150 to <4 x float>*
store <4 x float> %147, <4 x float>* %151
%152 = add nuw nsw i64 %130, 16
%153 = add <4 x i32> %131, <i32 16, i32 16, i32 16, i32 16>
%154 = icmp eq i64 %152, 1024
br i1 %154, label %155, label %129
155: ; preds = %129
%156 = bitcast i32* %8 to i8*
%157 = load i32, i32* @CL_MEM_USE_HOST_PTR
%158 = call i32 @clCreateBuffer(i32 %79, i32 %157, i64 4194304, float* %83, i32* %1)
store i32 %158, i32* %8
%159 = bitcast i32* %9 to i8*
%160 = load i32, i32* @CL_MEM_USE_HOST_PTR
%161 = call i32 @clCreateBuffer(i32 %79, i32 %160, i64 4096, float* %85, i32* %1)
store i32 %161, i32* %9
%162 = bitcast i32* %10 to i8*
%163 = load i32, i32* @CL_MEM_USE_HOST_PTR
%164 = call i32 @clCreateBuffer(i32 %79, i32 %163, i64 4096, float* %87, i32* %1)
store i32 %164, i32* %10
%165 = getelementptr inbounds [229 x i8], [229 x i8]* %11, i64 0, i64 0
%166 = bitcast [1 x i8*]* %12 to i8*
%167 = getelementptr inbounds [1 x i8*], [1 x i8*]* %12, i64 0, i64 0
store i8* %165, i8** %167
%168 = bitcast i64* %13 to i8*
store i64 229, i64* %13
%169 = call i32 @clCreateProgramWithSource(i32 %79, i32 1, i8** %167, i64* %13, i32* %1)
%170 = call i32 @clBuildProgram(i32 %169, i32 1, i32* %6, i32 0, i32 0, i32 0)
%171 = call i32 @clCreateKernel(i32 %169, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%172 = call i32 @clSetKernelArg(i32 %171, i32 0, i32 4, i32* %3)
%173 = call i32 @clSetKernelArg(i32 %171, i32 1, i32 4, i32* %8)
%174 = call i32 @clSetKernelArg(i32 %171, i32 2, i32 4, i32* %9)
%175 = call i32 @clSetKernelArg(i32 %171, i32 3, i32 4, i32* %10)
%176 = bitcast [1 x i64]* %14 to i8*
%177 = getelementptr inbounds [1 x i64], [1 x i64]* %14, i64 0, i64 0
%178 = load i32, i32* %3
%179 = zext i32 %178 to i64
store i64 %179, i64* %177
%180 = bitcast [1 x i64]* %15 to i8*
%181 = getelementptr inbounds [1 x i64], [1 x i64]* %15, i64 0, i64 0
store i64 16, i64* %181
%182 = bitcast [10 x i32]* %16 to i8*
%183 = getelementptr inbounds [10 x i32], [10 x i32]* %16, i64 0, i64 0
%184 = call i32 @clEnqueueNDRangeKernel(i32 %81, i32 %171, i32 1, i32 0, i64* %177, i64* %181, i32 0, i32 0, i32* %183)
%185 = load i32, i32* %10
%186 = load i32, i32* @CL_TRUE
%187 = getelementptr inbounds [10 x i32], [10 x i32]* %16, i64 0, i64 1
%188 = call i32 @clEnqueueReadBuffer(i32 %81, i32 %185, i32 %186, i32 0, i64 4096, float* %87, i32 0, i32 0, i32* %187)
%189 = call i32 @clWaitForEvents(i32 2, i32* %183)
store i32 %189, i32* %1
%190 = load i32, i32* %3
%191 = icmp eq i32 %190, 0
br i1 %191, label %205, label %192
192: ; preds = %155, %192
%193 = phi i64 [ %199, %192 ], [ 0, %155 ]
%194 = getelementptr inbounds float, float* %87, i64 %193
%195 = load float, float* %194
%196 = fpext float %195 to double
%197 = trunc i64 %193 to i32
%198 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %197, double %196)
%199 = add nuw nsw i64 %193, 1
%200 = load i32, i32* %3
%201 = zext i32 %200 to i64
%202 = icmp ult i64 %199, %201
br i1 %202, label %192, label %203
203: ; preds = %192
%204 = load i32, i32* %1
br label %205
205: ; preds = %203, %155
%206 = phi i32 [ %204, %203 ], [ %189, %155 ]
%207 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %206)
%208 = load i32, i32* %187
%209 = call i32 @clReleaseEvent(i32 %208)
%210 = load i32, i32* %183
%211 = call i32 @clReleaseEvent(i32 %210)
%212 = call i32 @clReleaseKernel(i32 %171)
%213 = call i32 @clReleaseProgram(i32 %169)
%214 = load i32, i32* %8
%215 = call i32 @clReleaseMemObject(i32 %214)
%216 = load i32, i32* %9
%217 = call i32 @clReleaseMemObject(i32 %216)
%218 = load i32, i32* %10
%219 = call i32 @clReleaseMemObject(i32 %218)
%220 = call i32 @clReleaseCommandQueue(i32 %81)
%221 = call i32 @clReleaseContext(i32 %79)
%222 = call i32 @free(float* %83)
%223 = call i32 @free(float* %85)
%224 = call i32 @free(float* %87)
ret i32 0
}