#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*/ pbuf;
typedef int /*<<< orphan*/ opencl_log;
typedef int /*<<< orphan*/ cl_uint;
typedef int /*<<< orphan*/ *cl_program;
typedef scalar_t__ cl_platform_id;
typedef scalar_t__ cl_mem;
typedef int /*<<< orphan*/ cl_kernel;
typedef int cl_int;
typedef int /*<<< orphan*/ cl_event;
typedef int /*<<< orphan*/ cl_device_id;
typedef scalar_t__ cl_context_properties;
typedef int /*<<< orphan*/ cl_context;
typedef int /*<<< orphan*/ cl_command_queue;

/* Variables and functions */
scalar_t__ CL_CONTEXT_PLATFORM;
int /*<<< orphan*/ CL_DEVICE_TYPE_ALL;
int CL_MEM_COPY_HOST_PTR;
int CL_MEM_READ_ONLY;
int CL_MEM_WRITE_ONLY;
int /*<<< orphan*/ CL_PLATFORM_VENDOR;
int /*<<< orphan*/ CL_PROGRAM_BUILD_LOG;
int /*<<< orphan*/ CL_QUEUE_PROFILING_ENABLE;
int CL_SUCCESS;
int /*<<< orphan*/ CL_TRUE;
int /*<<< orphan*/ checkErr(char *, int);
int clBuildProgram(int /*<<< orphan*/ *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *);
scalar_t__ clCreateBuffer(int /*<<< orphan*/, int, int, int *, int *);
int /*<<< orphan*/ clCreateCommandQueue(int /*<<< orphan*/, int /*<<< orphan*/,
                                        int /*<<< orphan*/, int *);
