#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 unsigned int cl_ulong;
typedef size_t cl_uint;
typedef int /*<<< orphan*/ cl_platform_id;
typedef int /*<<< orphan*/ cl_mem;
typedef scalar_t__ cl_int;
typedef int /*<<< orphan*/ cl_device_id;
typedef int /*<<< orphan*/ cl_context;
typedef int /*<<< orphan*/ cl_command_queue;
typedef int /*<<< orphan*/ alloc;

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_MAX_MEM_ALLOC_SIZE;
int /*<<< orphan*/ CL_DEVICE_TYPE_ALL;
int /*<<< orphan*/ CL_MEM_READ_WRITE;
scalar_t__ CL_SUCCESS;
int /*<<< orphan*/ CL_TRUE;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ clCreateBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                                  size_t const, int /*<<< orphan*/ *,
                                  scalar_t__ *);
int /*<<< orphan*/ clCreateCommandQueue(int /*<<< orphan*/, int /*<<< orphan*/,
                                        int /*<<< orphan*/, scalar_t__ *);
int /*<<< orphan*/ clCreateContext(int /*<<< orphan*/ *, int,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, scalar_t__ *);
scalar_t__ clEnqueueCopyBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, size_t const,
                               int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
scalar_t__ clEnqueueReadBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/,
                               size_t const, scalar_t__ *, int /*<<< orphan*/,
                               int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ clEnqueueWriteBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/,
                                size_t const, scalar_t__ *, int /*<<< orphan*/,
                                int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ clFinish(int /*<<< orphan*/);
scalar_t__ clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *, size_t *);
scalar_t__ clGetDeviceInfo(int /*<<< orphan*/, int /*<<< orphan*/, int,
                           unsigned int *, int /*<<< orphan*/ *);
