#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 uint;
struct timeval {
  double tv_sec;
  double tv_usec;
};
typedef int /*<<< orphan*/ local_size;
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_device_id;
typedef int /*<<< orphan*/ cl_context;
typedef int /*<<< orphan*/ cl_command_queue;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_TYPE_CPU;
int /*<<< orphan*/ CL_DEVICE_TYPE_GPU;
int /*<<< orphan*/ CL_KERNEL_WORK_GROUP_SIZE;
int CL_MEM_READ_ONLY;
int CL_MEM_READ_WRITE;
int CL_MEM_USE_HOST_PTR;
int /*<<< orphan*/ CL_PLATFORM_NAME;
int /*<<< orphan*/ CL_PROGRAM_BUILD_LOG;
int CL_SUCCESS;
int EXIT_FAILURE;
int clBuildProgram(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *);
int /*<<< orphan*/ clCreateBuffer(int /*<<< orphan*/, int, int, unsigned int *,
                                  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 clEnqueueNDRangeKernel(int /*<<< orphan*/, int /*<<< orphan*/, unsigned int,
                           int /*<<< orphan*/ *, size_t *, size_t *,
                           int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/ *);
int /*<<< orphan*/ clFinish(int /*<<< orphan*/);
int clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                   int /*<<< orphan*/ *, int *);
int clGetKernelWorkGroupInfo(int /*<<< orphan*/, int /*<<< orphan*/,
                             int /*<<< orphan*/, int, size_t *,
                             int /*<<< orphan*/ *);
int clGetPlatformIDs(int, int /*<<< orphan*/ *, int *);
int clGetPlatformInfo(int /*<<< orphan*/, int /*<<< orphan*/, size_t, char *,
                      size_t *);
int /*<<< orphan*/ clGetProgramBuildInfo(int /*<<< orphan*/, int /*<<< orphan*/,
                                         int /*<<< orphan*/, int, char *,
                                         size_t *);
