#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*/ dsytrf_(char *, int *, double *, int *, int *, double *,
                           int *, int *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int call_dsytrf(char uplo, int n, double *a, int lda, int *ipiv) {
  int info = 0;
  double wkopt;
  int lwork = -1;
  double *work = NULL;
  dsytrf_(&uplo, &n, a, &lda, ipiv, &wkopt, &lwork, &info);
  if (info != 0)
    return info;
  lwork = (int)wkopt;
  work = (double *)malloc(sizeof(double) * lwork);
  if (work == NULL) {
    fputs("ERROR: memory allocation (malloc) failed in call_dsytrf\n", stderr);
    return -999;
  }
  dsytrf_(&uplo, &n, a, &lda, ipiv, work, &lwork, &info);
  free(work);
  return info;
}


x86 assembly (clang, -O0):
<call_dsytrf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%r8
lea    -0x5(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
lea    -0x38(%rbp),%r9
lea    -0x3c(%rbp),%r10
lea    -0x2c(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <dsytrf_@plt>
cmpl   $0x0,-0x2c(%rbp)
je     11b5 <call_dsytrf+0x75>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1239 <call_dsytrf+0xf9>
cvttsd2si -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11fc <call_dsytrf+0xbc>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
lea    0xe15(%rip),%rdi
call   1050 <fputs@plt>
movl   $0xfffffc19,-0x4(%rbp)
jmp    1239 <call_dsytrf+0xf9>
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%r8
mov    -0x48(%rbp),%r9
lea    -0x5(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
lea    -0x3c(%rbp),%r10
lea    -0x2c(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <dsytrf_@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_dsytrf>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r8,%r14
mov    %rdx,%rbx
mov    %dil,0x7(%rsp)
mov    %esi,0x14(%rsp)
mov    %ecx,0x10(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
lea    0x8(%rsp),%r13
lea    0xc(%rsp),%r12
lea    0x7(%rsp),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rcx
lea    0x18(%rsp),%r9
push   %r13
push   %r12
call   1040 <dsytrf_@plt>
add    $0x10,%rsp
mov    0x8(%rsp),%eax
test   %eax,%eax
jne    120a <call_dsytrf+0xca>
cvttsd2si 0x18(%rsp),%edi
mov    %edi,0xc(%rsp)
shl    $0x3,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11f0 <call_dsytrf+0xb0>
mov    %rax,%r15
lea    0x7(%rsp),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %rbx,%rdx
mov    %r14,%r8
mov    %rax,%r9
push   %r13
push   %r12
call   1040 <dsytrf_@plt>
add    $0x10,%rsp
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%eax
jmp    120a <call_dsytrf+0xca>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    0xe00(%rip),%rdi
call   1050 <fputs@plt>
mov    $0xfffffc19,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [57 x i8] c"ERROR: memory allocation (malloc) failed in call_dsytrf\0A\00"
@stderr = global i32 0
define i32 @call_dsytrf(i8 signext %0, i32 %1, double* %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca double
%14 = alloca i32
%15 = alloca double*
store i8 %0, i8* %7
store i32 %1, i32* %8
store double* %2, double** %9
store i32 %3, i32* %10
store i32* %4, i32** %11
store i32 0, i32* %12
store i32 -1, i32* %14
store double* null, double** %15
%16 = load double*, double** %9
%17 = load i32*, i32** %11
%18 = call i32 @dsytrf_(i8* %7, i32* %8, double* %16, i32* %10, i32* %17, double* %13, i32* %14, i32* %12)
%19 = load i32, i32* %12
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %5
%22 = load i32, i32* %12
store i32 %22, i32* %6
br label %45
23: ; preds = %5
%24 = load double, double* %13
%25 = fptosi double %24 to i32
store i32 %25, i32* %14
%26 = load i32, i32* %14
%27 = sext i32 %26 to i64
%28 = mul i64 8, %27
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to double*
store double* %31, double** %15
%32 = load double*, double** %15
%33 = icmp eq double* %32, null
br i1 %33, label %34, label %37
34: ; preds = %23
%35 = load i32, i32* @stderr
%36 = call i32 @fputs(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %35)
store i32 -999, i32* %6
br label %45
37: ; preds = %23
%38 = load double*, double** %9
%39 = load i32*, i32** %11
%40 = load double*, double** %15
%41 = call i32 @dsytrf_(i8* %7, i32* %8, double* %38, i32* %10, i32* %39, double* %40, i32* %14, i32* %12)
%42 = load double*, double** %15
%43 = call i32 @free(double* %42)
%44 = load i32, i32* %12
store i32 %44, i32* %6
br label %45
45: ; preds = %37, %34, %21
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@.str = [57 x i8] c"ERROR: memory allocation (malloc) failed in call_dsytrf\0A\00"
@stderr = global i32 0
define i32 @call_dsytrf(i8 signext %0, i32 %1, double* %2, i32 %3, i32* %4) {
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
store i8 %0, i8* %6
store i32 %1, i32* %7
store i32 %3, i32* %8
%12 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%13 = bitcast double* %10 to i8*
%14 = bitcast i32* %11 to i8*
store i32 -1, i32* %11
%15 = call i32 @dsytrf_(i8* %6, i32* %7, double* %2, i32* %8, i32* %4, double* %10, i32* %11, i32* %9)
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %5
%19 = load double, double* %10
%20 = fptosi double %19 to i32
store i32 %20, i32* %11
%21 = shl i32 %20, 3
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to double*
%24 = icmp eq i64 %22, 0
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %26)
br label %32
28: ; preds = %18
%29 = call i32 @dsytrf_(i8* %6, i32* %7, double* %2, i32* %8, i32* %4, double* %23, i32* %11, i32* %9)
%30 = call i32 @free(double* %23)
%31 = load i32, i32* %9
br label %32
32: ; preds = %5, %28, %25
%33 = phi i32 [ -999, %25 ], [ %31, %28 ], [ %16, %5 ]
ret i32 %33
}