#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_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__ *, size_t *);
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;
      clReleaseEvent(buf_event);
      clReleaseMemObject(buf);
      clReleaseCommandQueue(queue);
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%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    0x2da7(%rip),%rcx
cmp    (%rcx),%rax
je     1203 <main+0x53>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1686 <main+0x4d6>
movq   $0x0,-0x130(%rbp)
mov    -0x130(%rbp),%rax
cmp    -0x98(%rbp),%rax
jae    167a <main+0x4ca>
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    0x2d30(%rip),%rcx
cmp    (%rcx),%rax
je     127a <main+0xca>
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1686 <main+0x4d6>
movq   $0x0,-0x138(%rbp)
mov    -0x138(%rbp),%rax
cmp    -0x128(%rbp),%rax
jae    165e <main+0x4ae>
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    0x2cb8(%rip),%rcx
cmp    (%rcx),%rax
je     12f2 <main+0x142>
mov    0x2cc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1686 <main+0x4d6>
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    0x2c6d(%rip),%rcx
cmp    (%rcx),%rax
je     133d <main+0x18d>
mov    0x2c7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1686 <main+0x4d6>
movl   $0x400,-0x14c(%rbp)
mov    %rsp,%rax
mov    %rax,-0x158(%rbp)
mov    %rsp,%rax
add    $0xffffffffffffe000,%rax
mov    %rax,-0x190(%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    0x2bfa(%rip),%rcx
cmp    (%rcx),%rax
je     13ba <main+0x20a>
mov    0x2c0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    1620 <main+0x470>
mov    -0x190(%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    0x2b7f(%rip),%rcx
cmp    (%rcx),%rax
je     1435 <main+0x285>
mov    0x2b8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    1620 <main+0x470>
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
call   1080 <clGetEventInfo@plt>
mov    0x2b21(%rip),%rcx
cmp    (%rcx),%rax
je     1493 <main+0x2e3>
mov    0x2b31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    1620 <main+0x470>
cmpq   $0x8,-0x178(%rbp)
08
jne    14b5 <main+0x305>
mov    -0x170(%rbp),%rax
cmp    -0x148(%rbp),%rax
je     14d0 <main+0x320>
mov    0x2af4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    1620 <main+0x470>
mov    -0x164(%rbp),%edi
mov    0x2af3(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x180(%rbp),%rcx
lea    -0x178(%rbp),%r8
call   1080 <clGetEventInfo@plt>
mov    0x2a92(%rip),%rcx
cmp    (%rcx),%rax
je     1522 <main+0x372>
mov    0x2aa2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    1620 <main+0x470>
cmpq   $0x8,-0x178(%rbp)
08
jne    1547 <main+0x397>
mov    -0x180(%rbp),%rax
mov    0x2a6a(%rip),%rcx
cmp    (%rcx),%rax
je     1562 <main+0x3b2>
mov    0x2a62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    1620 <main+0x470>
mov    -0x164(%rbp),%edi
mov    0x2a71(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x188(%rbp),%rcx
lea    -0x178(%rbp),%r8
call   1080 <clGetEventInfo@plt>
mov    0x2a00(%rip),%rcx
cmp    (%rcx),%rax
je     15b4 <main+0x404>
mov    0x2a10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    1620 <main+0x470>
cmpq   $0x8,-0x178(%rbp)
08
jne    15d9 <main+0x429>
mov    -0x188(%rbp),%rax
mov    0x29c8(%rip),%rcx
cmp    (%rcx),%rax
je     15f4 <main+0x444>
mov    0x29d0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x160(%rbp)
jmp    1620 <main+0x470>
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     1642 <main+0x492>
jmp    163d <main+0x48d>
jmp    1686 <main+0x4d6>
jmp    1647 <main+0x497>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    1285 <main+0xd5>
jmp    1663 <main+0x4b3>
mov    -0x130(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x130(%rbp)
jmp    120e <main+0x5e>
mov    0x291f(%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    0x2dac(%rip),%r13
cmp    0x0(%r13),%rax
jne    146d <main+0x2bd>
cmpq   $0x0,-0x60(%rbp)
je     1464 <main+0x2b4>
xor    %ebx,%ebx
mov    0x2dc6(%rip),%rax
lea    -0x110(%rbp),%rcx
lea    -0x58(%rbp),%r8
lea    -0x40(%rbp),%r12
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    146d <main+0x2bd>
mov    %rbx,-0x68(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1440 <main+0x290>
xor    %ebx,%ebx
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
lea    (%rbx,%rbp,1),%rdx
add    $0xfffffffffffffef0,%rdx
xor    %edi,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r12,%r9
call   1090 <clCreateContext@plt>
mov    %eax,%r15d
mov    -0x40(%rbp),%rax
cmp    0x0(%r13),%rax
jne    146d <main+0x2bd>
mov    -0x48(%rbp),%rax
mov    -0x110(%rbp,%rax,4),%esi
mov    %r15d,%edi
xor    %edx,%edx
mov    %r12,%rcx
call   1060 <clCreateCommandQueue@plt>
mov    %rax,%r14
mov    -0x40(%rbp),%rax
cmp    0x0(%r13),%rax
jne    146d <main+0x2bd>
mov    %rbx,-0x70(%rbp)
mov    %rsp,-0x38(%rbp)
mov    %r12,%r8
mov    %r13,%r12
mov    %rsp,%r13
add    $0xffffffffffffe000,%r13
mov    %r13,%rsp
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1040 <clCreateBuffer@plt>
mov    %eax,%ebx
mov    -0x40(%rbp),%rax
cmp    (%r12),%rax
jne    1478 <main+0x2c8>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edx
sub    $0x8,%rsp
mov    %r14,%rdi
mov    %ebx,%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    1478 <main+0x2c8>
mov    %r12,%r13
mov    %r14,%rdi
call   1030 <clFinish@plt>
mov    -0x2c(%rbp),%edi
mov    0x2c85(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x88(%rbp),%rcx
lea    -0x50(%rbp),%r15
mov    %r15,%r8
call   1080 <clGetEventInfo@plt>
cmp    (%r12),%rax
jne    1478 <main+0x2c8>
cmpq   $0x8,-0x50(%rbp)
jne    1478 <main+0x2c8>
cmp    %r14,-0x88(%rbp)
jne    1478 <main+0x2c8>
mov    -0x2c(%rbp),%edi
mov    0x2c57(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x80(%rbp),%rcx
mov    %r15,%r8
call   1080 <clGetEventInfo@plt>
cmp    0x0(%r13),%rax
jne    1478 <main+0x2c8>
cmpq   $0x8,-0x50(%rbp)
jne    1478 <main+0x2c8>
mov    -0x80(%rbp),%rax
mov    0x2bfc(%rip),%rcx
cmp    (%rcx),%rax
jne    1478 <main+0x2c8>
mov    -0x2c(%rbp),%edi
mov    0x2c21(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x78(%rbp),%rcx
mov    %r15,%r8
call   1080 <clGetEventInfo@plt>
cmp    0x0(%r13),%rax
jne    1478 <main+0x2c8>
cmpq   $0x8,-0x50(%rbp)
jne    1478 <main+0x2c8>
mov    -0x78(%rbp),%rax
mov    0x2ba6(%rip),%rcx
cmp    (%rcx),%rax
jne    1478 <main+0x2c8>
mov    -0x2c(%rbp),%edi
call   10d0 <clReleaseEvent@plt>
mov    %ebx,%edi
call   10c0 <clReleaseMemObject@plt>
mov    %r14,%rdi
call   10a0 <clReleaseCommandQueue@plt>
mov    -0x38(%rbp),%rsp
mov    -0x48(%rbp),%rcx
add    $0x1,%rcx
mov    -0x70(%rbp),%rbx
add    $0x4,%rbx
mov    %rcx,%rax
mov    %rcx,-0x48(%rbp)
cmp    -0x58(%rbp),%rcx
lea    -0x40(%rbp),%r12
jb     1249 <main+0x99>
nopl   0x0(%rax,%rax,1)
mov    -0x68(%rbp),%rbx
add    $0x1,%rbx
cmp    -0x60(%rbp),%rbx
mov    0x2b75(%rip),%rax
lea    -0x110(%rbp),%rcx
lea    -0x58(%rbp),%r8
jb     1211 <main+0x61>
mov    0x2b35(%rip),%rax
jmp    1474 <main+0x2c4>
mov    0x2b3c(%rip),%rax
mov    (%rax),%eax
jmp    1485 <main+0x2d5>
mov    0x2b31(%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
@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
store i32 0, i32* %1
%20 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%21 = call i64 @clGetPlatformIDs(i32 32, i32* %20, i64* %4)
store i64 %21, i64* %2
%22 = load i64, i64* %2
%23 = load i64, i64* @CL_SUCCESS
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %0
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %1
br label %163
27: ; preds = %0
store i64 0, i64* %7
br label %28
28: ; preds = %158, %27
%29 = load i64, i64* %7
%30 = load i64, i64* %4
%31 = icmp ult i64 %29, %30
br i1 %31, label %32, label %161
32: ; preds = %28
%33 = load i64, i64* %7
%34 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* @CL_DEVICE_TYPE_ALL
%37 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%38 = call i64 @clGetDeviceIDs(i32 %35, i32 %36, i32 32, i32* %37, i64* %6)
store i64 %38, i64* %2
%39 = load i64, i64* %2
%40 = load i64, i64* @CL_SUCCESS
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %32
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %1
br label %163
44: ; preds = %32
store i64 0, i64* %8
br label %45
45: ; preds = %154, %44
%46 = load i64, i64* %8
%47 = load i64, i64* %6
%48 = icmp ult i64 %46, %47
br i1 %48, label %49, label %157
49: ; preds = %45
%50 = load i64, i64* %8
%51 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 %50
%52 = call i32 @clCreateContext(i32* null, i32 1, i32* %51, i32* null, i32* null, i64* %2)
store i32 %52, i32* %9
%53 = load i64, i64* %2
%54 = load i64, i64* @CL_SUCCESS
%55 = icmp ne i64 %53, %54
br i1 %55, label %56, label %58
56: ; preds = %49
%57 = load i32, i32* @EXIT_FAILURE
store i32 %57, i32* %1
br label %163
58: ; preds = %49
%59 = load i32, i32* %9
%60 = load i64, i64* %8
%61 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = call i64 @clCreateCommandQueue(i32 %59, i32 %62, i32 0, i64* %2)
store i64 %63, i64* %10
%64 = load i64, i64* %2
%65 = load i64, i64* @CL_SUCCESS
%66 = icmp ne i64 %64, %65
br i1 %66, label %67, label %69
67: ; preds = %58
%68 = load i32, i32* @EXIT_FAILURE
store i32 %68, i32* %1
br label %163
69: ; preds = %58
store i32 1024, i32* %11
%70 = call i8* @llvm.stacksave()
store i8* %70, i8** %12
%71 = alloca i64, i64 1024
%72 = load i32, i32* %9
%73 = load i32, i32* @CL_MEM_READ_WRITE
%74 = call i32 @clCreateBuffer(i32 %72, i32 %73, i32 8192, i32* null, i64* %2)
store i32 %74, i32* %13
%75 = load i64, i64* %2
%76 = load i64, i64* @CL_SUCCESS
%77 = icmp ne i64 %75, %76
br i1 %77, label %78, label %80
78: ; preds = %69
%79 = load i32, i32* @EXIT_FAILURE
store i32 %79, i32* %1
store i32 1, i32* %14
br label %150
80: ; preds = %69
%81 = load i64, i64* %10
%82 = load i32, i32* %13
%83 = load i32, i32* @CL_TRUE
%84 = bitcast i64* %71 to i64**
%85 = call i64 @clEnqueueReadBuffer(i64 %81, i32 %82, i32 %83, i32 0, i32 8192, i64** %84, i32 0, i32* null, i32* %15)
%86 = load i64, i64* @CL_SUCCESS
%87 = icmp ne i64 %85, %86
br i1 %87, label %88, label %90
88: ; preds = %80
%89 = load i32, i32* @EXIT_FAILURE
store i32 %89, i32* %1
store i32 1, i32* %14
br label %150
90: ; preds = %80
%91 = load i64, i64* %10
%92 = call i32 @clFinish(i64 %91)
%93 = load i32, i32* %15
%94 = load i32, i32* @CL_EVENT_COMMAND_QUEUE
%95 = call i64 @clGetEventInfo(i32 %93, i32 %94, i32 8, i64* %16, i64* %17)
%96 = load i64, i64* @CL_SUCCESS
%97 = icmp ne i64 %95, %96
br i1 %97, label %98, label %100
98: ; preds = %90
%99 = load i32, i32* @EXIT_FAILURE
store i32 %99, i32* %1
store i32 1, i32* %14
br label %150
100: ; preds = %90
%101 = load i64, i64* %17
%102 = icmp ne i64 %101, 8
br i1 %102, label %107, label %103
103: ; preds = %100
%104 = load i64, i64* %16
%105 = load i64, i64* %10
%106 = icmp ne i64 %104, %105
br i1 %106, label %107, label %109
107: ; preds = %103, %100
%108 = load i32, i32* @EXIT_FAILURE
store i32 %108, i32* %1
store i32 1, i32* %14
br label %150
109: ; preds = %103
%110 = load i32, i32* %15
%111 = load i32, i32* @CL_EVENT_COMMAND_TYPE
%112 = call i64 @clGetEventInfo(i32 %110, i32 %111, i32 8, i64* %18, i64* %17)
%113 = load i64, i64* @CL_SUCCESS
%114 = icmp ne i64 %112, %113
br i1 %114, label %115, label %117
115: ; preds = %109
%116 = load i32, i32* @EXIT_FAILURE
store i32 %116, i32* %1
store i32 1, i32* %14
br label %150
117: ; preds = %109
%118 = load i64, i64* %17
%119 = icmp ne i64 %118, 8
br i1 %119, label %124, label %120
120: ; preds = %117
%121 = load i64, i64* %18
%122 = load i64, i64* @CL_COMMAND_READ_BUFFER
%123 = icmp ne i64 %121, %122
br i1 %123, label %124, label %126
124: ; preds = %120, %117
%125 = load i32, i32* @EXIT_FAILURE
store i32 %125, i32* %1
store i32 1, i32* %14
br label %150
126: ; preds = %120
%127 = load i32, i32* %15
%128 = load i32, i32* @CL_EVENT_COMMAND_EXECUTION_STATUS
%129 = call i64 @clGetEventInfo(i32 %127, i32 %128, i32 8, i64* %19, i64* %17)
%130 = load i64, i64* @CL_SUCCESS
%131 = icmp ne i64 %129, %130
br i1 %131, label %132, label %134
132: ; preds = %126
%133 = load i32, i32* @EXIT_FAILURE
store i32 %133, i32* %1
store i32 1, i32* %14
br label %150
134: ; preds = %126
%135 = load i64, i64* %17
%136 = icmp ne i64 %135, 8
br i1 %136, label %141, label %137
137: ; preds = %134
%138 = load i64, i64* %19
%139 = load i64, i64* @CL_COMPLETE
%140 = icmp ne i64 %138, %139
br i1 %140, label %141, label %143
141: ; preds = %137, %134
%142 = load i32, i32* @EXIT_FAILURE
store i32 %142, i32* %1
store i32 1, i32* %14
br label %150
143: ; preds = %137
%144 = load i32, i32* %15
%145 = call i32 @clReleaseEvent(i32 %144)
%146 = load i32, i32* %13
%147 = call i32 @clReleaseMemObject(i32 %146)
%148 = load i64, i64* %10
%149 = call i32 @clReleaseCommandQueue(i64 %148)
store i32 0, i32* %14
br label %150
150: ; preds = %143, %141, %132, %124, %115, %107, %98, %88, %78
%151 = load i8*, i8** %12
%152 = load i32, i32* %14
switch i32 %152, label %165 [
i32 0, label %153
i32 1, label %163
]
153: ; preds = %150
br label %154
154: ; preds = %153
%155 = load i64, i64* %8
%156 = add i64 %155, 1
store i64 %156, i64* %8
br label %45
157: ; preds = %45
br label %158
158: ; preds = %157
%159 = load i64, i64* %7
%160 = add i64 %159, 1
store i64 %160, i64* %7
br label %28
161: ; preds = %28
%162 = load i32, i32* @EXIT_SUCCESS
store i32 %162, i32* %1
br label %163
163: ; preds = %161, %150, %67, %56, %42, %25
%164 = load i32, i32* %1
ret i32 %164
165: ; preds = %150
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
@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 = bitcast i64* %1 to i8*
%12 = bitcast [32 x i32]* %2 to i8*
%13 = bitcast i64* %3 to i8*
%14 = bitcast [32 x i32]* %4 to i8*
%15 = bitcast i64* %5 to i8*
%16 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 0
%17 = call i64 @clGetPlatformIDs(i32 32, i32* %16, i64* %3)
store i64 %17, i64* %1
%18 = load i64, i64* @CL_SUCCESS
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %0
%21 = load i64, i64* %3
%22 = icmp eq i64 %21, 0
br i1 %22, label %137, label %23
23: ; preds = %20
%24 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 0
%25 = bitcast i32* %6 to i8*
%26 = bitcast i64* %7 to i8*
%27 = bitcast i64* %8 to i8*
%28 = bitcast i64* %9 to i8*
%29 = bitcast i64* %10 to i8*
br label %32
30: ; preds = %0
%31 = load i32, i32* @EXIT_FAILURE
br label %139
32: ; preds = %23, %133
%33 = phi i64 [ 0, %23 ], [ %134, %133 ]
%34 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* @CL_DEVICE_TYPE_ALL
%37 = call i64 @clGetDeviceIDs(i32 %35, i32 %36, i32 32, i32* %24, i64* %5)
store i64 %37, i64* %1
%38 = load i64, i64* @CL_SUCCESS
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = load i64, i64* %5
%42 = icmp eq i64 %41, 0
br i1 %42, label %133, label %45
43: ; preds = %32
%44 = load i32, i32* @EXIT_FAILURE
br label %139
45: ; preds = %40, %125
%46 = phi i64 [ %130, %125 ], [ 0, %40 ]
%47 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 %46
%48 = call i32 @clCreateContext(i32* null, i32 1, i32* %47, i32* null, i32* null, i64* %1)
%49 = load i64, i64* %1
%50 = load i64, i64* @CL_SUCCESS
%51 = icmp eq i64 %49, %50
br i1 %51, label %54, label %52
52: ; preds = %45
%53 = load i32, i32* @EXIT_FAILURE
br label %139
54: ; preds = %45
%55 = load i32, i32* %47
%56 = call i64 @clCreateCommandQueue(i32 %48, i32 %55, i32 0, i64* %1)
%57 = load i64, i64* %1
%58 = load i64, i64* @CL_SUCCESS
%59 = icmp eq i64 %57, %58
br i1 %59, label %62, label %60
60: ; preds = %54
%61 = load i32, i32* @EXIT_FAILURE
br label %139
62: ; preds = %54
%63 = call i8* @llvm.stacksave()
%64 = alloca [1024 x i64*]
%65 = load i32, i32* @CL_MEM_READ_WRITE
%66 = call i32 @clCreateBuffer(i32 %48, i32 %65, i32 8192, i32* null, i64* %1)
%67 = load i64, i64* %1
%68 = load i64, i64* @CL_SUCCESS
%69 = icmp eq i64 %67, %68
br i1 %69, label %72, label %70
70: ; preds = %62
%71 = load i32, i32* @EXIT_FAILURE
br label %139
72: ; preds = %62
%73 = getelementptr inbounds [1024 x i64*], [1024 x i64*]* %64, i64 0, i64 0
%74 = load i32, i32* @CL_TRUE
%75 = call i64 @clEnqueueReadBuffer(i64 %56, i32 %66, i32 %74, i32 0, i32 8192, i64** %73, i32 0, i32* null, i32* %6)
%76 = load i64, i64* @CL_SUCCESS
%77 = icmp eq i64 %75, %76
br i1 %77, label %80, label %78
78: ; preds = %72
%79 = load i32, i32* @EXIT_FAILURE
br label %139
80: ; preds = %72
%81 = call i32 @clFinish(i64 %56)
%82 = load i32, i32* %6
%83 = load i32, i32* @CL_EVENT_COMMAND_QUEUE
%84 = call i64 @clGetEventInfo(i32 %82, i32 %83, i32 8, i64* %7, i64* %8)
%85 = load i64, i64* @CL_SUCCESS
%86 = icmp eq i64 %84, %85
br i1 %86, label %87, label %119
87: ; preds = %80
%88 = load i64, i64* %8
%89 = icmp eq i64 %88, 8
%90 = load i64, i64* %7
%91 = icmp eq i64 %90, %56
%92 = select i1 %89, i1 %91, i1 false
br i1 %92, label %93, label %119
93: ; preds = %87
%94 = load i32, i32* %6
%95 = load i32, i32* @CL_EVENT_COMMAND_TYPE
%96 = call i64 @clGetEventInfo(i32 %94, i32 %95, i32 8, i64* %9, i64* %8)
%97 = load i64, i64* @CL_SUCCESS
%98 = icmp eq i64 %96, %97
%99 = load i64, i64* %8
%100 = icmp eq i64 %99, 8
%101 = select i1 %98, i1 %100, i1 false
br i1 %101, label %102, label %121
102: ; preds = %93
%103 = load i64, i64* %9
%104 = load i64, i64* @CL_COMMAND_READ_BUFFER
%105 = icmp eq i64 %103, %104
br i1 %105, label %106, label %121
106: ; preds = %102
%107 = load i32, i32* %6
%108 = load i32, i32* @CL_EVENT_COMMAND_EXECUTION_STATUS
%109 = call i64 @clGetEventInfo(i32 %107, i32 %108, i32 8, i64* %10, i64* %8)
%110 = load i64, i64* @CL_SUCCESS
%111 = icmp eq i64 %109, %110
%112 = load i64, i64* %8
%113 = icmp eq i64 %112, 8
%114 = select i1 %111, i1 %113, i1 false
br i1 %114, label %115, label %123
115: ; preds = %106
%116 = load i64, i64* %10
%117 = load i64, i64* @CL_COMPLETE
%118 = icmp eq i64 %116, %117
br i1 %118, label %125, label %123
119: ; preds = %87, %80
%120 = load i32, i32* @EXIT_FAILURE
br label %139
121: ; preds = %102, %93
%122 = load i32, i32* @EXIT_FAILURE
br label %139
123: ; preds = %115, %106
%124 = load i32, i32* @EXIT_FAILURE
br label %139
125: ; preds = %115
%126 = load i32, i32* %6
%127 = call i32 @clReleaseEvent(i32 %126)
%128 = call i32 @clReleaseMemObject(i32 %66)
%129 = call i32 @clReleaseCommandQueue(i64 %56)
%130 = add nuw i64 %46, 1
%131 = load i64, i64* %5
%132 = icmp ult i64 %130, %131
br i1 %132, label %45, label %133
133: ; preds = %125, %40
%134 = add nuw i64 %33, 1
%135 = load i64, i64* %3
%136 = icmp ult i64 %134, %135
br i1 %136, label %32, label %137
137: ; preds = %133, %20
%138 = load i32, i32* @EXIT_SUCCESS
br label %139
139: ; preds = %60, %52, %123, %121, %119, %78, %70, %137, %43, %30
%140 = phi i32 [ %31, %30 ], [ %44, %43 ], [ %138, %137 ], [ %71, %70 ], [ %79, %78 ], [ %120, %119 ], [ %122, %121 ], [ %124, %123 ], [ %61, %60 ], [ %53, %52 ]
ret i32 %140
}