void lsolve_dgesv(int n, double **a, double *b) {
  int nrhs = 1;
  int lda = n;
  int ldb = n;
  int info = 0;
  int *ipiv = (int *)malloc(n * sizeof(int));
  double *at = (double *)malloc(n * n * sizeof(double));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      at[i * n + j] = a[j][i];
  dgesv_(&n, &nrhs, at, &lda, ipiv, b, &ldb, &info);
  if (info != 0) {
    printf("Failed in %s\n", __func__);
  }
  free(at);
  at = 0;
  free(ipiv);
  ipiv = 0;
}


x86 assembly (clang, -O0):
<lsolve_dgesv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movslq -0x4(%rbp),%rdi
shl    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
movslq %eax,%rdi
shl    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1207 <lsolve_dgesv+0xc7>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f4 <lsolve_dgesv+0xb4>
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x40(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11af <lsolve_dgesv+0x6f>
jmp    11f9 <lsolve_dgesv+0xb9>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    119c <lsolve_dgesv+0x5c>
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    -0x4(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r10
lea    -0x28(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1050 <dgesv_@plt>
cmpl   $0x0,-0x28(%rbp)
je     1256 <lsolve_dgesv+0x116>
lea    0xdb8(%rip),%rdi
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lsolve_dgesv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x20(%rsp)
mov    %rsi,%rbx
mov    %edi,0x1c(%rsp)
movl   $0x1,0x18(%rsp)
mov    %edi,0x14(%rsp)
mov    %edi,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movslq %edi,%r13
lea    0x0(,%r13,4),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %r13d,%edi
imul   %edi,%edi
shl    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
test   %r13d,%r13d
jle    126d <lsolve_dgesv+0x12d>
mov    %r13d,%r9d
lea    -0x1(%r9),%r8
mov    %r9d,%edx
and    $0x3,%edx
mov    %r9d,%r11d
and    $0xfffffffc,%r11d
mov    %r12,%rdi
add    $0x18,%rdi
shl    $0x3,%r13
xor    %ecx,%ecx
mov    %r12,%r10
jmp    11e3 <lsolve_dgesv+0xa3>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rcx
add    %r13,%rdi
add    %r13,%r10
cmp    %r9,%rcx
je     126d <lsolve_dgesv+0x12d>
xor    %eax,%eax
cmp    $0x3,%r8
jb     1237 <lsolve_dgesv+0xf7>
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%rax,8),%rsi
movsd  (%rsi,%rcx,8),%xmm0
movsd  %xmm0,-0x18(%rdi,%rax,8)
mov    0x8(%rbx,%rax,8),%rsi
movsd  (%rsi,%rcx,8),%xmm0
movsd  %xmm0,-0x10(%rdi,%rax,8)
mov    0x10(%rbx,%rax,8),%rsi
movsd  (%rsi,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rdi,%rax,8)
mov    0x18(%rbx,%rax,8),%rsi
movsd  (%rsi,%rcx,8),%xmm0
movsd  %xmm0,(%rdi,%rax,8)
add    $0x4,%rax
cmp    %rax,%r11
jne    11f0 <lsolve_dgesv+0xb0>
test   %rdx,%rdx
je     11d0 <lsolve_dgesv+0x90>
lea    (%r10,%rax,8),%rsi
lea    (%rbx,%rax,8),%rax
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%rax,%rbp,8),%r14
movsd  (%r14,%rcx,8),%xmm0
movsd  %xmm0,(%rsi,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rdx
jne    1250 <lsolve_dgesv+0x110>
jmp    11d0 <lsolve_dgesv+0x90>
lea    0xc(%rsp),%rbp
lea    0x10(%rsp),%rbx
lea    0x1c(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rcx
mov    %r12,%rdx
mov    %r15,%r8
mov    0x20(%rsp),%r9
xor    %eax,%eax
push   %rbp
push   %rbx
call   1050 <dgesv_@plt>
add    $0x10,%rsp
cmpl   $0x0,0xc(%rsp)
je     12ba <lsolve_dgesv+0x17a>
lea    0xd54(%rip),%rdi
lea    0xd5b(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"Failed in %s\0A\00"
@__func__.lsolve_dgesv = [13 x i8] c"lsolve_dgesv\00"
define void @lsolve_dgesv(i32 %0, double** nocapture %1, double* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%10 = bitcast i32* %6 to i8*
store i32 %0, i32* %6
%11 = bitcast i32* %7 to i8*
store i32 %0, i32* %7
%12 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%13 = sext i32 %0 to i64
%14 = shl nsw i64 %13, 2
%15 = tail call i8* @malloc(i64 %14)
%16 = bitcast i8* %15 to i32*
%17 = mul nsw i32 %0, %0
%18 = zext i32 %17 to i64
%19 = shl nuw nsw i64 %18, 3
%20 = tail call i8* @malloc(i64 %19)
%21 = bitcast i8* %20 to double*
%22 = icmp sgt i32 %0, 0
br i1 %22, label %23, label %33
23: ; preds = %3
%24 = zext i32 %0 to i64
%25 = add nsw i64 %24, -1
%26 = and i64 %24, 3
%27 = icmp ult i64 %25, 3
%28 = and i64 %24, 4294967292
%29 = icmp eq i64 %26, 0
br label %30
30: ; preds = %51, %23
%31 = phi i64 [ 0, %23 ], [ %52, %51 ]
%32 = mul nsw i64 %31, %13
br i1 %27, label %37, label %54
33: ; preds = %51, %3
%34 = call i32 (i32*, i32*, double*, i32*, i32*, double*, i32*, i32*, ...) bitcast (i32 (...)* @dgesv_ to i32 (i32*, i32*, double*, i32*, i32*, double*, i32*, i32*, ...)*)(i32* %4, i32* %5, double* %21, i32* %6, i32* %16, double* %2, i32* %7, i32* %8)
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, 0
br i1 %36, label %89, label %87
37: ; preds = %54, %30
%38 = phi i64 [ 0, %30 ], [ %84, %54 ]
br i1 %29, label %51, label %39
39: ; preds = %37, %39
%40 = phi i64 [ %48, %39 ], [ %38, %37 ]
%41 = phi i64 [ %49, %39 ], [ 0, %37 ]
%42 = getelementptr inbounds double*, double** %1, i64 %40
%43 = load double*, double** %42
%44 = getelementptr inbounds double, double* %43, i64 %31
%45 = load double, double* %44
%46 = add nsw i64 %40, %32
%47 = getelementptr inbounds double, double* %21, i64 %46
store double %45, double* %47
%48 = add nuw nsw i64 %40, 1
%49 = add i64 %41, 1
%50 = icmp eq i64 %49, %26
br i1 %50, label %51, label %39
51: ; preds = %39, %37
%52 = add nuw nsw i64 %31, 1
%53 = icmp eq i64 %52, %24
br i1 %53, label %33, label %30
54: ; preds = %30, %54
%55 = phi i64 [ %84, %54 ], [ 0, %30 ]
%56 = phi i64 [ %85, %54 ], [ 0, %30 ]
%57 = getelementptr inbounds double*, double** %1, i64 %55
%58 = load double*, double** %57
%59 = getelementptr inbounds double, double* %58, i64 %31
%60 = load double, double* %59
%61 = add nsw i64 %55, %32
%62 = getelementptr inbounds double, double* %21, i64 %61
store double %60, double* %62
%63 = or i64 %55, 1
%64 = getelementptr inbounds double*, double** %1, i64 %63
%65 = load double*, double** %64
%66 = getelementptr inbounds double, double* %65, i64 %31
%67 = load double, double* %66
%68 = add nsw i64 %63, %32
%69 = getelementptr inbounds double, double* %21, i64 %68
store double %67, double* %69
%70 = or i64 %55, 2
%71 = getelementptr inbounds double*, double** %1, i64 %70
%72 = load double*, double** %71
%73 = getelementptr inbounds double, double* %72, i64 %31
%74 = load double, double* %73
%75 = add nsw i64 %70, %32
%76 = getelementptr inbounds double, double* %21, i64 %75
store double %74, double* %76
%77 = or i64 %55, 3
%78 = getelementptr inbounds double*, double** %1, i64 %77
%79 = load double*, double** %78
%80 = getelementptr inbounds double, double* %79, i64 %31
%81 = load double, double* %80
%82 = add nsw i64 %77, %32
%83 = getelementptr inbounds double, double* %21, i64 %82
store double %81, double* %83
%84 = add nuw nsw i64 %55, 4
%85 = add i64 %56, 4
%86 = icmp eq i64 %85, %28
br i1 %86, label %37, label %54
87: ; preds = %33
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__func__.lsolve_dgesv, i64 0, i64 0))
br label %89
89: ; preds = %87, %33
ret void
}