double *inverse(double *a, int size) {
  int *ipiv = malloc((size + 1) * sizeof(int));
  int lwork = size * size;
  double *work = malloc(lwork * sizeof(double));
  int info;
  dgetrf_(&size, &size, a, &size, ipiv, &info);
  dgetri_(&size, a, &size, ipiv, work, &lwork, &info);
  free(ipiv);
  free(work);
  return a;
}


x86 assembly (clang, -O0):
<inverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
shl    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%r8
lea    -0xc(%rbp),%rcx
lea    -0x2c(%rbp),%r9
mov    %rcx,%rdi
mov    %rcx,%rsi
mov    $0x0,%al
call   1060 <dgetrf_@plt>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    -0xc(%rbp),%rdx
lea    -0x1c(%rbp),%r9
lea    -0x2c(%rbp),%rax
mov    %rdx,%rdi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1050 <dgetri_@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inverse>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
mov    %esi,0x18(%rsp)
movslq %esi,%rbx
lea    0x4(,%rbx,4),%rdi
call   1040 <malloc@plt>
mov    %rax,%r12
imul   %ebx,%ebx
mov    %ebx,0x14(%rsp)
shl    $0x3,%rbx
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,%r15
lea    0x18(%rsp),%rbx
lea    0x1c(%rsp),%r13
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
mov    %r13,%r9
xor    %eax,%eax
call   1060 <dgetrf_@plt>
mov    %r13,(%rsp)
lea    0x14(%rsp),%r9
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1050 <dgetri_@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @inverse(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = call i8* @malloc(i64 %12)
%14 = bitcast i8* %13 to i32*
store i32* %14, i32** %5
%15 = load i32, i32* %4
%16 = load i32, i32* %4
%17 = mul nsw i32 %15, %16
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = call i8* @malloc(i64 %20)
%22 = bitcast i8* %21 to double*
store double* %22, double** %7
%23 = load double*, double** %3
%24 = load i32*, i32** %5
%25 = call i32 (i32*, i32*, double*, i32*, i32*, i32*, ...) bitcast (i32 (...)* @dgetrf_ to i32 (i32*, i32*, double*, i32*, i32*, i32*, ...)*)(i32* %4, i32* %4, double* %23, i32* %4, i32* %24, i32* %8)
%26 = load double*, double** %3
%27 = load i32*, i32** %5
%28 = load double*, double** %7
%29 = call i32 (i32*, double*, i32*, i32*, double*, i32*, i32*, ...) bitcast (i32 (...)* @dgetri_ to i32 (i32*, double*, i32*, i32*, double*, i32*, i32*, ...)*)(i32* %4, double* %26, i32* %4, i32* %27, double* %28, i32* %6, i32* %8)
%30 = load i32*, i32** %5
%31 = bitcast i32* %30 to i8*
%32 = load double*, double** %7
%33 = bitcast double* %32 to i8*
%34 = load double*, double** %3
ret double* %34
}

LLVM IR (-O2):
define double* @inverse(double* returned %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %1, i32* %3
%6 = add nsw i32 %1, 1
%7 = sext i32 %6 to i64
%8 = shl nsw i64 %7, 2
%9 = tail call i8* @malloc(i64 %8)
%10 = bitcast i8* %9 to i32*
%11 = bitcast i32* %4 to i8*
%12 = mul nsw i32 %1, %1
store i32 %12, i32* %4
%13 = zext i32 %12 to i64
%14 = shl nuw nsw i64 %13, 3
%15 = tail call i8* @malloc(i64 %14)
%16 = bitcast i8* %15 to double*
%17 = bitcast i32* %5 to i8*
%18 = call i32 (i32*, i32*, double*, i32*, i32*, i32*, ...) bitcast (i32 (...)* @dgetrf_ to i32 (i32*, i32*, double*, i32*, i32*, i32*, ...)*)(i32* %3, i32* %3, double* %0, i32* %3, i32* %10, i32* %5)
%19 = call i32 (i32*, double*, i32*, i32*, double*, i32*, i32*, ...) bitcast (i32 (...)* @dgetri_ to i32 (i32*, double*, i32*, i32*, double*, i32*, i32*, ...)*)(i32* %3, double* %0, i32* %3, i32* %10, double* %16, i32* %4, i32* %5)
ret double* %0
}