#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 /*<<< orphan*/ abort();
int /*<<< orphan*/ dgetri_(int *, double *, int *, int *, double *, int *,
                           int *);
int /*<<< orphan*/ free(double *);
double *malloc(int);
double *realloc(double *, int);
void dgetri(int n, double *a, int lda, int *ipiv, int *info) {
  int lwork = -1;
  double *work = malloc(sizeof(double));
  if (NULL == work) {
    abort();
  }
  dgetri_(&n, a, &lda, ipiv, work, &lwork, info);
  lwork = (int)work[0];
  work = realloc(work, sizeof(double) * lwork);
  if (NULL == work) {
    abort();
  }
  dgetri_(&n, a, &lda, ipiv, work, &lwork, info);
  free(work);
}


x86 assembly (clang, -O0):
<dgetri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    1192 <dgetri+0x42>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x28(%rbp),%rax
lea    -0x4(%rbp),%rdi
lea    -0x14(%rbp),%rdx
lea    -0x2c(%rbp),%r9
mov    %rax,(%rsp)
call   1060 <dgetri_@plt>
mov    -0x38(%rbp),%rax
cvttsd2si (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    11ec <dgetri+0x9c>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x28(%rbp),%rax
lea    -0x4(%rbp),%rdi
lea    -0x14(%rbp),%rdx
lea    -0x2c(%rbp),%r9
mov    %rax,(%rsp)
call   1060 <dgetri_@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dgetri>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r12
mov    %rcx,%r14
mov    %rsi,%r15
mov    %edi,0x14(%rsp)
mov    %edx,0x10(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
mov    $0x8,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11f7 <dgetri+0xa7>
mov    %rax,%rbx
mov    %r12,(%rsp)
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%r9
mov    %r15,%rsi
mov    %r14,%rcx
mov    %rax,%r8
call   1060 <dgetri_@plt>
cvttsd2si (%rbx),%esi
mov    %esi,0xc(%rsp)
shl    $0x3,%esi
mov    %rbx,%rdi
call   1070 <realloc@plt>
test   %rax,%rax
je     11f7 <dgetri+0xa7>
mov    %rax,%rbx
mov    %r12,(%rsp)
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%r9
mov    %r15,%rsi
mov    %r14,%rcx
mov    %rax,%r8
call   1060 <dgetri_@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
define void @dgetri(i32 %0, double* %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca double*
store i32 %0, i32* %6
store double* %1, double** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
store i32 -1, i32* %11
%13 = call double* @malloc(i32 8)
store double* %13, double** %12
%14 = load double*, double** %12
%15 = icmp eq double* null, %14
br i1 %15, label %16, label %18
16: ; preds = %5
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %5
%19 = load double*, double** %7
%20 = load i32*, i32** %9
%21 = load double*, double** %12
%22 = load i32*, i32** %10
%23 = call i32 @dgetri_(i32* %6, double* %19, i32* %8, i32* %20, double* %21, i32* %11, i32* %22)
%24 = load double*, double** %12
%25 = getelementptr inbounds double, double* %24, i64 0
%26 = load double, double* %25
%27 = fptosi double %26 to i32
store i32 %27, i32* %11
%28 = load double*, double** %12
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = mul i64 8, %30
%32 = trunc i64 %31 to i32
%33 = call double* @realloc(double* %28, i32 %32)
store double* %33, double** %12
%34 = load double*, double** %12
%35 = icmp eq double* null, %34
br i1 %35, label %36, label %38
36: ; preds = %18
%37 = call i32 (...) @abort()
unreachable
38: ; preds = %18
%39 = load double*, double** %7
%40 = load i32*, i32** %9
%41 = load double*, double** %12
%42 = load i32*, i32** %10
%43 = call i32 @dgetri_(i32* %6, double* %39, i32* %8, i32* %40, double* %41, i32* %11, i32* %42)
%44 = load double*, double** %12
%45 = call i32 @free(double* %44)
ret void
}

LLVM IR (-O2):
define void @dgetri(i32 %0, double* %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %6
store i32 %2, i32* %7
%9 = bitcast i32* %8 to i8*
store i32 -1, i32* %8
%10 = tail call double* @malloc(i32 8)
%11 = icmp eq double* %10, null
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %5
%15 = call i32 @dgetri_(i32* %6, double* %1, i32* %7, i32* %3, double* %10, i32* %8, i32* %4)
%16 = load double, double* %10
%17 = fptosi double %16 to i32
store i32 %17, i32* %8
%18 = shl i32 %17, 3
%19 = call double* @realloc(double* %10, i32 %18)
%20 = icmp eq double* %19, null
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %14
%24 = call i32 @dgetri_(i32* %6, double* %1, i32* %7, i32* %3, double* %19, i32* %8, i32* %4)
%25 = call i32 @free(double* %19)
ret void
}