#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 cl_uint;
typedef int /*<<< orphan*/ cl_kernel;
typedef int /*<<< orphan*/ cl_int;
typedef int /*<<< orphan*/ cl_device_id;

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_MAX_WORK_GROUP_SIZE;
int /*<<< orphan*/ CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS;
int /*<<< orphan*/ CL_DEVICE_MAX_WORK_ITEM_SIZES;
int /*<<< orphan*/ CL_KERNEL_WORK_GROUP_SIZE;
int /*<<< orphan*/ clGetDeviceInfo(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                   void *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clGetKernelWorkGroupInfo(int /*<<< orphan*/,
                                            int /*<<< orphan*/,
                                            int /*<<< orphan*/, int, size_t *,
                                            int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ oclCheckStatus(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void checkNDRangeWithDevice(cl_device_id device, cl_kernel kernel, int nb_dim,
                            const size_t globalThreads[],
                            const size_t localThreads[]) {
  int i;
  cl_int status;
  cl_uint maxDimensions;
  status = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
                           sizeof(cl_uint), (void *)&maxDimensions, NULL);
  oclCheckStatus(status,
                 "clGetDeviceInfo(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS) failed.");
  if (maxDimensions < nb_dim) {
    fprintf(stderr, "Error: device supports %d dimensions when we require %d",
            maxDimensions, nb_dim);
    exit(1);
  }
  size_t maxWorkItemSizes[maxDimensions];
  status = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_SIZES,
                           sizeof(size_t) * maxDimensions,
                           (void *)maxWorkItemSizes, NULL);
  oclCheckStatus(status,
                 "clGetDeviceInfo(CL_DEVICE_MAX_WORK_ITEM_SIZES) failed.");
  for (i = 0; i < nb_dim; i++) {
    if ((localThreads[i] > maxWorkItemSizes[i])) {
      fprintf(stderr,
              "Error: device support work-groups of %Zd work-items when the "
              "application requires %Zd work-items in dimension %d\n",
              maxWorkItemSizes[i], globalThreads[i], i);
      exit(1);
    }
  }
  size_t requiredWorkGroupSize = 1;
  for (i = 0; i < nb_dim; i++) {
    requiredWorkGroupSize *= localThreads[i];
  }
  size_t maxWorkGroupSize;
  status = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE,
                           sizeof(size_t), (void *)&maxWorkGroupSize, NULL);
  oclCheckStatus(status,
                 "clGetDeviceInfo(CL_DEVICE_MAX_WORK_GROUP_SIZE) failed.");
  if (requiredWorkGroupSize > maxWorkGroupSize) {
    fprintf(stderr,
            "Error: device supports %Zd work-items per work-group, when the "
            "application requires %Zd",
            maxWorkGroupSize, requiredWorkGroupSize);
    exit(1);
  }
  size_t kernelWorkGroupSize;
  status = clGetKernelWorkGroupInfo(kernel, device, CL_KERNEL_WORK_GROUP_SIZE,
                                    sizeof(size_t), &kernelWorkGroupSize, 0);
  oclCheckStatus(status, "clGetKernelWorkGroupInfo failed.");
  if ((cl_uint)(requiredWorkGroupSize) > kernelWorkGroupSize) {
    fprintf(stderr, "Error: \n");
    fprintf(stderr, " work-group size required by the application : %Zd\n",
            requiredWorkGroupSize);
    fprintf(stderr, " maximum work-group size supported for the kernel : %Zd\n",
            kernelWorkGroupSize);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<checkNDRangeWithDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rcx
mov    $0x4,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <clGetDeviceInfo@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
lea    0xe6b(%rip),%rsi
call   1060 <oclCheckStatus@plt>
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cd <checkNDRangeWithDevice+0x7d>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x2c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <clGetDeviceInfo@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
lea    0xe53(%rip),%rsi
call   1060 <oclCheckStatus@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12a7 <checkNDRangeWithDevice+0x157>
mov    -0x60(%rbp),%rcx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
movslq -0x24(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
jbe    1294 <checkNDRangeWithDevice+0x144>
mov    -0x60(%rbp),%rax
mov    0x2d6e(%rip),%rcx
mov    (%rcx),%edi
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x24(%rbp),%r8d
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1299 <checkNDRangeWithDevice+0x149>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    122d <checkNDRangeWithDevice+0xdd>
movq   $0x1,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12e5 <checkNDRangeWithDevice+0x195>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
imul   -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12b6 <checkNDRangeWithDevice+0x166>
mov    -0x4(%rbp),%edi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rcx
mov    $0x8,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <clGetDeviceInfo@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
lea    0xe0c(%rip),%rsi
call   1060 <oclCheckStatus@plt>
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jbe    134d <checkNDRangeWithDevice+0x1fd>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    0x2c66(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%ecx
lea    -0x58(%rbp),%r8
xor    %r9d,%r9d
call   1030 <clGetKernelWorkGroupInfo@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
lea    0xe32(%rip),%rsi
call   1060 <oclCheckStatus@plt>
mov    -0x48(%rbp),%rax
cltq
cmp    -0x58(%rbp),%rax
jbe    13e6 <checkNDRangeWithDevice+0x296>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkNDRangeWithDevice>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r12
mov    %rcx,-0x40(%rbp)
mov    %edx,%r13d
mov    %esi,-0x30(%rbp)
mov    %edi,%r15d
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rcx
mov    $0x4,%edx
xor    %r8d,%r8d
call   1040 <clGetDeviceInfo@plt>
lea    0xe6e(%rip),%rsi
mov    %eax,%edi
call   1060 <oclCheckStatus@plt>
mov    -0x2c(%rbp),%edx
cmp    %r13d,%edx
jl     135d <checkNDRangeWithDevice+0x20d>
mov    %rsp,-0x48(%rbp)
mov    %rsp,%r14
lea    0xf(,%rdx,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    -0x2c(%rbp),%edx
shl    $0x3,%edx
mov    %r15d,%edi
mov    %r14,%rcx
xor    %r8d,%r8d
call   1040 <clGetDeviceInfo@plt>
lea    0xe92(%rip),%rsi
mov    %eax,%edi
call   1060 <oclCheckStatus@plt>
mov    $0x1,%ebx
test   %r13d,%r13d
jle    12ae <checkNDRangeWithDevice+0x15e>
mov    %r13d,%ecx
xor    %r8d,%r8d
nopl   (%rax)
mov    (%r14,%r8,8),%rdx
cmp    %rdx,(%r12,%r8,8)
ja     1334 <checkNDRangeWithDevice+0x1e4>
add    $0x1,%r8
cmp    %r8,%rcx
jne    1200 <checkNDRangeWithDevice+0xb0>
test   %r13d,%r13d
jle    12ae <checkNDRangeWithDevice+0x15e>
lea    -0x1(%rcx),%rdx
mov    %ecx,%eax
and    $0x7,%eax
cmp    $0x7,%rdx
jae    1238 <checkNDRangeWithDevice+0xe8>
mov    $0x1,%ebx
xor    %edx,%edx
jmp    1288 <checkNDRangeWithDevice+0x138>
and    $0xfffffff8,%ecx
mov    $0x1,%ebx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
imul   (%r12,%rdx,8),%rbx
imul   0x8(%r12,%rdx,8),%rbx
imul   0x10(%r12,%rdx,8),%rbx
imul   0x18(%r12,%rdx,8),%rbx
imul   0x20(%r12,%rdx,8),%rbx
imul   0x28(%r12,%rdx,8),%rbx
imul   0x30(%r12,%rdx,8),%rbx
imul   0x38(%r12,%rdx,8),%rbx
add    $0x8,%rdx
cmp    %rdx,%rcx
jne    1250 <checkNDRangeWithDevice+0x100>
test   %rax,%rax
je     12ae <checkNDRangeWithDevice+0x15e>
lea    (%r12,%rdx,8),%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
imul   (%rcx,%rdx,8),%rbx
add    $0x1,%rdx
cmp    %rdx,%rax
jne    12a0 <checkNDRangeWithDevice+0x150>
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rcx
mov    %r15d,%edi
mov    $0x8,%edx
xor    %r8d,%r8d
call   1040 <clGetDeviceInfo@plt>
lea    0xe4b(%rip),%rsi
mov    %eax,%edi
call   1060 <oclCheckStatus@plt>
mov    -0x50(%rbp),%rdx
cmp    %rdx,%rbx
ja     1381 <checkNDRangeWithDevice+0x231>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%r8
mov    -0x30(%rbp),%edi
mov    %r15d,%esi
mov    $0x8,%ecx
xor    %r9d,%r9d
call   1030 <clGetKernelWorkGroupInfo@plt>
lea    0xe9f(%rip),%rsi
mov    %eax,%edi
call   1060 <oclCheckStatus@plt>
movslq %ebx,%rax
cmp    -0x38(%rbp),%rax
ja     13a5 <checkNDRangeWithDevice+0x255>
mov    -0x48(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rax
mov    (%rax,%r8,8),%rcx
lea    0xd5f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
lea    0xccf(%rip),%rsi
mov    %r13d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2c24(%rip),%r14
mov    (%r14),%edi
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edi
lea    0xe0f(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edi
mov    -0x38(%rbp),%rdx
lea    0xe2b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS = global i32 0
@.str = [60 x i8] c"clGetDeviceInfo(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS) failed.\00"
@stderr = global i32 0
@.str.1 = [56 x i8] c"Error: device supports %d dimensions when we require %d\00"
@CL_DEVICE_MAX_WORK_ITEM_SIZES = global i32 0
@.str.2 = [55 x i8] c"clGetDeviceInfo(CL_DEVICE_MAX_WORK_ITEM_SIZES) failed.\00"
@.str.3 = [114 x i8] c"Error: device support work-groups of %Zd work-items when the application requires %Zd work-items in dimension %d\0A\00"
@CL_DEVICE_MAX_WORK_GROUP_SIZE = global i32 0
@.str.4 = [55 x i8] c"clGetDeviceInfo(CL_DEVICE_MAX_WORK_GROUP_SIZE) failed.\00"
@.str.5 = [88 x i8] c"Error: device supports %Zd work-items per work-group, when the application requires %Zd\00"
@CL_KERNEL_WORK_GROUP_SIZE = global i32 0
@.str.6 = [33 x i8] c"clGetKernelWorkGroupInfo failed.\00"
@.str.7 = [9 x i8] c"Error: \0A\00"
@.str.8 = [52 x i8] c" work-group size required by the application : %Zd\0A\00"
@.str.9 = [57 x i8] c" maximum work-group size supported for the kernel : %Zd\0A\00"
define void @checkNDRangeWithDevice(i32 %0, i32 %1, i32 %2, i64* %3, i64* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i64* %3, i64** %9
store i64* %4, i64** %10
%19 = load i32, i32* %6
%20 = load i32, i32* @CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
%21 = bitcast i32* %13 to i8*
%22 = call i32 @clGetDeviceInfo(i32 %19, i32 %20, i32 4, i8* %21, i32* null)
store i32 %22, i32* %12
%23 = load i32, i32* %12
%24 = call i32 @oclCheckStatus(i32 %23, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* %13
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %34
28: ; preds = %5
%29 = load i32, i32* @stderr
%30 = load i32, i32* %13
%31 = load i32, i32* %8
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %5
%35 = load i32, i32* %13
%36 = zext i32 %35 to i64
%37 = call i8* @llvm.stacksave()
store i8* %37, i8** %14
%38 = alloca i64, i64 %36
store i64 %36, i64* %15
%39 = load i32, i32* %6
%40 = load i32, i32* @CL_DEVICE_MAX_WORK_ITEM_SIZES
%41 = load i32, i32* %13
%42 = sext i32 %41 to i64
%43 = mul i64 8, %42
%44 = trunc i64 %43 to i32
%45 = bitcast i64* %38 to i8*
%46 = call i32 @clGetDeviceInfo(i32 %39, i32 %40, i32 %44, i8* %45, i32* null)
store i32 %46, i32* %12
%47 = load i32, i32* %12
%48 = call i32 @oclCheckStatus(i32 %47, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %11
br label %49
49: ; preds = %79, %34
%50 = load i32, i32* %11
%51 = load i32, i32* %8
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %82
53: ; preds = %49
%54 = load i64*, i64** %10
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i64, i64* %54, i64 %56
%58 = load i64, i64* %57
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i64, i64* %38, i64 %60
%62 = load i64, i64* %61
%63 = icmp ugt i64 %58, %62
br i1 %63, label %64, label %78
64: ; preds = %53
%65 = load i32, i32* @stderr
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i64, i64* %38, i64 %67
%69 = load i64, i64* %68
%70 = load i64*, i64** %9
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i64, i64* %70, i64 %72
%74 = load i64, i64* %73
%75 = load i32, i32* %11
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str.3, i64 0, i64 0), i64 %69, i64 %74, i32 %75)
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %53
br label %79
79: ; preds = %78
%80 = load i32, i32* %11
%81 = add nsw i32 %80, 1
store i32 %81, i32* %11
br label %49
82: ; preds = %49
store i64 1, i64* %16
store i32 0, i32* %11
br label %83
83: ; preds = %95, %82
%84 = load i32, i32* %11
%85 = load i32, i32* %8
%86 = icmp slt i32 %84, %85
br i1 %86, label %87, label %98
87: ; preds = %83
%88 = load i64*, i64** %10
%89 = load i32, i32* %11
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i64, i64* %88, i64 %90
%92 = load i64, i64* %91
%93 = load i64, i64* %16
%94 = mul i64 %93, %92
store i64 %94, i64* %16
br label %95
95: ; preds = %87
%96 = load i32, i32* %11
%97 = add nsw i32 %96, 1
store i32 %97, i32* %11
br label %83
98: ; preds = %83
%99 = load i32, i32* %6
%100 = load i32, i32* @CL_DEVICE_MAX_WORK_GROUP_SIZE
%101 = bitcast i64* %17 to i8*
%102 = call i32 @clGetDeviceInfo(i32 %99, i32 %100, i32 8, i8* %101, i32* null)
store i32 %102, i32* %12
%103 = load i32, i32* %12
%104 = call i32 @oclCheckStatus(i32 %103, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
%105 = load i64, i64* %16
%106 = load i64, i64* %17
%107 = icmp ugt i64 %105, %106
br i1 %107, label %108, label %114
108: ; preds = %98
%109 = load i32, i32* @stderr
%110 = load i64, i64* %17
%111 = load i64, i64* %16
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.5, i64 0, i64 0), i64 %110, i64 %111)
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %98
%115 = load i32, i32* %7
%116 = load i32, i32* %6
%117 = load i32, i32* @CL_KERNEL_WORK_GROUP_SIZE
%118 = call i32 @clGetKernelWorkGroupInfo(i32 %115, i32 %116, i32 %117, i32 8, i64* %18, i32 0)
store i32 %118, i32* %12
%119 = load i32, i32* %12
%120 = call i32 @oclCheckStatus(i32 %119, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%121 = load i64, i64* %16
%122 = trunc i64 %121 to i32
%123 = sext i32 %122 to i64
%124 = load i64, i64* %18
%125 = icmp ugt i64 %123, %124
br i1 %125, label %126, label %136
126: ; preds = %114
%127 = load i32, i32* @stderr
%128 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%129 = load i32, i32* @stderr
%130 = load i64, i64* %16
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.8, i64 0, i64 0), i64 %130)
%132 = load i32, i32* @stderr
%133 = load i64, i64* %18
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.9, i64 0, i64 0), i64 %133)
%135 = call i32 @exit(i32 1)
unreachable
136: ; preds = %114
%137 = load i8*, i8** %14
ret void
}

LLVM IR (-O2):
@CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS = global i32 0
@.str = [60 x i8] c"clGetDeviceInfo(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS) failed.\00"
@stderr = global i32 0
@.str.1 = [56 x i8] c"Error: device supports %d dimensions when we require %d\00"
@CL_DEVICE_MAX_WORK_ITEM_SIZES = global i32 0
@.str.2 = [55 x i8] c"clGetDeviceInfo(CL_DEVICE_MAX_WORK_ITEM_SIZES) failed.\00"
@.str.3 = [114 x i8] c"Error: device support work-groups of %Zd work-items when the application requires %Zd work-items in dimension %d\0A\00"
@CL_DEVICE_MAX_WORK_GROUP_SIZE = global i32 0
@.str.4 = [55 x i8] c"clGetDeviceInfo(CL_DEVICE_MAX_WORK_GROUP_SIZE) failed.\00"
@.str.5 = [88 x i8] c"Error: device supports %Zd work-items per work-group, when the application requires %Zd\00"
@CL_KERNEL_WORK_GROUP_SIZE = global i32 0
@.str.6 = [33 x i8] c"clGetKernelWorkGroupInfo failed.\00"
@.str.7 = [9 x i8] c"Error: \0A\00"
@.str.8 = [52 x i8] c" work-group size required by the application : %Zd\0A\00"
@.str.9 = [57 x i8] c" maximum work-group size supported for the kernel : %Zd\0A\00"
define void @checkNDRangeWithDevice(i32 %0, i32 %1, i32 %2, i64* nocapture %3, i64* nocapture %4) {
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = bitcast i32* %6 to i8*
%10 = load i32, i32* @CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
%11 = call i32 @clGetDeviceInfo(i32 %0, i32 %10, i32 4, i8* %9, i32* null)
%12 = call i32 @oclCheckStatus(i32 %11, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, %2
br i1 %14, label %15, label %19
15: ; preds = %5
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %2)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %5
%20 = zext i32 %13 to i64
%21 = call i8* @llvm.stacksave()
%22 = alloca i64, i64 %20
%23 = load i32, i32* @CL_DEVICE_MAX_WORK_ITEM_SIZES
%24 = load i32, i32* %6
%25 = shl i32 %24, 3
%26 = bitcast i64* %22 to i8*
%27 = call i32 @clGetDeviceInfo(i32 %0, i32 %23, i32 %25, i8* %26, i32* null)
%28 = call i32 @oclCheckStatus(i32 %27, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp sgt i32 %2, 0
br i1 %29, label %30, label %110
30: ; preds = %19
%31 = zext i32 %2 to i64
br label %39
32: ; preds = %54
br i1 %29, label %33, label %110
33: ; preds = %32
%34 = add nsw i64 %31, -1
%35 = and i64 %31, 7
%36 = icmp ult i64 %34, 7
br i1 %36, label %95, label %37
37: ; preds = %33
%38 = and i64 %31, 4294967288
br label %57
39: ; preds = %30, %54
%40 = phi i64 [ 0, %30 ], [ %55, %54 ]
%41 = getelementptr inbounds i64, i64* %4, i64 %40
%42 = load i64, i64* %41
%43 = getelementptr inbounds i64, i64* %22, i64 %40
%44 = load i64, i64* %43
%45 = icmp ugt i64 %42, %44
br i1 %45, label %46, label %54
46: ; preds = %39
%47 = trunc i64 %40 to i32
%48 = and i64 %40, 4294967295
%49 = load i32, i32* @stderr
%50 = getelementptr inbounds i64, i64* %3, i64 %48
%51 = load i64, i64* %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str.3, i64 0, i64 0), i64 %44, i64 %51, i32 %47)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %39
%55 = add nuw nsw i64 %40, 1
%56 = icmp eq i64 %55, %31
br i1 %56, label %32, label %39
57: ; preds = %57, %37
%58 = phi i64 [ 0, %37 ], [ %92, %57 ]
%59 = phi i64 [ 1, %37 ], [ %91, %57 ]
%60 = phi i64 [ 0, %37 ], [ %93, %57 ]
%61 = getelementptr inbounds i64, i64* %4, i64 %58
%62 = load i64, i64* %61
%63 = mul i64 %62, %59
%64 = or i64 %58, 1
%65 = getelementptr inbounds i64, i64* %4, i64 %64
%66 = load i64, i64* %65
%67 = mul i64 %66, %63
%68 = or i64 %58, 2
%69 = getelementptr inbounds i64, i64* %4, i64 %68
%70 = load i64, i64* %69
%71 = mul i64 %70, %67
%72 = or i64 %58, 3
%73 = getelementptr inbounds i64, i64* %4, i64 %72
%74 = load i64, i64* %73
%75 = mul i64 %74, %71
%76 = or i64 %58, 4
%77 = getelementptr inbounds i64, i64* %4, i64 %76
%78 = load i64, i64* %77
%79 = mul i64 %78, %75
%80 = or i64 %58, 5
%81 = getelementptr inbounds i64, i64* %4, i64 %80
%82 = load i64, i64* %81
%83 = mul i64 %82, %79
%84 = or i64 %58, 6
%85 = getelementptr inbounds i64, i64* %4, i64 %84
%86 = load i64, i64* %85
%87 = mul i64 %86, %83
%88 = or i64 %58, 7
%89 = getelementptr inbounds i64, i64* %4, i64 %88
%90 = load i64, i64* %89
%91 = mul i64 %90, %87
%92 = add nuw nsw i64 %58, 8
%93 = add i64 %60, 8
%94 = icmp eq i64 %93, %38
br i1 %94, label %95, label %57
95: ; preds = %57, %33
%96 = phi i64 [ undef, %33 ], [ %91, %57 ]
%97 = phi i64 [ 0, %33 ], [ %92, %57 ]
%98 = phi i64 [ 1, %33 ], [ %91, %57 ]
%99 = icmp eq i64 %35, 0
br i1 %99, label %110, label %100
100: ; preds = %95, %100
%101 = phi i64 [ %107, %100 ], [ %97, %95 ]
%102 = phi i64 [ %106, %100 ], [ %98, %95 ]
%103 = phi i64 [ %108, %100 ], [ 0, %95 ]
%104 = getelementptr inbounds i64, i64* %4, i64 %101
%105 = load i64, i64* %104
%106 = mul i64 %105, %102
%107 = add nuw nsw i64 %101, 1
%108 = add i64 %103, 1
%109 = icmp eq i64 %108, %35
br i1 %109, label %110, label %100
110: ; preds = %95, %100, %19, %32
%111 = phi i64 [ 1, %32 ], [ 1, %19 ], [ %96, %95 ], [ %106, %100 ]
%112 = bitcast i64* %7 to i8*
%113 = load i32, i32* @CL_DEVICE_MAX_WORK_GROUP_SIZE
%114 = call i32 @clGetDeviceInfo(i32 %0, i32 %113, i32 8, i8* %112, i32* null)
%115 = call i32 @oclCheckStatus(i32 %114, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
%116 = load i64, i64* %7
%117 = icmp ugt i64 %111, %116
br i1 %117, label %118, label %122
118: ; preds = %110
%119 = load i32, i32* @stderr
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.5, i64 0, i64 0), i64 %116, i64 %111)
%121 = call i32 @exit(i32 1)
unreachable
122: ; preds = %110
%123 = bitcast i64* %8 to i8*
%124 = load i32, i32* @CL_KERNEL_WORK_GROUP_SIZE
%125 = call i32 @clGetKernelWorkGroupInfo(i32 %1, i32 %0, i32 %124, i32 8, i64* %8, i32 0)
%126 = call i32 @oclCheckStatus(i32 %125, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%127 = shl i64 %111, 32
%128 = ashr exact i64 %127, 32
%129 = load i64, i64* %8
%130 = icmp ugt i64 %128, %129
br i1 %130, label %131, label %140
131: ; preds = %122
%132 = load i32, i32* @stderr
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%134 = load i32, i32* @stderr
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.8, i64 0, i64 0), i64 %111)
%136 = load i32, i32* @stderr
%137 = load i64, i64* %8
%138 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.9, i64 0, i64 0), i64 %137)
%139 = call i32 @exit(i32 1)
unreachable
140: ; preds = %122
ret void
}