#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 abs(double);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void check_zero(double *v, int n, int dim) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < dim; j++) {
      if (!(abs(v[dim * i + j] - 0.0) < 1.0e-14)) {
        printf("Error: The array contains non-zero values: %f\n",
               v[dim * i + j]);
        exit(0);
      }
    }
  }
  printf("PASS\n");
}


x86 assembly (clang, -O0):
<check_zero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f0 <check_zero+0xc0>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11dd <check_zero+0xad>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
subsd  %xmm1,%xmm0
call   1030 <abs@plt>
movaps %xmm0,%xmm1
movsd  0xe6b(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     11ca <check_zero+0x9a>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe4c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11cf <check_zero+0x9f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115c <check_zero+0x2c>
jmp    11e2 <check_zero+0xb2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1149 <check_zero+0x19>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_zero>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,0x4(%rsp)
test   %esi,%esi
jle    11b4 <check_zero+0x74>
mov    %rdi,%rbx
movslq 0x4(%rsp),%r12
mov    %esi,%r15d
mov    %r12d,%ebp
shl    $0x3,%r12
xor    %r13d,%r13d
jmp    117c <check_zero+0x3c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
add    %r12,%rbx
cmp    %r15,%r13
je     11b4 <check_zero+0x74>
cmpl   $0x0,0x4(%rsp)
jle    1170 <check_zero+0x30>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
movsd  (%rbx,%r14,8),%xmm0
call   1040 <abs@plt>
movsd  0xe5d(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11ce <check_zero+0x8e>
add    $0x1,%r14
cmp    %r14,%rbp
jne    1190 <check_zero+0x50>
jmp    1170 <check_zero+0x30>
lea    0xe7c(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
movsd  (%rbx,%r14,8),%xmm0
lea    0xe2d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"Error: The array contains non-zero values: %f\0A\00"
@.str.1 = [6 x i8] c"PASS\0A\00"
define void @check_zero(double* %0, i32 %1, i32 %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %48, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %51
13: ; preds = %9
store i32 0, i32* %8
br label %14
14: ; preds = %44, %13
%15 = load i32, i32* %8
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %47
18: ; preds = %14
%19 = load double*, double** %4
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = mul nsw i32 %20, %21
%23 = load i32, i32* %8
%24 = add nsw i32 %22, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %19, i64 %25
%27 = load double, double* %26
%28 = fsub double %27, 0.000000e+00
%29 = call double @abs(double %28)
%30 = fcmp olt double %29, 0x3D06849B86A12B9B
br i1 %30, label %43, label %31
31: ; preds = %18
%32 = load double*, double** %4
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = mul nsw i32 %33, %34
%36 = load i32, i32* %8
%37 = add nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %32, i64 %38
%40 = load double, double* %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %40)
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %18
br label %44
44: ; preds = %43
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %14
47: ; preds = %14
br label %48
48: ; preds = %47
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %9
51: ; preds = %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"Error: The array contains non-zero values: %f\0A\00"
@str = [5 x i8] c"PASS\00"
define void @check_zero(double* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %14
5: ; preds = %3
%6 = icmp sgt i32 %2, 0
%7 = sext i32 %2 to i64
%8 = zext i32 %1 to i64
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %5, %18
%11 = phi i64 [ 0, %5 ], [ %19, %18 ]
br i1 %6, label %12, label %18
12: ; preds = %10
%13 = mul nsw i64 %11, %7
br label %21
14: ; preds = %18, %3
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret void
16: ; preds = %21
%17 = icmp eq i64 %28, %9
br i1 %17, label %18, label %21
18: ; preds = %16, %10
%19 = add nuw nsw i64 %11, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %14, label %10
21: ; preds = %12, %16
%22 = phi i64 [ 0, %12 ], [ %28, %16 ]
%23 = add nsw i64 %22, %13
%24 = getelementptr inbounds double, double* %0, i64 %23
%25 = load double, double* %24
%26 = tail call double @abs(double %25)
%27 = fcmp olt double %26, 0x3D06849B86A12B9B
%28 = add nuw nsw i64 %22, 1
br i1 %27, label %16, label %29
29: ; preds = %21
%30 = getelementptr inbounds double, double* %0, i64 %23
%31 = load double, double* %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %31)
%33 = tail call i32 @exit(i32 0)
unreachable
}