#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*/ 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_GPU;
int /*<<< orphan*/ CL_MEM_READ_ONLY;
int /*<<< orphan*/ CL_MEM_WRITE_ONLY;
int /*<<< orphan*/ CL_TRUE;
scalar_t__ EOF;
int /*<<< orphan*/ clBuildProgram(int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ **, char *,
                                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clCreateBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                                  int const, 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 const, float *, int /*<<< orphan*/,
                                       int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ clEnqueueWriteBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                                        int /*<<< orphan*/, int /*<<< orphan*/,
                                        int const, 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*/ desabilita_cache_compilacao();
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 *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, float *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, float, float);
int /*<<< orphan*/ stderr;
int main(void) {
  desabilita_cache_compilacao();
  int i;
  const int LIST_SIZE = 100000;
  float *A = (float *)malloc(sizeof(float) * LIST_SIZE);
  FILE *arq = fopen("p4.txt", "r");
  while ((fscanf(arq, "%f\n", &A[i])) != EOF) {
    i++;
  }
  FILE *fp;
  char *source_str;
  size_t source_size;
  fp = fopen("kernel.cl", "r");
  if (!fp) {
    fprintf(stderr, "Failed to load kernel.\n");
    exit(1);
  }
  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);
  ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id,
                       &ret_num_devices);
  cl_context context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret);
  cl_command_queue command_queue =
      clCreateCommandQueue(context, device_id, 0, &ret);
  cl_mem a_mem_obj = clCreateBuffer(context, CL_MEM_READ_ONLY,
                                    LIST_SIZE * sizeof(float), NULL, &ret);
  cl_mem b_mem_obj = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
                                    LIST_SIZE * sizeof(float), NULL, &ret);
  cl_mem c_mem_obj = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
                                    LIST_SIZE * sizeof(float), NULL, &ret);
  ret = clEnqueueWriteBuffer(command_queue, a_mem_obj, CL_TRUE, 0,
                             LIST_SIZE * sizeof(float), A, 0, NULL, NULL);
  cl_program program =
      clCreateProgramWithSource(context, 1, (const char **)&source_str,
                                (const size_t *)&source_size, &ret);
  ret = clBuildProgram(program, 1, &device_id, "-cl-opt-disable", NULL, NULL);
  cl_kernel kernel = clCreateKernel(program, "vector_add", &ret);
  ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&a_mem_obj);
  ret = clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&b_mem_obj);
  ret = clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&c_mem_obj);
  size_t global_item_size = 1;
  size_t local_item_size = 1;
  ret =
      clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_item_size,
                             &local_item_size, 0, NULL, NULL);
  float *B = (float *)malloc(sizeof(float) * LIST_SIZE);
  float *C = (float *)malloc(sizeof(float) * LIST_SIZE);
  ret = clEnqueueReadBuffer(command_queue, b_mem_obj, CL_TRUE, 0,
                            LIST_SIZE * sizeof(float), B, 0, NULL, NULL);
  ret = clEnqueueReadBuffer(command_queue, c_mem_obj, CL_TRUE, 0,
                            LIST_SIZE * sizeof(float), C, 0, NULL, NULL);
  float totalDiff = 0;
  for (i = 0; i < LIST_SIZE; i++) {
    printf("%f\t%.15f\n", A[i], B[i]);
  }
  ret = clFlush(command_queue);
  ret = clFinish(command_queue);
  ret = clReleaseKernel(kernel);
  ret = clReleaseProgram(program);
  ret = clReleaseMemObject(a_mem_obj);
  ret = clReleaseMemObject(c_mem_obj);
  ret = clReleaseCommandQueue(command_queue);
  ret = clReleaseContext(context);
  free(A);
  free(B);
  free(C);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1160 <desabilita_cache_compilacao@plt>
