#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 /*<<< orphan*/ printf(char *, char const *);
int RunKernel(cl_command_queue cmd_q, cl_kernel kernel, int hA, int wA,
              const char *info) {
  printf("\nStart executing %s\n", info);
  const size_t local_size[2] = {16, 16};
  const size_t global_size[2] = {(hA + 15) / 16 * 16, (wA + 15) / 16 * 16};
  cl_int status = clEnqueueNDRangeKernel(cmd_q, kernel, 2, NULL, global_size,
                                         local_size, 0, NULL, NULL);
  assert(status == CL_SUCCESS);
  status = clFinish(cmd_q);
  assert(status == CL_SUCCESS);
  printf("Finish executing %s\n", info);
  return 0;
}


x86 assembly (clang, -O0):
<RunKernel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe9d(%rip),%rdi
call   1050 <printf@plt>
mov    0xec1(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0xf,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
shl    $0x4,%eax
cltq
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%eax
add    $0xf,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
shl    $0x4,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x40(%rbp),%r8
lea    -0x30(%rbp),%r9
mov    $0x2,%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,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x2dee(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x4(%rbp),%edi
call   1030 <clFinish@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RunKernel>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %r8,%r14
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%r12d
lea    0xed0(%rip),%rdi
mov    %r8,%rsi
call   1050 <printf@plt>
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movd   %ebx,%xmm0
movd   %ebp,%xmm1
punpckldq %xmm0,%xmm1
paddd  0xe78(%rip),%xmm1
movdqa %xmm1,%xmm0
psrad  $0x1f,%xmm0
psrld  $0x1c,%xmm0
paddd  %xmm1,%xmm0
pand   0xe6e(%rip),%xmm0
pxor   %xmm1,%xmm1
pxor   %xmm2,%xmm2
pcmpgtd %xmm0,%xmm2
punpckldq %xmm2,%xmm0
movdqa %xmm0,0x20(%rsp)
movdqu %xmm1,0x8(%rsp)
movl   $0x0,(%rsp)
lea    0x20(%rsp),%r8
lea    0x30(%rsp),%r9
mov    %r12d,%edi
mov    %r15d,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1040 <clEnqueueNDRangeKernel@plt>
mov    0x2df8(%rip),%rbx
xor    %edi,%edi
cmp    (%rbx),%rax
sete   %dil
call   1060 <assert@plt>
mov    %r12d,%edi
call   1030 <clFinish@plt>
xor    %edi,%edi
cmp    (%rbx),%rax
sete   %dil
call   1060 <assert@plt>
lea    0xe32(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\0AStart executing %s\0A\00"
@__const.RunKernel.local_size = [2 x i64] [i64 16, i64 16]
@CL_SUCCESS = global i64 0
@.str.1 = [21 x i8] c"Finish executing %s\0A\00"
define i32 @RunKernel(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [2 x i64]
%12 = alloca [2 x i64]
%13 = alloca i64
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%14 = load i8*, i8** %10
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = bitcast [2 x i64]* %11 to i8*
%17 = getelementptr inbounds [2 x i64], [2 x i64]* %12, i64 0, i64 0
%18 = load i32, i32* %8
%19 = add nsw i32 %18, 15
%20 = sdiv i32 %19, 16
%21 = mul nsw i32 %20, 16
%22 = sext i32 %21 to i64
store i64 %22, i64* %17
%23 = getelementptr inbounds i64, i64* %17, i64 1
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 15
%26 = sdiv i32 %25, 16
%27 = mul nsw i32 %26, 16
%28 = sext i32 %27 to i64
store i64 %28, i64* %23
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = getelementptr inbounds [2 x i64], [2 x i64]* %12, i64 0, i64 0
%32 = getelementptr inbounds [2 x i64], [2 x i64]* %11, i64 0, i64 0
%33 = call i64 @clEnqueueNDRangeKernel(i32 %29, i32 %30, i32 2, i32* null, i64* %31, i64* %32, i32 0, i32* null, i32* null)
store i64 %33, i64* %13
%34 = load i64, i64* %13
%35 = load i64, i64* @CL_SUCCESS
%36 = icmp eq i64 %34, %35
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i32, i32* %6
%40 = call i64 @clFinish(i32 %39)
store i64 %40, i64* %13
%41 = load i64, i64* %13
%42 = load i64, i64* @CL_SUCCESS
%43 = icmp eq i64 %41, %42
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i8*, i8** %10
%47 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"\0AStart executing %s\0A\00"
@__const.RunKernel.local_size = [2 x i64] [i64 16, i64 16]
@CL_SUCCESS = global i64 0
@.str.1 = [21 x i8] c"Finish executing %s\0A\00"
define i32 @RunKernel(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca [2 x i64]
%7 = alloca <2 x i64>
%8 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %4)
%9 = bitcast [2 x i64]* %6 to i8*
%10 = bitcast <2 x i64>* %7 to i8*
%11 = getelementptr inbounds <2 x i64>, <2 x i64>* %7, i64 0, i64 0
%12 = insertelement <2 x i32> poison, i32 %2, i64 0
%13 = insertelement <2 x i32> %12, i32 %3, i64 1
%14 = add nsw <2 x i32> %13, <i32 15, i32 15>
%15 = sdiv <2 x i32> %14, <i32 16, i32 16>
%16 = shl nsw <2 x i32> %15, <i32 4, i32 4>
%17 = sext <2 x i32> %16 to <2 x i64>
store <2 x i64> %17, <2 x i64>* %7
%18 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
%19 = call i64 @clEnqueueNDRangeKernel(i32 %0, i32 %1, i32 2, i32* null, i64* %11, i64* %18, i32 0, i32* null, i32* null)
%20 = load i64, i64* @CL_SUCCESS
%21 = icmp eq i64 %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i64 @clFinish(i32 %0)
%25 = load i64, i64* @CL_SUCCESS
%26 = icmp eq i64 %24, %25
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret i32 0
}