#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 fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ mat3_cmp(double **, double **);
double mat3_det(double **);
int /*<<< orphan*/ mat3_inv(double **, double **);
int /*<<< orphan*/ mat3_mul(double **, double **, double **);
int /*<<< orphan*/ mat3_print(double **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int test_matrix(void) {
  double M[3][3] = {{1., 3., 1.}, {1., 1., 2.}, {2., 3., 4.}};
  double comp[3][3] = {{2., 9., -5.}, {0., -2., 1.}, {-1., -3., 2.}};
  double eye[3][3] = {{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}};
  double det, inv[3][3], mmul[3][3];
  det = mat3_det(M);
  if (fabs(det + 1.) > 1e-10) {
    fprintf(stderr, "Error with determinant, got %.3e expected -1.\n", det);
    return -1;
  }
  mat3_inv(inv, M);
  if (mat3_cmp(inv, comp) != 0) {
    fprintf(stderr, "Error with matrix inversion!\n");
    printf("Got:\n");
    mat3_print(inv);
    printf("Expected:\n");
    mat3_print(comp);
    return -1;
  }
  mat3_mul(mmul, M, inv);
  if (mat3_cmp(mmul, eye) != 0) {
    fprintf(stderr, "Error with matrix multiplication!\n");
    printf("Got:\n");
    mat3_print(mmul);
    printf("Expected:\n");
    mat3_print(eye);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
lea    -0x50(%rbp),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x48,%edx
call   1090 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe92(%rip),%rsi
mov    $0x48,%edx
call   1090 <memcpy@plt>
lea    -0xf0(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1060 <memset@plt>
movsd  0xe15(%rip),%xmm0
movsd  %xmm0,-0xf0(%rbp)
ff
movsd  0xe05(%rip),%xmm0
movsd  %xmm0,-0xd0(%rbp)
ff
movsd  0xdf5(%rip),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
lea    -0x50(%rbp),%rdi
call   1030 <mat3_det@plt>
movsd  %xmm0,-0xf8(%rbp)
ff
movsd  0xdd4(%rip),%xmm0
addsd  -0xf8(%rbp),%xmm0
ff
call   1070 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xdb3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1282 <test_matrix+0xe2>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
movsd  -0xf8(%rbp),%xmm0
ff
lea    0xe39(%rip),%rsi
mov    $0x1,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1390 <test_matrix+0x1f0>
lea    -0x140(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   10b0 <mat3_inv@plt>
lea    -0x140(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   10c0 <mat3_cmp@plt>
cmp    $0x0,%rax
je     1302 <test_matrix+0x162>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
lea    -0x140(%rbp),%rdi
call   10a0 <mat3_print@plt>
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   10a0 <mat3_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1390 <test_matrix+0x1f0>
lea    -0x190(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x140(%rbp),%rdx
call   1050 <mat3_mul@plt>
lea    -0x190(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
call   10c0 <mat3_cmp@plt>
cmp    $0x0,%rax
je     1389 <test_matrix+0x1e9>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xda1(%rip),%rdi
call   1040 <printf@plt>
lea    -0x190(%rbp),%rdi
call   10a0 <mat3_print@plt>
lea    0xd8f(%rip),%rdi
call   1040 <printf@plt>
lea    -0xf0(%rbp),%rdi
call   10a0 <mat3_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1390 <test_matrix+0x1f0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_matrix>:
push   %rbx
sub    $0x1a0,%rsp
mov    0xec1(%rip),%rax
mov    %rax,0xa0(%rsp)
movaps 0xea2(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe83(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe64(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe48(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
mov    0xecc(%rip),%rax
mov    %rax,0xf0(%rsp)
movaps 0xead(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xe8e(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xe6f(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movapd 0xe4f(%rip),%xmm0
movapd %xmm0,0xb0(%rsp)
xorpd  %xmm0,%xmm0
movapd %xmm0,0x10(%rsp)
movapd %xmm0,0x30(%rsp)
movapd %xmm0,0x40(%rsp)
movapd %xmm0,0x20(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x10(%rsp)
mov    %rax,0x30(%rsp)
mov    %rax,0x50(%rsp)
lea    0x60(%rsp),%rdi
call   1030 <mat3_det@plt>
movapd %xmm0,%xmm1
movsd  0xd9b(%rip),%xmm0
movsd  %xmm1,0x8(%rsp)
addsd  %xmm1,%xmm0
call   1060 <fabs@plt>
test   %eax,%eax
jle    129a <test_matrix+0x11a>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
jmp    137f <test_matrix+0x1ff>
lea    0x100(%rsp),%rbx
lea    0x60(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <mat3_inv@plt>
lea    0xb0(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <mat3_cmp@plt>
test   %rax,%rax
je     130a <test_matrix+0x18a>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
lea    0x100(%rsp),%rdi
call   1080 <mat3_print@plt>
lea    0xe22(%rip),%rdi
call   1040 <puts@plt>
lea    0xb0(%rsp),%rdi
jmp    137a <test_matrix+0x1fa>
lea    0x150(%rsp),%rbx
lea    0x60(%rsp),%rsi
lea    0x100(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <mat3_mul@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <mat3_cmp@plt>
test   %rax,%rax
je     138d <test_matrix+0x20d>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
lea    0xdac(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdc1(%rip),%rdi
call   1040 <puts@plt>
lea    0x150(%rsp),%rdi
call   1080 <mat3_print@plt>
lea    0xdad(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rdi
call   1080 <mat3_print@plt>
mov    $0xffffffff,%eax
add    $0x1a0,%rsp
pop    %rbx
ret
xor    %eax,%eax
jmp    1384 <test_matrix+0x204>

LLVM IR (-O0):
@__const.test_matrix.M = [3 x [3 x double]] [[3 x double] [double 1.000000e+00, double 3.000000e+00, double 1.000000e+00], [3 x double] [double 1.000000e+00, double 1.000000e+00, double 2.000000e+00], [3 x double] [double 2.000000e+00, double 3.000000e+00, double 4.000000e+00]]
@__const.test_matrix.comp = [3 x [3 x double]] [[3 x double] [double 2.000000e+00, double 9.000000e+00, double -5.000000e+00], [3 x double] [double 0.000000e+00, double -2.000000e+00, double 1.000000e+00], [3 x double] [double -1.000000e+00, double -3.000000e+00, double 2.000000e+00]]
@stderr = global i32 0
@.str = [47 x i8] c"Error with determinant, got %.3e expected -1.\0A\00"
@.str.1 = [30 x i8] c"Error with matrix inversion!\0A\00"
@.str.2 = [6 x i8] c"Got:\0A\00"
@.str.3 = [11 x i8] c"Expected:\0A\00"
@.str.4 = [35 x i8] c"Error with matrix multiplication!\0A\00"
define i32 @test_matrix() {
%1 = alloca i32
%2 = alloca [3 x [3 x double]]
%3 = alloca [3 x [3 x double]]
%4 = alloca [3 x [3 x double]]
%5 = alloca double
%6 = alloca [3 x [3 x double]]
%7 = alloca [3 x [3 x double]]
%8 = bitcast [3 x [3 x double]]* %2 to i8*
%9 = bitcast [3 x [3 x double]]* %3 to i8*
%10 = bitcast [3 x [3 x double]]* %4 to i8*
%11 = bitcast i8* %10 to [3 x [3 x double]]*
%12 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i32 0, i32 0
%13 = getelementptr inbounds [3 x double], [3 x double]* %12, i32 0, i32 0
store double 1.000000e+00, double* %13
%14 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i32 0, i32 1
%15 = getelementptr inbounds [3 x double], [3 x double]* %14, i32 0, i32 1
store double 1.000000e+00, double* %15
%16 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i32 0, i32 2
%17 = getelementptr inbounds [3 x double], [3 x double]* %16, i32 0, i32 2
store double 1.000000e+00, double* %17
%18 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %2, i64 0, i64 0
%19 = bitcast [3 x double]* %18 to double**
%20 = call double @mat3_det(double** %19)
store double %20, double* %5
%21 = load double, double* %5
%22 = fadd double %21, 1.000000e+00
%23 = call i32 @fabs(double %22)
%24 = sitofp i32 %23 to double
%25 = fcmp ogt double %24, 1.000000e-10
br i1 %25, label %26, label %30
26: ; preds = %0
%27 = load i32, i32* @stderr
%28 = load double, double* %5
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %28)
store i32 -1, i32* %1
br label %79
30: ; preds = %0
%31 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 0
%32 = bitcast [3 x double]* %31 to double**
%33 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %2, i64 0, i64 0
%34 = bitcast [3 x double]* %33 to double**
%35 = call i32 @mat3_inv(double** %32, double** %34)
%36 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 0
%37 = bitcast [3 x double]* %36 to double**
%38 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 0
%39 = bitcast [3 x double]* %38 to double**
%40 = call i64 @mat3_cmp(double** %37, double** %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %30
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%45 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%46 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 0
%47 = bitcast [3 x double]* %46 to double**
%48 = call i32 @mat3_print(double** %47)
%49 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%50 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 0
%51 = bitcast [3 x double]* %50 to double**
%52 = call i32 @mat3_print(double** %51)
store i32 -1, i32* %1
br label %79
53: ; preds = %30
%54 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 0
%55 = bitcast [3 x double]* %54 to double**
%56 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %2, i64 0, i64 0
%57 = bitcast [3 x double]* %56 to double**
%58 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 0
%59 = bitcast [3 x double]* %58 to double**
%60 = call i32 @mat3_mul(double** %55, double** %57, double** %59)
%61 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 0
%62 = bitcast [3 x double]* %61 to double**
%63 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 0
%64 = bitcast [3 x double]* %63 to double**
%65 = call i64 @mat3_cmp(double** %62, double** %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %78
67: ; preds = %53
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%70 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%71 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 0
%72 = bitcast [3 x double]* %71 to double**
%73 = call i32 @mat3_print(double** %72)
%74 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%75 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 0
%76 = bitcast [3 x double]* %75 to double**
%77 = call i32 @mat3_print(double** %76)
store i32 -1, i32* %1
br label %79
78: ; preds = %53
store i32 0, i32* %1
br label %79
79: ; preds = %78, %67, %42, %26
%80 = load i32, i32* %1
ret i32 %80
}

LLVM IR (-O2):
@__const.test_matrix.M = [3 x [3 x double]] [[3 x double] [double 1.000000e+00, double 3.000000e+00, double 1.000000e+00], [3 x double] [double 1.000000e+00, double 1.000000e+00, double 2.000000e+00], [3 x double] [double 2.000000e+00, double 3.000000e+00, double 4.000000e+00]]
@__const.test_matrix.comp = [3 x [3 x double]] [[3 x double] [double 2.000000e+00, double 9.000000e+00, double -5.000000e+00], [3 x double] [double 0.000000e+00, double -2.000000e+00, double 1.000000e+00], [3 x double] [double -1.000000e+00, double -3.000000e+00, double 2.000000e+00]]
@stderr = global i32 0
@.str = [47 x i8] c"Error with determinant, got %.3e expected -1.\0A\00"
@.str.1 = [30 x i8] c"Error with matrix inversion!\0A\00"
@.str.4 = [35 x i8] c"Error with matrix multiplication!\0A\00"
@str.6 = [5 x i8] c"Got:\00"
@str.7 = [10 x i8] c"Expected:\00"
define i32 @test_matrix() {
%1 = alloca [3 x [3 x double]]
%2 = alloca [3 x [3 x double]]
%3 = alloca [3 x [3 x double]]
%4 = alloca [3 x [3 x double]]
%5 = alloca [3 x [3 x double]]
%6 = bitcast [3 x [3 x double]]* %1 to i8*
%7 = bitcast [3 x [3 x double]]* %2 to i8*
%8 = bitcast [3 x [3 x double]]* %3 to i8*
%9 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 0, i64 0
store double 1.000000e+00, double* %9
%10 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 1, i64 1
store double 1.000000e+00, double* %10
%11 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 2, i64 2
store double 1.000000e+00, double* %11
%12 = bitcast [3 x [3 x double]]* %4 to i8*
%13 = bitcast [3 x [3 x double]]* %5 to i8*
%14 = bitcast [3 x [3 x double]]* %1 to double**
%15 = call double @mat3_det(double** %14)
%16 = fadd double %15, 1.000000e+00
%17 = call i32 @fabs(double %16)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %15)
br label %48
22: ; preds = %0
%23 = bitcast [3 x [3 x double]]* %4 to double**
%24 = call i32 @mat3_inv(double** %23, double** %14)
%25 = bitcast [3 x [3 x double]]* %2 to double**
%26 = call i64 @mat3_cmp(double** %23, double** %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.6, i64 0, i64 0))
%32 = call i32 @mat3_print(double** %23)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.7, i64 0, i64 0))
%34 = call i32 @mat3_print(double** %25)
br label %48
35: ; preds = %22
%36 = bitcast [3 x [3 x double]]* %5 to double**
%37 = call i32 @mat3_mul(double** %36, double** %14, double** %23)
%38 = bitcast [3 x [3 x double]]* %3 to double**
%39 = call i64 @mat3_cmp(double** %36, double** %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %48, label %41
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.6, i64 0, i64 0))
%45 = call i32 @mat3_print(double** %36)
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.7, i64 0, i64 0))
%47 = call i32 @mat3_print(double** %38)
br label %48
48: ; preds = %35, %41, %28, %19
%49 = phi i32 [ -1, %19 ], [ -1, %28 ], [ -1, %41 ], [ 0, %35 ]
ret i32 %49
}