#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ cl_kernel;
typedef scalar_t__ cl_int;
typedef int /*<<< orphan*/ cl_command_queue;

/* Variables and functions */
scalar_t__ CL_SUCCESS;
int /*<<< orphan*/ assert(int);
scalar_t__ clEnqueueNDRangeKernel(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ *, size_t const *,
                                  size_t const *, int /*<<< orphan*/,
                                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ clFinish(int /*<<< orphan*/);
int RunKernel(cl_command_queue cmd_q, cl_kernel kernel, int num_elem) {
  const size_t global_size[1] = {(num_elem + 255) / 256 * 256};
  const size_t local_size[1] = {256};
  cl_int status = clEnqueueNDRangeKernel(cmd_q, kernel, 1, NULL, global_size,
                                         local_size, 0, NULL, NULL);
  assert(status == CL_SUCCESS);
  status = clFinish(cmd_q);
  assert(status == CL_SUCCESS);
  return 0;
}


x86 assembly (clang, -O0):
<RunKernel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xff,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
shl    $0x8,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    0xe9f(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%r8
lea    -0x20(%rbp),%r9
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1040 <clEnqueueNDRangeKernel@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x4(%rbp),%edi
call   1030 <clFinish@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RunKernel>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
lea    0xff(%rdx),%eax
add    $0x1fe,%edx
test   %eax,%eax
cmovns %eax,%edx
and    $0xffffff00,%edx
movslq %edx,%rax
mov    %rax,0x20(%rsp)
movq   $0x100,0x18(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
lea    0x20(%rsp),%r8
lea    0x18(%rsp),%r9
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <clEnqueueNDRangeKernel@plt>
mov    0x2e53(%rip),%r14
xor    %edi,%edi
cmp    (%r14),%rax
sete   %dil
call   1050 <assert@plt>
mov    %ebx,%edi
call   1030 <clFinish@plt>
xor    %edi,%edi
cmp    (%r14),%rax
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.RunKernel.local_size = [1 x i64] [i64 256]
@CL_SUCCESS = global i64 0
define i32 @RunKernel(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1 x i64]
%8 = alloca [1 x i64]
%9 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = getelementptr inbounds [1 x i64], [1 x i64]* %7, i64 0, i64 0
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 255
%13 = sdiv i32 %12, 256
%14 = mul nsw i32 %13, 256
%15 = sext i32 %14 to i64
store i64 %15, i64* %10
%16 = bitcast [1 x i64]* %8 to i8*
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = getelementptr inbounds [1 x i64], [1 x i64]* %7, i64 0, i64 0
%20 = getelementptr inbounds [1 x i64], [1 x i64]* %8, i64 0, i64 0
%21 = call i64 @clEnqueueNDRangeKernel(i32 %17, i32 %18, i32 1, i32* null, i64* %19, i64* %20, i32 0, i32* null, i32* null)
store i64 %21, i64* %9
%22 = load i64, i64* %9
%23 = load i64, i64* @CL_SUCCESS
%24 = icmp eq i64 %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32, i32* %4
%28 = call i64 @clFinish(i32 %27)
store i64 %28, i64* %9
%29 = load i64, i64* %9
%30 = load i64, i64* @CL_SUCCESS
%31 = icmp eq i64 %29, %30
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
ret i32 0
}

LLVM IR (-O2):
@CL_SUCCESS = global i64 0
define i32 @RunKernel(i32 %0, i32 %1, i32 %2) {
%4 = alloca [1 x i64]
%5 = alloca [1 x i64]
%6 = bitcast [1 x i64]* %4 to i8*
%7 = getelementptr inbounds [1 x i64], [1 x i64]* %4, i64 0, i64 0
%8 = add nsw i32 %2, 255
%9 = sdiv i32 %8, 256
%10 = shl nsw i32 %9, 8
%11 = sext i32 %10 to i64
store i64 %11, i64* %7
%12 = bitcast [1 x i64]* %5 to i8*
%13 = getelementptr inbounds [1 x i64], [1 x i64]* %5, i64 0, i64 0
store i64 256, i64* %13
%14 = call i64 @clEnqueueNDRangeKernel(i32 %0, i32 %1, i32 1, i32* null, i64* %7, i64* %13, i32 0, i32* null, i32* null)
%15 = load i64, i64* @CL_SUCCESS
%16 = icmp eq i64 %14, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i64 @clFinish(i32 %0)
%20 = load i64, i64* @CL_SUCCESS
%21 = icmp eq i64 %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
ret i32 0
}