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

/* Variables and functions */
int /*<<< orphan*/ CL_TRUE;
int /*<<< orphan*/ clEnqueueReadBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                                       int /*<<< orphan*/, int /*<<< orphan*/,
                                       size_t, double *, int /*<<< orphan*/,
                                       int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
double *malloc(size_t);
int /*<<< orphan*/ printf(char *);
void VerifyResults(cl_command_queue *queue, cl_mem *device_A, double scalar,
                   size_t arraySize) {
  size_t sizeBytes = arraySize * sizeof(double);
  double *checkA;
  checkA = malloc(sizeBytes);
  clEnqueueReadBuffer(*queue, *device_A, CL_TRUE, 0, sizeBytes, checkA, 0, NULL,
                      NULL);
  double a = 1.0;
  double b = 2.0;
  double c = 0.0;
  c = a;
  b = scalar * c;
  c = a + b;
  a = b * scalar + c;
  int errors = 0;
  for (size_t i = 0; i < arraySize; i++) {
    if (checkA[i] != a) {
      errors++;
    }
  }
  if (errors != 0) {
    printf("Error in result!\n");
  }
}


x86 assembly (clang, -O0):
<VerifyResults>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
xor    %ecx,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1050 <clEnqueueReadBuffer@plt>
movsd  0xe5f(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe4a(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x4c(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1266 <VerifyResults+0x136>
mov    -0x30(%rbp),%rax
mov    -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x38(%rbp),%xmm0
jne    1247 <VerifyResults+0x117>
jp     1247 <VerifyResults+0x117>
jmp    1250 <VerifyResults+0x120>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1255 <VerifyResults+0x125>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1216 <VerifyResults+0xe6>
cmpl   $0x0,-0x4c(%rbp)
je     127c <VerifyResults+0x14c>
lea    0xd99(%rip),%rdi
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VerifyResults>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
movdqa %xmm0,0x20(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x0(,%rdx,8),%r13
mov    %r13,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    (%r12),%edi
mov    (%r15),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
pxor   %xmm0,%xmm0
movdqu %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
xor    %ebx,%ebx
xor    %ecx,%ecx
mov    %r13,%r8
mov    %rbp,%r9
call   1050 <clEnqueueReadBuffer@plt>
test   %r14,%r14
je     12d9 <VerifyResults+0x1a9>
movsd  0xe5f(%rip),%xmm0
movapd 0x20(%rsp),%xmm7
addsd  %xmm7,%xmm0
mulsd  %xmm7,%xmm7
addsd  %xmm0,%xmm7
cmp    $0x4,%r14
jae    11c0 <VerifyResults+0x90>
xor    %eax,%eax
jmp    12a0 <VerifyResults+0x170>
mov    %r14,%rax
and    $0xfffffffffffffffc,%rax
movapd %xmm7,%xmm1
unpcklpd %xmm7,%xmm1
lea    -0x4(%rax),%rdx
mov    %rdx,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
test   %rdx,%rdx
je     12e8 <VerifyResults+0x1b8>
mov    %rcx,%rsi
and    $0xfffffffffffffffe,%rsi
xorpd  %xmm0,%xmm0
xor    %edx,%edx
pxor   %xmm2,%xmm2
nopl   0x0(%rax,%rax,1)
movupd 0x0(%rbp,%rdx,8),%xmm3
movupd 0x10(%rbp,%rdx,8),%xmm4
movupd 0x20(%rbp,%rdx,8),%xmm5
movupd 0x30(%rbp,%rdx,8),%xmm6
cmpneqpd %xmm1,%xmm3
shufps $0xe8,%xmm3,%xmm3
psubd  %xmm3,%xmm0
cmpneqpd %xmm1,%xmm4
shufps $0xe8,%xmm4,%xmm4
psubd  %xmm4,%xmm2
cmpneqpd %xmm1,%xmm5
shufps $0xe8,%xmm5,%xmm5
psubd  %xmm5,%xmm0
cmpneqpd %xmm1,%xmm6
shufps $0xe8,%xmm6,%xmm6
psubd  %xmm6,%xmm2
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rsi
jne    1200 <VerifyResults+0xd0>
test   $0x1,%cl
je     1281 <VerifyResults+0x151>
movupd 0x0(%rbp,%rdx,8),%xmm3
movupd 0x10(%rbp,%rdx,8),%xmm4
cmpneqpd %xmm1,%xmm3
shufps $0xe8,%xmm3,%xmm3
psubd  %xmm3,%xmm0
cmpneqpd %xmm1,%xmm4
shufps $0xe8,%xmm4,%xmm4
psubd  %xmm4,%xmm2
paddd  %xmm2,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%ebx
cmp    %r14,%rax
je     12bb <VerifyResults+0x18b>
nopw   0x0(%rax,%rax,1)
movsd  0x0(%rbp,%rax,8),%xmm0
cmpneqsd %xmm7,%xmm0
movq   %xmm0,%rcx
sub    %ecx,%ebx
add    $0x1,%rax
cmp    %rax,%r14
jne    12a0 <VerifyResults+0x170>
test   %ebx,%ebx
je     12d9 <VerifyResults+0x1a9>
lea    0xd42(%rip),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xorpd  %xmm0,%xmm0
xor    %edx,%edx
pxor   %xmm2,%xmm2
test   $0x1,%cl
jne    125b <VerifyResults+0x12b>
jmp    1281 <VerifyResults+0x151>

LLVM IR (-O0):
@CL_TRUE = global i32 0
@.str = [18 x i8] c"Error in result!\0A\00"
define void @VerifyResults(i32* %0, i32* %1, double %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca double
%8 = alloca i64
%9 = alloca i64
%10 = alloca double*
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca i64
store i32* %0, i32** %5
store i32* %1, i32** %6
store double %2, double* %7
store i64 %3, i64* %8
%16 = load i64, i64* %8
%17 = mul i64 %16, 8
store i64 %17, i64* %9
%18 = load i64, i64* %9
%19 = call double* @malloc(i64 %18)
store double* %19, double** %10
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = load i32, i32* @CL_TRUE
%25 = load i64, i64* %9
%26 = load double*, double** %10
%27 = call i32 @clEnqueueReadBuffer(i32 %21, i32 %23, i32 %24, i32 0, i64 %25, double* %26, i32 0, i32* null, i32* null)
store double 1.000000e+00, double* %11
store double 2.000000e+00, double* %12
store double 0.000000e+00, double* %13
%28 = load double, double* %11
store double %28, double* %13
%29 = load double, double* %7
%30 = load double, double* %13
%31 = fmul double %29, %30
store double %31, double* %12
%32 = load double, double* %11
%33 = load double, double* %12
%34 = fadd double %32, %33
store double %34, double* %13
%35 = load double, double* %12
%36 = load double, double* %7
%37 = load double, double* %13
%38 = call double @llvm.fmuladd.f64(double %35, double %36, double %37)
store double %38, double* %11
store i32 0, i32* %14
store i64 0, i64* %15
br label %39
39: ; preds = %54, %4
%40 = load i64, i64* %15
%41 = load i64, i64* %8
%42 = icmp ult i64 %40, %41
br i1 %42, label %43, label %57
43: ; preds = %39
%44 = load double*, double** %10
%45 = load i64, i64* %15
%46 = getelementptr inbounds double, double* %44, i64 %45
%47 = load double, double* %46
%48 = load double, double* %11
%49 = fcmp une double %47, %48
br i1 %49, label %50, label %53
50: ; preds = %43
%51 = load i32, i32* %14
%52 = add nsw i32 %51, 1
store i32 %52, i32* %14
br label %53
53: ; preds = %50, %43
br label %54
54: ; preds = %53
%55 = load i64, i64* %15
%56 = add i64 %55, 1
store i64 %56, i64* %15
br label %39
57: ; preds = %39
%58 = load i32, i32* %14
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %62
62: ; preds = %60, %57
ret void
}

LLVM IR (-O2):
@CL_TRUE = global i32 0
@str = [17 x i8] c"Error in result!\00"
define void @VerifyResults(i32* nocapture %0, i32* nocapture %1, double %2, i64 %3) {
%5 = shl i64 %3, 3
%6 = tail call double* @malloc(i64 %5)
%7 = load i32, i32* %0
%8 = load i32, i32* %1
%9 = load i32, i32* @CL_TRUE
%10 = tail call i32 @clEnqueueReadBuffer(i32 %7, i32 %8, i32 %9, i32 0, i64 %5, double* %6, i32 0, i32* null, i32* null)
%11 = fadd double %2, 1.000000e+00
%12 = tail call double @llvm.fmuladd.f64(double %2, double %2, double %11)
%13 = icmp eq i64 %3, 0
br i1 %13, label %106, label %14
14: ; preds = %4
%15 = icmp ult i64 %3, 4
br i1 %15, label %88, label %16
16: ; preds = %14
%17 = and i64 %3, -4
%18 = insertelement <2 x double> poison, double %12, i64 0
%19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
%20 = insertelement <2 x double> poison, double %12, i64 0
%21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
%22 = add i64 %17, -4
%23 = lshr exact i64 %22, 2
%24 = add nuw nsw i64 %23, 1
%25 = and i64 %24, 1
%26 = icmp eq i64 %22, 0
br i1 %26, label %62, label %27
27: ; preds = %16
%28 = and i64 %24, 9223372036854775806
br label %29
29: ; preds = %29, %27
%30 = phi i64 [ 0, %27 ], [ %59, %29 ]
%31 = phi <2 x i32> [ zeroinitializer, %27 ], [ %57, %29 ]
%32 = phi <2 x i32> [ zeroinitializer, %27 ], [ %58, %29 ]
%33 = phi i64 [ 0, %27 ], [ %60, %29 ]
%34 = getelementptr inbounds double, double* %6, i64 %30
%35 = bitcast double* %34 to <2 x double>*
%36 = load <2 x double>, <2 x double>* %35
%37 = getelementptr inbounds double, double* %34, i64 2
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = fcmp une <2 x double> %36, %19
%41 = fcmp une <2 x double> %39, %21
%42 = zext <2 x i1> %40 to <2 x i32>
%43 = zext <2 x i1> %41 to <2 x i32>
%44 = add <2 x i32> %31, %42
%45 = add <2 x i32> %32, %43
%46 = or i64 %30, 4
%47 = getelementptr inbounds double, double* %6, i64 %46
%48 = bitcast double* %47 to <2 x double>*
%49 = load <2 x double>, <2 x double>* %48
%50 = getelementptr inbounds double, double* %47, i64 2
%51 = bitcast double* %50 to <2 x double>*
%52 = load <2 x double>, <2 x double>* %51
%53 = fcmp une <2 x double> %49, %19
%54 = fcmp une <2 x double> %52, %21
%55 = zext <2 x i1> %53 to <2 x i32>
%56 = zext <2 x i1> %54 to <2 x i32>
%57 = add <2 x i32> %44, %55
%58 = add <2 x i32> %45, %56
%59 = add nuw i64 %30, 8
%60 = add i64 %33, 2
%61 = icmp eq i64 %60, %28
br i1 %61, label %62, label %29
62: ; preds = %29, %16
%63 = phi <2 x i32> [ undef, %16 ], [ %57, %29 ]
%64 = phi <2 x i32> [ undef, %16 ], [ %58, %29 ]
%65 = phi i64 [ 0, %16 ], [ %59, %29 ]
%66 = phi <2 x i32> [ zeroinitializer, %16 ], [ %57, %29 ]
%67 = phi <2 x i32> [ zeroinitializer, %16 ], [ %58, %29 ]
%68 = icmp eq i64 %25, 0
br i1 %68, label %82, label %69
69: ; preds = %62
%70 = getelementptr inbounds double, double* %6, i64 %65
%71 = bitcast double* %70 to <2 x double>*
%72 = load <2 x double>, <2 x double>* %71
%73 = getelementptr inbounds double, double* %70, i64 2
%74 = bitcast double* %73 to <2 x double>*
%75 = load <2 x double>, <2 x double>* %74
%76 = fcmp une <2 x double> %72, %19
%77 = fcmp une <2 x double> %75, %21
%78 = zext <2 x i1> %76 to <2 x i32>
%79 = zext <2 x i1> %77 to <2 x i32>
%80 = add <2 x i32> %66, %78
%81 = add <2 x i32> %67, %79
br label %82
82: ; preds = %62, %69
%83 = phi <2 x i32> [ %63, %62 ], [ %80, %69 ]
%84 = phi <2 x i32> [ %64, %62 ], [ %81, %69 ]
%85 = add <2 x i32> %84, %83
%86 = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %85)
%87 = icmp eq i64 %17, %3
br i1 %87, label %91, label %88
88: ; preds = %14, %82
%89 = phi i64 [ 0, %14 ], [ %17, %82 ]
%90 = phi i32 [ 0, %14 ], [ %86, %82 ]
br label %94
91: ; preds = %94, %82
%92 = phi i32 [ %86, %82 ], [ %101, %94 ]
%93 = icmp eq i32 %92, 0
br i1 %93, label %106, label %104
94: ; preds = %88, %94
%95 = phi i64 [ %102, %94 ], [ %89, %88 ]
%96 = phi i32 [ %101, %94 ], [ %90, %88 ]
%97 = getelementptr inbounds double, double* %6, i64 %95
%98 = load double, double* %97
%99 = fcmp une double %98, %12
%100 = zext i1 %99 to i32
%101 = add nuw nsw i32 %96, %100
%102 = add nuw i64 %95, 1
%103 = icmp eq i64 %102, %3
br i1 %103, label %91, label %94
104: ; preds = %91
%105 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %106
106: ; preds = %4, %104, %91
ret void
}