#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 *alloc_memory(int);
int /*<<< orphan*/ dgetrf(int, int, double *, int, int *, int *);
int /*<<< orphan*/ dgetri(int, double *, int, int *, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ stderr;
void invert_double_matrix(double *matrix, int dim) {
  int info;
  int *pivots = alloc_memory(sizeof(int) * dim);
  dgetrf(dim, dim, matrix, dim, pivots, &info);
  if (info != 0) {
    fprintf(stderr, "DGETRF error, INFO == %d\n", info);
  }
  dgetri(dim, matrix, dim, pivots, &info);
  if (info != 0) {
    fprintf(stderr, "DGETRI error, INFO == %d\n", info);
  }
  free(pivots);
}


x86 assembly (clang, -O0):
<invert_double_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <alloc_memory@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8
lea    -0x10(%rbp),%r9
call   1040 <dgetrf@plt>
cmpl   $0x0,-0x10(%rbp)
je     11ae <invert_double_matrix+0x5e>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1060 <dgetri@plt>
cmpl   $0x0,-0x10(%rbp)
je     11e7 <invert_double_matrix+0x97>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invert_double_matrix>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
lea    0x0(,%rbx,4),%edi
call   1070 <alloc_memory@plt>
mov    %rax,%r14
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    %ebx,%esi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %rax,%r8
call   1040 <dgetrf@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
je     11a0 <invert_double_matrix+0x50>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xc(%rsp),%r8
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %r14,%rcx
call   1060 <dgetri@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
je     11d1 <invert_double_matrix+0x81>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"DGETRF error, INFO == %d\0A\00"
@.str.1 = [26 x i8] c"DGETRI error, INFO == %d\0A\00"
define void @invert_double_matrix(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store double* %0, double** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = trunc i64 %9 to i32
%11 = call i32* @alloc_memory(i32 %10)
store i32* %11, i32** %6
%12 = load i32, i32* %4
%13 = load i32, i32* %4
%14 = load double*, double** %3
%15 = load i32, i32* %4
%16 = load i32*, i32** %6
%17 = call i32 @dgetrf(i32 %12, i32 %13, double* %14, i32 %15, i32* %16, i32* %5)
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i32, i32* %5
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %20, %2
%25 = load i32, i32* %4
%26 = load double*, double** %3
%27 = load i32, i32* %4
%28 = load i32*, i32** %6
%29 = call i32 @dgetri(i32 %25, double* %26, i32 %27, i32* %28, i32* %5)
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %24
%33 = load i32, i32* @stderr
%34 = load i32, i32* %5
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %32, %24
%37 = load i32*, i32** %6
%38 = call i32 @free(i32* %37)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"DGETRF error, INFO == %d\0A\00"
@.str.1 = [26 x i8] c"DGETRI error, INFO == %d\0A\00"
define void @invert_double_matrix(double* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = shl i32 %1, 2
%6 = tail call i32* @alloc_memory(i32 %5)
%7 = call i32 @dgetrf(i32 %1, i32 %1, double* %0, i32 %1, i32* %6, i32* %3)
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %13
13: ; preds = %10, %2
%14 = call i32 @dgetri(i32 %1, double* %0, i32 %1, i32* %6, i32* %3)
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %20
20: ; preds = %17, %13
%21 = call i32 @free(i32* %6)
ret void
}