int /*<<< orphan*/ clReleaseMemObject(int /*<<< orphan*/);
int clSetKernelArg(int /*<<< orphan*/, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned int *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ initialize_graph(unsigned int *, unsigned int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *readSourceFromFile(char *, size_t *);
scalar_t__ strstr(char *, char const *);
int main(int argc, char **argv) {
  int err;
  cl_device_id device_id;
  cl_context context;
  cl_command_queue commands;
  cl_program program;
  cl_kernel kernel;
  unsigned work_dim = 1;
  size_t global_size;
  size_t local_size;
  cl_mem buf_graph;
  cl_mem buf_dist;
  uint num_platforms = 0;
  err = clGetPlatformIDs(0, NULL, &num_platforms);
  if (err != CL_SUCCESS)
    do {
      printf("Err: "
             "clGetPlatformIDs[1] (%d)",
             err);
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  else
    printf("Number of available platforms: %u\n", num_platforms);
  if (!num_platforms)
    do {
      printf("Err: "
             "Err: no platforms found");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  cl_platform_id platforms[num_platforms];
  err = clGetPlatformIDs(num_platforms, platforms, NULL);
  if (err != CL_SUCCESS)
    do {
      printf("Err: "
             "clGetPlatformIDs[2]");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  int i;
  int platform_id = 0;
  for (i = 0; i < num_platforms; ++i) {
    const char *preferred_platform_name = "NVIDIA";
    size_t name_len = 0;
    err = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 0, NULL, &name_len);
    if (err != CL_SUCCESS)
      do {
        printf("Err: "
               "clGetPlatformInfo[1]");
        printf("\n");
        return EXIT_FAILURE;
      } while (0);
    char platform_name[name_len + 1];
    err = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, name_len,
                            platform_name, NULL);
    if (err != CL_SUCCESS)
      do {
        printf("Err: "
               "clGetPlatformInfo[2]");
        printf("\n");
        return EXIT_FAILURE;
      } while (0);
    platform_name[name_len] = '\0';
    if (strstr(platform_name, preferred_platform_name) != 0) {
      printf("Preferred platform found: %s\n", platform_name);
      platform_id = i;
      break;
    }
  }
  int gpu = 1;
  uint num_devices = 0;
  err = clGetDeviceIDs(platforms[platform_id],
                       gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 1,
                       &device_id, &num_devices);
  if (err != CL_SUCCESS)
    do {
      printf("Err: "
             " (code %d) clGetDeviceIDs",
             err);
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
  if (err != CL_SUCCESS)
    do {
      printf("Err: "
             "clCreateContext");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  commands = clCreateCommandQueue(context, device_id, 0, &err);
  if (err != CL_SUCCESS)
    do {
      printf("Err: "
             "clCreateCommandQueue");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  char *source;
  size_t src_size = 0;
  source = readSourceFromFile("MSTKernel.cl", &src_size);
  if (!source || src_size == 0)
    do {
      printf("Err: "
             "readSourceFromFile");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  else
    printf("Read %ld bytes source file\n", src_size);
  program = clCreateProgramWithSource(context, 1, (const char **)&source,
                                      &src_size, &err);
  if (!program)
    do {
      printf("Err: "
             "clCreateProgramWithSource");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
  if (err != CL_SUCCESS) {
    printf("Err: clBuildProgram\n");
    size_t len;
    char buf[2048];
    clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buf),
                          buf, &len);
    printf("%s\n", buf);
    return EXIT_FAILURE;
  }
  kernel = clCreateKernel(program, "FindMinDist", &err);
  if (!kernel || err != CL_SUCCESS)
    do {
      printf("Err: "
             "clCreateKernel");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  unsigned *graph;
  unsigned *dist;
  graph = (unsigned *)malloc(sizeof(unsigned) * 1024 * 1024);
  dist = (unsigned *)malloc(sizeof(unsigned) * 1024);
  initialize_graph(graph, dist);
  buf_graph = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
                             sizeof(unsigned) * 1024 * 1024, graph, &err);
  buf_dist = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
                            sizeof(unsigned) * 1024, dist, &err);
  if (!buf_graph || !buf_dist)
    do {
      printf("Err: "
             "clCreateBuffer");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &buf_graph);
  err |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &buf_dist);
  if (err != CL_SUCCESS)
    do {
      printf("Err: "
             "clSetKernelArg");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  global_size = 1024;
  err = clGetKernelWorkGroupInfo(kernel, device_id, CL_KERNEL_WORK_GROUP_SIZE,
                                 sizeof(local_size), &local_size, NULL);
  if (err != CL_SUCCESS)
    do {
      printf("Err: "
             "clGetKernelWorkGroupInfo");
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  printf("Set global_work_size = %ld, local_work_size = %ld\n", global_size,
         local_size);
  struct timeval t1, t2;
  gettimeofday(&t1, NULL);
  err = clEnqueueNDRangeKernel(commands, kernel, work_dim, NULL, &global_size,
                               &local_size, 0, NULL, NULL);
  if (err != CL_SUCCESS)
    do {
      printf("Err: "
             "clEnqueueNDRangeKernel (%d)",
             err);
      printf("\n");
      return EXIT_FAILURE;
    } while (0);
  clFinish(commands);
  gettimeofday(&t2, NULL);
  printf("Elapsed time: %lf ms\n",
         (t2.tv_sec - t1.tv_sec) * 1000.0 + (t2.tv_usec - t1.tv_usec) / 1000.0);
  clReleaseMemObject(buf_graph);
  clReleaseMemObject(buf_dist);
  free(graph);
  free(dist);
  return CL_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x900,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x4c(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x4c(%rbp),%rdx
call   10c0 <clGetPlatformIDs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2cf5(%rip),%rcx
cmp    (%rcx),%eax
je     12e0 <main+0x80>
jmp    12b0 <main+0x50>
mov    -0x14(%rbp),%esi
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xf6a(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1c3b <main+0x9db>
mov    -0x4c(%rbp),%esi
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
cmpl   $0x0,-0x4c(%rbp)
jne    132d <main+0xcd>
jmp    1300 <main+0xa0>
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xf1d(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x2c8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1c3b <main+0x9db>
mov    -0x4c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x8e8(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x60(%rbp)
mov    -0x4c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
call   10c0 <clGetPlatformIDs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2c28(%rip),%rcx
cmp    (%rcx),%eax
je     13b1 <main+0x151>
jmp    137d <main+0x11d>
lea    0xce2(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x2c10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1591 <main+0x331>
mov    -0x8e8(%rbp),%rax
lea    0xca6(%rip),%rcx
mov    %rcx,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    0x2bcd(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x80(%rbp),%r8
mov    %rcx,%rdx
call   10f0 <clGetPlatformInfo@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2b86(%rip),%rcx
cmp    (%rcx),%eax
je     1453 <main+0x1f3>
jmp    141f <main+0x1bf>
lea    0xc60(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x2b6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
mov    -0x8e8(%rbp),%rax
mov    -0x80(%rbp),%rsi
mov    %rsi,%rdx
add    $0x1,%rdx
mov    %rsp,%rcx
mov    %rcx,-0x88(%rbp)
add    $0x10,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0x8f0(%rbp)
mov    %rcx,%rsp
mov    %rdx,-0x90(%rbp)
movslq -0x68(%rbp),%rdx
mov    (%rax,%rdx,4),%edi
mov    0x2b24(%rip),%rax
mov    (%rax),%esi
mov    -0x80(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10f0 <clGetPlatformInfo@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2adf(%rip),%rcx
cmp    (%rcx),%eax
je     14fa <main+0x29a>
jmp    14c6 <main+0x266>
lea    0xbd3(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x2ac7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    154a <main+0x2ea>
mov    -0x8f0(%rbp),%rdi
mov    -0x80(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    -0x78(%rbp),%rsi
call   1180 <strstr@plt>
cmp    $0x0,%rax
je     1543 <main+0x2e3>
mov    -0x8f0(%rbp),%rsi
lea    0xb90(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    -0x68(%rbp),%eax
mov    %eax,-0x6c(%rbp)
movl   $0x8,-0x64(%rbp)
jmp    154a <main+0x2ea>
movl   $0x0,-0x64(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,%rsp
mov    -0x64(%rbp),%eax
mov    %eax,-0x8f4(%rbp)
test   %eax,%eax
je     157e <main+0x31e>
jmp    156a <main+0x30a>
mov    -0x8f4(%rbp),%eax
sub    $0x8,%eax
je     1591 <main+0x331>
jmp    1c34 <main+0x9d4>
jmp    1583 <main+0x323>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    13bf <main+0x15f>
mov    -0x8e8(%rbp),%rax
movl   $0x1,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
movslq -0x6c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x8f8(%rbp)
cmpl   $0x0,-0x94(%rbp)
je     15da <main+0x37a>
mov    0x2a03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8fc(%rbp)
jmp    15e9 <main+0x389>
mov    0x29d7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8fc(%rbp)
mov    -0x8f8(%rbp),%edi
mov    -0x8fc(%rbp),%esi
mov    $0x1,%edx
lea    -0x18(%rbp),%rcx
lea    -0x98(%rbp),%r8
call   1090 <clGetDeviceIDs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2981(%rip),%rcx
cmp    (%rcx),%eax
je     165b <main+0x3fb>
jmp    1624 <main+0x3c4>
mov    -0x14(%rbp),%esi
lea    0xaaa(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xbf6(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x2966(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
xor    %edi,%edi
mov    $0x1,%esi
lea    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x14(%rbp),%r9
mov    %r8,%rcx
call   1100 <clCreateContext@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2914(%rip),%rcx
cmp    (%rcx),%eax
je     16c5 <main+0x465>
jmp    1691 <main+0x431>
lea    0xa5f(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xb8c(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x28fc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
lea    -0x14(%rbp),%rcx
call   10b0 <clCreateCommandQueue@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    0x28b5(%rip),%rcx
cmp    (%rcx),%eax
je     1724 <main+0x4c4>
jmp    16f0 <main+0x490>
lea    0xa15(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xb2d(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x289d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
movq   $0x0,-0xa8(%rbp)
lea    0x9f0(%rip),%rdi
lea    -0xa8(%rbp),%rsi
call   1130 <readSourceFromFile@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
je     1765 <main+0x505>
cmpq   $0x0,-0xa8(%rbp)
jne    179e <main+0x53e>
jmp    176a <main+0x50a>
lea    0x9c2(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xab3(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x2823(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
mov    -0xa8(%rbp),%rsi
lea    0x99f(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
lea    -0xa0(%rbp),%rdx
lea    -0xa8(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1060 <clCreateProgramWithSource@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1818 <main+0x5b8>
jmp    17e4 <main+0x584>
lea    0x97c(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0xa39(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x27a9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
mov    -0x24(%rbp),%edi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rdx
mov    %r9,%rcx
mov    %r9,%r8
call   1030 <clBuildProgram@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x275b(%rip),%rcx
cmp    (%rcx),%eax
je     18a7 <main+0x647>
lea    0x93a(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2778(%rip),%rax
mov    (%rax),%edx
lea    -0x8b0(%rbp),%r8
mov    $0x800,%ecx
lea    -0xb0(%rbp),%r9
call   1110 <clGetProgramBuildInfo@plt>
lea    -0x8b0(%rbp),%rsi
lea    0x84c(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x271a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
mov    -0x24(%rbp),%edi
lea    0x8ea(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1150 <clCreateKernel@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     18d9 <main+0x679>
mov    -0x14(%rbp),%eax
mov    0x26c7(%rip),%rcx
cmp    (%rcx),%eax
je     1912 <main+0x6b2>
jmp    18de <main+0x67e>
lea    0x8c2(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0x93f(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x26af(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
mov    $0x400000,%edi
call   1120 <malloc@plt>
mov    %rax,-0x8b8(%rbp)
mov    $0x1000,%edi
call   1120 <malloc@plt>
mov    %rax,-0x8c0(%rbp)
mov    -0x8b8(%rbp),%rdi
mov    -0x8c0(%rbp),%rsi
call   1160 <initialize_graph@plt>
mov    -0x1c(%rbp),%edi
mov    0x2657(%rip),%rax
mov    (%rax),%esi
mov    0x2686(%rip),%rax
or     (%rax),%esi
mov    -0x8b8(%rbp),%rcx
mov    $0x400000,%edx
lea    -0x14(%rbp),%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,-0x44(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x266a(%rip),%rax
mov    (%rax),%esi
mov    0x2659(%rip),%rax
or     (%rax),%esi
mov    -0x8c0(%rbp),%rcx
mov    $0x1000,%edx
lea    -0x14(%rbp),%r8
call   1070 <clCreateBuffer@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     19b5 <main+0x755>
cmpl   $0x0,-0x48(%rbp)
jne    19ee <main+0x78e>
jmp    19ba <main+0x75a>
lea    0x7fa(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0x863(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x25d3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
mov    -0x28(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
lea    -0x44(%rbp),%rcx
call   1170 <clSetKernelArg@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
mov    $0x4,%edx
lea    -0x48(%rbp),%rcx
call   1170 <clSetKernelArg@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x256e(%rip),%rcx
cmp    (%rcx),%eax
je     1a6b <main+0x80b>
jmp    1a37 <main+0x7d7>
lea    0x791(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0x7e6(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x2556(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
movq   $0x400,-0x38(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2520(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%ecx
lea    -0x40(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1080 <clGetKernelWorkGroupInfo@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x24f6(%rip),%rcx
cmp    (%rcx),%eax
je     1ae3 <main+0x883>
jmp    1aaf <main+0x84f>
lea    0x72d(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0x76e(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x24de(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0x70f(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    -0x8d0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <gettimeofday@plt>
mov    -0x20(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x38(%rbp),%r8
lea    -0x40(%rbp),%r9
xor    %eax,%eax
sub    $0x20,%rsp
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   10a0 <clEnqueueNDRangeKernel@plt>
add    $0x20,%rsp
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2445(%rip),%rcx
cmp    (%rcx),%eax
je     1b97 <main+0x937>
jmp    1b60 <main+0x900>
mov    -0x14(%rbp),%esi
lea    0x6ca(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    0x6ba(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x242a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1c34 <main+0x9d4>
mov    -0x20(%rbp),%edi
call   1050 <clFinish@plt>
lea    -0x8e0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <gettimeofday@plt>
movsd  -0x8e0(%rbp),%xmm0
ff
subsd  -0x8d0(%rbp),%xmm0
ff
movsd  -0x8d8(%rbp),%xmm1
ff
subsd  -0x8c8(%rbp),%xmm1
ff
movsd  0x429(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0x41d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
lea    0x663(%rip),%rdi
mov    $0x1,%al
call   10d0 <printf@plt>
mov    -0x44(%rbp),%edi
call   1140 <clReleaseMemObject@plt>
mov    -0x48(%rbp),%edi
call   1140 <clReleaseMemObject@plt>
mov    -0x8b8(%rbp),%rdi
call   1040 <free@plt>
mov    -0x8c0(%rbp),%rdi
call   1040 <free@plt>
mov    0x2370(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x878,%rsp
movl   $0x0,-0x30(%rbp)
lea    -0x30(%rbp),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   10e0 <clGetPlatformIDs@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2cee(%rip),%rbx
cmp    (%rbx),%eax
jne    13ef <main+0x16f>
mov    -0x30(%rbp),%esi
lea    0xd62(%rip),%rdi
xor    %eax,%eax
call   10f0 <printf@plt>
mov    -0x30(%rbp),%eax
test   %rax,%rax
je     1401 <main+0x181>
mov    %rsp,%r14
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    -0x30(%rbp),%edi
mov    %r12,%rsi
xor    %edx,%edx
call   10e0 <clGetPlatformIDs@plt>
mov    %eax,-0x2c(%rbp)
cmp    (%rbx),%eax
jne    1427 <main+0x1a7>
mov    %rbx,-0x70(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    143a <main+0x1ba>
mov    %r14,-0x40(%rbp)
mov    0x2ca0(%rip),%r13
mov    0x2c79(%rip),%r14
xor    %r15d,%r15d
mov    %r12,-0x58(%rbp)
xchg   %ax,%ax
movq   $0x0,-0x8a0(%rbp)
mov    (%r12,%r15,4),%edi
mov    0x0(%r13),%esi
xor    %edx,%edx
xor    %ecx,%ecx
lea    -0x8a0(%rbp),%r8
call   1110 <clGetPlatformInfo@plt>
mov    %eax,-0x2c(%rbp)
cmp    (%r14),%eax
jne    143f <main+0x1bf>
mov    %rsp,-0x48(%rbp)
mov    -0x8a0(%rbp),%rax
mov    %rsp,%rbx
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%r12,%r15,4),%edi
mov    0x0(%r13),%esi
mov    -0x8a0(%rbp),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1110 <clGetPlatformInfo@plt>
mov    %eax,-0x2c(%rbp)
cmp    (%r14),%eax
jne    1462 <main+0x1e2>
mov    %r14,%r12
mov    -0x8a0(%rbp),%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
lea    0xcc6(%rip),%rsi
call   11a0 <strstr@plt>
test   %rax,%rax
jne    1490 <main+0x210>
mov    -0x48(%rbp),%rsp
add    $0x1,%r15
movslq -0x30(%rbp),%rax
cmp    %rax,%r15
mov    %r12,%r14
mov    -0x58(%rbp),%r12
jl     1330 <main+0xb0>
xor    %r15d,%r15d
mov    -0x40(%rbp),%r14
jmp    14ad <main+0x22d>
lea    0xc12(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10f0 <printf@plt>
jmp    140f <main+0x18f>
lea    0xc41(%rip),%rdi
xor    %eax,%eax
call   10f0 <printf@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    0x2b98(%rip),%rax
mov    (%rax),%eax
jmp    17fb <main+0x57b>
lea    0xc38(%rip),%rdi
xor    %eax,%eax
call   10f0 <printf@plt>
jmp    17e5 <main+0x565>
xor    %r15d,%r15d
jmp    14ad <main+0x22d>
lea    0xc40(%rip),%rdi
xor    %eax,%eax
call   10f0 <printf@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    0x2b5a(%rip),%rax
mov    (%rax),%eax
jmp    1487 <main+0x207>
lea    0xc37(%rip),%rdi
xor    %eax,%eax
call   10f0 <printf@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    0x2b37(%rip),%rax
mov    (%rax),%eax
mov    -0x48(%rbp),%rsp
mov    -0x40(%rbp),%r14
jmp    17f8 <main+0x578>
lea    0xc23(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10f0 <printf@plt>
mov    -0x48(%rbp),%rsp
mov    -0x40(%rbp),%r14
mov    -0x58(%rbp),%r12
movl   $0x0,-0x64(%rbp)
mov    (%r12,%r15,4),%edi
mov    0x2b11(%rip),%rax
mov    (%rax),%esi
lea    -0x34(%rbp),%rcx
lea    -0x64(%rbp),%r8
mov    $0x1,%edx
call   10b0 <clGetDeviceIDs@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2ac3(%rip),%r15
cmp    (%r15),%eax
jne    17d5 <main+0x555>
lea    -0x34(%rbp),%rdx
lea    -0x2c(%rbp),%r9
xor    %edi,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1120 <clCreateContext@plt>
mov    %eax,%r13d
mov    -0x2c(%rbp),%eax
cmp    (%r15),%eax
jne    180a <main+0x58a>
mov    -0x34(%rbp),%esi
lea    -0x2c(%rbp),%rcx
mov    %r13d,%edi
xor    %edx,%edx
call   10d0 <clCreateCommandQueue@plt>
mov    %eax,%r12d
mov    -0x2c(%rbp),%eax
cmp    (%r15),%eax
jne    1816 <main+0x596>
movq   $0x0,-0x60(%rbp)
lea    0xbe9(%rip),%rdi
lea    -0x60(%rbp),%rsi
call   1150 <readSourceFromFile@plt>
mov    %rax,-0x90(%rbp)
test   %rax,%rax
je     1822 <main+0x5a2>
mov    -0x60(%rbp),%rsi
test   %rsi,%rsi
je     1822 <main+0x5a2>
lea    0xbe1(%rip),%rdi
xor    %eax,%eax
call   10f0 <printf@plt>
lea    -0x90(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x2c(%rbp),%r8
mov    %r13d,%edi
mov    $0x1,%esi
call   1070 <clCreateProgramWithSource@plt>
test   %eax,%eax
je     182e <main+0x5ae>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
mov    %eax,-0x2c(%rbp)
cmp    (%r15),%eax
jne    183a <main+0x5ba>
lea    0xbc9(%rip),%rsi
lea    -0x2c(%rbp),%rdx
mov    %ebx,%edi
call   1170 <clCreateKernel@plt>
test   %eax,%eax
je     187c <main+0x5fc>
mov    -0x2c(%rbp),%ecx
cmp    (%r15),%ecx
jne    187c <main+0x5fc>
mov    %eax,-0x48(%rbp)
mov    %r14,-0x40(%rbp)
mov    $0x400000,%edi
call   1140 <malloc@plt>
mov    %rax,%rbx
mov    $0x1000,%edi
call   1140 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1180 <initialize_graph@plt>
mov    0x29a1(%rip),%rax
mov    0x29ca(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    -0x2c(%rbp),%r8
mov    %r13d,%edi
mov    $0x400000,%edx
mov    %rbx,-0x58(%rbp)
mov    %rbx,%rcx
mov    %r8,%rbx
call   1090 <clCreateBuffer@plt>
mov    %eax,%r15d
mov    %eax,-0x50(%rbp)
mov    0x29a6(%rip),%rax
mov    0x2997(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r13d,%edi
mov    $0x1000,%edx
mov    %r14,%r13
mov    %r14,%rcx
mov    %rbx,%r8
call   1090 <clCreateBuffer@plt>
mov    %eax,-0x4c(%rbp)
test   %r15d,%r15d
je     1888 <main+0x608>
test   %eax,%eax
je     1888 <main+0x608>
lea    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%ebx
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1190 <clSetKernelArg@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x4c(%rbp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x4,%edx
call   1190 <clSetKernelArg@plt>
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x28ef(%rip),%r15
cmp    (%r15),%eax
mov    -0x40(%rbp),%r14
jne    1894 <main+0x614>
movq   $0x400,-0x98(%rbp)
mov    -0x34(%rbp),%esi
mov    0x28d5(%rip),%rax
mov    (%rax),%edx
lea    -0x78(%rbp),%r8
mov    %ebx,%edi
mov    $0x8,%ecx
xor    %r9d,%r9d
call   10a0 <clGetKernelWorkGroupInfo@plt>
mov    %eax,-0x2c(%rbp)
cmp    (%r15),%eax
jne    18a0 <main+0x620>
mov    -0x78(%rbp),%rdx
lea    0xaed(%rip),%rdi
mov    $0x400,%esi
xor    %eax,%eax
call   10f0 <printf@plt>
lea    -0x8a0(%rbp),%rdi
xor    %esi,%esi
call   1100 <gettimeofday@plt>
sub    $0x20,%rsp
xorpd  %xmm0,%xmm0
movupd %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
lea    -0x98(%rbp),%r8
lea    -0x78(%rbp),%r9
mov    %r12d,%edi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   10c0 <clEnqueueNDRangeKernel@plt>
add    $0x20,%rsp
mov    %eax,-0x2c(%rbp)
cmp    (%r15),%eax
jne    18ac <main+0x62c>
mov    %r12d,%edi
call   1060 <clFinish@plt>
lea    -0x88(%rbp),%rdi
xor    %esi,%esi
call   1100 <gettimeofday@plt>
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x80(%rbp),%xmm1
subsd  -0x8a0(%rbp),%xmm0
ff
subsd  -0x898(%rbp),%xmm1
ff
movsd  0x86b(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
lea    0xa98(%rip),%rdi
mov    $0x1,%al
call   10f0 <printf@plt>
mov    -0x50(%rbp),%edi
call   1160 <clReleaseMemObject@plt>
mov    -0x4c(%rbp),%edi
call   1160 <clReleaseMemObject@plt>
mov    -0x58(%rbp),%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
jmp    18d1 <main+0x651>
lea    0x8fc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10f0 <printf@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    0x27c2(%rip),%rax
mov    (%rax),%eax
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8e6(%rip),%rdi
jmp    142e <main+0x1ae>
lea    0x8ef(%rip),%rdi
jmp    142e <main+0x1ae>
lea    0x90a(%rip),%rdi
jmp    142e <main+0x1ae>
lea    0x932(%rip),%rdi
jmp    142e <main+0x1ae>
lea    0xa15(%rip),%rdi
call   1080 <puts@plt>
mov    -0x34(%rbp),%esi
mov    0x2788(%rip),%rax
mov    (%rax),%edx
lea    -0x8a0(%rbp),%r15
lea    -0x88(%rbp),%r9
mov    %ebx,%edi
mov    $0x800,%ecx
mov    %r15,%r8
call   1130 <clGetProgramBuildInfo@plt>
mov    %r15,%rdi
call   1080 <puts@plt>
jmp    17ef <main+0x56f>
lea    0x90f(%rip),%rdi
jmp    142e <main+0x1ae>
lea    0x917(%rip),%rdi
jmp    1446 <main+0x1c6>
lea    0x91f(%rip),%rdi
jmp    142e <main+0x1ae>
lea    0x927(%rip),%rdi
jmp    142e <main+0x1ae>
lea    0x96c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10f0 <printf@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    0x26eb(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
jmp    145e <main+0x1de>

LLVM IR (-O0):
%struct.timeval = type { double, double }
@CL_SUCCESS = global i32 0
@.str = [30 x i8] c"Err: clGetPlatformIDs[1] (%d)\00"
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [35 x i8] c"Number of available platforms: %u\0A\00"
@.str.3 = [29 x i8] c"Err: Err: no platforms found\00"
@.str.4 = [25 x i8] c"Err: clGetPlatformIDs[2]\00"
@.str.5 = [7 x i8] c"NVIDIA\00"
@CL_PLATFORM_NAME = global i32 0
@.str.6 = [26 x i8] c"Err: clGetPlatformInfo[1]\00"
@.str.7 = [26 x i8] c"Err: clGetPlatformInfo[2]\00"
@.str.8 = [30 x i8] c"Preferred platform found: %s\0A\00"
@CL_DEVICE_TYPE_GPU = global i32 0
@CL_DEVICE_TYPE_CPU = global i32 0
@.str.9 = [31 x i8] c"Err: (code %d) clGetDeviceIDs\00"
@.str.10 = [21 x i8] c"Err: clCreateContext\00"
@.str.11 = [26 x i8] c"Err: clCreateCommandQueue\00"
@.str.12 = [13 x i8] c"MSTKernel.cl\00"
@.str.13 = [24 x i8] c"Err: readSourceFromFile\00"
@.str.14 = [28 x i8] c"Read %ld bytes source file\0A\00"
@.str.15 = [31 x i8] c"Err: clCreateProgramWithSource\00"
@.str.16 = [21 x i8] c"Err: clBuildProgram\0A\00"
@CL_PROGRAM_BUILD_LOG = global i32 0
@.str.17 = [4 x i8] c"%s\0A\00"
@.str.18 = [12 x i8] c"FindMinDist\00"
@.str.19 = [20 x i8] c"Err: clCreateKernel\00"
@CL_MEM_READ_ONLY = global i32 0
@CL_MEM_USE_HOST_PTR = global i32 0
@CL_MEM_READ_WRITE = global i32 0
@.str.20 = [20 x i8] c"Err: clCreateBuffer\00"
@.str.21 = [20 x i8] c"Err: clSetKernelArg\00"
@CL_KERNEL_WORK_GROUP_SIZE = global i32 0
@.str.22 = [30 x i8] c"Err: clGetKernelWorkGroupInfo\00"
@.str.23 = [51 x i8] c"Set global_work_size = %ld, local_work_size = %ld\0A\00"
@.str.24 = [33 x i8] c"Err: clEnqueueNDRangeKernel (%d)\00"
@.str.25 = [22 x i8] c"Elapsed time: %lf ms\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 i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i8*
%24 = alloca i64
%25 = alloca i8*
%26 = alloca i64
%27 = alloca i32
%28 = alloca i32
%29 = alloca i8*
%30 = alloca i64
%31 = alloca i64
%32 = alloca [2048 x i8]
%33 = alloca i32*
%34 = alloca i32*
%35 = alloca %struct.timeval
%36 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %12
store i32 0, i32* %17
%37 = call i32 @clGetPlatformIDs(i32 0, i32* null, i32* %17)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = load i32, i32* @CL_SUCCESS
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %48
41: ; preds = %2
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
store i32 %46, i32* %3
br label %362
47: ; No predecessors!
br label %51
48: ; preds = %2
%49 = load i32, i32* %17
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %48, %47
%52 = load i32, i32* %17
%53 = icmp ne i32 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %51
br label %55
55: ; preds = %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
store i32 %58, i32* %3
br label %362
59: ; No predecessors!
br label %60
60: ; preds = %59, %51
%61 = load i32, i32* %17
%62 = zext i32 %61 to i64
%63 = call i8* @llvm.stacksave()
store i8* %63, i8** %18
%64 = alloca i32, i64 %62
store i64 %62, i64* %19
%65 = load i32, i32* %17
%66 = call i32 @clGetPlatformIDs(i32 %65, i32* %64, i32* null)
store i32 %66, i32* %6
%67 = load i32, i32* %6
%68 = load i32, i32* @CL_SUCCESS
%69 = icmp ne i32 %67, %68
br i1 %69, label %70, label %77
70: ; preds = %60
br label %71
71: ; preds = %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
store i32 %74, i32* %3
store i32 1, i32* %20
br label %360
75: ; No predecessors!
br label %76
76: ; preds = %75
br label %77
77: ; preds = %76, %60
store i32 0, i32* %22
store i32 0, i32* %21
br label %78
78: ; preds = %135, %77
%79 = load i32, i32* %21
%80 = load i32, i32* %17
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %138
82: ; preds = %78
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8** %23
store i64 0, i64* %24
%83 = load i32, i32* %21
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %64, i64 %84
%86 = load i32, i32* %85
%87 = load i32, i32* @CL_PLATFORM_NAME
%88 = call i32 @clGetPlatformInfo(i32 %86, i32 %87, i64 0, i8* null, i64* %24)
store i32 %88, i32* %6
%89 = load i32, i32* %6
%90 = load i32, i32* @CL_SUCCESS
%91 = icmp ne i32 %89, %90
br i1 %91, label %92, label %99
92: ; preds = %82
br label %93
93: ; preds = %92
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%96 = load i32, i32* @EXIT_FAILURE
store i32 %96, i32* %3
store i32 1, i32* %20
br label %360
97: ; No predecessors!
br label %98
98: ; preds = %97
br label %99
99: ; preds = %98, %82
%100 = load i64, i64* %24
%101 = add i64 %100, 1
%102 = call i8* @llvm.stacksave()
store i8* %102, i8** %25
%103 = alloca i8, i64 %101
store i64 %101, i64* %26
%104 = load i32, i32* %21
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i32, i32* %64, i64 %105
%107 = load i32, i32* %106
%108 = load i32, i32* @CL_PLATFORM_NAME
%109 = load i64, i64* %24
%110 = call i32 @clGetPlatformInfo(i32 %107, i32 %108, i64 %109, i8* %103, i64* null)
store i32 %110, i32* %6
%111 = load i32, i32* %6
%112 = load i32, i32* @CL_SUCCESS
%113 = icmp ne i32 %111, %112
br i1 %113, label %114, label %121
114: ; preds = %99
br label %115
115: ; preds = %114
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%118 = load i32, i32* @EXIT_FAILURE
store i32 %118, i32* %3
store i32 1, i32* %20
br label %131
119: ; No predecessors!
br label %120
120: ; preds = %119
br label %121
121: ; preds = %120, %99
%122 = load i64, i64* %24
%123 = getelementptr inbounds i8, i8* %103, i64 %122
store i8 0, i8* %123
%124 = load i8*, i8** %23
%125 = call i64 @strstr(i8* %103, i8* %124)
%126 = icmp ne i64 %125, 0
br i1 %126, label %127, label %130
127: ; preds = %121
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %103)
%129 = load i32, i32* %21
store i32 %129, i32* %22
store i32 8, i32* %20
br label %131
130: ; preds = %121
store i32 0, i32* %20
br label %131
131: ; preds = %130, %127, %115
%132 = load i8*, i8** %25
%133 = load i32, i32* %20
switch i32 %133, label %360 [
i32 0, label %134
i32 8, label %138
]
134: ; preds = %131
br label %135
135: ; preds = %134
%136 = load i32, i32* %21
%137 = add nsw i32 %136, 1
store i32 %137, i32* %21
br label %78
138: ; preds = %131, %78
store i32 1, i32* %27
store i32 0, i32* %28
%139 = load i32, i32* %22
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i32, i32* %64, i64 %140
%142 = load i32, i32* %141
%143 = load i32, i32* %27
%144 = icmp ne i32 %143, 0
br i1 %144, label %145, label %147
145: ; preds = %138
%146 = load i32, i32* @CL_DEVICE_TYPE_GPU
br label %149
147: ; preds = %138
%148 = load i32, i32* @CL_DEVICE_TYPE_CPU
br label %149
149: ; preds = %147, %145
%150 = phi i32 [ %146, %145 ], [ %148, %147 ]
%151 = call i32 @clGetDeviceIDs(i32 %142, i32 %150, i32 1, i32* %7, i32* %28)
store i32 %151, i32* %6
%152 = load i32, i32* %6
%153 = load i32, i32* @CL_SUCCESS
%154 = icmp ne i32 %152, %153
br i1 %154, label %155, label %163
155: ; preds = %149
br label %156
156: ; preds = %155
%157 = load i32, i32* %6
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %157)
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%160 = load i32, i32* @EXIT_FAILURE
store i32 %160, i32* %3
store i32 1, i32* %20
br label %360
161: ; No predecessors!
br label %162
162: ; preds = %161
br label %163
163: ; preds = %162, %149
%164 = call i32 @clCreateContext(i32 0, i32 1, i32* %7, i32* null, i32* null, i32* %6)
store i32 %164, i32* %8
%165 = load i32, i32* %6
%166 = load i32, i32* @CL_SUCCESS
%167 = icmp ne i32 %165, %166
br i1 %167, label %168, label %175
168: ; preds = %163
br label %169
169: ; preds = %168
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%172 = load i32, i32* @EXIT_FAILURE
store i32 %172, i32* %3
store i32 1, i32* %20
br label %360
173: ; No predecessors!
br label %174
174: ; preds = %173
br label %175
175: ; preds = %174, %163
%176 = load i32, i32* %8
%177 = load i32, i32* %7
%178 = call i32 @clCreateCommandQueue(i32 %176, i32 %177, i32 0, i32* %6)
store i32 %178, i32* %9
%179 = load i32, i32* %6
%180 = load i32, i32* @CL_SUCCESS
%181 = icmp ne i32 %179, %180
br i1 %181, label %182, label %189
182: ; preds = %175
br label %183
183: ; preds = %182
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0))
%185 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%186 = load i32, i32* @EXIT_FAILURE
store i32 %186, i32* %3
store i32 1, i32* %20
br label %360
187: ; No predecessors!
br label %188
188: ; preds = %187
br label %189
189: ; preds = %188, %175
store i64 0, i64* %30
%190 = call i8* @readSourceFromFile(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i64* %30)
store i8* %190, i8** %29
%191 = load i8*, i8** %29
%192 = icmp ne i8* %191, null
br i1 %192, label %193, label %196
193: ; preds = %189
%194 = load i64, i64* %30
%195 = icmp eq i64 %194, 0
br i1 %195, label %196, label %203
196: ; preds = %193, %189
br label %197
197: ; preds = %196
%198 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0))
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%200 = load i32, i32* @EXIT_FAILURE
store i32 %200, i32* %3
store i32 1, i32* %20
br label %360
201: ; No predecessors!
br label %202
202: ; preds = %201
br label %206
203: ; preds = %193
%204 = load i64, i64* %30
%205 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.14, i64 0, i64 0), i64 %204)
br label %206
206: ; preds = %203, %202
%207 = load i32, i32* %8
%208 = call i32 @clCreateProgramWithSource(i32 %207, i32 1, i8** %29, i64* %30, i32* %6)
store i32 %208, i32* %10
%209 = load i32, i32* %10
%210 = icmp ne i32 %209, 0
br i1 %210, label %218, label %211
211: ; preds = %206
br label %212
212: ; preds = %211
%213 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0))
%214 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%215 = load i32, i32* @EXIT_FAILURE
store i32 %215, i32* %3
store i32 1, i32* %20
br label %360
216: ; No predecessors!
br label %217
217: ; preds = %216
br label %218
218: ; preds = %217, %206
%219 = load i32, i32* %10
%220 = call i32 @clBuildProgram(i32 %219, i32 0, i32* null, i32* null, i32* null, i32* null)
store i32 %220, i32* %6
%221 = load i32, i32* %6
%222 = load i32, i32* @CL_SUCCESS
%223 = icmp ne i32 %221, %222
br i1 %223, label %224, label %234
224: ; preds = %218
%225 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0))
%226 = load i32, i32* %10
%227 = load i32, i32* %7
%228 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%229 = getelementptr inbounds [2048 x i8], [2048 x i8]* %32, i64 0, i64 0
%230 = call i32 @clGetProgramBuildInfo(i32 %226, i32 %227, i32 %228, i32 2048, i8* %229, i64* %31)
%231 = getelementptr inbounds [2048 x i8], [2048 x i8]* %32, i64 0, i64 0
%232 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i64 0, i64 0), i8* %231)
%233 = load i32, i32* @EXIT_FAILURE
store i32 %233, i32* %3
store i32 1, i32* %20
br label %360
234: ; preds = %218
%235 = load i32, i32* %10
%236 = call i32 @clCreateKernel(i32 %235, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0), i32* %6)
store i32 %236, i32* %11
%237 = load i32, i32* %11
%238 = icmp ne i32 %237, 0
br i1 %238, label %239, label %243
239: ; preds = %234
%240 = load i32, i32* %6
%241 = load i32, i32* @CL_SUCCESS
%242 = icmp ne i32 %240, %241
br i1 %242, label %243, label %250
243: ; preds = %239, %234
br label %244
244: ; preds = %243
%245 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.19, i64 0, i64 0))
%246 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%247 = load i32, i32* @EXIT_FAILURE
store i32 %247, i32* %3
store i32 1, i32* %20
br label %360
248: ; No predecessors!
br label %249
249: ; preds = %248
br label %250
250: ; preds = %249, %239
%251 = call i64 @malloc(i32 4194304)
%252 = inttoptr i64 %251 to i32*
store i32* %252, i32** %33
%253 = call i64 @malloc(i32 4096)
%254 = inttoptr i64 %253 to i32*
store i32* %254, i32** %34
%255 = load i32*, i32** %33
%256 = load i32*, i32** %34
%257 = call i32 @initialize_graph(i32* %255, i32* %256)
%258 = load i32, i32* %8
%259 = load i32, i32* @CL_MEM_READ_ONLY
%260 = load i32, i32* @CL_MEM_USE_HOST_PTR
%261 = or i32 %259, %260
%262 = load i32*, i32** %33
%263 = call i32 @clCreateBuffer(i32 %258, i32 %261, i32 4194304, i32* %262, i32* %6)
store i32 %263, i32* %15
%264 = load i32, i32* %8
%265 = load i32, i32* @CL_MEM_READ_WRITE
%266 = load i32, i32* @CL_MEM_USE_HOST_PTR
%267 = or i32 %265, %266
%268 = load i32*, i32** %34
%269 = call i32 @clCreateBuffer(i32 %264, i32 %267, i32 4096, i32* %268, i32* %6)
store i32 %269, i32* %16
%270 = load i32, i32* %15
%271 = icmp ne i32 %270, 0
br i1 %271, label %272, label %275
272: ; preds = %250
%273 = load i32, i32* %16
%274 = icmp ne i32 %273, 0
br i1 %274, label %282, label %275
275: ; preds = %272, %250
br label %276
276: ; preds = %275
%277 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.20, i64 0, i64 0))
%278 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%279 = load i32, i32* @EXIT_FAILURE
store i32 %279, i32* %3
store i32 1, i32* %20
br label %360
280: ; No predecessors!
br label %281
281: ; preds = %280
br label %282
282: ; preds = %281, %272
%283 = load i32, i32* %11
%284 = call i32 @clSetKernelArg(i32 %283, i32 0, i32 4, i32* %15)
store i32 %284, i32* %6
%285 = load i32, i32* %11
%286 = call i32 @clSetKernelArg(i32 %285, i32 1, i32 4, i32* %16)
%287 = load i32, i32* %6
%288 = or i32 %287, %286
store i32 %288, i32* %6
%289 = load i32, i32* %6
%290 = load i32, i32* @CL_SUCCESS
%291 = icmp ne i32 %289, %290
br i1 %291, label %292, label %299
292: ; preds = %282
br label %293
293: ; preds = %292
%294 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.21, i64 0, i64 0))
%295 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%296 = load i32, i32* @EXIT_FAILURE
store i32 %296, i32* %3
store i32 1, i32* %20
br label %360
297: ; No predecessors!
br label %298
298: ; preds = %297
br label %299
299: ; preds = %298, %282
store i64 1024, i64* %13
%300 = load i32, i32* %11
%301 = load i32, i32* %7
%302 = load i32, i32* @CL_KERNEL_WORK_GROUP_SIZE
%303 = call i32 @clGetKernelWorkGroupInfo(i32 %300, i32 %301, i32 %302, i32 8, i64* %14, i32* null)
store i32 %303, i32* %6
%304 = load i32, i32* %6
%305 = load i32, i32* @CL_SUCCESS
%306 = icmp ne i32 %304, %305
br i1 %306, label %307, label %314
307: ; preds = %299
br label %308
308: ; preds = %307
%309 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.22, i64 0, i64 0))
%310 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%311 = load i32, i32* @EXIT_FAILURE
store i32 %311, i32* %3
store i32 1, i32* %20
br label %360
312: ; No predecessors!
br label %313
313: ; preds = %312
br label %314
314: ; preds = %313, %299
%315 = load i64, i64* %13
%316 = load i64, i64* %14
%317 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.23, i64 0, i64 0), i64 %315, i64 %316)
%318 = call i32 @gettimeofday(%struct.timeval* %35, i32* null)
%319 = load i32, i32* %9
%320 = load i32, i32* %11
%321 = load i32, i32* %12
%322 = call i32 @clEnqueueNDRangeKernel(i32 %319, i32 %320, i32 %321, i32* null, i64* %13, i64* %14, i32 0, i32* null, i32* null)
store i32 %322, i32* %6
%323 = load i32, i32* %6
%324 = load i32, i32* @CL_SUCCESS
%325 = icmp ne i32 %323, %324
br i1 %325, label %326, label %334
326: ; preds = %314
br label %327
327: ; preds = %326
%328 = load i32, i32* %6
%329 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.24, i64 0, i64 0), i32 %328)
%330 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%331 = load i32, i32* @EXIT_FAILURE
store i32 %331, i32* %3
store i32 1, i32* %20
br label %360
332: ; No predecessors!
br label %333
333: ; preds = %332
br label %334
334: ; preds = %333, %314
%335 = load i32, i32* %9
%336 = call i32 @clFinish(i32 %335)
%337 = call i32 @gettimeofday(%struct.timeval* %36, i32* null)
%338 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 0
%339 = load double, double* %338
%340 = getelementptr inbounds %struct.timeval, %struct.timeval* %35, i32 0, i32 0
%341 = load double, double* %340
%342 = fsub double %339, %341
%343 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 1
%344 = load double, double* %343
%345 = getelementptr inbounds %struct.timeval, %struct.timeval* %35, i32 0, i32 1
%346 = load double, double* %345
%347 = fsub double %344, %346
%348 = fdiv double %347, 1.000000e+03
%349 = call double @llvm.fmuladd.f64(double %342, double 1.000000e+03, double %348)
%350 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.25, i64 0, i64 0), double %349)
%351 = load i32, i32* %15
%352 = call i32 @clReleaseMemObject(i32 %351)
%353 = load i32, i32* %16
%354 = call i32 @clReleaseMemObject(i32 %353)
%355 = load i32*, i32** %33
%356 = call i32 @free(i32* %355)
%357 = load i32*, i32** %34
%358 = call i32 @free(i32* %357)
%359 = load i32, i32* @CL_SUCCESS
store i32 %359, i32* %3
store i32 1, i32* %20
br label %360
360: ; preds = %334, %327, %308, %293, %276, %244, %224, %212, %197, %183, %169, %156, %131, %93, %71
%361 = load i8*, i8** %18
br label %362
362: ; preds = %360, %55, %42
%363 = load i32, i32* %3
ret i32 %363
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@CL_SUCCESS = global i32 0
@.str = [30 x i8] c"Err: clGetPlatformIDs[1] (%d)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [35 x i8] c"Number of available platforms: %u\0A\00"
@.str.3 = [29 x i8] c"Err: Err: no platforms found\00"
@.str.4 = [25 x i8] c"Err: clGetPlatformIDs[2]\00"
@.str.5 = [7 x i8] c"NVIDIA\00"
@CL_PLATFORM_NAME = global i32 0
@.str.6 = [26 x i8] c"Err: clGetPlatformInfo[1]\00"
@.str.7 = [26 x i8] c"Err: clGetPlatformInfo[2]\00"
@.str.8 = [30 x i8] c"Preferred platform found: %s\0A\00"
@CL_DEVICE_TYPE_GPU = global i32 0
@CL_DEVICE_TYPE_CPU = global i32 0
@.str.9 = [31 x i8] c"Err: (code %d) clGetDeviceIDs\00"
@.str.10 = [21 x i8] c"Err: clCreateContext\00"
@.str.11 = [26 x i8] c"Err: clCreateCommandQueue\00"
@.str.12 = [13 x i8] c"MSTKernel.cl\00"
@.str.13 = [24 x i8] c"Err: readSourceFromFile\00"
@.str.14 = [28 x i8] c"Read %ld bytes source file\0A\00"
@.str.15 = [31 x i8] c"Err: clCreateProgramWithSource\00"
@CL_PROGRAM_BUILD_LOG = global i32 0
@.str.18 = [12 x i8] c"FindMinDist\00"
@.str.19 = [20 x i8] c"Err: clCreateKernel\00"
@CL_MEM_READ_ONLY = global i32 0
@CL_MEM_USE_HOST_PTR = global i32 0
@CL_MEM_READ_WRITE = global i32 0
@.str.20 = [20 x i8] c"Err: clCreateBuffer\00"
@.str.21 = [20 x i8] c"Err: clSetKernelArg\00"
@CL_KERNEL_WORK_GROUP_SIZE = global i32 0
@.str.22 = [30 x i8] c"Err: clGetKernelWorkGroupInfo\00"
@.str.23 = [51 x i8] c"Set global_work_size = %ld, local_work_size = %ld\0A\00"
@.str.24 = [33 x i8] c"Err: clEnqueueNDRangeKernel (%d)\00"
@.str.25 = [22 x i8] c"Elapsed time: %lf ms\0A\00"
@str = [20 x i8] c"Err: clBuildProgram\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca [2048 x i8]
%16 = alloca %struct.timeval
%17 = alloca %struct.timeval
%18 = bitcast i32* %3 to i8*
%19 = bitcast i32* %4 to i8*
%20 = bitcast i64* %5 to i8*
%21 = bitcast i64* %6 to i8*
%22 = bitcast i32* %7 to i8*
%23 = bitcast i32* %8 to i8*
%24 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%25 = call i32 @clGetPlatformIDs(i32 0, i32* null, i32* %9)
store i32 %25, i32* %3
%26 = load i32, i32* @CL_SUCCESS
%27 = icmp eq i32 %25, %26
br i1 %27, label %32, label %28
28: ; preds = %2
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %25)
%30 = call i32 @putchar(i32 10)
%31 = load i32, i32* @EXIT_FAILURE
br label %259
32: ; preds = %2
%33 = load i32, i32* %9
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @putchar(i32 10)
%40 = load i32, i32* @EXIT_FAILURE
br label %259
41: ; preds = %32
%42 = zext i32 %35 to i64
%43 = call i8* @llvm.stacksave()
%44 = alloca i32, i64 %42
%45 = load i32, i32* %9
%46 = call i32 @clGetPlatformIDs(i32 %45, i32* %44, i32* null)
store i32 %46, i32* %3
%47 = load i32, i32* @CL_SUCCESS
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %54
49: ; preds = %41
%50 = load i32, i32* %9
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %98
52: ; preds = %49
%53 = bitcast i64* %10 to i8*
br label %58
54: ; preds = %41
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @putchar(i32 10)
%57 = load i32, i32* @EXIT_FAILURE
br label %257
58: ; preds = %52, %93
%59 = phi i64 [ 0, %52 ], [ %94, %93 ]
store i64 0, i64* %10
%60 = getelementptr inbounds i32, i32* %44, i64 %59
%61 = load i32, i32* %60
%62 = load i32, i32* @CL_PLATFORM_NAME
%63 = call i32 @clGetPlatformInfo(i32 %61, i32 %62, i64 0, i8* null, i64* %10)
store i32 %63, i32* %3
%64 = load i32, i32* @CL_SUCCESS
%65 = icmp eq i32 %63, %64
br i1 %65, label %70, label %66
66: ; preds = %58
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%68 = call i32 @putchar(i32 10)
%69 = load i32, i32* @EXIT_FAILURE
br label %257
70: ; preds = %58
%71 = load i64, i64* %10
%72 = add i64 %71, 1
%73 = call i8* @llvm.stacksave()
%74 = alloca i8, i64 %72
%75 = load i32, i32* %60
%76 = load i32, i32* @CL_PLATFORM_NAME
%77 = load i64, i64* %10
%78 = call i32 @clGetPlatformInfo(i32 %75, i32 %76, i64 %77, i8* %74, i64* null)
store i32 %78, i32* %3
%79 = load i32, i32* @CL_SUCCESS
%80 = icmp eq i32 %78, %79
br i1 %80, label %85, label %81
81: ; preds = %70
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%83 = call i32 @putchar(i32 10)
%84 = load i32, i32* @EXIT_FAILURE
br label %257
85: ; preds = %70
%86 = load i64, i64* %10
%87 = getelementptr inbounds i8, i8* %74, i64 %86
store i8 0, i8* %87
%88 = call i64 @strstr(i8* %74, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%89 = icmp eq i64 %88, 0
br i1 %89, label %93, label %90
90: ; preds = %85
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %74)
%92 = and i64 %59, 4294967295
br label %98
93: ; preds = %85
%94 = add nuw nsw i64 %59, 1
%95 = load i32, i32* %9
%96 = sext i32 %95 to i64
%97 = icmp slt i64 %94, %96
br i1 %97, label %58, label %98
98: ; preds = %93, %49, %90
%99 = phi i64 [ %92, %90 ], [ 0, %49 ], [ 0, %93 ]
%100 = bitcast i32* %11 to i8*
store i32 0, i32* %11
%101 = getelementptr inbounds i32, i32* %44, i64 %99
%102 = load i32, i32* %101
%103 = load i32, i32* @CL_DEVICE_TYPE_GPU
%104 = call i32 @clGetDeviceIDs(i32 %102, i32 %103, i32 1, i32* %4, i32* %11)
store i32 %104, i32* %3
%105 = load i32, i32* @CL_SUCCESS
%106 = icmp eq i32 %104, %105
br i1 %106, label %111, label %107
107: ; preds = %98
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %104)
%109 = call i32 @putchar(i32 10)
%110 = load i32, i32* @EXIT_FAILURE
br label %255
111: ; preds = %98
%112 = call i32 @clCreateContext(i32 0, i32 1, i32* %4, i32* null, i32* null, i32* %3)
%113 = load i32, i32* %3
%114 = load i32, i32* @CL_SUCCESS
%115 = icmp eq i32 %113, %114
br i1 %115, label %120, label %116
116: ; preds = %111
%117 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%118 = call i32 @putchar(i32 10)
%119 = load i32, i32* @EXIT_FAILURE
br label %255
120: ; preds = %111
%121 = load i32, i32* %4
%122 = call i32 @clCreateCommandQueue(i32 %112, i32 %121, i32 0, i32* %3)
%123 = load i32, i32* %3
%124 = load i32, i32* @CL_SUCCESS
%125 = icmp eq i32 %123, %124
br i1 %125, label %130, label %126
126: ; preds = %120
%127 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0))
%128 = call i32 @putchar(i32 10)
%129 = load i32, i32* @EXIT_FAILURE
br label %255
130: ; preds = %120
%131 = bitcast i8** %12 to i8*
%132 = bitcast i64* %13 to i8*
store i64 0, i64* %13
%133 = call i8* @readSourceFromFile(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i64* %13)
store i8* %133, i8** %12
%134 = icmp eq i8* %133, null
%135 = load i64, i64* %13
%136 = icmp eq i64 %135, 0
%137 = select i1 %134, i1 true, i1 %136
br i1 %137, label %138, label %142
138: ; preds = %130
%139 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0))
%140 = call i32 @putchar(i32 10)
%141 = load i32, i32* @EXIT_FAILURE
br label %253
142: ; preds = %130
%143 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.14, i64 0, i64 0), i64 %135)
%144 = call i32 @clCreateProgramWithSource(i32 %112, i32 1, i8** %12, i64* %13, i32* %3)
%145 = icmp eq i32 %144, 0
br i1 %145, label %146, label %150
146: ; preds = %142
%147 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0))
%148 = call i32 @putchar(i32 10)
%149 = load i32, i32* @EXIT_FAILURE
br label %253
150: ; preds = %142
%151 = call i32 @clBuildProgram(i32 %144, i32 0, i32* null, i32* null, i32* null, i32* null)
store i32 %151, i32* %3
%152 = load i32, i32* @CL_SUCCESS
%153 = icmp eq i32 %151, %152
br i1 %153, label %163, label %154
154: ; preds = %150
%155 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%156 = bitcast i64* %14 to i8*
%157 = getelementptr inbounds [2048 x i8], [2048 x i8]* %15, i64 0, i64 0
%158 = load i32, i32* %4
%159 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%160 = call i32 @clGetProgramBuildInfo(i32 %144, i32 %158, i32 %159, i32 2048, i8* %157, i64* %14)
%161 = call i32 @puts(i8* %157)
%162 = load i32, i32* @EXIT_FAILURE
br label %253
163: ; preds = %150
%164 = call i32 @clCreateKernel(i32 %144, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0), i32* %3)
%165 = icmp eq i32 %164, 0
br i1 %165, label %170, label %166
166: ; preds = %163
%167 = load i32, i32* %3
%168 = load i32, i32* @CL_SUCCESS
%169 = icmp eq i32 %167, %168
br i1 %169, label %174, label %170
170: ; preds = %163, %166
%171 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.19, i64 0, i64 0))
%172 = call i32 @putchar(i32 10)
%173 = load i32, i32* @EXIT_FAILURE
br label %253
174: ; preds = %166
%175 = call i64 @malloc(i32 4194304)
%176 = inttoptr i64 %175 to i32*
%177 = call i64 @malloc(i32 4096)
%178 = inttoptr i64 %177 to i32*
%179 = call i32 @initialize_graph(i32* %176, i32* %178)
%180 = load i32, i32* @CL_MEM_READ_ONLY
%181 = load i32, i32* @CL_MEM_USE_HOST_PTR
%182 = or i32 %181, %180
%183 = call i32 @clCreateBuffer(i32 %112, i32 %182, i32 4194304, i32* %176, i32* %3)
store i32 %183, i32* %7
%184 = load i32, i32* @CL_MEM_READ_WRITE
%185 = load i32, i32* @CL_MEM_USE_HOST_PTR
%186 = or i32 %185, %184
%187 = call i32 @clCreateBuffer(i32 %112, i32 %186, i32 4096, i32* %178, i32* %3)
store i32 %187, i32* %8
%188 = icmp ne i32 %183, 0
%189 = icmp ne i32 %187, 0
%190 = select i1 %188, i1 %189, i1 false
br i1 %190, label %195, label %191
191: ; preds = %174
%192 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.20, i64 0, i64 0))
%193 = call i32 @putchar(i32 10)
%194 = load i32, i32* @EXIT_FAILURE
br label %253
195: ; preds = %174
%196 = call i32 @clSetKernelArg(i32 %164, i32 0, i32 4, i32* %7)
store i32 %196, i32* %3
%197 = call i32 @clSetKernelArg(i32 %164, i32 1, i32 4, i32* %8)
%198 = load i32, i32* %3
%199 = or i32 %198, %197
store i32 %199, i32* %3
%200 = load i32, i32* @CL_SUCCESS
%201 = icmp eq i32 %199, %200
br i1 %201, label %206, label %202
202: ; preds = %195
%203 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.21, i64 0, i64 0))
%204 = call i32 @putchar(i32 10)
%205 = load i32, i32* @EXIT_FAILURE
br label %253
206: ; preds = %195
store i64 1024, i64* %5
%207 = load i32, i32* %4
%208 = load i32, i32* @CL_KERNEL_WORK_GROUP_SIZE
%209 = call i32 @clGetKernelWorkGroupInfo(i32 %164, i32 %207, i32 %208, i32 8, i64* %6, i32* null)
store i32 %209, i32* %3
%210 = load i32, i32* @CL_SUCCESS
%211 = icmp eq i32 %209, %210
br i1 %211, label %216, label %212
212: ; preds = %206
%213 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.22, i64 0, i64 0))
%214 = call i32 @putchar(i32 10)
%215 = load i32, i32* @EXIT_FAILURE
br label %253
216: ; preds = %206
%217 = load i64, i64* %6
%218 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.23, i64 0, i64 0), i64 1024, i64 %217)
%219 = bitcast %struct.timeval* %16 to i8*
%220 = bitcast %struct.timeval* %17 to i8*
%221 = call i32 @gettimeofday(%struct.timeval* %16, i32* null)
%222 = call i32 @clEnqueueNDRangeKernel(i32 %122, i32 %164, i32 1, i32* null, i64* %5, i64* %6, i32 0, i32* null, i32* null)
store i32 %222, i32* %3
%223 = load i32, i32* @CL_SUCCESS
%224 = icmp eq i32 %222, %223
br i1 %224, label %228, label %225
225: ; preds = %216
%226 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.24, i64 0, i64 0), i32 %222)
%227 = call i32 @putchar(i32 10)
br label %250
228: ; preds = %216
%229 = call i32 @clFinish(i32 %122)
%230 = call i32 @gettimeofday(%struct.timeval* %17, i32* null)
%231 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i64 0, i32 0
%232 = load double, double* %231
%233 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i64 0, i32 0
%234 = load double, double* %233
%235 = fsub double %232, %234
%236 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i64 0, i32 1
%237 = load double, double* %236
%238 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i64 0, i32 1
%239 = load double, double* %238
%240 = fsub double %237, %239
%241 = fdiv double %240, 1.000000e+03
%242 = call double @llvm.fmuladd.f64(double %235, double 1.000000e+03, double %241)
%243 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.25, i64 0, i64 0), double %242)
%244 = load i32, i32* %7
%245 = call i32 @clReleaseMemObject(i32 %244)
%246 = load i32, i32* %8
%247 = call i32 @clReleaseMemObject(i32 %246)
%248 = call i32 @free(i32* %176)
%249 = call i32 @free(i32* %178)
br label %250
250: ; preds = %228, %225
%251 = phi i32* [ @EXIT_FAILURE, %225 ], [ @CL_SUCCESS, %228 ]
%252 = load i32, i32* %251
br label %253
253: ; preds = %191, %202, %212, %250, %170, %154, %146, %138
%254 = phi i32 [ %141, %138 ], [ %162, %154 ], [ %173, %170 ], [ %149, %146 ], [ %205, %202 ], [ %215, %212 ], [ %252, %250 ], [ %194, %191 ]
br label %255
255: ; preds = %253, %126, %116, %107
%256 = phi i32 [ %110, %107 ], [ %119, %116 ], [ %129, %126 ], [ %254, %253 ]
br label %257
257: ; preds = %81, %66, %255, %54
%258 = phi i32 [ %57, %54 ], [ %256, %255 ], [ %69, %66 ], [ %84, %81 ]
br label %259
259: ; preds = %257, %37, %28
%260 = phi i32 [ %31, %28 ], [ %258, %257 ], [ %40, %37 ]
ret i32 %260
}