movl   $0x186a0,-0xc(%rbp)
mov    $0x61a80,%edi
call   1170 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xcfb(%rip),%rdi
lea    0xcfb(%rip),%rsi
call   11b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xcda(%rip),%rsi
call   1120 <fscanf@plt>
mov    0x2c9d(%rip),%rcx
cmp    (%rcx),%rax
je     1352 <main+0x82>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1315 <main+0x45>
lea    0xcb4(%rip),%rdi
lea    0xca7(%rip),%rsi
call   11b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1393 <main+0xc3>
mov    0x2c45(%rip),%rax
mov    (%rax),%edi
lea    0xc93(%rip),%rsi
call   1140 <fprintf@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
mov    $0x100000,%edi
call   1170 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100000,%edx
call   1070 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   10d0 <fclose@plt>
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    $0x1,%edi
lea    -0x40(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1100 <clGetPlatformIDs@plt>
mov    %eax,-0x54(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2bdb(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
lea    -0x48(%rbp),%rcx
lea    -0x4c(%rbp),%r8
call   10c0 <clGetDeviceIDs@plt>
mov    %eax,-0x54(%rbp)
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x1,%esi
lea    -0x48(%rbp),%rdx
lea    -0x54(%rbp),%r9
mov    %r8,%rdi
mov    %r8,%rcx
call   1130 <clCreateContext@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%edi
mov    -0x48(%rbp),%rsi
xor    %edx,%edx
lea    -0x54(%rbp),%rcx
call   10f0 <clCreateCommandQueue@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x58(%rbp),%edi
mov    0x2b6d(%rip),%rax
mov    (%rax),%esi
mov    $0x61a80,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x54(%rbp),%r8
call   10a0 <clCreateBuffer@plt>
mov    %eax,-0x60(%rbp)
mov    -0x58(%rbp),%edi
mov    0x2b74(%rip),%rax
mov    (%rax),%esi
mov    $0x61a80,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x54(%rbp),%r8
call   10a0 <clCreateBuffer@plt>
mov    %eax,-0x64(%rbp)
mov    -0x58(%rbp),%edi
mov    0x2b53(%rip),%rax
mov    (%rax),%esi
mov    $0x61a80,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x54(%rbp),%r8
call   10a0 <clCreateBuffer@plt>
mov    %eax,-0x68(%rbp)
mov    -0x5c(%rbp),%edi
mov    -0x60(%rbp),%esi
mov    0x2b37(%rip),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%r9
xor    %ecx,%ecx
mov    $0x61a80,%r8d
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   11f0 <clEnqueueWriteBuffer@plt>
mov    %eax,-0x54(%rbp)
mov    -0x58(%rbp),%edi
mov    $0x1,%esi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x54(%rbp),%r8
call   1060 <clCreateProgramWithSource@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%edi
mov    $0x1,%esi
lea    -0x48(%rbp),%rdx
lea    0xb1e(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1030 <clBuildProgram@plt>
mov    %eax,-0x54(%rbp)
mov    -0x6c(%rbp),%edi
lea    0xb14(%rip),%rsi
lea    -0x54(%rbp),%rdx
call   11c0 <clCreateKernel@plt>
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%edi
lea    -0x60(%rbp),%rcx
xor    %esi,%esi
mov    $0x4,%edx
call   11e0 <clSetKernelArg@plt>
mov    %eax,-0x54(%rbp)
mov    -0x70(%rbp),%edi
lea    -0x64(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   11e0 <clSetKernelArg@plt>
mov    %eax,-0x54(%rbp)
mov    -0x70(%rbp),%edi
lea    -0x68(%rbp),%rcx
mov    $0x2,%esi
mov    $0x4,%edx
call   11e0 <clSetKernelArg@plt>
mov    %eax,-0x54(%rbp)
movq   $0x1,-0x78(%rbp)
movq   $0x1,-0x80(%rbp)
mov    -0x5c(%rbp),%edi
mov    -0x70(%rbp),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x78(%rbp),%r8
lea    -0x80(%rbp),%r9
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   10e0 <clEnqueueNDRangeKernel@plt>
mov    %eax,-0x54(%rbp)
mov    $0x61a80,%edi
call   1170 <malloc@plt>
mov    %rax,-0x88(%rbp)
mov    $0x61a80,%edi
call   1170 <malloc@plt>
mov    %rax,-0x90(%rbp)
mov    -0x5c(%rbp),%edi
mov    -0x64(%rbp),%esi
mov    0x29f0(%rip),%rax
mov    (%rax),%edx
mov    -0x88(%rbp),%r9
xor    %ecx,%ecx
mov    $0x61a80,%r8d
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1180 <clEnqueueReadBuffer@plt>
mov    %eax,-0x54(%rbp)
mov    -0x5c(%rbp),%edi
mov    -0x68(%rbp),%esi
mov    0x29af(%rip),%rax
mov    (%rax),%edx
mov    -0x90(%rbp),%r9
xor    %ecx,%ecx
mov    $0x61a80,%r8d
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1180 <clEnqueueReadBuffer@plt>
mov    %eax,-0x54(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x94(%rbp)
ff
movl   $0x0,-0x8(%rbp)
cmpl   $0x186a0,-0x8(%rbp)
jge    16c3 <main+0x3f3>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x88(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
lea    0x99a(%rip),%rdi
call   1110 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    167f <main+0x3af>
mov    -0x5c(%rbp),%edi
call   1090 <clFlush@plt>
mov    %eax,-0x54(%rbp)
mov    -0x5c(%rbp),%edi
call   1050 <clFinish@plt>
mov    %eax,-0x54(%rbp)
mov    -0x70(%rbp),%edi
call   1080 <clReleaseKernel@plt>
mov    %eax,-0x54(%rbp)
mov    -0x6c(%rbp),%edi
call   10b0 <clReleaseProgram@plt>
mov    %eax,-0x54(%rbp)
mov    -0x60(%rbp),%edi
call   11a0 <clReleaseMemObject@plt>
mov    %eax,-0x54(%rbp)
mov    -0x68(%rbp),%edi
call   11a0 <clReleaseMemObject@plt>
mov    %eax,-0x54(%rbp)
mov    -0x5c(%rbp),%edi
call   1150 <clReleaseCommandQueue@plt>
mov    %eax,-0x54(%rbp)
mov    -0x58(%rbp),%edi
call   1190 <clReleaseContext@plt>
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x88(%rbp),%rdi
call   1040 <free@plt>
mov    -0x90(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
xor    %eax,%eax
call   1160 <desabilita_cache_compilacao@plt>
mov    $0x61a80,%edi
call   1170 <malloc@plt>
mov    %rax,%r15
lea    0xd17(%rip),%rdi
lea    0xd17(%rip),%rsi
call   11b0 <fopen@plt>
mov    %rax,%rbp
lea    0xd0a(%rip),%r14
mov    0x2cc2(%rip),%r12
mov    %r15,%rbx
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1120 <fscanf@plt>
add    $0x4,%rbx
cmp    (%r12),%rax
jne    1320 <main+0x50>
lea    0xcde(%rip),%rdi
lea    0xcd1(%rip),%rsi
call   11b0 <fopen@plt>
test   %rax,%rax
je     16d2 <main+0x402>
mov    %rax,%rbp
mov    $0x100000,%edi
call   1170 <malloc@plt>
mov    %rax,0x68(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
mov    %rbp,%rcx
call   1070 <fread@plt>
mov    %rax,0x60(%rsp)
mov    %rbp,%rdi
call   10d0 <fclose@plt>
movq   $0x0,0x40(%rsp)
movq   $0x0,0x30(%rsp)
lea    0x40(%rsp),%rsi
lea    0x70(%rsp),%rdx
mov    $0x1,%edi
call   1100 <clGetPlatformIDs@plt>
mov    %eax,0x1c(%rsp)
mov    0x40(%rsp),%rdi
mov    0x2c12(%rip),%rax
mov    (%rax),%esi
lea    0x30(%rsp),%rbp
lea    0x74(%rsp),%r8
mov    $0x1,%edx
mov    %rbp,%rcx
call   10c0 <clGetDeviceIDs@plt>
mov    %eax,0x1c(%rsp)
xor    %r14d,%r14d
lea    0x1c(%rsp),%rbx
xor    %edi,%edi
mov    $0x1,%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rbx,%r9
call   1130 <clCreateContext@plt>
mov    %eax,%r12d
mov    0x30(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
mov    %rbx,%rcx
call   10f0 <clCreateCommandQueue@plt>
mov    %eax,0x24(%rsp)
mov    0x2b9f(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    $0x61a80,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   10a0 <clCreateBuffer@plt>
mov    %eax,%r13d
mov    %eax,0x2c(%rsp)
mov    0x2ba5(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r12d,%edi
mov    $0x61a80,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   10a0 <clCreateBuffer@plt>
mov    %eax,0x28(%rsp)
mov    0x0(%rbp),%esi
mov    %r12d,%edi
mov    $0x61a80,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   10a0 <clCreateBuffer@plt>
mov    %eax,0x20(%rsp)
mov    0x2b74(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    0x24(%rsp),%ebp
mov    %ebp,%edi
mov    %r13d,%esi
xor    %ecx,%ecx
mov    $0x61a80,%r8d
mov    %r15,%r9
call   11f0 <clEnqueueWriteBuffer@plt>
mov    %eax,0x1c(%rsp)
lea    0x68(%rsp),%rdx
lea    0x60(%rsp),%rcx
mov    %r12d,0x3c(%rsp)
mov    %r12d,%edi
mov    %ebp,%r12d
mov    $0x1,%esi
mov    %rbx,%r8
call   1060 <clCreateProgramWithSource@plt>
mov    %eax,%ebp
lea    0xb72(%rip),%rcx
mov    %eax,%edi
mov    $0x1,%esi
lea    0x30(%rsp),%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
mov    %eax,0x1c(%rsp)
lea    0xb60(%rip),%rsi
mov    %ebp,0x38(%rsp)
mov    %ebp,%edi
mov    %rbx,%rdx
call   11c0 <clCreateKernel@plt>
mov    %eax,%r13d
lea    0x2c(%rsp),%rcx
mov    %eax,%edi
xor    %esi,%esi
mov    $0x4,%edx
call   11e0 <clSetKernelArg@plt>
mov    %eax,0x1c(%rsp)
lea    0x28(%rsp),%rcx
mov    %r13d,%edi
mov    $0x1,%esi
mov    $0x4,%edx
call   11e0 <clSetKernelArg@plt>
mov    %eax,0x1c(%rsp)
lea    0x20(%rsp),%rcx
mov    %r13d,%edi
mov    $0x2,%esi
mov    $0x4,%edx
call   11e0 <clSetKernelArg@plt>
mov    %eax,0x1c(%rsp)
movq   $0x1,0x58(%rsp)
movq   $0x1,0x50(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
lea    0x58(%rsp),%r8
lea    0x50(%rsp),%r9
mov    %r12d,%ebx
mov    %r12d,%edi
mov    %r13d,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   10e0 <clEnqueueNDRangeKernel@plt>
mov    %eax,0x1c(%rsp)
mov    $0x61a80,%edi
call   1170 <malloc@plt>
mov    %rax,%rbp
mov    $0x61a80,%edi
call   1170 <malloc@plt>
mov    %rax,%r12
mov    0x28(%rsp),%esi
mov    0x2a32(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %ebx,%edi
xor    %ecx,%ecx
mov    $0x61a80,%r8d
mov    %rbp,%r9
call   1180 <clEnqueueReadBuffer@plt>
mov    %eax,0x1c(%rsp)
mov    0x20(%rsp),%esi
mov    0x2a00(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %ebx,%edi
xor    %ecx,%ecx
mov    $0x61a80,%r8d
mov    %r12,0x48(%rsp)
mov    %r12,%r9
call   1180 <clEnqueueReadBuffer@plt>
mov    %eax,0x1c(%rsp)
lea    0xa3f(%rip),%rbx
nopl   0x0(%rax,%rax,1)
movss  (%r15,%r14,4),%xmm0
movss  0x0(%rbp,%r14,4),%xmm1
mov    %rbx,%rdi
call   1110 <printf@plt>
add    $0x1,%r14
cmp    $0x186a0,%r14
jne    1620 <main+0x350>
mov    0x24(%rsp),%ebx
mov    %ebx,%edi
call   1090 <clFlush@plt>
mov    %eax,0x1c(%rsp)
mov    %ebx,%edi
call   1050 <clFinish@plt>
mov    %eax,0x1c(%rsp)
mov    %r13d,%edi
call   1080 <clReleaseKernel@plt>
mov    %eax,0x1c(%rsp)
mov    0x38(%rsp),%edi
call   10b0 <clReleaseProgram@plt>
mov    %eax,0x1c(%rsp)
mov    0x2c(%rsp),%edi
call   11a0 <clReleaseMemObject@plt>
mov    %eax,0x1c(%rsp)
mov    0x20(%rsp),%edi
call   11a0 <clReleaseMemObject@plt>
mov    %eax,0x1c(%rsp)
mov    %ebx,%edi
call   1150 <clReleaseCommandQueue@plt>
mov    %eax,0x1c(%rsp)
mov    0x3c(%rsp),%edi
call   1190 <clReleaseContext@plt>
mov    %eax,0x1c(%rsp)
mov    %r15,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    0x48(%rsp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x28e7(%rip),%rax
mov    (%rax),%edi
lea    0x945(%rip),%rsi
call   1140 <fprintf@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"p4.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%f\0A\00"
@EOF = global i64 0
@.str.3 = [10 x i8] c"kernel.cl\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Failed to load kernel.\0A\00"
@CL_DEVICE_TYPE_GPU = global i32 0
@CL_MEM_READ_ONLY = global i32 0
@CL_MEM_WRITE_ONLY = global i32 0
@CL_TRUE = global i32 0
@.str.5 = [16 x i8] c"-cl-opt-disable\00"
@.str.6 = [11 x i8] c"vector_add\00"
@.str.7 = [10 x i8] c"%f\09%.15f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i64
%22 = alloca i64
%23 = alloca float*
%24 = alloca float*
%25 = alloca float
store i32 0, i32* %1
%26 = call i32 (...) @desabilita_cache_compilacao()
store i32 100000, i32* %3
%27 = call i64 @malloc(i32 400000)
%28 = inttoptr i64 %27 to float*
store float* %28, float** %4
%29 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %5
br label %30
30: ; preds = %39, %0
%31 = load i32*, i32** %5
%32 = load float*, float** %4
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds float, float* %32, i64 %34
%36 = call i64 @fscanf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float* %35)
%37 = load i64, i64* @EOF
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %30
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %30
42: ; preds = %30
%43 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %43, i32** %6
%44 = load i32*, i32** %6
%45 = icmp ne i32* %44, null
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %42
%51 = call i64 @malloc(i32 1048576)
%52 = inttoptr i64 %51 to i8*
store i8* %52, i8** %7
%53 = load i8*, i8** %7
%54 = load i32*, i32** %6
%55 = call i64 @fread(i8* %53, i32 1, i32 1048576, i32* %54)
store i64 %55, i64* %8
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
store i32* null, i32** %9
store i32* null, i32** %10
%58 = call i32 @clGetPlatformIDs(i32 1, i32** %9, i32* %12)
store i32 %58, i32* %13
%59 = load i32*, i32** %9
%60 = load i32, i32* @CL_DEVICE_TYPE_GPU
%61 = call i32 @clGetDeviceIDs(i32* %59, i32 %60, i32 1, i32** %10, i32* %11)
store i32 %61, i32* %13
%62 = call i32 @clCreateContext(i32* null, i32 1, i32** %10, i32* null, i32* null, i32* %13)
store i32 %62, i32* %14
%63 = load i32, i32* %14
%64 = load i32*, i32** %10
%65 = call i32 @clCreateCommandQueue(i32 %63, i32* %64, i32 0, i32* %13)
store i32 %65, i32* %15
%66 = load i32, i32* %14
%67 = load i32, i32* @CL_MEM_READ_ONLY
%68 = call i32 @clCreateBuffer(i32 %66, i32 %67, i32 400000, i32* null, i32* %13)
store i32 %68, i32* %16
%69 = load i32, i32* %14
%70 = load i32, i32* @CL_MEM_WRITE_ONLY
%71 = call i32 @clCreateBuffer(i32 %69, i32 %70, i32 400000, i32* null, i32* %13)
store i32 %71, i32* %17
%72 = load i32, i32* %14
%73 = load i32, i32* @CL_MEM_WRITE_ONLY
%74 = call i32 @clCreateBuffer(i32 %72, i32 %73, i32 400000, i32* null, i32* %13)
store i32 %74, i32* %18
%75 = load i32, i32* %15
%76 = load i32, i32* %16
%77 = load i32, i32* @CL_TRUE
%78 = load float*, float** %4
%79 = call i32 @clEnqueueWriteBuffer(i32 %75, i32 %76, i32 %77, i32 0, i32 400000, float* %78, i32 0, i32* null, i32* null)
store i32 %79, i32* %13
%80 = load i32, i32* %14
%81 = call i32 @clCreateProgramWithSource(i32 %80, i32 1, i8** %7, i64* %8, i32* %13)
store i32 %81, i32* %19
%82 = load i32, i32* %19
%83 = call i32 @clBuildProgram(i32 %82, i32 1, i32** %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32* null, i32* null)
store i32 %83, i32* %13
%84 = load i32, i32* %19
%85 = call i32 @clCreateKernel(i32 %84, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* %13)
store i32 %85, i32* %20
%86 = load i32, i32* %20
%87 = bitcast i32* %16 to i8*
%88 = call i32 @clSetKernelArg(i32 %86, i32 0, i32 4, i8* %87)
store i32 %88, i32* %13
%89 = load i32, i32* %20
%90 = bitcast i32* %17 to i8*
%91 = call i32 @clSetKernelArg(i32 %89, i32 1, i32 4, i8* %90)
store i32 %91, i32* %13
%92 = load i32, i32* %20
%93 = bitcast i32* %18 to i8*
%94 = call i32 @clSetKernelArg(i32 %92, i32 2, i32 4, i8* %93)
store i32 %94, i32* %13
store i64 1, i64* %21
store i64 1, i64* %22
%95 = load i32, i32* %15
%96 = load i32, i32* %20
%97 = call i32 @clEnqueueNDRangeKernel(i32 %95, i32 %96, i32 1, i32* null, i64* %21, i64* %22, i32 0, i32* null, i32* null)
store i32 %97, i32* %13
%98 = call i64 @malloc(i32 400000)
%99 = inttoptr i64 %98 to float*
store float* %99, float** %23
%100 = call i64 @malloc(i32 400000)
%101 = inttoptr i64 %100 to float*
store float* %101, float** %24
%102 = load i32, i32* %15
%103 = load i32, i32* %17
%104 = load i32, i32* @CL_TRUE
%105 = load float*, float** %23
%106 = call i32 @clEnqueueReadBuffer(i32 %102, i32 %103, i32 %104, i32 0, i32 400000, float* %105, i32 0, i32* null, i32* null)
store i32 %106, i32* %13
%107 = load i32, i32* %15
%108 = load i32, i32* %18
%109 = load i32, i32* @CL_TRUE
%110 = load float*, float** %24
%111 = call i32 @clEnqueueReadBuffer(i32 %107, i32 %108, i32 %109, i32 0, i32 400000, float* %110, i32 0, i32* null, i32* null)
store i32 %111, i32* %13
store float 0.000000e+00, float* %25
store i32 0, i32* %2
br label %112
112: ; preds = %127, %50
%113 = load i32, i32* %2
%114 = icmp slt i32 %113, 100000
br i1 %114, label %115, label %130
115: ; preds = %112
%116 = load float*, float** %4
%117 = load i32, i32* %2
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds float, float* %116, i64 %118
%120 = load float, float* %119
%121 = load float*, float** %23
%122 = load i32, i32* %2
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds float, float* %121, i64 %123
%125 = load float, float* %124
%126 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), float %120, float %125)
br label %127
127: ; preds = %115
%128 = load i32, i32* %2
%129 = add nsw i32 %128, 1
store i32 %129, i32* %2
br label %112
130: ; preds = %112
%131 = load i32, i32* %15
%132 = call i32 @clFlush(i32 %131)
store i32 %132, i32* %13
%133 = load i32, i32* %15
%134 = call i32 @clFinish(i32 %133)
store i32 %134, i32* %13
%135 = load i32, i32* %20
%136 = call i32 @clReleaseKernel(i32 %135)
store i32 %136, i32* %13
%137 = load i32, i32* %19
%138 = call i32 @clReleaseProgram(i32 %137)
store i32 %138, i32* %13
%139 = load i32, i32* %16
%140 = call i32 @clReleaseMemObject(i32 %139)
store i32 %140, i32* %13
%141 = load i32, i32* %18
%142 = call i32 @clReleaseMemObject(i32 %141)
store i32 %142, i32* %13
%143 = load i32, i32* %15
%144 = call i32 @clReleaseCommandQueue(i32 %143)
store i32 %144, i32* %13
%145 = load i32, i32* %14
%146 = call i32 @clReleaseContext(i32 %145)
store i32 %146, i32* %13
%147 = load float*, float** %4
%148 = call i32 @free(float* %147)
%149 = load float*, float** %23
%150 = call i32 @free(float* %149)
%151 = load float*, float** %24
%152 = call i32 @free(float* %151)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"p4.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%f\0A\00"
@EOF = global i64 0
@.str.3 = [10 x i8] c"kernel.cl\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Failed to load kernel.\0A\00"
@CL_DEVICE_TYPE_GPU = global i32 0
@CL_MEM_READ_ONLY = global i32 0
@CL_MEM_WRITE_ONLY = global i32 0
@CL_TRUE = global i32 0
@.str.5 = [16 x i8] c"-cl-opt-disable\00"
@.str.6 = [11 x i8] c"vector_add\00"
@.str.7 = [10 x i8] c"%f\09%.15f\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = tail call i32 (...) @desabilita_cache_compilacao()
%14 = tail call i64 @malloc(i32 400000)
%15 = inttoptr i64 %14 to float*
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %17, %0
%18 = phi i64 [ %23, %17 ], [ 0, %0 ]
%19 = getelementptr inbounds float, float* %15, i64 %18
%20 = tail call i64 @fscanf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float* %19)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
%23 = add i64 %18, 1
br i1 %22, label %24, label %17
24: ; preds = %17
%25 = bitcast i8** %1 to i8*
%26 = bitcast i64* %2 to i8*
%27 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = tail call i64 @malloc(i32 1048576)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %1
%36 = tail call i64 @fread(i8* %35, i32 1, i32 1048576, i32* %27)
store i64 %36, i64* %2
%37 = tail call i32 @fclose(i32* %27)
%38 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%39 = bitcast i32** %4 to i8*
store i32* null, i32** %4
%40 = bitcast i32* %5 to i8*
%41 = bitcast i32* %6 to i8*
%42 = bitcast i32* %7 to i8*
%43 = call i32 @clGetPlatformIDs(i32 1, i32** %3, i32* %6)
store i32 %43, i32* %7
%44 = load i32*, i32** %3
%45 = load i32, i32* @CL_DEVICE_TYPE_GPU
%46 = call i32 @clGetDeviceIDs(i32* %44, i32 %45, i32 1, i32** %4, i32* %5)
store i32 %46, i32* %7
%47 = call i32 @clCreateContext(i32* null, i32 1, i32** %4, i32* null, i32* null, i32* %7)
%48 = load i32*, i32** %4
%49 = call i32 @clCreateCommandQueue(i32 %47, i32* %48, i32 0, i32* %7)
%50 = bitcast i32* %8 to i8*
%51 = load i32, i32* @CL_MEM_READ_ONLY
%52 = call i32 @clCreateBuffer(i32 %47, i32 %51, i32 400000, i32* null, i32* %7)
store i32 %52, i32* %8
%53 = bitcast i32* %9 to i8*
%54 = load i32, i32* @CL_MEM_WRITE_ONLY
%55 = call i32 @clCreateBuffer(i32 %47, i32 %54, i32 400000, i32* null, i32* %7)
store i32 %55, i32* %9
%56 = bitcast i32* %10 to i8*
%57 = load i32, i32* @CL_MEM_WRITE_ONLY
%58 = call i32 @clCreateBuffer(i32 %47, i32 %57, i32 400000, i32* null, i32* %7)
store i32 %58, i32* %10
%59 = load i32, i32* @CL_TRUE
%60 = call i32 @clEnqueueWriteBuffer(i32 %49, i32 %52, i32 %59, i32 0, i32 400000, float* %15, i32 0, i32* null, i32* null)
store i32 %60, i32* %7
%61 = call i32 @clCreateProgramWithSource(i32 %47, i32 1, i8** %1, i64* %2, i32* %7)
%62 = call i32 @clBuildProgram(i32 %61, i32 1, i32** %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32* null, i32* null)
store i32 %62, i32* %7
%63 = call i32 @clCreateKernel(i32 %61, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* %7)
%64 = call i32 @clSetKernelArg(i32 %63, i32 0, i32 4, i8* %50)
store i32 %64, i32* %7
%65 = call i32 @clSetKernelArg(i32 %63, i32 1, i32 4, i8* %53)
store i32 %65, i32* %7
%66 = call i32 @clSetKernelArg(i32 %63, i32 2, i32 4, i8* %56)
store i32 %66, i32* %7
%67 = bitcast i64* %11 to i8*
store i64 1, i64* %11
%68 = bitcast i64* %12 to i8*
store i64 1, i64* %12
%69 = call i32 @clEnqueueNDRangeKernel(i32 %49, i32 %63, i32 1, i32* null, i64* %11, i64* %12, i32 0, i32* null, i32* null)
store i32 %69, i32* %7
%70 = call i64 @malloc(i32 400000)
%71 = inttoptr i64 %70 to float*
%72 = call i64 @malloc(i32 400000)
%73 = inttoptr i64 %72 to float*
%74 = load i32, i32* %9
%75 = load i32, i32* @CL_TRUE
%76 = call i32 @clEnqueueReadBuffer(i32 %49, i32 %74, i32 %75, i32 0, i32 400000, float* %71, i32 0, i32* null, i32* null)
store i32 %76, i32* %7
%77 = load i32, i32* %10
%78 = load i32, i32* @CL_TRUE
%79 = call i32 @clEnqueueReadBuffer(i32 %49, i32 %77, i32 %78, i32 0, i32 400000, float* %73, i32 0, i32* null, i32* null)
store i32 %79, i32* %7
br label %80
80: ; preds = %33, %80
%81 = phi i64 [ 0, %33 ], [ %87, %80 ]
%82 = getelementptr inbounds float, float* %15, i64 %81
%83 = load float, float* %82
%84 = getelementptr inbounds float, float* %71, i64 %81
%85 = load float, float* %84
%86 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), float %83, float %85)
%87 = add nuw nsw i64 %81, 1
%88 = icmp eq i64 %87, 100000
br i1 %88, label %89, label %80
89: ; preds = %80
%90 = call i32 @clFlush(i32 %49)
store i32 %90, i32* %7
%91 = call i32 @clFinish(i32 %49)
store i32 %91, i32* %7
%92 = call i32 @clReleaseKernel(i32 %63)
store i32 %92, i32* %7
%93 = call i32 @clReleaseProgram(i32 %61)
store i32 %93, i32* %7
%94 = load i32, i32* %8
%95 = call i32 @clReleaseMemObject(i32 %94)
store i32 %95, i32* %7
%96 = load i32, i32* %10
%97 = call i32 @clReleaseMemObject(i32 %96)
store i32 %97, i32* %7
%98 = call i32 @clReleaseCommandQueue(i32 %49)
store i32 %98, i32* %7
%99 = call i32 @clReleaseContext(i32 %47)
store i32 %99, i32* %7
%100 = call i32 @free(float* %15)
%101 = call i32 @free(float* %71)
%102 = call i32 @free(float* %73)
ret i32 0
}