#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*/ dsyev_(char *, char *, int *, double *, int *, double *,
                          double *, int *, int *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int call_dsyev(char jobz, char uplo, int n, double *a, int lda, double *w) {
  int info = 0;
  double wkopt;
  int lwork = -1;
  double *work = NULL;
  dsyev_(&jobz, &uplo, &n, a, &lda, w, &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_dsyev\n", stderr);
    return -999;
  }
  dsyev_(&jobz, &uplo, &n, a, &lda, w, work, &lwork, &info);
  free(work);
  return 0;
}


x86 assembly (clang, -O0):
<call_dsyev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %sil,%al
mov    %dil,%sil
mov    %sil,-0x5(%rbp)
mov    %al,-0x6(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r9
lea    -0x5(%rbp),%rdi
lea    -0x6(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x1c(%rbp),%r8
lea    -0x38(%rbp),%r11
lea    -0x3c(%rbp),%r10
lea    -0x2c(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <dsyev_@plt>
cmpl   $0x0,-0x2c(%rbp)
je     11c6 <call_dsyev+0x86>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1254 <call_dsyev+0x114>
cvttsd2si -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    120d <call_dsyev+0xcd>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
lea    0xe04(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xfffffc19,-0x4(%rbp)
jmp    1254 <call_dsyev+0x114>
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r9
mov    -0x48(%rbp),%r11
lea    -0x5(%rbp),%rdi
lea    -0x6(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x1c(%rbp),%r8
lea    -0x3c(%rbp),%r10
lea    -0x2c(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <dsyev_@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_dsyev>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r9,%r14
mov    %rcx,%rbx
mov    %dil,0x7(%rsp)
mov    %sil,0x6(%rsp)
mov    %edx,0x14(%rsp)
mov    %r8d,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
sub    $0x8,%rsp
lea    0x14(%rsp),%r13
lea    0x10(%rsp),%r12
lea    0x20(%rsp),%rax
lea    0xf(%rsp),%rdi
lea    0xe(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%r8
push   %r13
push   %r12
push   %rax
call   1060 <dsyev_@plt>
add    $0x20,%rsp
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    121f <call_dsyev+0xdf>
cvttsd2si 0x18(%rsp),%edi
mov    %edi,0x8(%rsp)
shl    $0x3,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1205 <call_dsyev+0xc5>
mov    %rax,%r15
sub    $0x8,%rsp
lea    0xf(%rsp),%rdi
lea    0xe(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%r8
mov    %rbx,%rcx
mov    %r14,%r9
push   %r13
push   %r12
push   %rax
call   1060 <dsyev_@plt>
add    $0x20,%rsp
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    121f <call_dsyev+0xdf>
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
lea    0xdeb(%rip),%rdi
call   1040 <fputs@plt>
mov    $0xfffffc19,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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