#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 */

/* Variables and functions */
double sqrt(int);
int cs240_verify(double *x, int n, double elapsedTime) {
  int i;
  double answer = sqrt(n);
  double diff;
  int correct = 1;
  for (i = 0; i < n; i++) {
    diff = x[i] - answer;
    if (diff < 0)
      diff = -diff;
    if (diff > 0.00001) {
      correct = 0;
      break;
    }
  }
  return correct;
}


x86 assembly (clang, -O0):
<cs240_verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c7 <cs240_verify+0xb7>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1191 <cs240_verify+0x81>
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe62(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b4 <cs240_verify+0xa4>
movl   $0x0,-0x34(%rbp)
jmp    11c7 <cs240_verify+0xb7>
jmp    11b9 <cs240_verify+0xa9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113f <cs240_verify+0x2f>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cs240_verify>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <sqrt@plt>
mov    $0x1,%eax
test   %ebp,%ebp
jle    1179 <cs240_verify+0x69>
mov    %ebp,%ecx
xor    %edx,%edx
movapd 0xecc(%rip),%xmm1
xorpd  %xmm2,%xmm2
movsd  0xed0(%rip),%xmm3
movsd  (%rbx,%rdx,8),%xmm4
subsd  %xmm0,%xmm4
movapd %xmm4,%xmm5
xorpd  %xmm1,%xmm5
movapd %xmm4,%xmm6
cmpltsd %xmm2,%xmm6
andpd  %xmm6,%xmm5
andnpd %xmm4,%xmm6
orpd   %xmm5,%xmm6
ucomisd %xmm3,%xmm6
ja     1177 <cs240_verify+0x67>
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1140 <cs240_verify+0x30>
jmp    1179 <cs240_verify+0x69>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cs240_verify(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
%11 = load i32, i32* %5
%12 = call double @sqrt(i32 %11)
store double %12, double* %8
store i32 1, i32* %10
store i32 0, i32* %7
br label %13
13: ; preds = %35, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %38
17: ; preds = %13
%18 = load double*, double** %4
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double, double* %8
%24 = fsub double %22, %23
store double %24, double* %9
%25 = load double, double* %9
%26 = fcmp olt double %25, 0.000000e+00
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = load double, double* %9
%29 = fneg double %28
store double %29, double* %9
br label %30
30: ; preds = %27, %17
%31 = load double, double* %9
%32 = fcmp ogt double %31, 1.000000e-05
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 0, i32* %10
br label %38
34: ; preds = %30
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %13
38: ; preds = %33, %13
%39 = load i32, i32* %10
ret i32 %39
}

LLVM IR (-O2):
define i32 @cs240_verify(double* nocapture %0, i32 %1, double %2) {
%4 = tail call double @sqrt(i32 %1)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %10
8: ; preds = %10
%9 = icmp eq i64 %19, %7
br i1 %9, label %20, label %10
10: ; preds = %6, %8
%11 = phi i64 [ 0, %6 ], [ %19, %8 ]
%12 = getelementptr inbounds double, double* %0, i64 %11
%13 = load double, double* %12
%14 = fsub double %13, %4
%15 = fcmp olt double %14, 0.000000e+00
%16 = fneg double %14
%17 = select i1 %15, double %16, double %14
%18 = fcmp ogt double %17, 1.000000e-05
%19 = add nuw nsw i64 %11, 1
br i1 %18, label %20, label %8
20: ; preds = %8, %10, %3
%21 = phi i32 [ 1, %3 ], [ 0, %10 ], [ 1, %8 ]
ret i32 %21
}