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

/* Variables and functions */
scalar_t__ CL_COMMAND_READ_BUFFER;
scalar_t__ CL_COMPLETE;
int /*<<< orphan*/ CL_DEVICE_TYPE_ALL;
int /*<<< orphan*/ CL_EVENT_COMMAND_EXECUTION_STATUS;
int /*<<< orphan*/ CL_EVENT_COMMAND_QUEUE;
int /*<<< orphan*/ CL_EVENT_COMMAND_TYPE;
int /*<<< orphan*/ CL_EVENT_REFERENCE_COUNT;
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*/, int,
                                  int /*<<< orphan*/ *, scalar_t__ *);
scalar_t__ 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__ clEnqueueReadBuffer(scalar_t__, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/, int,
                               scalar_t__ **, int /*<<< orphan*/,
                               int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clFinish(scalar_t__);
scalar_t__ clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *, size_t *);
scalar_t__ clGetEventInfo(int /*<<< orphan*/, int /*<<< orphan*/, int, ...);
scalar_t__ clGetPlatformIDs(int, int /*<<< orphan*/ *, size_t *);
int /*<<< orphan*/ clReleaseCommandQueue(scalar_t__);
int /*<<< orphan*/ clReleaseEvent(int /*<<< orphan*/);
int /*<<< orphan*/ clReleaseMemObject(int /*<<< orphan*/);
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;
    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;
      const int buf_size = 1024;
      cl_int host_buf[buf_size];
      cl_mem buf = clCreateBuffer(context, CL_MEM_READ_WRITE,
                                  sizeof(cl_int) * buf_size, NULL, &err);
      if (err != CL_SUCCESS)
        return EXIT_FAILURE;
      cl_event buf_event;
      if (clEnqueueReadBuffer(queue, buf, CL_TRUE, 0, sizeof(cl_int) * buf_size,
                              &host_buf, 0, NULL, &buf_event) != CL_SUCCESS)
        return EXIT_FAILURE;
      clFinish(queue);
      cl_command_queue event_command_queue;
      size_t param_val_size_ret;
      if (clGetEventInfo(buf_event, CL_EVENT_COMMAND_QUEUE,
                         sizeof(cl_command_queue), &event_command_queue,
                         &param_val_size_ret) != CL_SUCCESS)
        return EXIT_FAILURE;
      if (param_val_size_ret != sizeof(cl_command_queue) ||
          event_command_queue != queue)
        return EXIT_FAILURE;
      cl_command_type command_type;
      if (clGetEventInfo(buf_event, CL_EVENT_COMMAND_TYPE,
                         sizeof(cl_command_type), &command_type,
                         &param_val_size_ret) != CL_SUCCESS)
        return EXIT_FAILURE;
      if (param_val_size_ret != sizeof(cl_command_type) ||
          command_type != CL_COMMAND_READ_BUFFER)
        return EXIT_FAILURE;
      cl_int execution_status;
      if (clGetEventInfo(buf_event, CL_EVENT_COMMAND_EXECUTION_STATUS,
                         sizeof(cl_int), &execution_status,
                         &param_val_size_ret) != CL_SUCCESS)
        return EXIT_FAILURE;
      if (param_val_size_ret != sizeof(cl_int) ||
          execution_status != CL_COMPLETE)
        return EXIT_FAILURE;
      cl_uint ref_count;
      if (clGetEventInfo(buf_event, CL_EVENT_REFERENCE_COUNT, sizeof(cl_uint),
                         &ref_count, &param_val_size_ret) != CL_SUCCESS)
        return EXIT_FAILURE;
      if (param_val_size_ret != sizeof(cl_uint) || ref_count != 1)
        return EXIT_FAILURE;
      clReleaseEvent(buf_event);
      clReleaseMemObject(buf);
      clReleaseCommandQueue(queue);
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rsi
mov    $0x20,%edi
lea    -0x98(%rbp),%rdx
call   1070 <clGetPlatformIDs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
je     1203 <main+0x53>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1717 <main+0x567>
movq   $0x0,-0x130(%rbp)
mov    -0x130(%rbp),%rax
cmp    -0x98(%rbp),%rax
jae    170b <main+0x55b>
mov    -0x130(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%edi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
lea    -0x120(%rbp),%rcx
mov    $0x20,%edx
lea    -0x128(%rbp),%r8
call   1050 <clGetDeviceIDs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d28(%rip),%rcx
cmp    (%rcx),%rax
je     127a <main+0xca>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1717 <main+0x567>
movq   $0x0,-0x138(%rbp)
mov    -0x138(%rbp),%rax
cmp    -0x128(%rbp),%rax
jae    16ef <main+0x53f>
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   1090 <clCreateContext@plt>
mov    %eax,-0x13c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2cb0(%rip),%rcx
cmp    (%rcx),%rax
je     12f2 <main+0x142>
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1717 <main+0x567>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rax
mov    -0x120(%rbp,%rax,4),%esi
xor    %edx,%edx
lea    -0x10(%rbp),%rcx
call   1060 <clCreateCommandQueue@plt>
mov    %rax,-0x148(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c65(%rip),%rcx
cmp    (%rcx),%rax
je     133d <main+0x18d>
mov    0x2c75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1717 <main+0x567>
movl   $0x400,-0x14c(%rbp)
mov    %rsp,%rax
mov    %rax,-0x158(%rbp)
mov    %rsp,%rax
add    $0xffffffffffffe000,%rax
mov    %rax,-0x198(%rbp)
mov    %rax,%rsp
mov    -0x13c(%rbp),%edi
mov    0x2c67(%rip),%rax
mov    (%rax),%esi
mov    $0x2000,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
call   1040 <clCreateBuffer@plt>
mov    %eax,-0x15c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2bf2(%rip),%rcx
cmp    (%rcx),%rax
je     13ba <main+0x20a>
mov    0x2c02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
mov    -0x198(%rbp),%r9
mov    -0x148(%rbp),%rdi
mov    -0x15c(%rbp),%esi
mov    0x2c13(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
mov    $0x2000,%r8d
xor    %eax,%eax
lea    -0x164(%rbp),%rax
sub    $0x20,%rsp
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   10b0 <clEnqueueReadBuffer@plt>
add    $0x20,%rsp
mov    0x2b77(%rip),%rcx
cmp    (%rcx),%rax
je     1435 <main+0x285>
mov    0x2b87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
mov    -0x148(%rbp),%rdi
call   1030 <clFinish@plt>
mov    -0x164(%rbp),%edi
mov    0x2b6a(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x170(%rbp),%rcx
lea    -0x178(%rbp),%r8
mov    $0x0,%al
call   1080 <clGetEventInfo@plt>
mov    0x2b17(%rip),%rcx
cmp    (%rcx),%rax
je     1495 <main+0x2e5>
mov    0x2b27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
cmpq   $0x8,-0x178(%rbp)
08
jne    14b7 <main+0x307>
mov    -0x170(%rbp),%rax
cmp    -0x148(%rbp),%rax
je     14d2 <main+0x322>
mov    0x2aea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
mov    -0x164(%rbp),%edi
mov    0x2af1(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x180(%rbp),%rcx
lea    -0x178(%rbp),%r8
mov    $0x0,%al
call   1080 <clGetEventInfo@plt>
mov    0x2a86(%rip),%rcx
cmp    (%rcx),%rax
je     1526 <main+0x376>
mov    0x2a96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
cmpq   $0x8,-0x178(%rbp)
08
jne    154b <main+0x39b>
mov    -0x180(%rbp),%rax
mov    0x2a5e(%rip),%rcx
cmp    (%rcx),%rax
je     1566 <main+0x3b6>
mov    0x2a56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
mov    -0x164(%rbp),%edi
mov    0x2a6d(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x188(%rbp),%rcx
lea    -0x178(%rbp),%r8
mov    $0x0,%al
call   1080 <clGetEventInfo@plt>
mov    0x29f2(%rip),%rcx
cmp    (%rcx),%rax
je     15ba <main+0x40a>
mov    0x2a02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
cmpq   $0x8,-0x178(%rbp)
08
jne    15df <main+0x42f>
mov    -0x188(%rbp),%rax
mov    0x29ba(%rip),%rcx
cmp    (%rcx),%rax
je     15fa <main+0x44a>
mov    0x29c2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
mov    -0x164(%rbp),%edi
mov    0x29a9(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x190(%rbp),%rcx
lea    -0x178(%rbp),%r8
mov    $0x0,%al
call   1080 <clGetEventInfo@plt>
mov    0x295e(%rip),%rcx
cmp    (%rcx),%rax
je     164e <main+0x49e>
mov    0x296e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
cmpq   $0x8,-0x178(%rbp)
08
jne    166a <main+0x4ba>
cmpq   $0x1,-0x190(%rbp)
01
je     1685 <main+0x4d5>
mov    0x2937(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    16b1 <main+0x501>
mov    -0x164(%rbp),%edi
call   10d0 <clReleaseEvent@plt>
mov    -0x15c(%rbp),%edi
call   10c0 <clReleaseMemObject@plt>
mov    -0x148(%rbp),%rdi
call   10a0 <clReleaseCommandQueue@plt>
movl   $0x0,-0x160(%rbp)
mov    -0x158(%rbp),%rax
mov    %rax,%rsp
mov    -0x160(%rbp),%eax
test   %eax,%eax
je     16d3 <main+0x523>
jmp    16ce <main+0x51e>
jmp    1717 <main+0x567>
jmp    16d8 <main+0x528>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    1285 <main+0xd5>
jmp    16f4 <main+0x544>
mov    -0x130(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x130(%rbp)
jmp    120e <main+0x5e>
mov    0x2886(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
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    $0x168,%rsp
lea    -0x190(%rbp),%rsi
lea    -0x60(%rbp),%rdx
mov    $0x20,%edi
call   1070 <clGetPlatformIDs@plt>
mov    %rax,-0x40(%rbp)
mov    0x2da4(%rip),%r13
cmp    0x0(%r13),%rax
jne    14bd <main+0x30d>
cmpq   $0x0,-0x60(%rbp)
je     14b4 <main+0x304>
mov    0x2dc8(%rip),%rax
lea    -0x110(%rbp),%rcx
lea    -0x58(%rbp),%r8
lea    -0x40(%rbp),%r14
lea    -0x48(%rbp),%r12
xor    %ebx,%ebx
mov    -0x190(%rbp,%rbx,4),%edi
mov    (%rax),%esi
mov    $0x20,%edx
call   1050 <clGetDeviceIDs@plt>
mov    %rax,-0x40(%rbp)
cmp    0x0(%r13),%rax
jne    14bd <main+0x30d>
mov    %rbx,-0x68(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1490 <main+0x2e0>
xor    %ebx,%ebx
xor    %eax,%eax
mov    %rax,-0x50(%rbp)
lea    (%rbx,%rbp,1),%rdx
add    $0xfffffffffffffef0,%rdx
xor    %edi,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   1090 <clCreateContext@plt>
mov    %eax,%r15d
mov    -0x40(%rbp),%rax
cmp    0x0(%r13),%rax
jne    14bd <main+0x30d>
mov    -0x50(%rbp),%rax
mov    -0x110(%rbp,%rax,4),%esi
mov    %r15d,%edi
xor    %edx,%edx
mov    %r14,%rcx
call   1060 <clCreateCommandQueue@plt>
mov    %r14,%r8
mov    %rax,%r14
mov    -0x40(%rbp),%rax
cmp    0x0(%r13),%rax
jne    14bd <main+0x30d>
mov    %rbx,-0x70(%rbp)
mov    %r12,%rbx
mov    %rsp,-0x38(%rbp)
mov    %r13,%r12
mov    %rsp,%r13
add    $0xffffffffffffe000,%r13
mov    %r13,%rsp
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1040 <clCreateBuffer@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
cmp    (%r12),%rax
jne    14c8 <main+0x318>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edx
sub    $0x8,%rsp
mov    %r14,%r15
mov    %r14,%rdi
mov    %ecx,%r14d
mov    %ecx,%esi
xor    %ecx,%ecx
mov    $0x2000,%r8d
mov    %r13,%r9
lea    -0x2c(%rbp),%rax
push   %rax
push   $0x0
push   $0x0
call   10b0 <clEnqueueReadBuffer@plt>
add    $0x20,%rsp
cmp    (%r12),%rax
jne    14c8 <main+0x318>
mov    %r12,%r13
mov    %r15,%rdi
call   1030 <clFinish@plt>
mov    -0x2c(%rbp),%edi
mov    0x2c78(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x90(%rbp),%rcx
mov    %rbx,%r12
mov    %rbx,%r8
xor    %eax,%eax
call   1080 <clGetEventInfo@plt>
cmp    0x0(%r13),%rax
jne    14c8 <main+0x318>
cmpq   $0x8,-0x48(%rbp)
jne    14c8 <main+0x318>
cmp    %r15,-0x90(%rbp)
jne    14c8 <main+0x318>
mov    -0x2c(%rbp),%edi
mov    0x2c49(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x88(%rbp),%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1080 <clGetEventInfo@plt>
cmp    0x0(%r13),%rax
jne    14c8 <main+0x318>
cmpq   $0x8,-0x48(%rbp)
jne    14c8 <main+0x318>
mov    -0x88(%rbp),%rax
mov    0x2bde(%rip),%rcx
cmp    (%rcx),%rax
jne    14c8 <main+0x318>
mov    -0x2c(%rbp),%edi
mov    0x2c0b(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x80(%rbp),%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1080 <clGetEventInfo@plt>
cmp    0x0(%r13),%rax
jne    14c8 <main+0x318>
cmpq   $0x8,-0x48(%rbp)
jne    14c8 <main+0x318>
mov    -0x80(%rbp),%rax
mov    0x2b86(%rip),%rcx
cmp    (%rcx),%rax
jne    14c8 <main+0x318>
mov    -0x2c(%rbp),%edi
mov    0x2b93(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x78(%rbp),%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1080 <clGetEventInfo@plt>
cmp    0x0(%r13),%rax
jne    14c8 <main+0x318>
cmpq   $0x8,-0x48(%rbp)
jne    14c8 <main+0x318>
cmpq   $0x1,-0x78(%rbp)
jne    14c8 <main+0x318>
mov    -0x2c(%rbp),%edi
call   10d0 <clReleaseEvent@plt>
mov    %r14d,%edi
call   10c0 <clReleaseMemObject@plt>
mov    %r15,%rdi
call   10a0 <clReleaseCommandQueue@plt>
mov    -0x38(%rbp),%rsp
mov    -0x50(%rbp),%rcx
add    $0x1,%rcx
mov    -0x70(%rbp),%rbx
add    $0x4,%rbx
mov    %rcx,%rax
mov    %rcx,-0x50(%rbp)
cmp    -0x58(%rbp),%rcx
lea    -0x40(%rbp),%r14
jb     124d <main+0x9d>
nop
mov    -0x68(%rbp),%rbx
add    $0x1,%rbx
cmp    -0x60(%rbp),%rbx
mov    0x2b25(%rip),%rax
lea    -0x110(%rbp),%rcx
lea    -0x58(%rbp),%r8
jb     1215 <main+0x65>
mov    0x2add(%rip),%rax
jmp    14c4 <main+0x314>
mov    0x2ae4(%rip),%rax
mov    (%rax),%eax
jmp    14d5 <main+0x325>
mov    0x2ad9(%rip),%rax
mov    (%rax),%eax
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%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_MEM_READ_WRITE = global i32 0
@CL_TRUE = global i32 0
@CL_EVENT_COMMAND_QUEUE = global i32 0
@CL_EVENT_COMMAND_TYPE = global i32 0
@CL_COMMAND_READ_BUFFER = global i64 0
@CL_EVENT_COMMAND_EXECUTION_STATUS = global i32 0
@CL_COMPLETE = global i64 0
@CL_EVENT_REFERENCE_COUNT = 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 i64
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
store i32 0, i32* %1
%21 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%22 = call i64 @clGetPlatformIDs(i32 32, i32* %21, i64* %4)
store i64 %22, i64* %2
%23 = load i64, i64* %2
%24 = load i64, i64* @CL_SUCCESS
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %0
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %1
br label %180
28: ; preds = %0
store i64 0, i64* %7
br label %29
29: ; preds = %175, %28
%30 = load i64, i64* %7
%31 = load i64, i64* %4
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %178
33: ; preds = %29
%34 = load i64, i64* %7
%35 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* @CL_DEVICE_TYPE_ALL
%38 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%39 = call i64 @clGetDeviceIDs(i32 %36, i32 %37, i32 32, i32* %38, i64* %6)
store i64 %39, i64* %2
%40 = load i64, i64* %2
%41 = load i64, i64* @CL_SUCCESS
%42 = icmp ne i64 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %33
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %1
br label %180
45: ; preds = %33
store i64 0, i64* %8
br label %46
46: ; preds = %171, %45
%47 = load i64, i64* %8
%48 = load i64, i64* %6
%49 = icmp ult i64 %47, %48
br i1 %49, label %50, label %174
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 %180
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 i64 @clCreateCommandQueue(i32 %60, i32 %63, i32 0, i64* %2)
store i64 %64, i64* %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 %180
70: ; preds = %59
store i32 1024, i32* %11
%71 = call i8* @llvm.stacksave()
store i8* %71, i8** %12
%72 = alloca i64, i64 1024
%73 = load i32, i32* %9
%74 = load i32, i32* @CL_MEM_READ_WRITE
%75 = call i32 @clCreateBuffer(i32 %73, i32 %74, i32 8192, i32* null, i64* %2)
store i32 %75, i32* %13
%76 = load i64, i64* %2
%77 = load i64, i64* @CL_SUCCESS
%78 = icmp ne i64 %76, %77
br i1 %78, label %79, label %81
79: ; preds = %70
%80 = load i32, i32* @EXIT_FAILURE
store i32 %80, i32* %1
store i32 1, i32* %14
br label %167
81: ; preds = %70
%82 = load i64, i64* %10
%83 = load i32, i32* %13
%84 = load i32, i32* @CL_TRUE
%85 = bitcast i64* %72 to i64**
%86 = call i64 @clEnqueueReadBuffer(i64 %82, i32 %83, i32 %84, i32 0, i32 8192, i64** %85, i32 0, i32* null, i32* %15)
%87 = load i64, i64* @CL_SUCCESS
%88 = icmp ne i64 %86, %87
br i1 %88, label %89, label %91
89: ; preds = %81
%90 = load i32, i32* @EXIT_FAILURE
store i32 %90, i32* %1
store i32 1, i32* %14
br label %167
91: ; preds = %81
%92 = load i64, i64* %10
%93 = call i32 @clFinish(i64 %92)
%94 = load i32, i32* %15
%95 = load i32, i32* @CL_EVENT_COMMAND_QUEUE
%96 = call i64 (i32, i32, i32, ...) @clGetEventInfo(i32 %94, i32 %95, i32 8, i64* %16, i64* %17)
%97 = load i64, i64* @CL_SUCCESS
%98 = icmp ne i64 %96, %97
br i1 %98, label %99, label %101
99: ; preds = %91
%100 = load i32, i32* @EXIT_FAILURE
store i32 %100, i32* %1
store i32 1, i32* %14
br label %167
101: ; preds = %91
%102 = load i64, i64* %17
%103 = icmp ne i64 %102, 8
br i1 %103, label %108, label %104
104: ; preds = %101
%105 = load i64, i64* %16
%106 = load i64, i64* %10
%107 = icmp ne i64 %105, %106
br i1 %107, label %108, label %110
108: ; preds = %104, %101
%109 = load i32, i32* @EXIT_FAILURE
store i32 %109, i32* %1
store i32 1, i32* %14
br label %167
110: ; preds = %104
%111 = load i32, i32* %15
%112 = load i32, i32* @CL_EVENT_COMMAND_TYPE
%113 = call i64 (i32, i32, i32, ...) @clGetEventInfo(i32 %111, i32 %112, i32 8, i64* %18, i64* %17)
%114 = load i64, i64* @CL_SUCCESS
%115 = icmp ne i64 %113, %114
br i1 %115, label %116, label %118
116: ; preds = %110
%117 = load i32, i32* @EXIT_FAILURE
store i32 %117, i32* %1
store i32 1, i32* %14
br label %167
118: ; preds = %110
%119 = load i64, i64* %17
%120 = icmp ne i64 %119, 8
br i1 %120, label %125, label %121
121: ; preds = %118
%122 = load i64, i64* %18
%123 = load i64, i64* @CL_COMMAND_READ_BUFFER
%124 = icmp ne i64 %122, %123
br i1 %124, label %125, label %127
125: ; preds = %121, %118
%126 = load i32, i32* @EXIT_FAILURE
store i32 %126, i32* %1
store i32 1, i32* %14
br label %167
127: ; preds = %121
%128 = load i32, i32* %15
%129 = load i32, i32* @CL_EVENT_COMMAND_EXECUTION_STATUS
%130 = call i64 (i32, i32, i32, ...) @clGetEventInfo(i32 %128, i32 %129, i32 8, i64* %19, i64* %17)
%131 = load i64, i64* @CL_SUCCESS
%132 = icmp ne i64 %130, %131
br i1 %132, label %133, label %135
133: ; preds = %127
%134 = load i32, i32* @EXIT_FAILURE
store i32 %134, i32* %1
store i32 1, i32* %14
br label %167
135: ; preds = %127
%136 = load i64, i64* %17
%137 = icmp ne i64 %136, 8
br i1 %137, label %142, label %138
138: ; preds = %135
%139 = load i64, i64* %19
%140 = load i64, i64* @CL_COMPLETE
%141 = icmp ne i64 %139, %140
br i1 %141, label %142, label %144
142: ; preds = %138, %135
%143 = load i32, i32* @EXIT_FAILURE
store i32 %143, i32* %1
store i32 1, i32* %14
br label %167
144: ; preds = %138
%145 = load i32, i32* %15
%146 = load i32, i32* @CL_EVENT_REFERENCE_COUNT
%147 = call i64 (i32, i32, i32, ...) @clGetEventInfo(i32 %145, i32 %146, i32 8, i64* %20, i64* %17)
%148 = load i64, i64* @CL_SUCCESS
%149 = icmp ne i64 %147, %148
br i1 %149, label %150, label %152
150: ; preds = %144
%151 = load i32, i32* @EXIT_FAILURE
store i32 %151, i32* %1
store i32 1, i32* %14
br label %167
152: ; preds = %144
%153 = load i64, i64* %17
%154 = icmp ne i64 %153, 8
br i1 %154, label %158, label %155
155: ; preds = %152
%156 = load i64, i64* %20
%157 = icmp ne i64 %156, 1
br i1 %157, label %158, label %160
158: ; preds = %155, %152
%159 = load i32, i32* @EXIT_FAILURE
store i32 %159, i32* %1
store i32 1, i32* %14
br label %167
160: ; preds = %155
%161 = load i32, i32* %15
%162 = call i32 @clReleaseEvent(i32 %161)
%163 = load i32, i32* %13
%164 = call i32 @clReleaseMemObject(i32 %163)
%165 = load i64, i64* %10
%166 = call i32 @clReleaseCommandQueue(i64 %165)
store i32 0, i32* %14
br label %167
167: ; preds = %160, %158, %150, %142, %133, %125, %116, %108, %99, %89, %79
%168 = load i8*, i8** %12
%169 = load i32, i32* %14
switch i32 %169, label %182 [
i32 0, label %170
i32 1, label %180
]
170: ; preds = %167
br label %171
171: ; preds = %170
%172 = load i64, i64* %8
%173 = add i64 %172, 1
store i64 %173, i64* %8
br label %46
174: ; preds = %46
br label %175
175: ; preds = %174
%176 = load i64, i64* %7
%177 = add i64 %176, 1
store i64 %177, i64* %7
br label %29
178: ; preds = %29
%179 = load i32, i32* @EXIT_SUCCESS
store i32 %179, i32* %1
br label %180
180: ; preds = %178, %167, %68, %57, %43, %26
%181 = load i32, i32* %1
ret i32 %181
182: ; preds = %167
unreachable
}

LLVM IR (-O2):
@CL_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
@CL_DEVICE_TYPE_ALL = global i32 0
@CL_MEM_READ_WRITE = global i32 0
@CL_TRUE = global i32 0
@CL_EVENT_COMMAND_QUEUE = global i32 0
@CL_EVENT_COMMAND_TYPE = global i32 0
@CL_COMMAND_READ_BUFFER = global i64 0
@CL_EVENT_COMMAND_EXECUTION_STATUS = global i32 0
@CL_COMPLETE = global i64 0
@CL_EVENT_REFERENCE_COUNT = 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 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = bitcast i64* %1 to i8*
%13 = bitcast [32 x i32]* %2 to i8*
%14 = bitcast i64* %3 to i8*
%15 = bitcast [32 x i32]* %4 to i8*
%16 = bitcast i64* %5 to i8*
%17 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 0
%18 = call i64 @clGetPlatformIDs(i32 32, i32* %17, i64* %3)
store i64 %18, i64* %1
%19 = load i64, i64* @CL_SUCCESS
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %0
%22 = load i64, i64* %3
%23 = icmp eq i64 %22, 0
br i1 %23, label %153, label %24
24: ; preds = %21
%25 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 0
%26 = bitcast i32* %6 to i8*
%27 = bitcast i64* %7 to i8*
%28 = bitcast i64* %8 to i8*
%29 = bitcast i64* %9 to i8*
%30 = bitcast i64* %10 to i8*
%31 = bitcast i64* %11 to i8*
br label %34
32: ; preds = %0
%33 = load i32, i32* @EXIT_FAILURE
br label %155
34: ; preds = %24, %149
%35 = phi i64 [ 0, %24 ], [ %150, %149 ]
%36 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = load i32, i32* @CL_DEVICE_TYPE_ALL
%39 = call i64 @clGetDeviceIDs(i32 %37, i32 %38, i32 32, i32* %25, i64* %5)
store i64 %39, i64* %1
%40 = load i64, i64* @CL_SUCCESS
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %34
%43 = load i64, i64* %5
%44 = icmp eq i64 %43, 0
br i1 %44, label %149, label %47
45: ; preds = %34
%46 = load i32, i32* @EXIT_FAILURE
br label %155
47: ; preds = %42, %141
%48 = phi i64 [ %146, %141 ], [ 0, %42 ]
%49 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 %48
%50 = call i32 @clCreateContext(i32* null, i32 1, i32* %49, i32* null, i32* null, i64* %1)
%51 = load i64, i64* %1
%52 = load i64, i64* @CL_SUCCESS
%53 = icmp eq i64 %51, %52
br i1 %53, label %56, label %54
54: ; preds = %47
%55 = load i32, i32* @EXIT_FAILURE
br label %155
56: ; preds = %47
%57 = load i32, i32* %49
%58 = call i64 @clCreateCommandQueue(i32 %50, i32 %57, i32 0, i64* %1)
%59 = load i64, i64* %1
%60 = load i64, i64* @CL_SUCCESS
%61 = icmp eq i64 %59, %60
br i1 %61, label %64, label %62
62: ; preds = %56
%63 = load i32, i32* @EXIT_FAILURE
br label %155
64: ; preds = %56
%65 = call i8* @llvm.stacksave()
%66 = alloca [1024 x i64*]
%67 = load i32, i32* @CL_MEM_READ_WRITE
%68 = call i32 @clCreateBuffer(i32 %50, i32 %67, i32 8192, i32* null, i64* %1)
%69 = load i64, i64* %1
%70 = load i64, i64* @CL_SUCCESS
%71 = icmp eq i64 %69, %70
br i1 %71, label %74, label %72
72: ; preds = %64
%73 = load i32, i32* @EXIT_FAILURE
br label %155
74: ; preds = %64
%75 = getelementptr inbounds [1024 x i64*], [1024 x i64*]* %66, i64 0, i64 0
%76 = load i32, i32* @CL_TRUE
%77 = call i64 @clEnqueueReadBuffer(i64 %58, i32 %68, i32 %76, i32 0, i32 8192, i64** %75, i32 0, i32* null, i32* %6)
%78 = load i64, i64* @CL_SUCCESS
%79 = icmp eq i64 %77, %78
br i1 %79, label %82, label %80
80: ; preds = %74
%81 = load i32, i32* @EXIT_FAILURE
br label %155
82: ; preds = %74
%83 = call i32 @clFinish(i64 %58)
%84 = load i32, i32* %6
%85 = load i32, i32* @CL_EVENT_COMMAND_QUEUE
%86 = call i64 (i32, i32, i32, ...) @clGetEventInfo(i32 %84, i32 %85, i32 8, i64* %7, i64* %8)
%87 = load i64, i64* @CL_SUCCESS
%88 = icmp eq i64 %86, %87
br i1 %88, label %89, label %133
89: ; preds = %82
%90 = load i64, i64* %8
%91 = icmp eq i64 %90, 8
%92 = load i64, i64* %7
%93 = icmp eq i64 %92, %58
%94 = select i1 %91, i1 %93, i1 false
br i1 %94, label %95, label %133
95: ; preds = %89
%96 = load i32, i32* %6
%97 = load i32, i32* @CL_EVENT_COMMAND_TYPE
%98 = call i64 (i32, i32, i32, ...) @clGetEventInfo(i32 %96, i32 %97, i32 8, i64* %9, i64* %8)
%99 = load i64, i64* @CL_SUCCESS
%100 = icmp eq i64 %98, %99
%101 = load i64, i64* %8
%102 = icmp eq i64 %101, 8
%103 = select i1 %100, i1 %102, i1 false
br i1 %103, label %104, label %135
104: ; preds = %95
%105 = load i64, i64* %9
%106 = load i64, i64* @CL_COMMAND_READ_BUFFER
%107 = icmp eq i64 %105, %106
br i1 %107, label %108, label %135
108: ; preds = %104
%109 = load i32, i32* %6
%110 = load i32, i32* @CL_EVENT_COMMAND_EXECUTION_STATUS
%111 = call i64 (i32, i32, i32, ...) @clGetEventInfo(i32 %109, i32 %110, i32 8, i64* %10, i64* %8)
%112 = load i64, i64* @CL_SUCCESS
%113 = icmp eq i64 %111, %112
%114 = load i64, i64* %8
%115 = icmp eq i64 %114, 8
%116 = select i1 %113, i1 %115, i1 false
br i1 %116, label %117, label %137
117: ; preds = %108
%118 = load i64, i64* %10
%119 = load i64, i64* @CL_COMPLETE
%120 = icmp eq i64 %118, %119
br i1 %120, label %121, label %137
121: ; preds = %117
%122 = load i32, i32* %6
%123 = load i32, i32* @CL_EVENT_REFERENCE_COUNT
%124 = call i64 (i32, i32, i32, ...) @clGetEventInfo(i32 %122, i32 %123, i32 8, i64* %11, i64* %8)
%125 = load i64, i64* @CL_SUCCESS
%126 = icmp eq i64 %124, %125
br i1 %126, label %127, label %139
127: ; preds = %121
%128 = load i64, i64* %8
%129 = icmp ne i64 %128, 8
%130 = load i64, i64* %11
%131 = icmp ne i64 %130, 1
%132 = select i1 %129, i1 true, i1 %131
br i1 %132, label %139, label %141
133: ; preds = %89, %82
%134 = load i32, i32* @EXIT_FAILURE
br label %155
135: ; preds = %104, %95
%136 = load i32, i32* @EXIT_FAILURE
br label %155
137: ; preds = %117, %108
%138 = load i32, i32* @EXIT_FAILURE
br label %155
139: ; preds = %127, %121
%140 = load i32, i32* @EXIT_FAILURE
br label %155
141: ; preds = %127
%142 = load i32, i32* %6
%143 = call i32 @clReleaseEvent(i32 %142)
%144 = call i32 @clReleaseMemObject(i32 %68)
%145 = call i32 @clReleaseCommandQueue(i64 %58)
%146 = add nuw i64 %48, 1
%147 = load i64, i64* %5
%148 = icmp ult i64 %146, %147
br i1 %148, label %47, label %149
149: ; preds = %141, %42
%150 = add nuw i64 %35, 1
%151 = load i64, i64* %3
%152 = icmp ult i64 %150, %151
br i1 %152, label %34, label %153
153: ; preds = %149, %21
%154 = load i32, i32* @EXIT_SUCCESS
br label %155
155: ; preds = %62, %54, %139, %137, %135, %133, %80, %72, %153, %45, %32
%156 = phi i32 [ %33, %32 ], [ %46, %45 ], [ %154, %153 ], [ %73, %72 ], [ %81, %80 ], [ %134, %133 ], [ %136, %135 ], [ %138, %137 ], [ %140, %139 ], [ %63, %62 ], [ %55, %54 ]
ret i32 %156
}