scalar_t__ clGetPlatformIDs(int, int /*<<< orphan*/ *, size_t *);
int /*<<< orphan*/ clReleaseCommandQueue(int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseMemObject(int /*<<< orphan*/);
int /*<<< orphan*/ free(scalar_t__ *);
scalar_t__ *malloc(size_t const);
scalar_t__ memcmp(scalar_t__ *, scalar_t__ *, size_t const);
int /*<<< orphan*/ memset(scalar_t__ *, int, size_t const);
int main(void) {
  cl_int err;
  cl_platform_id platforms[32];
  cl_uint nplatforms;
  cl_device_id devices[32];
  cl_uint ndevices;
  cl_uint i, j;
  err = clGetPlatformIDs(32, platforms, &nplatforms);
  if (err != CL_SUCCESS)
    return EXIT_FAILURE;
  for (i = 0; i < nplatforms; i++) {
    err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 32, devices,
                         &ndevices);
    if (err != CL_SUCCESS)
      return EXIT_FAILURE;
    if (ndevices > 32)
      ndevices = 32;
    for (j = 0; j < ndevices; j++) {
      cl_context context =
          clCreateContext(NULL, 1, &devices[j], NULL, NULL, &err);
      if (err != CL_SUCCESS)
        return EXIT_FAILURE;
      cl_command_queue queue =
          clCreateCommandQueue(context, devices[j], 0, &err);
      if (err != CL_SUCCESS)
        return EXIT_FAILURE;
      cl_ulong alloc;
      if (clGetDeviceInfo(devices[j], CL_DEVICE_MAX_MEM_ALLOC_SIZE,
                          sizeof(alloc), &alloc, NULL) != CL_SUCCESS)
        return EXIT_FAILURE;
      while (alloc > (1024U * 1024U))
        alloc /= 2;
      const size_t buf_size = (alloc / sizeof(cl_int)) * sizeof(cl_int);
      cl_int *host_buf1 = malloc(buf_size);
      if (host_buf1 == NULL)
        return EXIT_FAILURE;
      cl_int *host_buf2 = malloc(buf_size);
      if (host_buf2 == NULL)
        return EXIT_FAILURE;
      memset(host_buf1, 1, buf_size);
      memset(host_buf2, 2, buf_size);
      cl_mem buf1 =
          clCreateBuffer(context, CL_MEM_READ_WRITE, buf_size, NULL, &err);
      if (err != CL_SUCCESS)
        return EXIT_FAILURE;
      cl_mem buf2 =
          clCreateBuffer(context, CL_MEM_READ_WRITE, buf_size, NULL, &err);
      if (err != CL_SUCCESS)
        return EXIT_FAILURE;
      if (clEnqueueWriteBuffer(queue, buf1, CL_TRUE, 0, buf_size, host_buf1, 0,
                               NULL, NULL) != CL_SUCCESS)
        return EXIT_FAILURE;
      if (clEnqueueCopyBuffer(queue, buf1, buf2, 0, 0, buf_size, 0, NULL,
                              NULL) != CL_SUCCESS)
        return EXIT_FAILURE;
      if (clEnqueueReadBuffer(queue, buf2, CL_TRUE, 0, buf_size, host_buf2, 0,
                              NULL, NULL) != CL_SUCCESS)
        return EXIT_FAILURE;
      if (clFinish(queue) != CL_SUCCESS)
        return EXIT_FAILURE;
      if (memcmp(host_buf2, host_buf1, buf_size) != 0)
        return EXIT_FAILURE;
      free(host_buf2);
      free(host_buf1);
      clReleaseMemObject(buf2);
      clReleaseMemObject(buf1);
      clReleaseCommandQueue(queue);
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rsi
mov    $0x20,%edi
lea    -0x98(%rbp),%rdx
call   1090 <clGetPlatformIDs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d77(%rip),%rcx
cmp    (%rcx),%rax
je     1253 <main+0x53>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
movq   $0x0,-0x130(%rbp)
mov    -0x130(%rbp),%rax
cmp    -0x98(%rbp),%rax
jae    175a <main+0x55a>
mov    -0x130(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%edi
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
lea    -0x120(%rbp),%rcx
mov    $0x20,%edx
lea    -0x128(%rbp),%r8
call   1060 <clGetDeviceIDs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d00(%rip),%rcx
cmp    (%rcx),%rax
je     12ca <main+0xca>
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
cmpq   $0x20,-0x128(%rbp)
20
jbe    12e3 <main+0xe3>
movq   $0x20,-0x128(%rbp)
movq   $0x0,-0x138(%rbp)
mov    -0x138(%rbp),%rax
cmp    -0x128(%rbp),%rax
jae    173e <main+0x53e>
mov    -0x138(%rbp),%rax
lea    -0x120(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x1,%esi
lea    -0x10(%rbp),%r9
mov    %r8,%rdi
mov    %r8,%rcx
call   10d0 <clCreateContext@plt>
mov    %eax,-0x13c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c6f(%rip),%rcx
cmp    (%rcx),%rax
je     135b <main+0x15b>
mov    0x2c6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rax
mov    -0x120(%rbp,%rax,4),%esi
xor    %edx,%edx
lea    -0x10(%rbp),%rcx
call   1080 <clCreateCommandQueue@plt>
mov    %eax,-0x140(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c25(%rip),%rcx
cmp    (%rcx),%rax
je     13a5 <main+0x1a5>
mov    0x2c25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x138(%rbp),%rax
mov    -0x120(%rbp,%rax,4),%edi
mov    0x2c3e(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
lea    -0x144(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <clGetDeviceInfo@plt>
mov    0x2bd7(%rip),%rcx
cmp    (%rcx),%rax
je     13f3 <main+0x1f3>
mov    0x2bd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
jmp    13f8 <main+0x1f8>
cmpl   $0x100000,-0x144(%rbp)
jbe    141c <main+0x21c>
mov    -0x144(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    13f8 <main+0x1f8>
mov    -0x144(%rbp),%eax
shr    $0x3,%rax
shl    $0x3,%rax
mov    %rax,-0x150(%rbp)
mov    -0x150(%rbp),%rdi
call   10f0 <malloc@plt>
mov    %rax,-0x158(%rbp)
cmpq   $0x0,-0x158(%rbp)
jne    1463 <main+0x263>
mov    0x2b67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x150(%rbp),%rdi
call   10f0 <malloc@plt>
mov    %rax,-0x160(%rbp)
cmpq   $0x0,-0x160(%rbp)
jne    1495 <main+0x295>
mov    0x2b35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x158(%rbp),%rdi
mov    -0x150(%rbp),%rdx
mov    $0x1,%esi
call   10a0 <memset@plt>
mov    -0x160(%rbp),%rdi
mov    -0x150(%rbp),%rdx
mov    $0x2,%esi
call   10a0 <memset@plt>
mov    -0x13c(%rbp),%edi
mov    0x2b06(%rip),%rax
mov    (%rax),%esi
mov    -0x150(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
call   1050 <clCreateBuffer@plt>
mov    %eax,-0x164(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ab7(%rip),%rcx
cmp    (%rcx),%rax
je     1513 <main+0x313>
mov    0x2ab7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x13c(%rbp),%edi
mov    0x2ab8(%rip),%rax
mov    (%rax),%esi
mov    -0x150(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
call   1050 <clCreateBuffer@plt>
mov    %eax,-0x168(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2a69(%rip),%rcx
cmp    (%rcx),%rax
je     1561 <main+0x361>
mov    0x2a69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x140(%rbp),%edi
mov    -0x164(%rbp),%esi
mov    0x2a6c(%rip),%rax
mov    (%rax),%edx
mov    -0x150(%rbp),%r8
mov    -0x158(%rbp),%r9
xor    %ecx,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1120 <clEnqueueWriteBuffer@plt>
mov    0x2a03(%rip),%rcx
cmp    (%rcx),%rax
je     15c7 <main+0x3c7>
mov    0x2a03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x140(%rbp),%edi
mov    -0x164(%rbp),%esi
mov    -0x168(%rbp),%edx
mov    -0x150(%rbp),%r9
xor    %r8d,%r8d
xor    %eax,%eax
mov    %r8d,%ecx
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   10b0 <clEnqueueCopyBuffer@plt>
mov    0x29a3(%rip),%rcx
cmp    (%rcx),%rax
je     1627 <main+0x427>
mov    0x29a3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x140(%rbp),%edi
mov    -0x168(%rbp),%esi
mov    0x29a6(%rip),%rax
mov    (%rax),%edx
mov    -0x150(%rbp),%r8
mov    -0x160(%rbp),%r9
xor    %ecx,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1100 <clEnqueueReadBuffer@plt>
mov    0x293d(%rip),%rcx
cmp    (%rcx),%rax
je     168d <main+0x48d>
mov    0x293d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x140(%rbp),%edi
call   1040 <clFinish@plt>
mov    0x2911(%rip),%rcx
cmp    (%rcx),%rax
je     16b9 <main+0x4b9>
mov    0x2911(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x160(%rbp),%rdi
mov    -0x158(%rbp),%rsi
mov    -0x150(%rbp),%rdx
call   10c0 <memcmp@plt>
cmp    $0x0,%rax
je     16ee <main+0x4ee>
mov    0x28dc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1766 <main+0x566>
mov    -0x160(%rbp),%rdi
call   1030 <free@plt>
mov    -0x158(%rbp),%rdi
call   1030 <free@plt>
mov    -0x168(%rbp),%edi
call   1110 <clReleaseMemObject@plt>
mov    -0x164(%rbp),%edi
call   1110 <clReleaseMemObject@plt>
mov    -0x140(%rbp),%edi
call   10e0 <clReleaseCommandQueue@plt>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    12ee <main+0xee>
jmp    1743 <main+0x543>
mov    -0x130(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x130(%rbp)
jmp    125e <main+0x5e>
mov    0x2857(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
lea    0xd0(%rsp),%rsi
lea    0x38(%rsp),%rdx
mov    $0x20,%edi
call   1090 <clGetPlatformIDs@plt>
mov    %rax,0x20(%rsp)
mov    0x2d7c(%rip),%r15
cmp    (%r15),%rax
jne    1529 <main+0x329>
cmpq   $0x0,0x38(%rsp)
je     1520 <main+0x320>
xor    %ebx,%ebx
mov    0x2d7e(%rip),%rax
lea    0x50(%rsp),%rcx
lea    0x30(%rsp),%r8
lea    0x20(%rsp),%r14
mov    0xd0(%rsp,%rbx,4),%edi
mov    (%rax),%esi
mov    $0x20,%edx
call   1060 <clGetDeviceIDs@plt>
mov    %rax,0x20(%rsp)
cmp    (%r15),%rax
jne    1529 <main+0x329>
mov    %rbx,0x40(%rsp)
mov    0x30(%rsp),%rax
cmp    $0x21,%rax
jb     129d <main+0x9d>
movq   $0x20,0x30(%rsp)
jmp    12a6 <main+0xa6>
test   %rax,%rax
je     14fb <main+0x2fb>
xor    %ebp,%ebp
lea    (%rsp,%rbp,4),%rbx
add    $0x50,%rbx
xor    %edi,%edi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   10d0 <clCreateContext@plt>
mov    %eax,%r12d
mov    0x20(%rsp),%rax
cmp    (%r15),%rax
jne    1529 <main+0x329>
mov    (%rbx),%esi
mov    %r12d,%edi
xor    %edx,%edx
mov    %r14,%rcx
call   1080 <clCreateCommandQueue@plt>
mov    %eax,0x1c(%rsp)
mov    0x20(%rsp),%rax
cmp    (%r15),%rax
jne    1529 <main+0x329>
mov    %rbp,0x48(%rsp)
mov    (%rbx),%edi
mov    0x2cf1(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
lea    0x2c(%rsp),%rcx
xor    %r8d,%r8d
call   1070 <clGetDeviceInfo@plt>
cmp    (%r15),%rax
jne    1529 <main+0x329>
mov    %r15,%r13
mov    0x2c(%rsp),%ebx
cmp    $0x100001,%ebx
jb     134f <main+0x14f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
shr    %ebx
cmp    $0x200001,%eax
ja     1340 <main+0x140>
mov    %ebx,0x2c(%rsp)
and    $0xfffffff8,%ebx
mov    %rbx,%rdi
call   10f0 <malloc@plt>
test   %rax,%rax
je     1529 <main+0x329>
mov    %rax,%r14
mov    %rbx,%rdi
call   10f0 <malloc@plt>
test   %rax,%rax
je     1529 <main+0x329>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   10a0 <memset@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    %rbx,%rdx
call   10a0 <memset@plt>
mov    0x2c37(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    %rbx,%rdx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
call   1050 <clCreateBuffer@plt>
mov    %eax,0x28(%rsp)
mov    0x20(%rsp),%rax
cmp    0x0(%r13),%rax
jne    1529 <main+0x329>
mov    0x2c09(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    %rbx,%rdx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
call   1050 <clCreateBuffer@plt>
mov    %eax,%ebp
mov    0x20(%rsp),%rax
cmp    0x0(%r13),%rax
jne    1529 <main+0x329>
mov    0x2be5(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    0x1c(%rsp),%edi
mov    0x28(%rsp),%esi
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r14,%r9
call   1120 <clEnqueueWriteBuffer@plt>
cmp    0x0(%r13),%rax
jne    1529 <main+0x329>
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    0x1c(%rsp),%edi
mov    0x28(%rsp),%esi
mov    %ebp,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rbx,%r9
call   10b0 <clEnqueueCopyBuffer@plt>
cmp    0x0(%r13),%rax
jne    1529 <main+0x329>
mov    0x2b7e(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    0x1c(%rsp),%edi
mov    %ebp,%esi
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r15,%r9
call   1100 <clEnqueueReadBuffer@plt>
cmp    0x0(%r13),%rax
jne    1529 <main+0x329>
mov    0x1c(%rsp),%edi
call   1040 <clFinish@plt>
cmp    0x0(%r13),%rax
jne    1529 <main+0x329>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10c0 <memcmp@plt>
test   %rax,%rax
jne    1529 <main+0x329>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1110 <clReleaseMemObject@plt>
mov    0x28(%rsp),%edi
call   1110 <clReleaseMemObject@plt>
mov    0x1c(%rsp),%edi
call   10e0 <clReleaseCommandQueue@plt>
mov    0x48(%rsp),%rbp
add    $0x1,%rbp
cmp    0x30(%rsp),%rbp
mov    %r13,%r15
lea    0x20(%rsp),%r14
jb     12a8 <main+0xa8>
mov    0x40(%rsp),%rbx
add    $0x1,%rbx
cmp    0x38(%rsp),%rbx
mov    0x2ac0(%rip),%rax
lea    0x50(%rsp),%rcx
lea    0x30(%rsp),%r8
jb     1261 <main+0x61>
mov    0x2a91(%rip),%rax
jmp    1530 <main+0x330>
mov    0x2a90(%rip),%rax
mov    (%rax),%eax
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CL_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
@CL_DEVICE_TYPE_ALL = global i32 0
@CL_DEVICE_MAX_MEM_ALLOC_SIZE = global i32 0
@CL_MEM_READ_WRITE = global i32 0
@CL_TRUE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [32 x i32]
%4 = alloca i64
%5 = alloca [32 x i32]
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64*
%14 = alloca i64*
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %1
%17 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%18 = call i64 @clGetPlatformIDs(i32 32, i32* %17, i64* %4)
store i64 %18, i64* %2
%19 = load i64, i64* %2
%20 = load i64, i64* @CL_SUCCESS
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = load i32, i32* @EXIT_FAILURE
store i32 %23, i32* %1
br label %198
24: ; preds = %0
store i64 0, i64* %7
br label %25
25: ; preds = %193, %24
%26 = load i64, i64* %7
%27 = load i64, i64* %4
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %196
29: ; preds = %25
%30 = load i64, i64* %7
%31 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* @CL_DEVICE_TYPE_ALL
%34 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%35 = call i64 @clGetDeviceIDs(i32 %32, i32 %33, i32 32, i32* %34, i64* %6)
store i64 %35, i64* %2
%36 = load i64, i64* %2
%37 = load i64, i64* @CL_SUCCESS
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %29
%40 = load i32, i32* @EXIT_FAILURE
store i32 %40, i32* %1
br label %198
41: ; preds = %29
%42 = load i64, i64* %6
%43 = icmp ugt i64 %42, 32
br i1 %43, label %44, label %45
44: ; preds = %41
store i64 32, i64* %6
br label %45
45: ; preds = %44, %41
store i64 0, i64* %8
br label %46
46: ; preds = %189, %45
%47 = load i64, i64* %8
%48 = load i64, i64* %6
%49 = icmp ult i64 %47, %48
br i1 %49, label %50, label %192
50: ; preds = %46
%51 = load i64, i64* %8
%52 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 %51
%53 = call i32 @clCreateContext(i32* null, i32 1, i32* %52, i32* null, i32* null, i64* %2)
store i32 %53, i32* %9
%54 = load i64, i64* %2
%55 = load i64, i64* @CL_SUCCESS
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %50
%58 = load i32, i32* @EXIT_FAILURE
store i32 %58, i32* %1
br label %198
59: ; preds = %50
%60 = load i32, i32* %9
%61 = load i64, i64* %8
%62 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = call i32 @clCreateCommandQueue(i32 %60, i32 %63, i32 0, i64* %2)
store i32 %64, i32* %10
%65 = load i64, i64* %2
%66 = load i64, i64* @CL_SUCCESS
%67 = icmp ne i64 %65, %66
br i1 %67, label %68, label %70
68: ; preds = %59
%69 = load i32, i32* @EXIT_FAILURE
store i32 %69, i32* %1
br label %198
70: ; preds = %59
%71 = load i64, i64* %8
%72 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 %71
%73 = load i32, i32* %72
%74 = load i32, i32* @CL_DEVICE_MAX_MEM_ALLOC_SIZE
%75 = call i64 @clGetDeviceInfo(i32 %73, i32 %74, i32 4, i32* %11, i32* null)
%76 = load i64, i64* @CL_SUCCESS
%77 = icmp ne i64 %75, %76
br i1 %77, label %78, label %80
78: ; preds = %70
%79 = load i32, i32* @EXIT_FAILURE
store i32 %79, i32* %1
br label %198
80: ; preds = %70
br label %81
81: ; preds = %84, %80
%82 = load i32, i32* %11
%83 = icmp ugt i32 %82, 1048576
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = load i32, i32* %11
%86 = udiv i32 %85, 2
store i32 %86, i32* %11
br label %81
87: ; preds = %81
%88 = load i32, i32* %11
%89 = zext i32 %88 to i64
%90 = udiv i64 %89, 8
%91 = mul i64 %90, 8
store i64 %91, i64* %12
%92 = load i64, i64* %12
%93 = call i64* @malloc(i64 %92)
store i64* %93, i64** %13
%94 = load i64*, i64** %13
%95 = icmp eq i64* %94, null
br i1 %95, label %96, label %98
96: ; preds = %87
%97 = load i32, i32* @EXIT_FAILURE
store i32 %97, i32* %1
br label %198
98: ; preds = %87
%99 = load i64, i64* %12
%100 = call i64* @malloc(i64 %99)
store i64* %100, i64** %14
%101 = load i64*, i64** %14
%102 = icmp eq i64* %101, null
br i1 %102, label %103, label %105
103: ; preds = %98
%104 = load i32, i32* @EXIT_FAILURE
store i32 %104, i32* %1
br label %198
105: ; preds = %98
%106 = load i64*, i64** %13
%107 = load i64, i64* %12
%108 = call i32 @memset(i64* %106, i32 1, i64 %107)
%109 = load i64*, i64** %14
%110 = load i64, i64* %12
%111 = call i32 @memset(i64* %109, i32 2, i64 %110)
%112 = load i32, i32* %9
%113 = load i32, i32* @CL_MEM_READ_WRITE
%114 = load i64, i64* %12
%115 = call i32 @clCreateBuffer(i32 %112, i32 %113, i64 %114, i32* null, i64* %2)
store i32 %115, i32* %15
%116 = load i64, i64* %2
%117 = load i64, i64* @CL_SUCCESS
%118 = icmp ne i64 %116, %117
br i1 %118, label %119, label %121
119: ; preds = %105
%120 = load i32, i32* @EXIT_FAILURE
store i32 %120, i32* %1
br label %198
121: ; preds = %105
%122 = load i32, i32* %9
%123 = load i32, i32* @CL_MEM_READ_WRITE
%124 = load i64, i64* %12
%125 = call i32 @clCreateBuffer(i32 %122, i32 %123, i64 %124, i32* null, i64* %2)
store i32 %125, i32* %16
%126 = load i64, i64* %2
%127 = load i64, i64* @CL_SUCCESS
%128 = icmp ne i64 %126, %127
br i1 %128, label %129, label %131
129: ; preds = %121
%130 = load i32, i32* @EXIT_FAILURE
store i32 %130, i32* %1
br label %198
131: ; preds = %121
%132 = load i32, i32* %10
%133 = load i32, i32* %15
%134 = load i32, i32* @CL_TRUE
%135 = load i64, i64* %12
%136 = load i64*, i64** %13
%137 = call i64 @clEnqueueWriteBuffer(i32 %132, i32 %133, i32 %134, i32 0, i64 %135, i64* %136, i32 0, i32* null, i32* null)
%138 = load i64, i64* @CL_SUCCESS
%139 = icmp ne i64 %137, %138
br i1 %139, label %140, label %142
140: ; preds = %131
%141 = load i32, i32* @EXIT_FAILURE
store i32 %141, i32* %1
br label %198
142: ; preds = %131
%143 = load i32, i32* %10
%144 = load i32, i32* %15
%145 = load i32, i32* %16
%146 = load i64, i64* %12
%147 = call i64 @clEnqueueCopyBuffer(i32 %143, i32 %144, i32 %145, i32 0, i32 0, i64 %146, i32 0, i32* null, i32* null)
%148 = load i64, i64* @CL_SUCCESS
%149 = icmp ne i64 %147, %148
br i1 %149, label %150, label %152
150: ; preds = %142
%151 = load i32, i32* @EXIT_FAILURE
store i32 %151, i32* %1
br label %198
152: ; preds = %142
%153 = load i32, i32* %10
%154 = load i32, i32* %16
%155 = load i32, i32* @CL_TRUE
%156 = load i64, i64* %12
%157 = load i64*, i64** %14
%158 = call i64 @clEnqueueReadBuffer(i32 %153, i32 %154, i32 %155, i32 0, i64 %156, i64* %157, i32 0, i32* null, i32* null)
%159 = load i64, i64* @CL_SUCCESS
%160 = icmp ne i64 %158, %159
br i1 %160, label %161, label %163
161: ; preds = %152
%162 = load i32, i32* @EXIT_FAILURE
store i32 %162, i32* %1
br label %198
163: ; preds = %152
%164 = load i32, i32* %10
%165 = call i64 @clFinish(i32 %164)
%166 = load i64, i64* @CL_SUCCESS
%167 = icmp ne i64 %165, %166
br i1 %167, label %168, label %170
168: ; preds = %163
%169 = load i32, i32* @EXIT_FAILURE
store i32 %169, i32* %1
br label %198
170: ; preds = %163
%171 = load i64*, i64** %14
%172 = load i64*, i64** %13
%173 = load i64, i64* %12
%174 = call i64 @memcmp(i64* %171, i64* %172, i64 %173)
%175 = icmp ne i64 %174, 0
br i1 %175, label %176, label %178
176: ; preds = %170
%177 = load i32, i32* @EXIT_FAILURE
store i32 %177, i32* %1
br label %198
178: ; preds = %170
%179 = load i64*, i64** %14
%180 = call i32 @free(i64* %179)
%181 = load i64*, i64** %13
%182 = call i32 @free(i64* %181)
%183 = load i32, i32* %16
%184 = call i32 @clReleaseMemObject(i32 %183)
%185 = load i32, i32* %15
%186 = call i32 @clReleaseMemObject(i32 %185)
%187 = load i32, i32* %10
%188 = call i32 @clReleaseCommandQueue(i32 %187)
br label %189
189: ; preds = %178
%190 = load i64, i64* %8
%191 = add i64 %190, 1
store i64 %191, i64* %8
br label %46
192: ; preds = %46
br label %193
193: ; preds = %192
%194 = load i64, i64* %7
%195 = add i64 %194, 1
store i64 %195, i64* %7
br label %25
196: ; preds = %25
%197 = load i32, i32* @EXIT_SUCCESS
store i32 %197, i32* %1
br label %198
198: ; preds = %196, %176, %168, %161, %150, %140, %129, %119, %103, %96, %78, %68, %57, %39, %22
%199 = load i32, i32* %1
ret i32 %199
}

LLVM IR (-O2):
@CL_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
@CL_DEVICE_TYPE_ALL = global i32 0
@CL_DEVICE_MAX_MEM_ALLOC_SIZE = global i32 0
@CL_MEM_READ_WRITE = global i32 0
@CL_TRUE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i64
%2 = alloca [32 x i32]
%3 = alloca i64
%4 = alloca [32 x i32]
%5 = alloca i64
%6 = alloca i32
%7 = bitcast i64* %1 to i8*
%8 = bitcast [32 x i32]* %2 to i8*
%9 = bitcast i64* %3 to i8*
%10 = bitcast [32 x i32]* %4 to i8*
%11 = bitcast i64* %5 to i8*
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 0
%13 = call i64 @clGetPlatformIDs(i32 32, i32* %12, i64* %3)
store i64 %13, i64* %1
%14 = load i64, i64* @CL_SUCCESS
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %22
16: ; preds = %0
%17 = load i64, i64* %3
%18 = icmp eq i64 %17, 0
br i1 %18, label %131, label %19
19: ; preds = %16
%20 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 0
%21 = bitcast i32* %6 to i8*
br label %24
22: ; preds = %0
%23 = load i32, i32* @EXIT_FAILURE
br label %133
24: ; preds = %19, %127
%25 = phi i64 [ 0, %19 ], [ %128, %127 ]
%26 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = load i32, i32* @CL_DEVICE_TYPE_ALL
%29 = call i64 @clGetDeviceIDs(i32 %27, i32 %28, i32 32, i32* %20, i64* %5)
store i64 %29, i64* %1
%30 = load i64, i64* @CL_SUCCESS
%31 = icmp eq i64 %29, %30
br i1 %31, label %34, label %32
32: ; preds = %24
%33 = load i32, i32* @EXIT_FAILURE
br label %133
34: ; preds = %24
%35 = load i64, i64* %5
%36 = icmp ugt i64 %35, 32
br i1 %36, label %37, label %38
37: ; preds = %34
store i64 32, i64* %5
br label %40
38: ; preds = %34
%39 = icmp eq i64 %35, 0
br i1 %39, label %127, label %40
40: ; preds = %37, %38
br label %41
41: ; preds = %40, %118
%42 = phi i64 [ %124, %118 ], [ 0, %40 ]
%43 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 %42
%44 = call i32 @clCreateContext(i32* null, i32 1, i32* %43, i32* null, i32* null, i64* %1)
%45 = load i64, i64* %1
%46 = load i64, i64* @CL_SUCCESS
%47 = icmp eq i64 %45, %46
br i1 %47, label %50, label %48
48: ; preds = %41
%49 = load i32, i32* @EXIT_FAILURE
br label %133
50: ; preds = %41
%51 = load i32, i32* %43
%52 = call i32 @clCreateCommandQueue(i32 %44, i32 %51, i32 0, i64* %1)
%53 = load i64, i64* %1
%54 = load i64, i64* @CL_SUCCESS
%55 = icmp eq i64 %53, %54
br i1 %55, label %58, label %56
56: ; preds = %50
%57 = load i32, i32* @EXIT_FAILURE
br label %133
58: ; preds = %50
%59 = load i32, i32* %43
%60 = load i32, i32* @CL_DEVICE_MAX_MEM_ALLOC_SIZE
%61 = call i64 @clGetDeviceInfo(i32 %59, i32 %60, i32 4, i32* %6, i32* null)
%62 = load i64, i64* @CL_SUCCESS
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %116
64: ; preds = %58
%65 = load i32, i32* %6
%66 = icmp ugt i32 %65, 1048576
br i1 %66, label %67, label %72
67: ; preds = %64, %67
%68 = phi i32 [ %69, %67 ], [ %65, %64 ]
%69 = lshr i32 %68, 1
%70 = icmp ugt i32 %68, 2097153
br i1 %70, label %67, label %71
71: ; preds = %67
store i32 %69, i32* %6
br label %72
72: ; preds = %71, %64
%73 = phi i32 [ %69, %71 ], [ %65, %64 ]
%74 = and i32 %73, -8
%75 = zext i32 %74 to i64
%76 = call i64* @malloc(i64 %75)
%77 = icmp eq i64* %76, null
br i1 %77, label %116, label %78
78: ; preds = %72
%79 = call i64* @malloc(i64 %75)
%80 = icmp eq i64* %79, null
br i1 %80, label %116, label %81
81: ; preds = %78
%82 = call i32 @memset(i64* %76, i32 1, i64 %75)
%83 = call i32 @memset(i64* %79, i32 2, i64 %75)
%84 = load i32, i32* @CL_MEM_READ_WRITE
%85 = call i32 @clCreateBuffer(i32 %44, i32 %84, i64 %75, i32* null, i64* %1)
%86 = load i64, i64* %1
%87 = load i64, i64* @CL_SUCCESS
%88 = icmp eq i64 %86, %87
br i1 %88, label %89, label %116
89: ; preds = %81
%90 = load i32, i32* @CL_MEM_READ_WRITE
%91 = call i32 @clCreateBuffer(i32 %44, i32 %90, i64 %75, i32* null, i64* %1)
%92 = load i64, i64* %1
%93 = load i64, i64* @CL_SUCCESS
%94 = icmp eq i64 %92, %93
br i1 %94, label %95, label %116
95: ; preds = %89
%96 = load i32, i32* @CL_TRUE
%97 = call i64 @clEnqueueWriteBuffer(i32 %52, i32 %85, i32 %96, i32 0, i64 %75, i64* %76, i32 0, i32* null, i32* null)
%98 = load i64, i64* @CL_SUCCESS
%99 = icmp eq i64 %97, %98
br i1 %99, label %100, label %116
100: ; preds = %95
%101 = call i64 @clEnqueueCopyBuffer(i32 %52, i32 %85, i32 %91, i32 0, i32 0, i64 %75, i32 0, i32* null, i32* null)
%102 = load i64, i64* @CL_SUCCESS
%103 = icmp eq i64 %101, %102
br i1 %103, label %104, label %116
104: ; preds = %100
%105 = load i32, i32* @CL_TRUE
%106 = call i64 @clEnqueueReadBuffer(i32 %52, i32 %91, i32 %105, i32 0, i64 %75, i64* %79, i32 0, i32* null, i32* null)
%107 = load i64, i64* @CL_SUCCESS
%108 = icmp eq i64 %106, %107
br i1 %108, label %109, label %116
109: ; preds = %104
%110 = call i64 @clFinish(i32 %52)
%111 = load i64, i64* @CL_SUCCESS
%112 = icmp eq i64 %110, %111
br i1 %112, label %113, label %116
113: ; preds = %109
%114 = call i64 @memcmp(i64* %79, i64* %76, i64 %75)
%115 = icmp eq i64 %114, 0
br i1 %115, label %118, label %116
116: ; preds = %113, %109, %104, %100, %95, %89, %81, %78, %72, %58
%117 = load i32, i32* @EXIT_FAILURE
br label %133
118: ; preds = %113
%119 = call i32 @free(i64* %79)
%120 = call i32 @free(i64* %76)
%121 = call i32 @clReleaseMemObject(i32 %91)
%122 = call i32 @clReleaseMemObject(i32 %85)
%123 = call i32 @clReleaseCommandQueue(i32 %52)
%124 = add nuw i64 %42, 1
%125 = load i64, i64* %5
%126 = icmp ult i64 %124, %125
br i1 %126, label %41, label %127
127: ; preds = %118, %38
%128 = add nuw i64 %25, 1
%129 = load i64, i64* %3
%130 = icmp ult i64 %128, %129
br i1 %130, label %24, label %131
131: ; preds = %127, %16
%132 = load i32, i32* @EXIT_SUCCESS
br label %133
133: ; preds = %56, %48, %116, %131, %32, %22
%134 = phi i32 [ %23, %22 ], [ %33, %32 ], [ %132, %131 ], [ %117, %116 ], [ %57, %56 ], [ %49, %48 ]
ret i32 %134
}