#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 */
long RAND_MAX;
int /*<<< orphan*/ nr_copymat(double **, int, double **);
int /*<<< orphan*/ nr_free_matrix(double **, int, int, int, int);
int nr_gaussj(double **, int, int /*<<< orphan*/, int /*<<< orphan*/);
double **nr_matrix(int, int, int, int);
int /*<<< orphan*/ nr_multmat(double **, int, double **, double **);
int /*<<< orphan*/ nr_printmat(double **, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ rand();
void testmat(void) {
  double **mat1, **mat2, **mat3;
  double invmaxlong;
  int loop, i, j, n = 20;
  long maxlong = RAND_MAX;
  int maxloop = 2;
  invmaxlong = 1.0 / (double)maxlong;
  mat1 = nr_matrix(1, n, 1, n);
  mat2 = nr_matrix(1, n, 1, n);
  mat3 = nr_matrix(1, n, 1, n);
  for (loop = 0; loop < maxloop; loop++) {
    if (loop != 0)
      for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
          mat1[i][j] = 2.0 - 4.0 * invmaxlong * (double)rand();
    printf("Original matrix:\n");
    nr_printmat(mat1, n);
    nr_copymat(mat1, n, mat2);
    i = nr_gaussj(mat2, n, 0, 0);
    if (i)
      printf("Singular matrix.\n");
    printf("Inverted matrix:\n");
    nr_printmat(mat2, n);
    nr_multmat(mat1, n, mat2, mat3);
    printf("Original multiplied by inverse:\n");
    nr_printmat(mat3, n);
  }
  nr_free_matrix(mat1, 1, n, 1, n);
  nr_free_matrix(mat2, 1, n, 1, n);
  nr_free_matrix(mat3, 1, n, 1, n);
}


x86 assembly (clang, -O0):
<testmat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x14,-0x30(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
movl   $0x2,-0x3c(%rbp)
cvtsi2sdq -0x38(%rbp),%xmm1
movsd  0xe4e(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x30(%rbp),%esi
mov    -0x30(%rbp),%ecx
mov    $0x1,%edx
mov    %edx,%edi
call   1060 <nr_matrix@plt>
mov    %rax,-0x8(%rbp)
mov    -0x30(%rbp),%esi
mov    -0x30(%rbp),%ecx
mov    $0x1,%edx
mov    %edx,%edi
call   1060 <nr_matrix@plt>
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%esi
mov    -0x30(%rbp),%ecx
mov    $0x1,%edx
mov    %edx,%edi
call   1060 <nr_matrix@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1368 <testmat+0x1e8>
cmpl   $0x0,-0x24(%rbp)
je     12c5 <testmat+0x145>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     12c0 <testmat+0x140>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     12ad <testmat+0x12d>
movsd  0xdc8(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
movsd  -0x48(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd82(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1234 <testmat+0xb4>
jmp    12b2 <testmat+0x132>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1221 <testmat+0xa1>
jmp    12c5 <testmat+0x145>
lea    0xd4c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1070 <nr_printmat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1090 <nr_copymat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <nr_gaussj@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1316 <testmat+0x196>
lea    0xd19(%rip),%rdi
call   1030 <printf@plt>
lea    0xd1f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1070 <nr_printmat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <nr_multmat@plt>
lea    0xd05(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1070 <nr_printmat@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1204 <testmat+0x84>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x30(%rbp),%r8d
mov    $0x1,%ecx
mov    %ecx,%esi
call   1080 <nr_free_matrix@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x30(%rbp),%r8d
mov    $0x1,%ecx
mov    %ecx,%esi
call   1080 <nr_free_matrix@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x30(%rbp),%r8d
mov    $0x1,%ecx
mov    %ecx,%esi
call   1080 <nr_free_matrix@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testmat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e54(%rip),%rax
cvtsi2sdq (%rax),%xmm0
movsd  0xe5f(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    $0x1,%edi
mov    $0x14,%esi
mov    $0x1,%edx
mov    $0x14,%ecx
call   1060 <nr_matrix@plt>
mov    %rax,%r12
mov    $0x1,%edi
mov    $0x14,%esi
mov    $0x1,%edx
mov    $0x14,%ecx
call   1060 <nr_matrix@plt>
mov    %rax,%r14
mov    $0x1,%edi
mov    $0x14,%esi
mov    $0x1,%edx
mov    $0x14,%ecx
call   1060 <nr_matrix@plt>
mov    %rax,%r15
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    $0x14,%esi
call   1070 <nr_printmat@plt>
mov    %r12,%rdi
mov    $0x14,%esi
mov    %r14,%rdx
call   1090 <nr_copymat@plt>
mov    %r14,%rdi
mov    $0x14,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <nr_gaussj@plt>
test   %eax,%eax
je     1249 <testmat+0xc9>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
mulsd  0xdb1(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    $0x14,%esi
call   1070 <nr_printmat@plt>
mov    %r12,%rdi
mov    $0x14,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <nr_multmat@plt>
lea    0xdaa(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    $0x14,%esi
call   1070 <nr_printmat@plt>
mov    $0x1,%r13d
nopl   0x0(%rax,%rax,1)
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   10a0 <rand@plt>
movsd  0xd41(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
mov    (%r12,%r13,8),%rax
movsd  %xmm0,(%rax,%rbx,8)
add    $0x1,%rbx
cmp    $0x15,%rbx
jne    12c0 <testmat+0x140>
add    $0x1,%r13
cmp    $0x15,%r13
jne    12b0 <testmat+0x130>
lea    0xd13(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    $0x14,%esi
call   1070 <nr_printmat@plt>
mov    %r12,%rdi
mov    $0x14,%esi
mov    %r14,%rdx
call   1090 <nr_copymat@plt>
mov    %r14,%rdi
mov    $0x14,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <nr_gaussj@plt>
test   %eax,%eax
je     1348 <testmat+0x1c8>
lea    0xd17(%rip),%rdi
call   1030 <puts@plt>
lea    0xcda(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    $0x14,%esi
call   1070 <nr_printmat@plt>
mov    %r12,%rdi
mov    $0x14,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <nr_multmat@plt>
lea    0xcbf(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    $0x14,%esi
call   1070 <nr_printmat@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x14,%edx
mov    $0x1,%ecx
mov    $0x14,%r8d
call   1080 <nr_free_matrix@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x14,%edx
mov    $0x1,%ecx
mov    $0x14,%r8d
call   1080 <nr_free_matrix@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x14,%edx
mov    $0x1,%ecx
mov    $0x14,%r8d
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1080 <nr_free_matrix@plt>

LLVM IR (-O0):
@RAND_MAX = global i64 0
@.str = [18 x i8] c"Original matrix:\0A\00"
@.str.1 = [18 x i8] c"Singular matrix.\0A\00"
@.str.2 = [18 x i8] c"Inverted matrix:\0A\00"
@.str.3 = [33 x i8] c"Original multiplied by inverse:\0A\00"
define void @testmat() {
%1 = alloca double**
%2 = alloca double**
%3 = alloca double**
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
store i32 20, i32* %8
%11 = load i64, i64* @RAND_MAX
store i64 %11, i64* %9
store i32 2, i32* %10
%12 = load i64, i64* %9
%13 = sitofp i64 %12 to double
%14 = fdiv double 1.000000e+00, %13
store double %14, double* %4
%15 = load i32, i32* %8
%16 = load i32, i32* %8
%17 = call double** @nr_matrix(i32 1, i32 %15, i32 1, i32 %16)
store double** %17, double*** %1
%18 = load i32, i32* %8
%19 = load i32, i32* %8
%20 = call double** @nr_matrix(i32 1, i32 %18, i32 1, i32 %19)
store double** %20, double*** %2
%21 = load i32, i32* %8
%22 = load i32, i32* %8
%23 = call double** @nr_matrix(i32 1, i32 %21, i32 1, i32 %22)
store double** %23, double*** %3
store i32 0, i32* %5
br label %24
24: ; preds = %94, %0
%25 = load i32, i32* %5
%26 = load i32, i32* %10
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %97
28: ; preds = %24
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %64
31: ; preds = %28
store i32 1, i32* %6
br label %32
32: ; preds = %60, %31
%33 = load i32, i32* %6
%34 = load i32, i32* %8
%35 = icmp sle i32 %33, %34
br i1 %35, label %36, label %63
36: ; preds = %32
store i32 1, i32* %7
br label %37
37: ; preds = %56, %36
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = icmp sle i32 %38, %39
br i1 %40, label %41, label %59
41: ; preds = %37
%42 = load double, double* %4
%43 = fmul double 4.000000e+00, %42
%44 = call i64 (...) @rand()
%45 = sitofp i64 %44 to double
%46 = fneg double %43
%47 = call double @llvm.fmuladd.f64(double %46, double %45, double 2.000000e+00)
%48 = load double**, double*** %1
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double*, double** %48, i64 %50
%52 = load double*, double** %51
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
store double %47, double* %55
br label %56
56: ; preds = %41
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %37
59: ; preds = %37
br label %60
60: ; preds = %59
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %32
63: ; preds = %32
br label %64
64: ; preds = %63, %28
%65 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%66 = load double**, double*** %1
%67 = load i32, i32* %8
%68 = call i32 @nr_printmat(double** %66, i32 %67)
%69 = load double**, double*** %1
%70 = load i32, i32* %8
%71 = load double**, double*** %2
%72 = call i32 @nr_copymat(double** %69, i32 %70, double** %71)
%73 = load double**, double*** %2
%74 = load i32, i32* %8
%75 = call i32 @nr_gaussj(double** %73, i32 %74, i32 0, i32 0)
store i32 %75, i32* %6
%76 = load i32, i32* %6
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %64
%79 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %80
80: ; preds = %78, %64
%81 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%82 = load double**, double*** %2
%83 = load i32, i32* %8
%84 = call i32 @nr_printmat(double** %82, i32 %83)
%85 = load double**, double*** %1
%86 = load i32, i32* %8
%87 = load double**, double*** %2
%88 = load double**, double*** %3
%89 = call i32 @nr_multmat(double** %85, i32 %86, double** %87, double** %88)
%90 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%91 = load double**, double*** %3
%92 = load i32, i32* %8
%93 = call i32 @nr_printmat(double** %91, i32 %92)
br label %94
94: ; preds = %80
%95 = load i32, i32* %5
%96 = add nsw i32 %95, 1
store i32 %96, i32* %5
br label %24
97: ; preds = %24
%98 = load double**, double*** %1
%99 = load i32, i32* %8
%100 = load i32, i32* %8
%101 = call i32 @nr_free_matrix(double** %98, i32 1, i32 %99, i32 1, i32 %100)
%102 = load double**, double*** %2
%103 = load i32, i32* %8
%104 = load i32, i32* %8
%105 = call i32 @nr_free_matrix(double** %102, i32 1, i32 %103, i32 1, i32 %104)
%106 = load double**, double*** %3
%107 = load i32, i32* %8
%108 = load i32, i32* %8
%109 = call i32 @nr_free_matrix(double** %106, i32 1, i32 %107, i32 1, i32 %108)
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@str = [17 x i8] c"Original matrix:\00"
@str.4 = [17 x i8] c"Inverted matrix:\00"
@str.5 = [32 x i8] c"Original multiplied by inverse:\00"
@str.6 = [17 x i8] c"Singular matrix.\00"
define void @testmat() {
%1 = load i64, i64* @RAND_MAX
%2 = sitofp i64 %1 to double
%3 = fdiv double 1.000000e+00, %2
%4 = tail call double** @nr_matrix(i32 1, i32 20, i32 1, i32 20)
%5 = tail call double** @nr_matrix(i32 1, i32 20, i32 1, i32 20)
%6 = tail call double** @nr_matrix(i32 1, i32 20, i32 1, i32 20)
%7 = fmul double %3, -4.000000e+00
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @nr_printmat(double** %4, i32 20)
%10 = tail call i32 @nr_copymat(double** %4, i32 20, double** %5)
%11 = tail call i32 @nr_gaussj(double** %5, i32 20, i32 0, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
br label %15
15: ; preds = %0, %13
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
%17 = tail call i32 @nr_printmat(double** %5, i32 20)
%18 = tail call i32 @nr_multmat(double** %4, i32 20, double** %5, double** %6)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
%20 = tail call i32 @nr_printmat(double** %6, i32 20)
br label %21
21: ; preds = %33, %15
%22 = phi i64 [ 1, %15 ], [ %34, %33 ]
%23 = getelementptr inbounds double*, double** %4, i64 %22
br label %24
24: ; preds = %24, %21
%25 = phi i64 [ 1, %21 ], [ %31, %24 ]
%26 = tail call i64 (...) @rand()
%27 = sitofp i64 %26 to double
%28 = tail call double @llvm.fmuladd.f64(double %7, double %27, double 2.000000e+00)
%29 = load double*, double** %23
%30 = getelementptr inbounds double, double* %29, i64 %25
store double %28, double* %30
%31 = add nuw nsw i64 %25, 1
%32 = icmp eq i64 %31, 21
br i1 %32, label %33, label %24
33: ; preds = %24
%34 = add nuw nsw i64 %22, 1
%35 = icmp eq i64 %34, 21
br i1 %35, label %36, label %21
36: ; preds = %33
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%38 = tail call i32 @nr_printmat(double** %4, i32 20)
%39 = tail call i32 @nr_copymat(double** %4, i32 20, double** %5)
%40 = tail call i32 @nr_gaussj(double** %5, i32 20, i32 0, i32 0)
%41 = icmp eq i32 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %36
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
br label %44
44: ; preds = %42, %36
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
%46 = tail call i32 @nr_printmat(double** %5, i32 20)
%47 = tail call i32 @nr_multmat(double** %4, i32 20, double** %5, double** %6)
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
%49 = tail call i32 @nr_printmat(double** %6, i32 20)
%50 = tail call i32 @nr_free_matrix(double** %4, i32 1, i32 20, i32 1, i32 20)
%51 = tail call i32 @nr_free_matrix(double** %5, i32 1, i32 20, i32 1, i32 20)
%52 = tail call i32 @nr_free_matrix(double** %6, i32 1, i32 20, i32 1, i32 20)
ret void
}