int /*<<< orphan*/ clCreateContext(scalar_t__ *, int, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int *);
int /*<<< orphan*/ clCreateKernel(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ *clCreateProgramWithBinary(int /*<<< orphan*/, int,
                                              int /*<<< orphan*/ *, size_t *,
                                              unsigned char const **,
                                              int /*<<< orphan*/ *, int *);
int clEnqueueNDRangeKernel(int /*<<< orphan*/, int /*<<< orphan*/, int,
                           int /*<<< orphan*/ *, size_t *, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/ *);
int clEnqueueReadBuffer(int /*<<< orphan*/, scalar_t__, int /*<<< orphan*/,
                        int /*<<< orphan*/, int, int *, int /*<<< orphan*/,
                        int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clGetDeviceIDs(scalar_t__, int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ *, size_t *);
int clGetPlatformIDs(int, scalar_t__ *, int *);
int clGetPlatformInfo(scalar_t__, int /*<<< orphan*/, int, char *,
                      int /*<<< orphan*/ *);
int clGetProgramBuildInfo(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/, int, void *,
                          int /*<<< orphan*/ *);
int clSetKernelArg(int /*<<< orphan*/, int, int, scalar_t__ *);
int /*<<< orphan*/ clWaitForEvents(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ printDeviceName(unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *readKernelBin(size_t *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int buildProgramFromAmdBin(unsigned int platform_id, unsigned int dev_id,
                           char *binFile) {
  int i = 0;
  cl_int err = CL_SUCCESS;
  cl_int nPlatforms = 0;
  cl_platform_id *platforms = NULL;
  cl_platform_id platform = (cl_platform_id)NULL;
  cl_context_properties cprops[3];
  cl_context context;
  size_t nDevices = 0;
  cl_device_id devices[8];
  cl_device_id device_id = 0;
  size_t binary_size = 0;
  char *binary = NULL;
  cl_program program = NULL;
  char pbuf[100];
  cl_command_queue cmdq;
  cl_mem iBuf, oBuf;
  cl_kernel kernel;
  cl_int *inBuf, *outBuf;
  inBuf = (cl_int *)malloc(100 * sizeof(cl_int));
  outBuf = (cl_int *)malloc(100 * sizeof(cl_int));
  size_t N = 100;
  cl_event evnt;
  char buildOptions[200];
  char opencl_log[1024 * 64];
  err = clGetPlatformIDs(0, NULL, &nPlatforms);
  checkErr("clGetPlatformIDs", err);
  printf("Number of platforms found: %d\n", nPlatforms);
  if (nPlatforms == 0) {
    fprintf(stderr, "Cannot continue without any platforms. Exiting.\n");
    return (-1);
  }
  platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id) * nPlatforms);
  err = clGetPlatformIDs(nPlatforms, platforms, NULL);
  checkErr("clGetPlatformIDs", err);
  err = clGetPlatformInfo(platforms[platform_id], CL_PLATFORM_VENDOR,
                          sizeof(pbuf), pbuf, NULL);
  checkErr("clGetPlatformInfo", err);
  if (strcmp(pbuf, "Advanced Micro Devices, Inc.") == 0) {
    printf("Found AMD platform\n");
    platform = platforms[platform_id];
  }
  if (platform == (cl_context_properties)0) {
    fprintf(stderr, "Could not find an AMD platform. Exiting.\n");
    exit(0);
  }
  clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 8, devices, &nDevices);
  cprops[0] = CL_CONTEXT_PLATFORM;
  cprops[1] = (cl_context_properties)platform;
  cprops[2] = (cl_context_properties)NULL;
  context = clCreateContext(cprops, 1, &devices[dev_id], NULL, NULL, &err);
  checkErr("clCreateContext", err);
  printDeviceName(dev_id, devices[dev_id]);
  binary = readKernelBin(&binary_size, binFile);
  program =
      clCreateProgramWithBinary(context, 1, &devices[dev_id], &binary_size,
                                (const unsigned char **)&binary, NULL, &err);
  checkErr("clCreateProgramWithBinary", err);
  sprintf(buildOptions, "%s %s",
          "-fno-bin-llvmir -fno-bin-source -fno-bin-exe -fbin-amdil",
          "-cl-strict-aliasing -cl-mad-enable");
  err = clBuildProgram(program, 0, NULL, buildOptions, NULL, NULL);
  checkErr("clGetProgramBuildInfo",
           clGetProgramBuildInfo(program, devices[dev_id], CL_PROGRAM_BUILD_LOG,
                                 sizeof(opencl_log), (void *)opencl_log, NULL));
  if (err != CL_SUCCESS) {
    fprintf(stderr, "Compilation log: %s\n", opencl_log);
    exit(0);
  }
  printf("\n*** REPLACE THIS WITH ACTUAL WORK ***\n");
  for (i = 0; i < 100; i++)
    inBuf[i] = i;
  kernel = clCreateKernel(program, "test", &err);
  if (err) {
    printf("Create Kernel test FAILED\n");
    return 0;
  }
  cmdq = clCreateCommandQueue(context, devices[dev_id],
                              CL_QUEUE_PROFILING_ENABLE, &err);
  checkErr("Create CMDQ FAILED\n", err);
  iBuf = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
                        100 * sizeof(cl_int), inBuf, &err);
  if ((iBuf == (cl_mem)0)) {
    checkErr("Create Buffer FAILED\n", err);
  }
  oBuf = clCreateBuffer(context, CL_MEM_WRITE_ONLY, 100 * sizeof(cl_int), NULL,
                        &err);
  if ((oBuf == (cl_mem)0)) {
    checkErr("Create Buffer FAILED\n", err);
  }
  checkErr("Set Kernel Arg FAILED arg0\n",
           clSetKernelArg(kernel, 0, sizeof(cl_mem), &iBuf));
  checkErr("Set Kernel Arg FAILED arg1\n",
           clSetKernelArg(kernel, 1, sizeof(cl_mem), &oBuf));
  err = clEnqueueNDRangeKernel(cmdq, kernel, 1, NULL, &N, NULL, 0, NULL, &evnt);
  clWaitForEvents(1, &evnt);
  checkErr("Write FAILED\n",
           clEnqueueReadBuffer(cmdq, oBuf, CL_TRUE, 0, 100 * sizeof(cl_uint),
                               outBuf, 0, NULL, NULL));
  for (i = 0; i < 100; i++)
    printf("%d\n", outBuf[i]);
  return (0);
}


x86 assembly (clang, -O0):
<buildProgramFromAmdBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10240,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x60(%rbp)
movl   $0x0,-0x84(%rbp)
movq   $0x0,-0x90(%rbp)
movq   $0x0,-0x98(%rbp)
movq   $0x0,-0xa0(%rbp)
mov    $0x190,%edi
call   1100 <malloc@plt>
mov    %rax,-0x138(%rbp)
mov    $0x190,%edi
call   1100 <malloc@plt>
mov    %rax,-0x140(%rbp)
movq   $0x64,-0x148(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x24(%rbp),%rdx
call   1090 <clGetPlatformIDs@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xcd5(%rip),%rdi
call   1120 <checkErr@plt>
mov    -0x24(%rbp),%esi
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
cmpl   $0x0,-0x24(%rbp)
jne    136e <buildProgramFromAmdBin+0xfe>
mov    0x2c66(%rip),%rax
mov    (%rax),%edi
lea    0xcd5(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    185e <buildProgramFromAmdBin+0x5ee>
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1100 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <clGetPlatformIDs@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xc62(%rip),%rdi
call   1120 <checkErr@plt>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    0x2bd3(%rip),%rax
mov    (%rax),%esi
lea    -0x110(%rbp),%rcx
mov    $0x64,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   10b0 <clGetPlatformInfo@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xc87(%rip),%rdi
call   1120 <checkErr@plt>
lea    -0x110(%rbp),%rdi
lea    0xc86(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1419 <buildProgramFromAmdBin+0x1a9>
lea    0xc8d(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1442 <buildProgramFromAmdBin+0x1d2>
mov    0x2b8d(%rip),%rax
mov    (%rax),%edi
lea    0xc70(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1170 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    0x2b7b(%rip),%rax
mov    (%rax),%esi
lea    -0x80(%rbp),%rcx
mov    $0x8,%edx
lea    -0x60(%rbp),%r8
call   1050 <clGetDeviceIDs@plt>
mov    0x2b40(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0xc(%rbp),%eax
lea    -0x80(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x20(%rbp),%r9
mov    %r8,%rcx
call   10c0 <clCreateContext@plt>
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%esi
lea    0xc1a(%rip),%rdi
call   1120 <checkErr@plt>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%eax
mov    -0x80(%rbp,%rax,4),%esi
call   1060 <printDeviceName@plt>
mov    -0x18(%rbp),%rsi
lea    -0x90(%rbp),%rdi
call   1180 <readKernelBin@plt>
mov    %rax,-0x98(%rbp)
mov    -0x54(%rbp),%edi
mov    -0xc(%rbp),%eax
lea    -0x80(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
mov    $0x1,%esi
lea    -0x90(%rbp),%rcx
lea    -0x98(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
lea    -0x20(%rbp),%rax
mov    %rax,(%rsp)
call   1150 <clCreateProgramWithBinary@plt>
mov    %rax,-0xa0(%rbp)
mov    -0x20(%rbp),%esi
lea    0xbb8(%rip),%rdi
call   1120 <checkErr@plt>
lea    -0x220(%rbp),%rdi
lea    0xbbf(%rip),%rsi
lea    0xbbe(%rip),%rdx
lea    0xbf0(%rip),%rcx
call   1160 <sprintf@plt>
mov    -0xa0(%rbp),%rdi
lea    -0x220(%rbp),%rcx
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rdx
mov    %r9,%r8
call   1030 <clBuildProgram@plt>
mov    %eax,-0x20(%rbp)
mov    -0xa0(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    -0x80(%rbp,%rax,4),%esi
mov    0x2a4c(%rip),%rax
mov    (%rax),%edx
lea    -0x10220(%rbp),%r8
mov    $0x10000,%ecx
xor    %eax,%eax
mov    %eax,%r9d
call   10f0 <clGetProgramBuildInfo@plt>
mov    %eax,%esi
lea    0xbb5(%rip),%rdi
call   1120 <checkErr@plt>
mov    -0x20(%rbp),%eax
mov    0x29e4(%rip),%rcx
cmp    (%rcx),%eax
je     15e1 <buildProgramFromAmdBin+0x371>
mov    0x29f5(%rip),%rax
mov    (%rax),%edi
lea    -0x10220(%rbp),%rdx
lea    0xb9d(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1170 <exit@plt>
lea    0xb9d(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    161f <buildProgramFromAmdBin+0x3af>
mov    -0x1c(%rbp),%edx
mov    -0x138(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    15f6 <buildProgramFromAmdBin+0x386>
mov    -0xa0(%rbp),%rdi
lea    0xb80(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1140 <clCreateKernel@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1660 <buildProgramFromAmdBin+0x3f0>
lea    0xb65(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    185e <buildProgramFromAmdBin+0x5ee>
mov    -0x54(%rbp),%edi
mov    -0xc(%rbp),%eax
mov    -0x80(%rbp,%rax,4),%esi
mov    0x2987(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
call   1080 <clCreateCommandQueue@plt>
mov    %eax,-0x114(%rbp)
mov    -0x20(%rbp),%esi
lea    0xb41(%rip),%rdi
call   1120 <checkErr@plt>
mov    -0x54(%rbp),%edi
mov    0x2905(%rip),%rax
mov    (%rax),%esi
mov    0x290c(%rip),%rax
or     (%rax),%esi
mov    -0x138(%rbp),%rcx
mov    $0x190,%edx
lea    -0x20(%rbp),%r8
call   1040 <clCreateBuffer@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
jne    16df <buildProgramFromAmdBin+0x46f>
mov    -0x20(%rbp),%esi
lea    0xb07(%rip),%rdi
call   1120 <checkErr@plt>
mov    -0x54(%rbp),%edi
mov    0x28ef(%rip),%rax
mov    (%rax),%esi
mov    $0x190,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
call   1040 <clCreateBuffer@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1721 <buildProgramFromAmdBin+0x4b1>
mov    -0x20(%rbp),%esi
lea    0xac5(%rip),%rdi
call   1120 <checkErr@plt>
mov    -0x12c(%rbp),%edi
xor    %esi,%esi
mov    $0x8,%edx
lea    -0x120(%rbp),%rcx
call   1190 <clSetKernelArg@plt>
mov    %eax,%esi
lea    0xab4(%rip),%rdi
call   1120 <checkErr@plt>
mov    -0x12c(%rbp),%edi
mov    $0x1,%esi
mov    $0x8,%edx
lea    -0x128(%rbp),%rcx
call   1190 <clSetKernelArg@plt>
mov    %eax,%esi
lea    0xaa6(%rip),%rdi
call   1120 <checkErr@plt>
mov    -0x114(%rbp),%edi
mov    -0x12c(%rbp),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%r9d
lea    -0x148(%rbp),%r8
xor    %eax,%eax
lea    -0x14c(%rbp),%rax
mov    %r9,%rcx
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1070 <clEnqueueNDRangeKernel@plt>
mov    %eax,-0x20(%rbp)
mov    $0x1,%edi
lea    -0x14c(%rbp),%rsi
call   1130 <clWaitForEvents@plt>
mov    -0x114(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    0x2803(%rip),%rax
mov    (%rax),%edx
mov    -0x140(%rbp),%r9
xor    %ecx,%ecx
mov    $0x190,%r8d
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1110 <clEnqueueReadBuffer@plt>
mov    %eax,%esi
lea    0xa18(%rip),%rdi
call   1120 <checkErr@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    1857 <buildProgramFromAmdBin+0x5e7>
mov    -0x140(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0x7ea(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1823 <buildProgramFromAmdBin+0x5b3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildProgramFromAmdBin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x101f8,%rsp
mov    %rdx,%rbp
mov    %esi,%r15d
mov    %edi,%r13d
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
movl   $0x0,0x24(%rsp)
movq   $0x0,0x60(%rsp)
movq   $0x0,0x58(%rsp)
mov    $0x190,%edi
call   1110 <malloc@plt>
mov    %rax,%rbx
mov    $0x190,%edi
call   1110 <malloc@plt>
mov    %rax,%r14
movq   $0x64,0x40(%rsp)
lea    0x24(%rsp),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   10a0 <clGetPlatformIDs@plt>
lea    0xe97(%rip),%rdi
mov    %eax,%esi
call   1130 <checkErr@plt>
mov    0x24(%rsp),%esi
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    0x24(%rsp),%edi
test   %edi,%edi
je     16a6 <buildProgramFromAmdBin+0x426>
mov    %rbp,0x30(%rsp)
shl    $0x3,%edi
call   1110 <malloc@plt>
mov    %rax,%rbp
mov    0x24(%rsp),%edi
mov    %rax,%rsi
xor    %edx,%edx
call   10a0 <clGetPlatformIDs@plt>
lea    0xe4d(%rip),%rdi
mov    %eax,%esi
call   1130 <checkErr@plt>
mov    %r13d,%r12d
mov    0x0(%rbp,%r12,8),%rdi
mov    0x2c2f(%rip),%rax
mov    (%rax),%esi
lea    0xb0(%rsp),%r13
mov    $0x64,%edx
mov    %r13,%rcx
xor    %r8d,%r8d
call   10c0 <clGetPlatformInfo@plt>
mov    %eax,0x20(%rsp)
lea    0xe73(%rip),%rdi
mov    %eax,%esi
call   1130 <checkErr@plt>
lea    0xe77(%rip),%rsi
mov    %r13,%rdi
call   10e0 <strcmp@plt>
test   %rax,%rax
jne    187d <buildProgramFromAmdBin+0x5fd>
lea    0x1013(%rip),%rdi
call   1040 <puts@plt>
mov    0x0(%rbp,%r12,8),%rbp
test   %rbp,%rbp
je     187d <buildProgramFromAmdBin+0x5fd>
mov    0x2c0a(%rip),%rax
mov    (%rax),%esi
lea    0x90(%rsp),%rcx
lea    0x60(%rsp),%r8
mov    %rbp,%rdi
mov    $0x8,%edx
call   1060 <clGetDeviceIDs@plt>
mov    0x2bc7(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x70(%rsp)
mov    %rbp,0x78(%rsp)
movq   $0x0,0x80(%rsp)
mov    %r15d,%r13d
lea    0x90(%rsp,%r13,4),%r12
lea    0x70(%rsp),%rdi
lea    0x20(%rsp),%r9
mov    $0x1,%esi
mov    %r12,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <clCreateContext@plt>
mov    %r15d,%ebp
mov    %eax,%r15d
mov    0x20(%rsp),%esi
lea    0xe18(%rip),%rdi
call   1130 <checkErr@plt>
mov    0x90(%rsp,%r13,4),%esi
mov    %ebp,%edi
call   1070 <printDeviceName@plt>
lea    0x58(%rsp),%rbp
mov    %rbp,%rdi
mov    0x30(%rsp),%rsi
call   1190 <readKernelBin@plt>
mov    %rax,0x50(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,(%rsp)
lea    0x50(%rsp),%r8
mov    %r15d,0x30(%rsp)
mov    %r15d,%edi
mov    $0x1,%esi
mov    %r12,0x28(%rsp)
mov    %r12,%rdx
mov    %rbp,%rcx
xor    %r9d,%r9d
call   1160 <clCreateProgramWithBinary@plt>
mov    %rax,%r15
mov    0x20(%rsp),%esi
lea    0xdc1(%rip),%rdi
call   1130 <checkErr@plt>
lea    0xdcf(%rip),%rsi
lea    0xdce(%rip),%rdx
lea    0xe00(%rip),%rcx
lea    0x120(%rsp),%rbp
mov    %rbp,%rdi
call   1170 <sprintf@plt>
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %rbp,%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
mov    %eax,0x20(%rsp)
mov    0x90(%rsp,%r13,4),%esi
mov    0x2ae5(%rip),%rax
mov    (%rax),%edx
lea    0x1f0(%rsp),%r8
mov    %r15,%rdi
mov    $0x10000,%ecx
xor    %r9d,%r9d
call   1100 <clGetProgramBuildInfo@plt>
lea    0xdca(%rip),%rdi
mov    %eax,%esi
call   1130 <checkErr@plt>
mov    0x20(%rsp),%eax
mov    0x2a7a(%rip),%rcx
cmp    (%rcx),%eax
jne    189b <buildProgramFromAmdBin+0x61b>
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
movaps 0xac7(%rip),%xmm0
movups %xmm0,(%rbx)
movaps 0xacd(%rip),%xmm0
movups %xmm0,0x10(%rbx)
movaps 0xad2(%rip),%xmm0
movups %xmm0,0x20(%rbx)
movaps 0xad7(%rip),%xmm0
movups %xmm0,0x30(%rbx)
movaps 0xadc(%rip),%xmm0
movups %xmm0,0x40(%rbx)
movaps 0xae1(%rip),%xmm0
movups %xmm0,0x50(%rbx)
movaps 0xae6(%rip),%xmm0
movups %xmm0,0x60(%rbx)
movaps 0xaeb(%rip),%xmm0
movups %xmm0,0x70(%rbx)
movaps 0xaf0(%rip),%xmm0
movups %xmm0,0x80(%rbx)
movaps 0xaf2(%rip),%xmm0
movups %xmm0,0x90(%rbx)
movaps 0xaf4(%rip),%xmm0
movups %xmm0,0xa0(%rbx)
movaps 0xaf6(%rip),%xmm0
movups %xmm0,0xb0(%rbx)
movaps 0xaf8(%rip),%xmm0
movups %xmm0,0xc0(%rbx)
movaps 0xafa(%rip),%xmm0
movups %xmm0,0xd0(%rbx)
movaps 0xafc(%rip),%xmm0
movups %xmm0,0xe0(%rbx)
movaps 0xafe(%rip),%xmm0
movups %xmm0,0xf0(%rbx)
movaps 0xb00(%rip),%xmm0
movups %xmm0,0x100(%rbx)
movaps 0xb02(%rip),%xmm0
movups %xmm0,0x110(%rbx)
movaps 0xb04(%rip),%xmm0
movups %xmm0,0x120(%rbx)
movaps 0xb06(%rip),%xmm0
movups %xmm0,0x130(%rbx)
movaps 0xb08(%rip),%xmm0
movups %xmm0,0x140(%rbx)
movaps 0xb0a(%rip),%xmm0
movups %xmm0,0x150(%rbx)
movaps 0xb0c(%rip),%xmm0
movups %xmm0,0x160(%rbx)
movaps 0xb0e(%rip),%xmm0
movups %xmm0,0x170(%rbx)
movaps 0xb10(%rip),%xmm0
movups %xmm0,0x180(%rbx)
lea    0xc83(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %r15,%rdi
call   1150 <clCreateKernel@plt>
cmpl   $0x0,0x20(%rsp)
je     16c8 <buildProgramFromAmdBin+0x448>
lea    0xd04(%rip),%rdi
call   1040 <puts@plt>
xor    %r13d,%r13d
jmp    1868 <buildProgramFromAmdBin+0x5e8>
mov    0x290b(%rip),%rax
mov    (%rax),%edi
lea    0xb0a(%rip),%rsi
xor    %eax,%eax
call   10f0 <fprintf@plt>
mov    $0xffffffff,%r13d
jmp    1868 <buildProgramFromAmdBin+0x5e8>
mov    %eax,%r12d
mov    0x28(%rsp),%rax
mov    (%rax),%esi
mov    0x291f(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%r15
mov    0x30(%rsp),%ebp
mov    %ebp,%edi
mov    %r15,%rcx
call   1090 <clCreateCommandQueue@plt>
mov    %eax,0x28(%rsp)
mov    0x20(%rsp),%esi
lea    0xc09(%rip),%rdi
call   1130 <checkErr@plt>
mov    0x2897(%rip),%rax
mov    0x28a0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %ebp,%edi
mov    $0x190,%edx
mov    %rbx,%rcx
mov    %r15,%r8
call   1050 <clCreateBuffer@plt>
mov    %rax,0x48(%rsp)
test   %rax,%rax
jne    1740 <buildProgramFromAmdBin+0x4c0>
mov    0x20(%rsp),%esi
lea    0xbdf(%rip),%rdi
call   1130 <checkErr@plt>
mov    0x2891(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%r8
mov    %ebp,%edi
mov    $0x190,%edx
xor    %ecx,%ecx
call   1050 <clCreateBuffer@plt>
mov    %rax,0x38(%rsp)
test   %rax,%rax
jne    1776 <buildProgramFromAmdBin+0x4f6>
mov    0x20(%rsp),%esi
lea    0xba9(%rip),%rdi
call   1130 <checkErr@plt>
xor    %r13d,%r13d
lea    0x48(%rsp),%rcx
mov    %r12d,%edi
xor    %esi,%esi
mov    $0x8,%edx
call   11a0 <clSetKernelArg@plt>
lea    0xb9c(%rip),%rdi
mov    %eax,%esi
call   1130 <checkErr@plt>
lea    0x38(%rsp),%rcx
mov    %r12d,%edi
mov    $0x1,%esi
mov    $0x8,%edx
call   11a0 <clSetKernelArg@plt>
lea    0xb93(%rip),%rdi
mov    %eax,%esi
call   1130 <checkErr@plt>
lea    0x6c(%rsp),%r15
mov    %r15,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movl   $0x0,(%rsp)
lea    0x40(%rsp),%r8
mov    0x28(%rsp),%ebx
mov    %ebx,%edi
mov    %r12d,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r9d,%r9d
call   1080 <clEnqueueNDRangeKernel@plt>
mov    %eax,0x20(%rsp)
mov    $0x1,%edi
mov    %r15,%rsi
call   1140 <clWaitForEvents@plt>
mov    0x38(%rsp),%rsi
mov    0x27cc(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %ebx,%edi
xor    %ecx,%ecx
mov    $0x190,%r8d
mov    %r14,%r9
call   1120 <clEnqueueReadBuffer@plt>
lea    0xb2a(%rip),%rdi
mov    %eax,%esi
call   1130 <checkErr@plt>
lea    0x970(%rip),%rbp
xor    %ebx,%ebx
xchg   %ax,%ax
mov    (%r14,%rbx,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1850 <buildProgramFromAmdBin+0x5d0>
mov    %r13d,%eax
add    $0x101f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2734(%rip),%rax
mov    (%rax),%edi
lea    0x993(%rip),%rsi
xor    %eax,%eax
call   10f0 <fprintf@plt>
xor    %edi,%edi
call   1180 <exit@plt>
mov    0x2716(%rip),%rax
mov    (%rax),%edi
lea    0xa41(%rip),%rsi
lea    0x1f0(%rsp),%rdx
xor    %eax,%eax
call   10f0 <fprintf@plt>
xor    %edi,%edi
call   1180 <exit@plt>

LLVM IR (-O0):
@CL_SUCCESS = global i32 0
@.str = [17 x i8] c"clGetPlatformIDs\00"
@.str.1 = [31 x i8] c"Number of platforms found: %d\0A\00"
@stderr = global i32 0
@.str.2 = [49 x i8] c"Cannot continue without any platforms. Exiting.\0A\00"
@CL_PLATFORM_VENDOR = global i32 0
@.str.3 = [18 x i8] c"clGetPlatformInfo\00"
@.str.4 = [29 x i8] c"Advanced Micro Devices, Inc.\00"
@.str.5 = [20 x i8] c"Found AMD platform\0A\00"
@.str.6 = [42 x i8] c"Could not find an AMD platform. Exiting.\0A\00"
@CL_DEVICE_TYPE_ALL = global i32 0
@CL_CONTEXT_PLATFORM = global i64 0
@.str.7 = [16 x i8] c"clCreateContext\00"
@.str.8 = [26 x i8] c"clCreateProgramWithBinary\00"
@.str.9 = [6 x i8] c"%s %s\00"
@.str.10 = [57 x i8] c"-fno-bin-llvmir -fno-bin-source -fno-bin-exe -fbin-amdil\00"
@.str.11 = [35 x i8] c"-cl-strict-aliasing -cl-mad-enable\00"
@.str.12 = [22 x i8] c"clGetProgramBuildInfo\00"
@CL_PROGRAM_BUILD_LOG = global i32 0
@.str.13 = [21 x i8] c"Compilation log: %s\0A\00"
@.str.14 = [40 x i8] c"\0A*** REPLACE THIS WITH ACTUAL WORK ***\0A\00"
@.str.15 = [5 x i8] c"test\00"
@.str.16 = [27 x i8] c"Create Kernel test FAILED\0A\00"
@CL_QUEUE_PROFILING_ENABLE = global i32 0
@.str.17 = [20 x i8] c"Create CMDQ FAILED\0A\00"
@CL_MEM_READ_ONLY = global i32 0
@CL_MEM_COPY_HOST_PTR = global i32 0
@.str.18 = [22 x i8] c"Create Buffer FAILED\0A\00"
@CL_MEM_WRITE_ONLY = global i32 0
@.str.19 = [28 x i8] c"Set Kernel Arg FAILED arg0\0A\00"
@.str.20 = [28 x i8] c"Set Kernel Arg FAILED arg1\0A\00"
@.str.21 = [14 x i8] c"Write FAILED\0A\00"
@CL_TRUE = global i32 0
@.str.22 = [4 x i8] c"%d\0A\00"
define i32 @buildProgramFromAmdBin(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64*
%12 = alloca i64
%13 = alloca [3 x i64]
%14 = alloca i32
%15 = alloca i64
%16 = alloca [8 x i32]
%17 = alloca i32
%18 = alloca i64
%19 = alloca i8*
%20 = alloca i32*
%21 = alloca [100 x i8]
%22 = alloca i32
%23 = alloca i64
%24 = alloca i64
%25 = alloca i32
%26 = alloca i32*
%27 = alloca i32*
%28 = alloca i64
%29 = alloca i32
%30 = alloca [200 x i8]
%31 = alloca [65536 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 0, i32* %8
%32 = load i32, i32* @CL_SUCCESS
store i32 %32, i32* %9
store i32 0, i32* %10
store i64* null, i64** %11
store i64 0, i64* %12
store i64 0, i64* %15
store i32 0, i32* %17
store i64 0, i64* %18
store i8* null, i8** %19
store i32* null, i32** %20
%33 = call i64 @malloc(i32 400)
%34 = inttoptr i64 %33 to i32*
store i32* %34, i32** %26
%35 = call i64 @malloc(i32 400)
%36 = inttoptr i64 %35 to i32*
store i32* %36, i32** %27
store i64 100, i64* %28
%37 = call i32 @clGetPlatformIDs(i32 0, i64* null, i32* %10)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = call i32 @checkErr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %10
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %10
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %3
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %222
47: ; preds = %3
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = mul i64 8, %49
%51 = trunc i64 %50 to i32
%52 = call i64 @malloc(i32 %51)
%53 = inttoptr i64 %52 to i64*
store i64* %53, i64** %11
%54 = load i32, i32* %10
%55 = load i64*, i64** %11
%56 = call i32 @clGetPlatformIDs(i32 %54, i64* %55, i32* null)
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = call i32 @checkErr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %57)
%59 = load i64*, i64** %11
%60 = load i32, i32* %5
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds i64, i64* %59, i64 %61
%63 = load i64, i64* %62
%64 = load i32, i32* @CL_PLATFORM_VENDOR
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %21, i64 0, i64 0
%66 = call i32 @clGetPlatformInfo(i64 %63, i32 %64, i32 100, i8* %65, i32* null)
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = call i32 @checkErr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %21, i64 0, i64 0
%70 = call i64 @strcmp(i8* %69, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %79
72: ; preds = %47
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%74 = load i64*, i64** %11
%75 = load i32, i32* %5
%76 = zext i32 %75 to i64
%77 = getelementptr inbounds i64, i64* %74, i64 %76
%78 = load i64, i64* %77
store i64 %78, i64* %12
br label %79
79: ; preds = %72, %47
%80 = load i64, i64* %12
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %79
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%85 = call i32 @exit(i32 0)
unreachable
86: ; preds = %79
%87 = load i64, i64* %12
%88 = load i32, i32* @CL_DEVICE_TYPE_ALL
%89 = getelementptr inbounds [8 x i32], [8 x i32]* %16, i64 0, i64 0
%90 = call i32 @clGetDeviceIDs(i64 %87, i32 %88, i32 8, i32* %89, i64* %15)
%91 = load i64, i64* @CL_CONTEXT_PLATFORM
%92 = getelementptr inbounds [3 x i64], [3 x i64]* %13, i64 0, i64 0
store i64 %91, i64* %92
%93 = load i64, i64* %12
%94 = getelementptr inbounds [3 x i64], [3 x i64]* %13, i64 0, i64 1
store i64 %93, i64* %94
%95 = getelementptr inbounds [3 x i64], [3 x i64]* %13, i64 0, i64 2
store i64 0, i64* %95
%96 = getelementptr inbounds [3 x i64], [3 x i64]* %13, i64 0, i64 0
%97 = load i32, i32* %6
%98 = zext i32 %97 to i64
%99 = getelementptr inbounds [8 x i32], [8 x i32]* %16, i64 0, i64 %98
%100 = call i32 @clCreateContext(i64* %96, i32 1, i32* %99, i32* null, i32* null, i32* %9)
store i32 %100, i32* %14
%101 = load i32, i32* %9
%102 = call i32 @checkErr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %101)
%103 = load i32, i32* %6
%104 = load i32, i32* %6
%105 = zext i32 %104 to i64
%106 = getelementptr inbounds [8 x i32], [8 x i32]* %16, i64 0, i64 %105
%107 = load i32, i32* %106
%108 = call i32 @printDeviceName(i32 %103, i32 %107)
%109 = load i8*, i8** %7
%110 = call i8* @readKernelBin(i64* %18, i8* %109)
store i8* %110, i8** %19
%111 = load i32, i32* %14
%112 = load i32, i32* %6
%113 = zext i32 %112 to i64
%114 = getelementptr inbounds [8 x i32], [8 x i32]* %16, i64 0, i64 %113
%115 = call i32* @clCreateProgramWithBinary(i32 %111, i32 1, i32* %114, i64* %18, i8** %19, i32* null, i32* %9)
store i32* %115, i32** %20
%116 = load i32, i32* %9
%117 = call i32 @checkErr(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %116)
%118 = getelementptr inbounds [200 x i8], [200 x i8]* %30, i64 0, i64 0
%119 = call i32 @sprintf(i8* %118, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
%120 = load i32*, i32** %20
%121 = getelementptr inbounds [200 x i8], [200 x i8]* %30, i64 0, i64 0
%122 = call i32 @clBuildProgram(i32* %120, i32 0, i32* null, i8* %121, i32* null, i32* null)
store i32 %122, i32* %9
%123 = load i32*, i32** %20
%124 = load i32, i32* %6
%125 = zext i32 %124 to i64
%126 = getelementptr inbounds [8 x i32], [8 x i32]* %16, i64 0, i64 %125
%127 = load i32, i32* %126
%128 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%129 = getelementptr inbounds [65536 x i8], [65536 x i8]* %31, i64 0, i64 0
%130 = call i32 @clGetProgramBuildInfo(i32* %123, i32 %127, i32 %128, i32 65536, i8* %129, i32* null)
%131 = call i32 @checkErr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i32 %130)
%132 = load i32, i32* %9
%133 = load i32, i32* @CL_SUCCESS
%134 = icmp ne i32 %132, %133
br i1 %134, label %135, label %140
135: ; preds = %86
%136 = load i32, i32* @stderr
%137 = getelementptr inbounds [65536 x i8], [65536 x i8]* %31, i64 0, i64 0
%138 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0), i8* %137)
%139 = call i32 @exit(i32 0)
unreachable
140: ; preds = %86
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %8
br label %142
142: ; preds = %151, %140
%143 = load i32, i32* %8
%144 = icmp slt i32 %143, 100
br i1 %144, label %145, label %154
145: ; preds = %142
%146 = load i32, i32* %8
%147 = load i32*, i32** %26
%148 = load i32, i32* %8
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds i32, i32* %147, i64 %149
store i32 %146, i32* %150
br label %151
151: ; preds = %145
%152 = load i32, i32* %8
%153 = add nsw i32 %152, 1
store i32 %153, i32* %8
br label %142
154: ; preds = %142
%155 = load i32*, i32** %20
%156 = call i32 @clCreateKernel(i32* %155, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0), i32* %9)
store i32 %156, i32* %25
%157 = load i32, i32* %9
%158 = icmp ne i32 %157, 0
br i1 %158, label %159, label %161
159: ; preds = %154
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* %4
br label %222
161: ; preds = %154
%162 = load i32, i32* %14
%163 = load i32, i32* %6
%164 = zext i32 %163 to i64
%165 = getelementptr inbounds [8 x i32], [8 x i32]* %16, i64 0, i64 %164
%166 = load i32, i32* %165
%167 = load i32, i32* @CL_QUEUE_PROFILING_ENABLE
%168 = call i32 @clCreateCommandQueue(i32 %162, i32 %166, i32 %167, i32* %9)
store i32 %168, i32* %22
%169 = load i32, i32* %9
%170 = call i32 @checkErr(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i32 %169)
%171 = load i32, i32* %14
%172 = load i32, i32* @CL_MEM_READ_ONLY
%173 = load i32, i32* @CL_MEM_COPY_HOST_PTR
%174 = or i32 %172, %173
%175 = load i32*, i32** %26
%176 = call i64 @clCreateBuffer(i32 %171, i32 %174, i32 400, i32* %175, i32* %9)
store i64 %176, i64* %23
%177 = load i64, i64* %23
%178 = icmp eq i64 %177, 0
br i1 %178, label %179, label %182
179: ; preds = %161
%180 = load i32, i32* %9
%181 = call i32 @checkErr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.18, i64 0, i64 0), i32 %180)
br label %182
182: ; preds = %179, %161
%183 = load i32, i32* %14
%184 = load i32, i32* @CL_MEM_WRITE_ONLY
%185 = call i64 @clCreateBuffer(i32 %183, i32 %184, i32 400, i32* null, i32* %9)
store i64 %185, i64* %24
%186 = load i64, i64* %24
%187 = icmp eq i64 %186, 0
br i1 %187, label %188, label %191
188: ; preds = %182
%189 = load i32, i32* %9
%190 = call i32 @checkErr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.18, i64 0, i64 0), i32 %189)
br label %191
191: ; preds = %188, %182
%192 = load i32, i32* %25
%193 = call i32 @clSetKernelArg(i32 %192, i32 0, i32 8, i64* %23)
%194 = call i32 @checkErr(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0), i32 %193)
%195 = load i32, i32* %25
%196 = call i32 @clSetKernelArg(i32 %195, i32 1, i32 8, i64* %24)
%197 = call i32 @checkErr(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.20, i64 0, i64 0), i32 %196)
%198 = load i32, i32* %22
%199 = load i32, i32* %25
%200 = call i32 @clEnqueueNDRangeKernel(i32 %198, i32 %199, i32 1, i32* null, i64* %28, i32* null, i32 0, i32* null, i32* %29)
store i32 %200, i32* %9
%201 = call i32 @clWaitForEvents(i32 1, i32* %29)
%202 = load i32, i32* %22
%203 = load i64, i64* %24
%204 = load i32, i32* @CL_TRUE
%205 = load i32*, i32** %27
%206 = call i32 @clEnqueueReadBuffer(i32 %202, i64 %203, i32 %204, i32 0, i32 400, i32* %205, i32 0, i32* null, i32* null)
%207 = call i32 @checkErr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.21, i64 0, i64 0), i32 %206)
store i32 0, i32* %8
br label %208
208: ; preds = %218, %191
%209 = load i32, i32* %8
%210 = icmp slt i32 %209, 100
br i1 %210, label %211, label %221
211: ; preds = %208
%212 = load i32*, i32** %27
%213 = load i32, i32* %8
%214 = sext i32 %213 to i64
%215 = getelementptr inbounds i32, i32* %212, i64 %214
%216 = load i32, i32* %215
%217 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.22, i64 0, i64 0), i32 %216)
br label %218
218: ; preds = %211
%219 = load i32, i32* %8
%220 = add nsw i32 %219, 1
store i32 %220, i32* %8
br label %208
221: ; preds = %208
store i32 0, i32* %4
br label %222
222: ; preds = %221, %159, %44
%223 = load i32, i32* %4
ret i32 %223
}

LLVM IR (-O2):
@CL_SUCCESS = global i32 0
@.str = [17 x i8] c"clGetPlatformIDs\00"
@.str.1 = [31 x i8] c"Number of platforms found: %d\0A\00"
@stderr = global i32 0
@.str.2 = [49 x i8] c"Cannot continue without any platforms. Exiting.\0A\00"
@CL_PLATFORM_VENDOR = global i32 0
@.str.3 = [18 x i8] c"clGetPlatformInfo\00"
@.str.4 = [29 x i8] c"Advanced Micro Devices, Inc.\00"
@.str.6 = [42 x i8] c"Could not find an AMD platform. Exiting.\0A\00"
@CL_DEVICE_TYPE_ALL = global i32 0
@CL_CONTEXT_PLATFORM = global i64 0
@.str.7 = [16 x i8] c"clCreateContext\00"
@.str.8 = [26 x i8] c"clCreateProgramWithBinary\00"
@.str.9 = [6 x i8] c"%s %s\00"
@.str.10 = [57 x i8] c"-fno-bin-llvmir -fno-bin-source -fno-bin-exe -fbin-amdil\00"
@.str.11 = [35 x i8] c"-cl-strict-aliasing -cl-mad-enable\00"
@.str.12 = [22 x i8] c"clGetProgramBuildInfo\00"
@CL_PROGRAM_BUILD_LOG = global i32 0
@.str.13 = [21 x i8] c"Compilation log: %s\0A\00"
@.str.15 = [5 x i8] c"test\00"
@CL_QUEUE_PROFILING_ENABLE = global i32 0
@.str.17 = [20 x i8] c"Create CMDQ FAILED\0A\00"
@CL_MEM_READ_ONLY = global i32 0
@CL_MEM_COPY_HOST_PTR = global i32 0
@.str.18 = [22 x i8] c"Create Buffer FAILED\0A\00"
@CL_MEM_WRITE_ONLY = global i32 0
@.str.19 = [28 x i8] c"Set Kernel Arg FAILED arg0\0A\00"
@.str.20 = [28 x i8] c"Set Kernel Arg FAILED arg1\0A\00"
@.str.21 = [14 x i8] c"Write FAILED\0A\00"
@CL_TRUE = global i32 0
@.str.22 = [4 x i8] c"%d\0A\00"
@str = [39 x i8] c"\0A*** REPLACE THIS WITH ACTUAL WORK ***\00"
@str.23 = [26 x i8] c"Create Kernel test FAILED\00"
@str.24 = [19 x i8] c"Found AMD platform\00"
define i32 @buildProgramFromAmdBin(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca [3 x i64]
%7 = alloca i64
%8 = alloca [8 x i32]
%9 = alloca i64
%10 = alloca i8*
%11 = alloca [100 x i8]
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca [200 x i8]
%17 = alloca [65536 x i8]
%18 = bitcast i32* %4 to i8*
%19 = load i32, i32* @CL_SUCCESS
store i32 %19, i32* %4
%20 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%21 = bitcast [3 x i64]* %6 to i8*
%22 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%23 = bitcast [8 x i32]* %8 to i8*
%24 = bitcast i64* %9 to i8*
store i64 0, i64* %9
%25 = bitcast i8** %10 to i8*
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%27 = bitcast i64* %12 to i8*
%28 = bitcast i64* %13 to i8*
%29 = tail call i64 @malloc(i32 400)
%30 = inttoptr i64 %29 to i32*
%31 = tail call i64 @malloc(i32 400)
%32 = inttoptr i64 %31 to i32*
%33 = bitcast i64* %14 to i8*
store i64 100, i64* %14
%34 = bitcast i32* %15 to i8*
%35 = getelementptr inbounds [200 x i8], [200 x i8]* %16, i64 0, i64 0
%36 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%37 = call i32 @clGetPlatformIDs(i32 0, i64* null, i32* %5)
%38 = call i32 @checkErr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %5
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %3
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
br label %196
46: ; preds = %3
%47 = shl i32 %41, 3
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i64*
%50 = load i32, i32* %5
%51 = call i32 @clGetPlatformIDs(i32 %50, i64* %49, i32* null)
%52 = call i32 @checkErr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %51)
%53 = zext i32 %0 to i64
%54 = getelementptr inbounds i64, i64* %49, i64 %53
%55 = load i64, i64* %54
%56 = load i32, i32* @CL_PLATFORM_VENDOR
%57 = call i32 @clGetPlatformInfo(i64 %55, i32 %56, i32 100, i8* %26, i32* null)
store i32 %57, i32* %4
%58 = call i32 @checkErr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %46
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.24, i64 0, i64 0))
%63 = load i64, i64* %54
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %46, %61
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%68 = call i32 @exit(i32 0)
unreachable
69: ; preds = %61
%70 = load i32, i32* @CL_DEVICE_TYPE_ALL
%71 = getelementptr inbounds [8 x i32], [8 x i32]* %8, i64 0, i64 0
%72 = call i32 @clGetDeviceIDs(i64 %63, i32 %70, i32 8, i32* %71, i64* %7)
%73 = load i64, i64* @CL_CONTEXT_PLATFORM
%74 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 0
store i64 %73, i64* %74
%75 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 1
store i64 %63, i64* %75
%76 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 2
store i64 0, i64* %76
%77 = zext i32 %1 to i64
%78 = getelementptr inbounds [8 x i32], [8 x i32]* %8, i64 0, i64 %77
%79 = call i32 @clCreateContext(i64* %74, i32 1, i32* %78, i32* null, i32* null, i32* %4)
%80 = load i32, i32* %4
%81 = call i32 @checkErr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %80)
%82 = load i32, i32* %78
%83 = call i32 @printDeviceName(i32 %1, i32 %82)
%84 = call i8* @readKernelBin(i64* %9, i8* %2)
store i8* %84, i8** %10
%85 = call i32* @clCreateProgramWithBinary(i32 %79, i32 1, i32* %78, i64* %9, i8** %10, i32* null, i32* %4)
%86 = load i32, i32* %4
%87 = call i32 @checkErr(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %86)
%88 = call i32 @sprintf(i8* %35, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
%89 = call i32 @clBuildProgram(i32* %85, i32 0, i32* null, i8* %35, i32* null, i32* null)
store i32 %89, i32* %4
%90 = load i32, i32* %78
%91 = load i32, i32* @CL_PROGRAM_BUILD_LOG
%92 = call i32 @clGetProgramBuildInfo(i32* %85, i32 %90, i32 %91, i32 65536, i8* %36, i32* null)
%93 = call i32 @checkErr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i32 %92)
%94 = load i32, i32* %4
%95 = load i32, i32* @CL_SUCCESS
%96 = icmp eq i32 %94, %95
br i1 %96, label %101, label %97
97: ; preds = %69
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0), i8* %36)
%100 = call i32 @exit(i32 0)
unreachable
101: ; preds = %69
%102 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%103 = inttoptr i64 %29 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %103
%104 = getelementptr inbounds i32, i32* %30, i64 4
%105 = bitcast i32* %104 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %105
%106 = getelementptr inbounds i32, i32* %30, i64 8
%107 = bitcast i32* %106 to <4 x i32>*
store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32>* %107
%108 = getelementptr inbounds i32, i32* %30, i64 12
%109 = bitcast i32* %108 to <4 x i32>*
store <4 x i32> <i32 12, i32 13, i32 14, i32 15>, <4 x i32>* %109
%110 = getelementptr inbounds i32, i32* %30, i64 16
%111 = bitcast i32* %110 to <4 x i32>*
store <4 x i32> <i32 16, i32 17, i32 18, i32 19>, <4 x i32>* %111
%112 = getelementptr inbounds i32, i32* %30, i64 20
%113 = bitcast i32* %112 to <4 x i32>*
store <4 x i32> <i32 20, i32 21, i32 22, i32 23>, <4 x i32>* %113
%114 = getelementptr inbounds i32, i32* %30, i64 24
%115 = bitcast i32* %114 to <4 x i32>*
store <4 x i32> <i32 24, i32 25, i32 26, i32 27>, <4 x i32>* %115
%116 = getelementptr inbounds i32, i32* %30, i64 28
%117 = bitcast i32* %116 to <4 x i32>*
store <4 x i32> <i32 28, i32 29, i32 30, i32 31>, <4 x i32>* %117
%118 = getelementptr inbounds i32, i32* %30, i64 32
%119 = bitcast i32* %118 to <4 x i32>*
store <4 x i32> <i32 32, i32 33, i32 34, i32 35>, <4 x i32>* %119
%120 = getelementptr inbounds i32, i32* %30, i64 36
%121 = bitcast i32* %120 to <4 x i32>*
store <4 x i32> <i32 36, i32 37, i32 38, i32 39>, <4 x i32>* %121
%122 = getelementptr inbounds i32, i32* %30, i64 40
%123 = bitcast i32* %122 to <4 x i32>*
store <4 x i32> <i32 40, i32 41, i32 42, i32 43>, <4 x i32>* %123
%124 = getelementptr inbounds i32, i32* %30, i64 44
%125 = bitcast i32* %124 to <4 x i32>*
store <4 x i32> <i32 44, i32 45, i32 46, i32 47>, <4 x i32>* %125
%126 = getelementptr inbounds i32, i32* %30, i64 48
%127 = bitcast i32* %126 to <4 x i32>*
store <4 x i32> <i32 48, i32 49, i32 50, i32 51>, <4 x i32>* %127
%128 = getelementptr inbounds i32, i32* %30, i64 52
%129 = bitcast i32* %128 to <4 x i32>*
store <4 x i32> <i32 52, i32 53, i32 54, i32 55>, <4 x i32>* %129
%130 = getelementptr inbounds i32, i32* %30, i64 56
%131 = bitcast i32* %130 to <4 x i32>*
store <4 x i32> <i32 56, i32 57, i32 58, i32 59>, <4 x i32>* %131
%132 = getelementptr inbounds i32, i32* %30, i64 60
%133 = bitcast i32* %132 to <4 x i32>*
store <4 x i32> <i32 60, i32 61, i32 62, i32 63>, <4 x i32>* %133
%134 = getelementptr inbounds i32, i32* %30, i64 64
%135 = bitcast i32* %134 to <4 x i32>*
store <4 x i32> <i32 64, i32 65, i32 66, i32 67>, <4 x i32>* %135
%136 = getelementptr inbounds i32, i32* %30, i64 68
%137 = bitcast i32* %136 to <4 x i32>*
store <4 x i32> <i32 68, i32 69, i32 70, i32 71>, <4 x i32>* %137
%138 = getelementptr inbounds i32, i32* %30, i64 72
%139 = bitcast i32* %138 to <4 x i32>*
store <4 x i32> <i32 72, i32 73, i32 74, i32 75>, <4 x i32>* %139
%140 = getelementptr inbounds i32, i32* %30, i64 76
%141 = bitcast i32* %140 to <4 x i32>*
store <4 x i32> <i32 76, i32 77, i32 78, i32 79>, <4 x i32>* %141
%142 = getelementptr inbounds i32, i32* %30, i64 80
%143 = bitcast i32* %142 to <4 x i32>*
store <4 x i32> <i32 80, i32 81, i32 82, i32 83>, <4 x i32>* %143
%144 = getelementptr inbounds i32, i32* %30, i64 84
%145 = bitcast i32* %144 to <4 x i32>*
store <4 x i32> <i32 84, i32 85, i32 86, i32 87>, <4 x i32>* %145
%146 = getelementptr inbounds i32, i32* %30, i64 88
%147 = bitcast i32* %146 to <4 x i32>*
store <4 x i32> <i32 88, i32 89, i32 90, i32 91>, <4 x i32>* %147
%148 = getelementptr inbounds i32, i32* %30, i64 92
%149 = bitcast i32* %148 to <4 x i32>*
store <4 x i32> <i32 92, i32 93, i32 94, i32 95>, <4 x i32>* %149
%150 = getelementptr inbounds i32, i32* %30, i64 96
%151 = bitcast i32* %150 to <4 x i32>*
store <4 x i32> <i32 96, i32 97, i32 98, i32 99>, <4 x i32>* %151
%152 = call i32 @clCreateKernel(i32* %85, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0), i32* %4)
%153 = load i32, i32* %4
%154 = icmp eq i32 %153, 0
br i1 %154, label %157, label %155
155: ; preds = %101
%156 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.23, i64 0, i64 0))
br label %196
157: ; preds = %101
%158 = load i32, i32* %78
%159 = load i32, i32* @CL_QUEUE_PROFILING_ENABLE
%160 = call i32 @clCreateCommandQueue(i32 %79, i32 %158, i32 %159, i32* %4)
%161 = load i32, i32* %4
%162 = call i32 @checkErr(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i32 %161)
%163 = load i32, i32* @CL_MEM_READ_ONLY
%164 = load i32, i32* @CL_MEM_COPY_HOST_PTR
%165 = or i32 %164, %163
%166 = call i64 @clCreateBuffer(i32 %79, i32 %165, i32 400, i32* %30, i32* %4)
store i64 %166, i64* %12
%167 = icmp eq i64 %166, 0
br i1 %167, label %168, label %171
168: ; preds = %157
%169 = load i32, i32* %4
%170 = call i32 @checkErr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.18, i64 0, i64 0), i32 %169)
br label %171
171: ; preds = %168, %157
%172 = load i32, i32* @CL_MEM_WRITE_ONLY
%173 = call i64 @clCreateBuffer(i32 %79, i32 %172, i32 400, i32* null, i32* %4)
store i64 %173, i64* %13
%174 = icmp eq i64 %173, 0
br i1 %174, label %175, label %178
175: ; preds = %171
%176 = load i32, i32* %4
%177 = call i32 @checkErr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.18, i64 0, i64 0), i32 %176)
br label %178
178: ; preds = %175, %171
%179 = call i32 @clSetKernelArg(i32 %152, i32 0, i32 8, i64* %12)
%180 = call i32 @checkErr(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0), i32 %179)
%181 = call i32 @clSetKernelArg(i32 %152, i32 1, i32 8, i64* %13)
%182 = call i32 @checkErr(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.20, i64 0, i64 0), i32 %181)
%183 = call i32 @clEnqueueNDRangeKernel(i32 %160, i32 %152, i32 1, i32* null, i64* %14, i32* null, i32 0, i32* null, i32* %15)
store i32 %183, i32* %4
%184 = call i32 @clWaitForEvents(i32 1, i32* %15)
%185 = load i64, i64* %13
%186 = load i32, i32* @CL_TRUE
%187 = call i32 @clEnqueueReadBuffer(i32 %160, i64 %185, i32 %186, i32 0, i32 400, i32* %32, i32 0, i32* null, i32* null)
%188 = call i32 @checkErr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.21, i64 0, i64 0), i32 %187)
br label %189
189: ; preds = %178, %189
%190 = phi i64 [ 0, %178 ], [ %194, %189 ]
%191 = getelementptr inbounds i32, i32* %32, i64 %190
%192 = load i32, i32* %191
%193 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.22, i64 0, i64 0), i32 %192)
%194 = add nuw nsw i64 %190, 1
%195 = icmp eq i64 %194, 100
br i1 %195, label %196, label %189
196: ; preds = %189, %155, %43
%197 = phi i32 [ -1, %43 ], [ 0, %155 ], [ 0, %189 ]
ret i32 %197
}