#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 fabs(double);
bool cmp_matrix(double **x, double **y, int m, int n, double threshold) {
  bool equals = true;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (fabs(x[j][i] - y[j][i]) > threshold) {
        equals = false;
        break;
      }
    }
    if (!equals) {
      break;
    }
  }
  return equals;
}


x86 assembly (clang, -O0):
<cmp_matrix>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c5 <cmp_matrix+0xc5>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a3 <cmp_matrix+0xa3>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xe8b(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1190 <cmp_matrix+0x90>
movl   $0x0,-0x24(%rbp)
jmp    11a3 <cmp_matrix+0xa3>
jmp    1195 <cmp_matrix+0x95>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1138 <cmp_matrix+0x38>
cmpl   $0x0,-0x24(%rbp)
jne    11b2 <cmp_matrix+0xb2>
jmp    11c5 <cmp_matrix+0xc5>
jmp    11b7 <cmp_matrix+0xb7>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1125 <cmp_matrix+0x25>
mov    -0x24(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_matrix>:
mov    $0x1,%eax
test   %edx,%edx
jle    115b <cmp_matrix+0x5b>
mov    %edx,%r8d
mov    %ecx,%r9d
xor    %r10d,%r10d
movapd 0xee6(%rip),%xmm1
jmp    1129 <cmp_matrix+0x29>
nopl   0x0(%rax)
add    $0x1,%r10
cmp    %r8,%r10
je     115b <cmp_matrix+0x5b>
test   %ecx,%ecx
jle    1120 <cmp_matrix+0x20>
xor    %r11d,%r11d
mov    (%rdi,%r11,8),%rdx
movsd  (%rdx,%r10,8),%xmm2
mov    (%rsi,%r11,8),%rdx
subsd  (%rdx,%r10,8),%xmm2
andpd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
ja     1159 <cmp_matrix+0x59>
add    $0x1,%r11
cmp    %r11,%r9
jne    1130 <cmp_matrix+0x30>
jmp    1120 <cmp_matrix+0x20>
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @cmp_matrix(double** %0, double** %1, i32 %2, i32 %3, double %4) {
%6 = alloca double**
%7 = alloca double**
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store double** %0, double*** %6
store double** %1, double*** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store double %4, double* %10
store i32 1, i32* %11
store i32 0, i32* %12
br label %14
14: ; preds = %56, %5
%15 = load i32, i32* %12
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %59
18: ; preds = %14
store i32 0, i32* %13
br label %19
19: ; preds = %48, %18
%20 = load i32, i32* %13
%21 = load i32, i32* %9
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %51
23: ; preds = %19
%24 = load double**, double*** %6
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double*, double** %24, i64 %26
%28 = load double*, double** %27
%29 = load i32, i32* %12
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load double**, double*** %7
%34 = load i32, i32* %13
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double*, double** %33, i64 %35
%37 = load double*, double** %36
%38 = load i32, i32* %12
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = fsub double %32, %41
%43 = call double @llvm.fabs.f64(double %42)
%44 = load double, double* %10
%45 = fcmp ogt double %43, %44
br i1 %45, label %46, label %47
46: ; preds = %23
store i32 0, i32* %11
br label %51
47: ; preds = %23
br label %48
48: ; preds = %47
%49 = load i32, i32* %13
%50 = add nsw i32 %49, 1
store i32 %50, i32* %13
br label %19
51: ; preds = %46, %19
%52 = load i32, i32* %11
%53 = icmp ne i32 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %51
br label %59
55: ; preds = %51
br label %56
56: ; preds = %55
%57 = load i32, i32* %12
%58 = add nsw i32 %57, 1
store i32 %58, i32* %12
br label %14
59: ; preds = %54, %14
%60 = load i32, i32* %11
ret i32 %60
}

LLVM IR (-O2):
define i32 @cmp_matrix(double** nocapture %0, double** nocapture %1, i32 %2, i32 %3, double %4) {
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %32
7: ; preds = %5
%8 = icmp sgt i32 %3, 0
%9 = zext i32 %2 to i64
%10 = zext i32 %3 to i64
br label %11
11: ; preds = %7, %29
%12 = phi i64 [ 0, %7 ], [ %30, %29 ]
br i1 %8, label %15, label %29
13: ; preds = %15
%14 = icmp eq i64 %28, %10
br i1 %14, label %29, label %15
15: ; preds = %11, %13
%16 = phi i64 [ %28, %13 ], [ 0, %11 ]
%17 = getelementptr inbounds double*, double** %0, i64 %16
%18 = load double*, double** %17
%19 = getelementptr inbounds double, double* %18, i64 %12
%20 = load double, double* %19
%21 = getelementptr inbounds double*, double** %1, i64 %16
%22 = load double*, double** %21
%23 = getelementptr inbounds double, double* %22, i64 %12
%24 = load double, double* %23
%25 = fsub double %20, %24
%26 = tail call double @llvm.fabs.f64(double %25)
%27 = fcmp ogt double %26, %4
%28 = add nuw nsw i64 %16, 1
br i1 %27, label %32, label %13
29: ; preds = %13, %11
%30 = add nuw nsw i64 %12, 1
%31 = icmp eq i64 %30, %9
br i1 %31, label %32, label %11
32: ; preds = %29, %15, %5
%33 = phi i32 [ 1, %5 ], [ 0, %15 ], [ 1, %29 ]
ret i32 %33
}