#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 */
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ is_equal(double, double);
scalar_t__ malloc(int);
int /*<<< orphan*/ mult_square_matrix(int, double *, double *, double *);
int verify_lu(int n, double *a, double *l, double *u) {
  int i, no_error = 1;
  double *v = (double *)malloc(sizeof(double) * (n * n));
  mult_square_matrix(n, l, u, v);
  for (i = 0; i < n * n; i++) {
    if (!is_equal(a[i], v[i])) {
      no_error = 0;
      break;
    }
  }
  free(v);
  return no_error;
}


x86 assembly (clang, -O0):
<verify_lu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <mult_square_matrix@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x4(%rbp),%ecx
imul   -0x4(%rbp),%ecx
cmp    %ecx,%eax
jge    11ea <verify_lu+0xaa>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
call   1050 <is_equal@plt>
cmp    $0x0,%eax
jne    11d7 <verify_lu+0x97>
movl   $0x0,-0x28(%rbp)
jmp    11ea <verify_lu+0xaa>
jmp    11dc <verify_lu+0x9c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1191 <verify_lu+0x51>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_lu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %edi,%ebp
mov    %edi,%ebx
imul   %ebx,%ebx
lea    0x0(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
call   1040 <mult_square_matrix@plt>
mov    $0x1,%r15d
test   %ebx,%ebx
je     11b4 <verify_lu+0x74>
mov    %ebx,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  (%r14,%rbx,8),%xmm0
movsd  0x0(%r13,%rbx,8),%xmm1
call   1050 <is_equal@plt>
test   %eax,%eax
je     11b1 <verify_lu+0x71>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <verify_lu+0x50>
jmp    11b4 <verify_lu+0x74>
xor    %r15d,%r15d
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @verify_lu(i32 %0, double* %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
store i32 1, i32* %10
%12 = load i32, i32* %5
%13 = load i32, i32* %5
%14 = mul nsw i32 %12, %13
%15 = sext i32 %14 to i64
%16 = mul i64 8, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %11
%20 = load i32, i32* %5
%21 = load double*, double** %7
%22 = load double*, double** %8
%23 = load double*, double** %11
%24 = call i32 @mult_square_matrix(i32 %20, double* %21, double* %22, double* %23)
store i32 0, i32* %9
br label %25
25: ; preds = %46, %4
%26 = load i32, i32* %9
%27 = load i32, i32* %5
%28 = load i32, i32* %5
%29 = mul nsw i32 %27, %28
%30 = icmp slt i32 %26, %29
br i1 %30, label %31, label %49
31: ; preds = %25
%32 = load double*, double** %6
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = load double*, double** %11
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = call i32 @is_equal(double %36, double %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %31
store i32 0, i32* %10
br label %49
45: ; preds = %31
br label %46
46: ; preds = %45
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %25
49: ; preds = %44, %25
%50 = load double*, double** %11
%51 = call i32 @free(double* %50)
%52 = load i32, i32* %10
ret i32 %52
}

LLVM IR (-O2):
define i32 @verify_lu(i32 %0, double* nocapture %1, double* %2, double* %3) {
%5 = mul nsw i32 %0, %0
%6 = shl i32 %5, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to double*
%9 = tail call i32 @mult_square_matrix(i32 %0, double* %2, double* %3, double* %8)
%10 = icmp eq i32 %5, 0
br i1 %10, label %24, label %11
11: ; preds = %4
%12 = zext i32 %5 to i64
br label %15
13: ; preds = %15
%14 = icmp eq i64 %23, %12
br i1 %14, label %24, label %15
15: ; preds = %11, %13
%16 = phi i64 [ 0, %11 ], [ %23, %13 ]
%17 = getelementptr inbounds double, double* %1, i64 %16
%18 = load double, double* %17
%19 = getelementptr inbounds double, double* %8, i64 %16
%20 = load double, double* %19
%21 = tail call i32 @is_equal(double %18, double %20)
%22 = icmp eq i32 %21, 0
%23 = add nuw nsw i64 %16, 1
br i1 %22, label %24, label %13
24: ; preds = %13, %15, %4
%25 = phi i32 [ 1, %4 ], [ 0, %15 ], [ 1, %13 ]
%26 = tail call i32 @free(double* %8)
ret i32 %25
}