#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 int /*<<< orphan*/ cl_command_queue;

/* Variables and functions */
int /*<<< orphan*/ CheckOpenCLError(int, int);
double DBL_MAX;
double DBL_MIN;
double GetWallTime();
int clEnqueueNDRangeKernel(int /*<<< orphan*/, int /*<<< orphan*/, int,
                           int /*<<< orphan*/ *, size_t *, size_t *,
                           int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/ *);
int /*<<< orphan*/ clFinish(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void RunTest(cl_command_queue *queue, cl_kernel *kernel, size_t vecWidth,
             char *testName, int memops, int flops, size_t arraySize) {
  size_t localSize;
  size_t bestLocalSize;
  size_t globalSize = arraySize / vecWidth;
  double bestTime = DBL_MAX, worstTime = DBL_MIN, totalTime = 0.0;
  int err;
  for (localSize = 1; localSize <= 256; localSize *= 2) {
    if (globalSize % localSize != 0) {
      printf("Error, localSize must divide globalSize! (%zu %% %zu = %zu)\n",
             globalSize, localSize, globalSize % localSize);
    }
    double time = GetWallTime();
    for (int n = 0; n < 50; n++) {
      err = clEnqueueNDRangeKernel(*queue, *kernel, 1, NULL, &globalSize,
                                   &localSize, 0, NULL, NULL);
    }
    clFinish(*queue);
    CheckOpenCLError(err, 254);
    time = GetWallTime() - time;
    if (time < bestTime) {
      bestTime = time;
      bestLocalSize = localSize;
    }
    if (time > worstTime) {
      worstTime = time;
    }
    totalTime += time;
  }
  printf("%13s   %14.3lf   %8.6lf   %8.6lf   %8.6lf   %19zu   %11.3lf\n",
         testName,
         memops * 50 * arraySize * sizeof(double) / 1024.0 / 1024.0 / 1024.0 /
             bestTime,
         totalTime / 50, bestTime, worstTime, bestLocalSize,
         flops * 50 * arraySize / 1.0e9 / bestTime);
}


x86 assembly (clang, -O0):
<RunTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,-0x40(%rbp)
mov    0x2e52(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x2e3a(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movq   $0x1,-0x30(%rbp)
cmpq   $0x100,-0x30(%rbp)
ja     12fc <RunTest+0x1ac>
mov    -0x40(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x30(%rbp)
cmp    $0x0,%rdx
je     1208 <RunTest+0xb8>
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x40(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x30(%rbp)
mov    %rdx,%rcx
mov    -0x78(%rbp),%rdx
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <GetWallTime@plt>
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
cmpl   $0x32,-0x6c(%rbp)
jge    1273 <RunTest+0x123>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x40(%rbp),%r8
lea    -0x30(%rbp),%r9
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1040 <clEnqueueNDRangeKernel@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    121b <RunTest+0xcb>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <clFinish@plt>
mov    -0x5c(%rbp),%edi
mov    $0xfe,%esi
call   1060 <CheckOpenCLError@plt>
mov    $0x0,%al
call   1070 <GetWallTime@plt>
subsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12c2 <RunTest+0x172>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
movsd  -0x68(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    12dc <RunTest+0x18c>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x68(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11b7 <RunTest+0x67>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%eax
imul   $0x32,%eax,%eax
cltq
mov    0x10(%rbp),%rcx
imul   %rcx,%rax
shl    $0x3,%rax
movq   %rax,%xmm0
movaps 0xd00(%rip),%xmm6
punpckldq %xmm6,%xmm0
movapd 0xd04(%rip),%xmm5
subpd  %xmm5,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xcc5(%rip),%xmm1
divsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
movsd  -0x48(%rbp),%xmm2
divsd  %xmm2,%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  0xcab(%rip),%xmm3
divsd  %xmm3,%xmm1
movsd  -0x50(%rbp),%xmm3
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%eax
imul   $0x32,%eax,%eax
cltq
imul   %rcx,%rax
movq   %rax,%xmm4
punpckldq %xmm6,%xmm4
subpd  %xmm5,%xmm4
movaps %xmm4,%xmm5
unpckhpd %xmm4,%xmm4
addsd  %xmm5,%xmm4
movsd  0xc62(%rip),%xmm5
divsd  %xmm5,%xmm4
divsd  -0x48(%rbp),%xmm4
lea    0xccf(%rip),%rdi
mov    $0x5,%al
call   1050 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RunTest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9d,0x2c(%rsp)
mov    %r8d,0x28(%rsp)
mov    %rcx,0x48(%rsp)
mov    %rdx,%rcx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0xa0(%rsp),%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1194 <RunTest+0x44>
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
jmp    119a <RunTest+0x4a>
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
mov    %rsi,0x40(%rsp)
mov    0x2e3a(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x30(%rsp)
mov    0x2e21(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x38(%rsp)
movq   $0x1,0x20(%rsp)
mov    $0x1,%ecx
xorpd  %xmm1,%xmm1
lea    0x40(%rsp),%r15
lea    0x20(%rsp),%r12
nopl   (%rax)
mov    %rdx,0x58(%rsp)
mov    %rsi,%rax
or     %rcx,%rax
shr    $0x20,%rax
movsd  %xmm1,0x60(%rsp)
je     12f0 <RunTest+0x1a0>
mov    %rsi,%rax
xor    %edx,%edx
div    %rcx
mov    %rdx,%rax
test   %rax,%rax
je     121f <RunTest+0xcf>
lea    0xe36(%rip),%rdi
mov    %rcx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <GetWallTime@plt>
movsd  %xmm0,0x50(%rsp)
mov    $0x32,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
mov    (%rbx),%esi
xorpd  %xmm0,%xmm0
movupd %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1040 <clEnqueueNDRangeKernel@plt>
add    $0xffffffff,%ebp
jne    1240 <RunTest+0xf0>
mov    %eax,%r13d
mov    (%r14),%edi
call   1030 <clFinish@plt>
mov    %r13d,%edi
mov    $0xfe,%esi
call   1060 <CheckOpenCLError@plt>
xor    %eax,%eax
call   1070 <GetWallTime@plt>
movapd %xmm0,%xmm3
subsd  0x50(%rsp),%xmm3
movsd  0x30(%rsp),%xmm0
ucomisd %xmm3,%xmm0
mov    0x20(%rsp),%rcx
mov    0x58(%rsp),%rdx
cmova  %rcx,%rdx
movapd %xmm3,%xmm2
minsd  %xmm0,%xmm2
movsd  0x60(%rsp),%xmm1
addsd  %xmm3,%xmm1
maxsd  0x38(%rsp),%xmm3
add    %rcx,%rcx
mov    %rcx,0x20(%rsp)
cmp    $0x100,%rcx
ja     1306 <RunTest+0x1b6>
mov    0x40(%rsp),%rsi
movsd  %xmm3,0x38(%rsp)
movsd  %xmm2,0x30(%rsp)
jmp    11e0 <RunTest+0x90>
nopl   (%rax)
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
test   %rax,%rax
jne    120b <RunTest+0xbb>
jmp    121f <RunTest+0xcf>
imul   $0x32,0x28(%rsp),%eax
cltq
mov    0xa0(%rsp),%rcx
imul   %rcx,%rax
shl    $0x3,%rax
movq   %rax,%xmm6
movdqa 0xcd6(%rip),%xmm4
punpckldq %xmm4,%xmm6
movapd 0xcda(%rip),%xmm5
subpd  %xmm5,%xmm6
movapd %xmm6,%xmm0
unpckhpd %xmm6,%xmm0
addsd  %xmm6,%xmm0
movsd  0xce2(%rip),%xmm6
mulsd  %xmm6,%xmm0
mulsd  %xmm6,%xmm0
mulsd  %xmm6,%xmm0
divsd  0xcd6(%rip),%xmm1
divsd  %xmm2,%xmm0
imul   $0x32,0x2c(%rsp),%eax
cltq
imul   %rcx,%rax
movq   %rax,%xmm6
punpckldq %xmm4,%xmm6
subpd  %xmm5,%xmm6
movapd %xmm6,%xmm4
unpckhpd %xmm6,%xmm4
addsd  %xmm6,%xmm4
divsd  0xcae(%rip),%xmm4
divsd  %xmm2,%xmm4
lea    0xce8(%rip),%rdi
mov    0x48(%rsp),%rsi
mov    $0x5,%al
call   1050 <printf@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DBL_MAX = global double 0.000000e+00
@DBL_MIN = global double 0.000000e+00
@.str = [61 x i8] c"Error, localSize must divide globalSize! (%zu %% %zu = %zu)\0A\00"
@.str.1 = [61 x i8] c"%13s %14.3lf %8.6lf %8.6lf %8.6lf %19zu %11.3lf\0A\00"
define void @RunTest(i32* %0, i32* %1, i64 %2, i8* %3, i32 %4, i32 %5, i64 %6) {
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca i32
%22 = alloca double
%23 = alloca i32
store i32* %0, i32** %8
store i32* %1, i32** %9
store i64 %2, i64* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i64 %6, i64* %14
%24 = load i64, i64* %14
%25 = load i64, i64* %10
%26 = udiv i64 %24, %25
store i64 %26, i64* %17
%27 = load double, double* @DBL_MAX
store double %27, double* %18
%28 = load double, double* @DBL_MIN
store double %28, double* %19
store double 0.000000e+00, double* %20
store i64 1, i64* %15
br label %29
29: ; preds = %83, %7
%30 = load i64, i64* %15
%31 = icmp ule i64 %30, 256
br i1 %31, label %32, label %86
32: ; preds = %29
%33 = load i64, i64* %17
%34 = load i64, i64* %15
%35 = urem i64 %33, %34
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %32
%38 = load i64, i64* %17
%39 = load i64, i64* %15
%40 = load i64, i64* %17
%41 = load i64, i64* %15
%42 = urem i64 %40, %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i64 %38, i64 %39, i64 %42)
br label %44
44: ; preds = %37, %32
%45 = call double (...) @GetWallTime()
store double %45, double* %22
store i32 0, i32* %23
br label %46
46: ; preds = %55, %44
%47 = load i32, i32* %23
%48 = icmp slt i32 %47, 50
br i1 %48, label %49, label %58
49: ; preds = %46
%50 = load i32*, i32** %8
%51 = load i32, i32* %50
%52 = load i32*, i32** %9
%53 = load i32, i32* %52
%54 = call i32 @clEnqueueNDRangeKernel(i32 %51, i32 %53, i32 1, i32* null, i64* %17, i64* %15, i32 0, i32* null, i32* null)
store i32 %54, i32* %21
br label %55
55: ; preds = %49
%56 = load i32, i32* %23
%57 = add nsw i32 %56, 1
store i32 %57, i32* %23
br label %46
58: ; preds = %46
%59 = load i32*, i32** %8
%60 = load i32, i32* %59
%61 = call i32 @clFinish(i32 %60)
%62 = load i32, i32* %21
%63 = call i32 @CheckOpenCLError(i32 %62, i32 254)
%64 = call double (...) @GetWallTime()
%65 = load double, double* %22
%66 = fsub double %64, %65
store double %66, double* %22
%67 = load double, double* %22
%68 = load double, double* %18
%69 = fcmp olt double %67, %68
br i1 %69, label %70, label %73
70: ; preds = %58
%71 = load double, double* %22
store double %71, double* %18
%72 = load i64, i64* %15
store i64 %72, i64* %16
br label %73
73: ; preds = %70, %58
%74 = load double, double* %22
%75 = load double, double* %19
%76 = fcmp ogt double %74, %75
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = load double, double* %22
store double %78, double* %19
br label %79
79: ; preds = %77, %73
%80 = load double, double* %22
%81 = load double, double* %20
%82 = fadd double %81, %80
store double %82, double* %20
br label %83
83: ; preds = %79
%84 = load i64, i64* %15
%85 = mul i64 %84, 2
store i64 %85, i64* %15
br label %29
86: ; preds = %29
%87 = load i8*, i8** %11
%88 = load i32, i32* %12
%89 = mul nsw i32 %88, 50
%90 = sext i32 %89 to i64
%91 = load i64, i64* %14
%92 = mul i64 %90, %91
%93 = mul i64 %92, 8
%94 = uitofp i64 %93 to double
%95 = fdiv double %94, 1.024000e+03
%96 = fdiv double %95, 1.024000e+03
%97 = fdiv double %96, 1.024000e+03
%98 = load double, double* %18
%99 = fdiv double %97, %98
%100 = load double, double* %20
%101 = fdiv double %100, 5.000000e+01
%102 = load double, double* %18
%103 = load double, double* %19
%104 = load i64, i64* %16
%105 = load i32, i32* %13
%106 = mul nsw i32 %105, 50
%107 = sext i32 %106 to i64
%108 = load i64, i64* %14
%109 = mul i64 %107, %108
%110 = uitofp i64 %109 to double
%111 = fdiv double %110, 1.000000e+09
%112 = load double, double* %18
%113 = fdiv double %111, %112
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* %87, double %99, double %101, double %102, double %103, i64 %104, double %113)
ret void
}

LLVM IR (-O2):
@DBL_MAX = global double 0.000000e+00
@DBL_MIN = global double 0.000000e+00
@.str = [61 x i8] c"Error, localSize must divide globalSize! (%zu %% %zu = %zu)\0A\00"
@.str.1 = [61 x i8] c"%13s %14.3lf %8.6lf %8.6lf %8.6lf %19zu %11.3lf\0A\00"
define void @RunTest(i32* nocapture %0, i32* nocapture %1, i64 %2, i8* %3, i32 %4, i32 %5, i64 %6) {
%8 = alloca i64
%9 = alloca i64
%10 = bitcast i64* %8 to i8*
%11 = bitcast i64* %9 to i8*
%12 = udiv i64 %6, %2
store i64 %12, i64* %9
%13 = load double, double* @DBL_MAX
%14 = load double, double* @DBL_MIN
store i64 1, i64* %8
br label %15
15: ; preds = %43, %7
%16 = phi i64 [ %12, %7 ], [ %44, %43 ]
%17 = phi double [ 0.000000e+00, %7 ], [ %40, %43 ]
%18 = phi double [ %14, %7 ], [ %39, %43 ]
%19 = phi double [ %13, %7 ], [ %37, %43 ]
%20 = phi i64 [ undef, %7 ], [ %36, %43 ]
%21 = phi i64 [ 1, %7 ], [ %41, %43 ]
%22 = urem i64 %16, %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %15
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i64 %16, i64 %21, i64 %22)
br label %26
26: ; preds = %24, %15
%27 = call double (...) @GetWallTime()
br label %45
28: ; preds = %45
%29 = load i32, i32* %0
%30 = call i32 @clFinish(i32 %29)
%31 = call i32 @CheckOpenCLError(i32 %49, i32 254)
%32 = call double (...) @GetWallTime()
%33 = fsub double %32, %27
%34 = fcmp olt double %33, %19
%35 = load i64, i64* %8
%36 = select i1 %34, i64 %35, i64 %20
%37 = select i1 %34, double %33, double %19
%38 = fcmp ogt double %33, %18
%39 = select i1 %38, double %33, double %18
%40 = fadd double %17, %33
%41 = shl i64 %35, 1
store i64 %41, i64* %8
%42 = icmp ult i64 %41, 257
br i1 %42, label %43, label %52
43: ; preds = %28
%44 = load i64, i64* %9
br label %15
45: ; preds = %26, %45
%46 = phi i32 [ 0, %26 ], [ %50, %45 ]
%47 = load i32, i32* %0
%48 = load i32, i32* %1
%49 = call i32 @clEnqueueNDRangeKernel(i32 %47, i32 %48, i32 1, i32* null, i64* %9, i64* %8, i32 0, i32* null, i32* null)
%50 = add nuw nsw i32 %46, 1
%51 = icmp eq i32 %50, 50
br i1 %51, label %28, label %45
52: ; preds = %28
%53 = mul nsw i32 %4, 50
%54 = sext i32 %53 to i64
%55 = shl i64 %6, 3
%56 = mul i64 %55, %54
%57 = uitofp i64 %56 to double
%58 = fmul double %57, 0x3F50000000000000
%59 = fmul double %58, 0x3F50000000000000
%60 = fmul double %59, 0x3F50000000000000
%61 = fdiv double %60, %37
%62 = fdiv double %40, 5.000000e+01
%63 = mul nsw i32 %5, 50
%64 = sext i32 %63 to i64
%65 = mul i64 %64, %6
%66 = uitofp i64 %65 to double
%67 = fdiv double %66, 1.000000e+09
%68 = fdiv double %67, %37
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* %3, double %61, double %62, double %37, double %39, i64 %36, double %68)
ret void
}