int lapack_square_inverse(double *Ai, long m_long, double *A) {
  int m;
  int info = make_int(&m, m_long);
  if (info != 0)
    return 1;
  int i = 0;
  for (i = 0; i < m * m; ++i)
    Ai[i] = A[i];
  int *ipiv = (int *)malloc(m * sizeof(int));
  dgetrf_(&m, &m, Ai, &m, ipiv, &info);
  if (info != 0) {
    free(ipiv);
    return 2;
  }
  int NB = 8;
  int lwork = m * NB;
  double *work = (double *)malloc(lwork * sizeof(double));
  dgetri_(&m, Ai, &m, ipiv, work, &lwork, &info);
  free(ipiv);
  free(work);
  if (info != 0)
    return 3;
  return 0;
}


x86 assembly (clang, -O0):
<lapack_square_inverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x24(%rbp),%rdi
mov    $0x0,%al
call   1040 <make_int@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     118c <lapack_square_inverse+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    1298 <lapack_square_inverse+0x148>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    11d4 <lapack_square_inverse+0x84>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119a <lapack_square_inverse+0x4a>
movslq -0x24(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x38(%rbp),%r8
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r9
mov    %rcx,%rdi
mov    %rcx,%rsi
mov    $0x0,%al
call   1070 <dgetrf_@plt>
cmpl   $0x0,-0x28(%rbp)
je     1221 <lapack_square_inverse+0xd1>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x2,-0x4(%rbp)
jmp    1298 <lapack_square_inverse+0x148>
movl   $0x8,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
movslq -0x40(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rcx
mov    -0x48(%rbp),%r8
lea    -0x24(%rbp),%rdx
lea    -0x40(%rbp),%r9
lea    -0x28(%rbp),%rax
mov    %rdx,%rdi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1060 <dgetri_@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x28(%rbp)
je     1291 <lapack_square_inverse+0x141>
movl   $0x3,-0x4(%rbp)
jmp    1298 <lapack_square_inverse+0x148>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lapack_square_inverse>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rdi,%r14
lea    0xc(%rsp),%rdi
xor    %eax,%eax
call   1040 <make_int@plt>
mov    %eax,%ecx
mov    %eax,0x10(%rsp)
mov    $0x1,%eax
test   %ecx,%ecx
jne    13a0 <lapack_square_inverse+0x250>
movslq 0xc(%rsp),%rdi
mov    %edi,%eax
imul   %edi,%eax
test   %eax,%eax
je     1304 <lapack_square_inverse+0x1b4>
mov    %eax,%r9d
cmp    $0x4,%eax
jb     11b4 <lapack_square_inverse+0x64>
lea    (%rbx,%r9,8),%rax
cmp    %r14,%rax
jbe    1230 <lapack_square_inverse+0xe0>
lea    (%r14,%r9,8),%rax
cmp    %rbx,%rax
jbe    1230 <lapack_square_inverse+0xe0>
xor    %ecx,%ecx
mov    %rcx,%rdx
not    %rdx
add    %r9,%rdx
mov    %r9,%rsi
and    $0x3,%rsi
je     11e5 <lapack_square_inverse+0x95>
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,(%r14,%rcx,8)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
jne    11d0 <lapack_square_inverse+0x80>
cmp    $0x3,%rdx
jb     1304 <lapack_square_inverse+0x1b4>
nop
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,(%r14,%rcx,8)
movsd  0x8(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x8(%r14,%rcx,8)
movsd  0x10(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x10(%r14,%rcx,8)
movsd  0x18(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x18(%r14,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%r9
jne    11f0 <lapack_square_inverse+0xa0>
jmp    1304 <lapack_square_inverse+0x1b4>
mov    %r9d,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rax
mov    %rax,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %esi,%r8d
and    $0x3,%r8d
cmp    $0xc,%rax
jae    1256 <lapack_square_inverse+0x106>
xor    %edx,%edx
jmp    12c0 <lapack_square_inverse+0x170>
and    $0xfffffffffffffffc,%rsi
xor    %edx,%edx
nopl   0x0(%rax)
movups (%rbx,%rdx,8),%xmm0
movups 0x10(%rbx,%rdx,8),%xmm1
movups %xmm0,(%r14,%rdx,8)
movups %xmm1,0x10(%r14,%rdx,8)
movups 0x20(%rbx,%rdx,8),%xmm0
movups 0x30(%rbx,%rdx,8),%xmm1
movups %xmm0,0x20(%r14,%rdx,8)
movups %xmm1,0x30(%r14,%rdx,8)
movups 0x40(%rbx,%rdx,8),%xmm0
movups 0x50(%rbx,%rdx,8),%xmm1
movups %xmm0,0x40(%r14,%rdx,8)
movups %xmm1,0x50(%r14,%rdx,8)
movups 0x60(%rbx,%rdx,8),%xmm0
movups 0x70(%rbx,%rdx,8),%xmm1
movups %xmm0,0x60(%r14,%rdx,8)
movups %xmm1,0x70(%r14,%rdx,8)
add    $0x10,%rdx
add    $0xfffffffffffffffc,%rsi
jne    1260 <lapack_square_inverse+0x110>
test   %r8,%r8
je     12fb <lapack_square_inverse+0x1ab>
lea    (%r14,%rdx,8),%rsi
add    $0x10,%rsi
lea    (%rbx,%rdx,8),%rdx
add    $0x10,%rdx
shl    $0x5,%r8
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movups -0x10(%rdx,%rax,1),%xmm0
movups (%rdx,%rax,1),%xmm1
movups %xmm0,-0x10(%rsi,%rax,1)
movups %xmm1,(%rsi,%rax,1)
add    $0x20,%rax
cmp    %rax,%r8
jne    12e0 <lapack_square_inverse+0x190>
cmp    %r9,%rcx
jne    11b6 <lapack_square_inverse+0x66>
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r15
mov    %rcx,%rdi
mov    %rcx,%rsi
mov    %r14,%rdx
mov    %rax,%r8
mov    %r15,%r9
xor    %eax,%eax
call   1070 <dgetrf_@plt>
cmpl   $0x0,0x10(%rsp)
je     1346 <lapack_square_inverse+0x1f6>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x2,%eax
jmp    13a0 <lapack_square_inverse+0x250>
movslq 0xc(%rsp),%rdi
lea    0x0(,%rdi,8),%eax
mov    %eax,0x14(%rsp)
shl    $0x6,%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %r15,(%rsp)
lea    0xc(%rsp),%rdi
lea    0x14(%rsp),%r9
mov    %r14,%rsi
mov    %rdi,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <dgetri_@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
cmpl   $0x0,0x10(%rsp)
setne  %al
lea    (%rax,%rax,2),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @lapack_square_inverse(double* %0, i64 %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i64
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca double*
store double* %0, double** %5
store i64 %1, i64* %6
store double* %2, double** %7
%15 = load i64, i64* %6
%16 = call i32 (i32*, i64, ...) bitcast (i32 (...)* @make_int to i32 (i32*, i64, ...)*)(i32* %8, i64 %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 1, i32* %4
br label %75
20: ; preds = %3
store i32 0, i32* %10
store i32 0, i32* %10
br label %21
21: ; preds = %37, %20
%22 = load i32, i32* %10
%23 = load i32, i32* %8
%24 = load i32, i32* %8
%25 = mul nsw i32 %23, %24
%26 = icmp slt i32 %22, %25
br i1 %26, label %27, label %40
27: ; preds = %21
%28 = load double*, double** %7
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load double*, double** %5
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
store double %32, double* %36
br label %37
37: ; preds = %27
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %21
40: ; preds = %21
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 4
%44 = call i8* @malloc(i64 %43)
%45 = bitcast i8* %44 to i32*
store i32* %45, i32** %11
%46 = load double*, double** %5
%47 = load i32*, i32** %11
%48 = call i32 (i32*, i32*, double*, i32*, i32*, i32*, ...) bitcast (i32 (...)* @dgetrf_ to i32 (i32*, i32*, double*, i32*, i32*, i32*, ...)*)(i32* %8, i32* %8, double* %46, i32* %8, i32* %47, i32* %9)
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %40
%52 = load i32*, i32** %11
%53 = bitcast i32* %52 to i8*
store i32 2, i32* %4
br label %75
54: ; preds = %40
store i32 8, i32* %12
%55 = load i32, i32* %8
%56 = load i32, i32* %12
%57 = mul nsw i32 %55, %56
store i32 %57, i32* %13
%58 = load i32, i32* %13
%59 = sext i32 %58 to i64
%60 = mul i64 %59, 8
%61 = call i8* @malloc(i64 %60)
%62 = bitcast i8* %61 to double*
store double* %62, double** %14
%63 = load double*, double** %5
%64 = load i32*, i32** %11
%65 = load double*, double** %14
%66 = call i32 (i32*, double*, i32*, i32*, double*, i32*, i32*, ...) bitcast (i32 (...)* @dgetri_ to i32 (i32*, double*, i32*, i32*, double*, i32*, i32*, ...)*)(i32* %8, double* %63, i32* %8, i32* %64, double* %65, i32* %13, i32* %9)
%67 = load i32*, i32** %11
%68 = bitcast i32* %67 to i8*
%69 = load double*, double** %14
%70 = bitcast double* %69 to i8*
%71 = load i32, i32* %9
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %54
store i32 3, i32* %4
br label %75
74: ; preds = %54
store i32 0, i32* %4
br label %75
75: ; preds = %74, %73, %51, %19
%76 = load i32, i32* %4
ret i32 %76
}

LLVM IR (-O2):
define i32 @lapack_square_inverse(double* %0, i64 %1, double* nocapture %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = call i32 (i32*, i64, ...) bitcast (i32 (...)* @make_int to i32 (i32*, i64, ...)*)(i32* %4, i64 %1)
store i32 %9, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %161
11: ; preds = %3
%12 = load i32, i32* %4
%13 = mul i32 %12, %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %140, label %15
15: ; preds = %11
%16 = zext i32 %13 to i64
%17 = icmp ult i32 %13, 4
br i1 %17, label %103, label %18
18: ; preds = %15
%19 = getelementptr double, double* %0, i64 %16
%20 = getelementptr double, double* %2, i64 %16
%21 = icmp ugt double* %20, %0
%22 = icmp ugt double* %19, %2
%23 = and i1 %21, %22
br i1 %23, label %103, label %24
24: ; preds = %18
%25 = and i64 %16, 4294967292
%26 = add nsw i64 %25, -4
%27 = lshr exact i64 %26, 2
%28 = add nuw nsw i64 %27, 1
%29 = and i64 %28, 3
%30 = icmp ult i64 %26, 12
br i1 %30, label %82, label %31
31: ; preds = %24
%32 = and i64 %28, 9223372036854775804
br label %33
33: ; preds = %33, %31
%34 = phi i64 [ 0, %31 ], [ %79, %33 ]
%35 = phi i64 [ 0, %31 ], [ %80, %33 ]
%36 = getelementptr inbounds double, double* %2, i64 %34
%37 = bitcast double* %36 to <2 x double>*
%38 = load <2 x double>, <2 x double>* %37
%39 = getelementptr inbounds double, double* %36, i64 2
%40 = bitcast double* %39 to <2 x double>*
%41 = load <2 x double>, <2 x double>* %40
%42 = getelementptr inbounds double, double* %0, i64 %34
%43 = bitcast double* %42 to <2 x double>*
store <2 x double> %38, <2 x double>* %43
%44 = getelementptr inbounds double, double* %42, i64 2
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> %41, <2 x double>* %45
%46 = or i64 %34, 4
%47 = getelementptr inbounds double, double* %2, i64 %46
%48 = bitcast double* %47 to <2 x double>*
%49 = load <2 x double>, <2 x double>* %48
%50 = getelementptr inbounds double, double* %47, i64 2
%51 = bitcast double* %50 to <2 x double>*
%52 = load <2 x double>, <2 x double>* %51
%53 = getelementptr inbounds double, double* %0, i64 %46
%54 = bitcast double* %53 to <2 x double>*
store <2 x double> %49, <2 x double>* %54
%55 = getelementptr inbounds double, double* %53, i64 2
%56 = bitcast double* %55 to <2 x double>*
store <2 x double> %52, <2 x double>* %56
%57 = or i64 %34, 8
%58 = getelementptr inbounds double, double* %2, i64 %57
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = getelementptr inbounds double, double* %58, i64 2
%62 = bitcast double* %61 to <2 x double>*
%63 = load <2 x double>, <2 x double>* %62
%64 = getelementptr inbounds double, double* %0, i64 %57
%65 = bitcast double* %64 to <2 x double>*
store <2 x double> %60, <2 x double>* %65
%66 = getelementptr inbounds double, double* %64, i64 2
%67 = bitcast double* %66 to <2 x double>*
store <2 x double> %63, <2 x double>* %67
%68 = or i64 %34, 12
%69 = getelementptr inbounds double, double* %2, i64 %68
%70 = bitcast double* %69 to <2 x double>*
%71 = load <2 x double>, <2 x double>* %70
%72 = getelementptr inbounds double, double* %69, i64 2
%73 = bitcast double* %72 to <2 x double>*
%74 = load <2 x double>, <2 x double>* %73
%75 = getelementptr inbounds double, double* %0, i64 %68
%76 = bitcast double* %75 to <2 x double>*
store <2 x double> %71, <2 x double>* %76
%77 = getelementptr inbounds double, double* %75, i64 2
%78 = bitcast double* %77 to <2 x double>*
store <2 x double> %74, <2 x double>* %78
%79 = add nuw i64 %34, 16
%80 = add nuw i64 %35, 4
%81 = icmp eq i64 %80, %32
br i1 %81, label %82, label %33
82: ; preds = %33, %24
%83 = phi i64 [ 0, %24 ], [ %79, %33 ]
%84 = icmp eq i64 %29, 0
br i1 %84, label %101, label %85
85: ; preds = %82, %85
%86 = phi i64 [ %98, %85 ], [ %83, %82 ]
%87 = phi i64 [ %99, %85 ], [ 0, %82 ]
%88 = getelementptr inbounds double, double* %2, i64 %86
%89 = bitcast double* %88 to <2 x double>*
%90 = load <2 x double>, <2 x double>* %89
%91 = getelementptr inbounds double, double* %88, i64 2
%92 = bitcast double* %91 to <2 x double>*
%93 = load <2 x double>, <2 x double>* %92
%94 = getelementptr inbounds double, double* %0, i64 %86
%95 = bitcast double* %94 to <2 x double>*
store <2 x double> %90, <2 x double>* %95
%96 = getelementptr inbounds double, double* %94, i64 2
%97 = bitcast double* %96 to <2 x double>*
store <2 x double> %93, <2 x double>* %97
%98 = add nuw i64 %86, 4
%99 = add i64 %87, 1
%100 = icmp eq i64 %99, %29
br i1 %100, label %101, label %85
101: ; preds = %85, %82
%102 = icmp eq i64 %25, %16
br i1 %102, label %140, label %103
103: ; preds = %18, %15, %101
%104 = phi i64 [ 0, %18 ], [ 0, %15 ], [ %25, %101 ]
%105 = xor i64 %104, -1
%106 = add nsw i64 %105, %16
%107 = and i64 %16, 3
%108 = icmp eq i64 %107, 0
br i1 %108, label %118, label %109
109: ; preds = %103, %109
%110 = phi i64 [ %115, %109 ], [ %104, %103 ]
%111 = phi i64 [ %116, %109 ], [ 0, %103 ]
%112 = getelementptr inbounds double, double* %2, i64 %110
%113 = load double, double* %112
%114 = getelementptr inbounds double, double* %0, i64 %110
store double %113, double* %114
%115 = add nuw nsw i64 %110, 1
%116 = add i64 %111, 1
%117 = icmp eq i64 %116, %107
br i1 %117, label %118, label %109
118: ; preds = %109, %103
%119 = phi i64 [ %104, %103 ], [ %115, %109 ]
%120 = icmp ult i64 %106, 3
br i1 %120, label %140, label %121
121: ; preds = %118, %121
%122 = phi i64 [ %138, %121 ], [ %119, %118 ]
%123 = getelementptr inbounds double, double* %2, i64 %122
%124 = load double, double* %123
%125 = getelementptr inbounds double, double* %0, i64 %122
store double %124, double* %125
%126 = add nuw nsw i64 %122, 1
%127 = getelementptr inbounds double, double* %2, i64 %126
%128 = load double, double* %127
%129 = getelementptr inbounds double, double* %0, i64 %126
store double %128, double* %129
%130 = add nuw nsw i64 %122, 2
%131 = getelementptr inbounds double, double* %2, i64 %130
%132 = load double, double* %131
%133 = getelementptr inbounds double, double* %0, i64 %130
store double %132, double* %133
%134 = add nuw nsw i64 %122, 3
%135 = getelementptr inbounds double, double* %2, i64 %134
%136 = load double, double* %135
%137 = getelementptr inbounds double, double* %0, i64 %134
store double %136, double* %137
%138 = add nuw nsw i64 %122, 4
%139 = icmp eq i64 %138, %16
br i1 %139, label %140, label %121
140: ; preds = %118, %121, %101, %11
%141 = sext i32 %12 to i64
%142 = shl nsw i64 %141, 2
%143 = call i8* @malloc(i64 %142)
%144 = bitcast i8* %143 to i32*
%145 = call i32 (i32*, i32*, double*, i32*, i32*, i32*, ...) bitcast (i32 (...)* @dgetrf_ to i32 (i32*, i32*, double*, i32*, i32*, i32*, ...)*)(i32* %4, i32* %4, double* %0, i32* %4, i32* %144, i32* %5)
%146 = load i32, i32* %5
%147 = icmp eq i32 %146, 0
br i1 %147, label %149, label %148
148: ; preds = %140
br label %161
149: ; preds = %140
%150 = bitcast i32* %6 to i8*
%151 = load i32, i32* %4
%152 = shl nsw i32 %151, 3
store i32 %152, i32* %6
%153 = sext i32 %152 to i64
%154 = shl nsw i64 %153, 3
%155 = call i8* @malloc(i64 %154)
%156 = bitcast i8* %155 to double*
%157 = call i32 (i32*, double*, i32*, i32*, double*, i32*, i32*, ...) bitcast (i32 (...)* @dgetri_ to i32 (i32*, double*, i32*, i32*, double*, i32*, i32*, ...)*)(i32* %4, double* %0, i32* %4, i32* %144, double* %156, i32* %6, i32* %5)
%158 = load i32, i32* %5
%159 = icmp eq i32 %158, 0
%160 = select i1 %159, i32 0, i32 3
br label %161
161: ; preds = %148, %149, %3
%162 = phi i32 [ 1, %3 ], [ 2, %148 ], [ %160, %149 ]
ret i32 %162
}