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

/* Variables and functions */
int CL_SUCCESS;
double abs(float);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, int, float);
int square_array(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                 float *, int const);
int /*<<< orphan*/ stderr;
int run_square_array(cl_context ctx, cl_command_queue queue,
                     cl_kernel square_kernel) {
  int ret = 0;
  const int N = 10;
  float a_h[N];
  for (int i = 0; i < N; i++)
    a_h[i] = i;
  ret = square_array(ctx, queue, square_kernel, a_h, N);
  if (ret != CL_SUCCESS) {
    fprintf(stderr, "Error: Square Array Failed, %d\n", ret);
    return -1;
  }
  for (int i = 0; i < N; i++) {
    printf("%d %f\n", i, a_h[i]);
    if (abs(a_h[i] - i * i) > 0.001)
      ret = -2;
  }
  return ret;
}


x86 assembly (clang, -O0):
<run_square_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xa,-0x18(%rbp)
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jge    1194 <run_square_array+0x54>
cvtsi2ssl -0x24(%rbp),%xmm0
movslq -0x24(%rbp),%rax
movss  %xmm0,-0x60(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116d <run_square_array+0x2d>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x60(%rbp),%rcx
mov    $0xa,%r8d
call   1050 <square_array@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%eax
je     11ec <run_square_array+0xac>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    126d <run_square_array+0x12d>
movl   $0x0,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    1260 <run_square_array+0x120>
mov    -0x2c(%rbp),%esi
movslq -0x2c(%rbp),%rax
movss  -0x60(%rbp,%rax,4),%xmm0
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
movslq -0x2c(%rbp),%rax
movss  -0x60(%rbp,%rax,4),%xmm0
mov    -0x2c(%rbp),%eax
imul   -0x2c(%rbp),%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
call   1030 <abs@plt>
movsd  0xdc4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    124d <run_square_array+0x10d>
movl   $0xfffffffe,-0x14(%rbp)
jmp    1252 <run_square_array+0x112>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f3 <run_square_array+0xb3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_square_array>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x4110000041000000,%rax
mov    %rax,0x20(%rsp)
mov    %rsp,%rcx
mov    $0xa,%r8d
call   1050 <square_array@plt>
mov    %eax,%ebx
mov    0x2e51(%rip),%rax
cmp    (%rax),%ebx
jne    13da <run_square_array+0x29a>
movss  (%rsp),%xmm0
lea    0xee5(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <printf@plt>
movss  (%rsp),%xmm0
call   1030 <abs@plt>
movsd  %xmm0,0x38(%rsp)
movss  0x4(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
movss  0x4(%rsp),%xmm0
addss  0xe5a(%rip),%xmm0
call   1030 <abs@plt>
movsd  %xmm0,0x30(%rsp)
movss  0x8(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x2,%esi
call   1040 <printf@plt>
movss  0x8(%rsp),%xmm0
addss  0xe32(%rip),%xmm0
call   1030 <abs@plt>
movaps %xmm0,0xa0(%rsp)
movss  0xc(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x3,%esi
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm0
addss  0xe08(%rip),%xmm0
call   1030 <abs@plt>
movaps %xmm0,0x90(%rsp)
movss  0x10(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
movss  0x10(%rsp),%xmm0
addss  0xdde(%rip),%xmm0
call   1030 <abs@plt>
movaps %xmm0,0x80(%rsp)
movss  0x14(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x5,%esi
call   1040 <printf@plt>
movss  0x14(%rsp),%xmm0
addss  0xdb4(%rip),%xmm0
call   1030 <abs@plt>
movaps %xmm0,0x70(%rsp)
movss  0x18(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x6,%esi
call   1040 <printf@plt>
movss  0x18(%rsp),%xmm0
addss  0xd8d(%rip),%xmm0
call   1030 <abs@plt>
movaps %xmm0,0x60(%rsp)
movss  0x1c(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x7,%esi
call   1040 <printf@plt>
movss  0x1c(%rsp),%xmm0
addss  0xd66(%rip),%xmm0
call   1030 <abs@plt>
movaps %xmm0,0x50(%rsp)
movss  0x20(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
movss  0x20(%rsp),%xmm0
addss  0xd3f(%rip),%xmm0
call   1030 <abs@plt>
movaps %xmm0,0x40(%rsp)
movss  0x24(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x9,%esi
call   1040 <printf@plt>
movss  0x24(%rsp),%xmm0
addss  0xd18(%rip),%xmm0
call   1030 <abs@plt>
movsd  0xd13(%rip),%xmm1
movsd  0x38(%rsp),%xmm2
ucomisd %xmm1,%xmm2
mov    $0xfffffffe,%eax
cmova  %eax,%ebx
movsd  0x30(%rsp),%xmm2
ucomisd %xmm1,%xmm2
movapd 0x90(%rsp),%xmm3
unpcklpd 0xa0(%rsp),%xmm3
movapd 0x70(%rsp),%xmm4
unpcklpd 0x80(%rsp),%xmm4
movapd 0x50(%rsp),%xmm5
unpcklpd 0x60(%rsp),%xmm5
unpcklpd 0x40(%rsp),%xmm0
movapd 0xc84(%rip),%xmm1
movapd %xmm1,%xmm2
cmpltpd %xmm3,%xmm2
movapd %xmm1,%xmm3
cmpltpd %xmm4,%xmm3
packssdw %xmm2,%xmm3
movapd %xmm1,%xmm2
cmpltpd %xmm5,%xmm2
cmpltpd %xmm0,%xmm1
packssdw %xmm2,%xmm1
packssdw %xmm3,%xmm1
cmova  %eax,%ebx
pmovmskb %xmm1,%ecx
test   $0xaaaa,%ecx
cmovne %eax,%ebx
jmp    13f6 <run_square_array+0x2b6>
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
lea    0xc76(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@CL_SUCCESS = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Error: Square Array Failed, %d\0A\00"
@.str.1 = [7 x i8] c"%d %f\0A\00"
define i32 @run_square_array(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32 10, i32* %9
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %10
%15 = alloca float, i64 10
store i32 0, i32* %11
br label %16
16: ; preds = %25, %3
%17 = load i32, i32* %11
%18 = icmp slt i32 %17, 10
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load i32, i32* %11
%21 = sitofp i32 %20 to float
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds float, float* %15, i64 %23
store float %21, float* %24
br label %25
25: ; preds = %19
%26 = load i32, i32* %11
%27 = add nsw i32 %26, 1
store i32 %27, i32* %11
br label %16
28: ; preds = %16
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = call i32 @square_array(i32 %29, i32 %30, i32 %31, float* %15, i32 10)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = load i32, i32* @CL_SUCCESS
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = load i32, i32* @stderr
%38 = load i32, i32* %8
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %38)
store i32 -1, i32* %4
store i32 1, i32* %12
br label %69
40: ; preds = %28
store i32 0, i32* %13
br label %41
41: ; preds = %64, %40
%42 = load i32, i32* %13
%43 = icmp slt i32 %42, 10
br i1 %43, label %44, label %67
44: ; preds = %41
%45 = load i32, i32* %13
%46 = load i32, i32* %13
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds float, float* %15, i64 %47
%49 = load float, float* %48
%50 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %45, float %49)
%51 = load i32, i32* %13
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds float, float* %15, i64 %52
%54 = load float, float* %53
%55 = load i32, i32* %13
%56 = load i32, i32* %13
%57 = mul nsw i32 %55, %56
%58 = sitofp i32 %57 to float
%59 = fsub float %54, %58
%60 = call double @abs(float %59)
%61 = fcmp ogt double %60, 1.000000e-03
br i1 %61, label %62, label %63
62: ; preds = %44
store i32 -2, i32* %8
br label %63
63: ; preds = %62, %44
br label %64
64: ; preds = %63
%65 = load i32, i32* %13
%66 = add nsw i32 %65, 1
store i32 %66, i32* %13
br label %41
67: ; preds = %41
%68 = load i32, i32* %8
store i32 %68, i32* %4
store i32 1, i32* %12
br label %69
69: ; preds = %67, %36
%70 = load i8*, i8** %10
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@CL_SUCCESS = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Error: Square Array Failed, %d\0A\00"
@.str.1 = [7 x i8] c"%d %f\0A\00"
define i32 @run_square_array(i32 %0, i32 %1, i32 %2) {
%4 = alloca [10 x float]
%5 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 0
%6 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 1
%7 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 2
%8 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 3
%9 = bitcast [10 x float]* %4 to <4 x float>*
store <4 x float> <float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00>, <4 x float>* %9
%10 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 4
%11 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 5
%12 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 6
%13 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 7
%14 = bitcast float* %10 to <4 x float>*
store <4 x float> <float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00>, <4 x float>* %14
%15 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 8
store float 8.000000e+00, float* %15
%16 = getelementptr inbounds [10 x float], [10 x float]* %4, i64 0, i64 9
store float 9.000000e+00, float* %16
%17 = call i32 @square_array(i32 %0, i32 %1, i32 %2, float* %5, i32 10)
%18 = load i32, i32* @CL_SUCCESS
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %87
20: ; preds = %3
%21 = load float, float* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0, float %21)
%23 = load float, float* %5
%24 = call double @abs(float %23)
%25 = fcmp ogt double %24, 1.000000e-03
%26 = load float, float* %6
%27 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1, float %26)
%28 = load float, float* %6
%29 = fadd float %28, -1.000000e+00
%30 = call double @abs(float %29)
%31 = fcmp ogt double %30, 1.000000e-03
%32 = load float, float* %7
%33 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2, float %32)
%34 = load float, float* %7
%35 = fadd float %34, -4.000000e+00
%36 = call double @abs(float %35)
%37 = load float, float* %8
%38 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 3, float %37)
%39 = load float, float* %8
%40 = fadd float %39, -9.000000e+00
%41 = call double @abs(float %40)
%42 = load float, float* %10
%43 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 4, float %42)
%44 = load float, float* %10
%45 = fadd float %44, -1.600000e+01
%46 = call double @abs(float %45)
%47 = load float, float* %11
%48 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 5, float %47)
%49 = load float, float* %11
%50 = fadd float %49, -2.500000e+01
%51 = call double @abs(float %50)
%52 = load float, float* %12
%53 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6, float %52)
%54 = load float, float* %12
%55 = fadd float %54, -3.600000e+01
%56 = call double @abs(float %55)
%57 = load float, float* %13
%58 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 7, float %57)
%59 = load float, float* %13
%60 = fadd float %59, -4.900000e+01
%61 = call double @abs(float %60)
%62 = load float, float* %15
%63 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 8, float %62)
%64 = load float, float* %15
%65 = fadd float %64, -6.400000e+01
%66 = call double @abs(float %65)
%67 = load float, float* %16
%68 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 9, float %67)
%69 = load float, float* %16
%70 = fadd float %69, -8.100000e+01
%71 = call double @abs(float %70)
%72 = insertelement <8 x double> poison, double %71, i64 0
%73 = insertelement <8 x double> %72, double %66, i64 1
%74 = insertelement <8 x double> %73, double %61, i64 2
%75 = insertelement <8 x double> %74, double %56, i64 3
%76 = insertelement <8 x double> %75, double %51, i64 4
%77 = insertelement <8 x double> %76, double %46, i64 5
%78 = insertelement <8 x double> %77, double %41, i64 6
%79 = insertelement <8 x double> %78, double %36, i64 7
%80 = freeze <8 x double> %79
%81 = fcmp ogt <8 x double> %80, <double 1.000000e-03, double 1.000000e-03, double 1.000000e-03, double 1.000000e-03, double 1.000000e-03, double 1.000000e-03, double 1.000000e-03, double 1.000000e-03>
%82 = bitcast <8 x i1> %81 to i8
%83 = icmp ne i8 %82, 0
%84 = select i1 %83, i1 true, i1 %31
%85 = select i1 %84, i1 true, i1 %25
%86 = select i1 %85, i32 -2, i32 %17
br label %90
87: ; preds = %3
%88 = load i32, i32* @stderr
%89 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %90
90: ; preds = %20, %87
%91 = phi i32 [ -1, %87 ], [ %86, %20 ]
ret i32 %91
}