#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 */
float *eig_val(float **, int, int);
float **eig_vect(float **, int, int, float *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
float ***eig(float **mat, int rows, int cols) {
  float ***eigen;
  eigen = (float ***)malloc(sizeof(float **) * 2);
  if (eigen == NULL) {
    fprintf(stderr, "ERROR: Allocating memory for eigen vector eigen value "
                    "matrix failed\n");
    return NULL;
  }
  eigen[0] = (float **)malloc(sizeof(float *) * 1);
  if (eigen[0] == NULL) {
    fprintf(stderr, "ERROR: Allocating memory for eigen vector-eigen value "
                    "matrix failed\n");
    return NULL;
  }
  eigen[0][0] = eig_val(mat, rows, cols);
  if (eigen[0][0] == NULL)
    return NULL;
  eigen[1] = eig_vect(mat, rows, cols, eigen[0][0], cols);
  if (eigen[1] == NULL)
    return NULL;
  return eigen;
}


x86 assembly (clang, -O0):
<eig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118d <eig+0x4d>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1257 <eig+0x117>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11d1 <eig+0x91>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1257 <eig+0x117>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <eig_val@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
jne    120b <eig+0xcb>
movq   $0x0,-0x8(%rbp)
jmp    1257 <eig+0x117>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%r8d
call   1050 <eig_vect@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    124f <eig+0x10f>
movq   $0x0,-0x8(%rbp)
jmp    1257 <eig+0x117>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eig>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
mov    $0x10,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11ae <eig+0x6e>
mov    %rax,%rbx
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11c0 <eig+0x80>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1060 <eig_val@plt>
mov    (%rbx),%rcx
mov    %rax,(%rcx)
mov    (%rbx),%rax
mov    (%rax),%rcx
test   %rcx,%rcx
je     11d5 <eig+0x95>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebp,%r8d
call   1050 <eig_vect@plt>
mov    %rax,0x8(%rbx)
test   %rax,%rax
cmove  %rax,%rbx
jmp    11d7 <eig+0x97>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
jmp    11d0 <eig+0x90>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1030 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [69 x i8] c"ERROR: Allocating memory for eigen vector eigen value matrix failed\0A\00"
@.str.1 = [69 x i8] c"ERROR: Allocating memory for eigen vector-eigen value matrix failed\0A\00"
define float*** @eig(float** %0, i32 %1, i32 %2) {
%4 = alloca float***
%5 = alloca float**
%6 = alloca i32
%7 = alloca i32
%8 = alloca float***
store float** %0, float*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = call i64 @malloc(i32 16)
%10 = inttoptr i64 %9 to float***
store float*** %10, float**** %8
%11 = load float***, float**** %8
%12 = icmp eq float*** %11, null
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
store float*** null, float**** %4
br label %64
16: ; preds = %3
%17 = call i64 @malloc(i32 8)
%18 = inttoptr i64 %17 to float**
%19 = load float***, float**** %8
%20 = getelementptr inbounds float**, float*** %19, i64 0
store float** %18, float*** %20
%21 = load float***, float**** %8
%22 = getelementptr inbounds float**, float*** %21, i64 0
%23 = load float**, float*** %22
%24 = icmp eq float** %23, null
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0))
store float*** null, float**** %4
br label %64
28: ; preds = %16
%29 = load float**, float*** %5
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = call float* @eig_val(float** %29, i32 %30, i32 %31)
%33 = load float***, float**** %8
%34 = getelementptr inbounds float**, float*** %33, i64 0
%35 = load float**, float*** %34
%36 = getelementptr inbounds float*, float** %35, i64 0
store float* %32, float** %36
%37 = load float***, float**** %8
%38 = getelementptr inbounds float**, float*** %37, i64 0
%39 = load float**, float*** %38
%40 = getelementptr inbounds float*, float** %39, i64 0
%41 = load float*, float** %40
%42 = icmp eq float* %41, null
br i1 %42, label %43, label %44
43: ; preds = %28
store float*** null, float**** %4
br label %64
44: ; preds = %28
%45 = load float**, float*** %5
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = load float***, float**** %8
%49 = getelementptr inbounds float**, float*** %48, i64 0
%50 = load float**, float*** %49
%51 = getelementptr inbounds float*, float** %50, i64 0
%52 = load float*, float** %51
%53 = load i32, i32* %7
%54 = call float** @eig_vect(float** %45, i32 %46, i32 %47, float* %52, i32 %53)
%55 = load float***, float**** %8
%56 = getelementptr inbounds float**, float*** %55, i64 1
store float** %54, float*** %56
%57 = load float***, float**** %8
%58 = getelementptr inbounds float**, float*** %57, i64 1
%59 = load float**, float*** %58
%60 = icmp eq float** %59, null
br i1 %60, label %61, label %62
61: ; preds = %44
store float*** null, float**** %4
br label %64
62: ; preds = %44
%63 = load float***, float**** %8
store float*** %63, float**** %4
br label %64
64: ; preds = %62, %61, %43, %25, %13
%65 = load float***, float**** %4
ret float*** %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [69 x i8] c"ERROR: Allocating memory for eigen vector eigen value matrix failed\0A\00"
@.str.1 = [69 x i8] c"ERROR: Allocating memory for eigen vector-eigen value matrix failed\0A\00"
define float*** @eig(float** %0, i32 %1, i32 %2) {
%4 = tail call i64 @malloc(i32 16)
%5 = inttoptr i64 %4 to float***
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
br label %28
10: ; preds = %3
%11 = tail call i64 @malloc(i32 8)
%12 = inttoptr i64 %11 to float**
store float** %12, float*** %5
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0))
br label %28
17: ; preds = %10
%18 = tail call float* @eig_val(float** %0, i32 %1, i32 %2)
%19 = load float**, float*** %5
store float* %18, float** %19
%20 = load float**, float*** %5
%21 = load float*, float** %20
%22 = icmp eq float* %21, null
br i1 %22, label %28, label %23
23: ; preds = %17
%24 = tail call float** @eig_vect(float** %0, i32 %1, i32 %2, float* %21, i32 %2)
%25 = getelementptr inbounds float**, float*** %5, i64 1
store float** %24, float*** %25
%26 = icmp eq float** %24, null
%27 = select i1 %26, float*** null, float*** %5
br label %28
28: ; preds = %23, %17, %14, %7
%29 = phi float*** [ null, %7 ], [ null, %14 ], [ null, %17 ], [ %27, %23 ]
ret float*** %29
}