#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ lin_solve_triangular_equ(double *, double *, double *, int,
                                            int, int);
int /*<<< orphan*/ mtx_chol(double *, double *, int);
int /*<<< orphan*/ mtx_transpose(double *, double *, int, int);
void lin_solve_PSD(double *A, double *X, double *B, int dim_i, int dim_j) {
  double *L = (double *)calloc(dim_i * dim_i, sizeof(double));
  double *L_prime = (double *)calloc(dim_i * dim_i, sizeof(double));
  double *Z = (double *)calloc(dim_i * dim_j, sizeof(double));
  mtx_chol(A, L, dim_i);
  lin_solve_triangular_equ(L, Z, B, dim_i, dim_j, 1);
  mtx_transpose(L, L_prime, dim_i, dim_i);
  lin_solve_triangular_equ(L_prime, X, Z, dim_i, dim_j, 0);
  free(L);
  free(L_prime);
  free(Z);
}


x86 assembly (clang, -O0):
<lin_solve_PSD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
imul   -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
imul   -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
imul   -0x20(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <mtx_chol@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    $0x1,%r9d
call   1060 <lin_solve_triangular_equ@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <mtx_transpose@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
xor    %r9d,%r9d
call   1060 <lin_solve_triangular_equ@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lin_solve_PSD>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %ecx,%r14d
mov    %rdx,0x8(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,(%rsp)
mov    %ecx,%ebp
imul   %ecx,%ebp
mov    %ebp,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
mov    %r15d,%edi
imul   %r14d,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r13
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1070 <mtx_chol@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    0x8(%rsp),%rdx
mov    %r14d,%ecx
mov    %r15d,%r8d
mov    $0x1,%r9d
call   1060 <lin_solve_triangular_equ@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    %r14d,%ecx
call   1040 <mtx_transpose@plt>
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
mov    %r13,%rdx
mov    %r14d,%ecx
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1060 <lin_solve_triangular_equ@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @lin_solve_PSD(double* %0, double* %1, double* %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%14 = load i32, i32* %9
%15 = load i32, i32* %9
%16 = mul nsw i32 %14, %15
%17 = call i64 @calloc(i32 %16, i32 8)
%18 = inttoptr i64 %17 to double*
store double* %18, double** %11
%19 = load i32, i32* %9
%20 = load i32, i32* %9
%21 = mul nsw i32 %19, %20
%22 = call i64 @calloc(i32 %21, i32 8)
%23 = inttoptr i64 %22 to double*
store double* %23, double** %12
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = mul nsw i32 %24, %25
%27 = call i64 @calloc(i32 %26, i32 8)
%28 = inttoptr i64 %27 to double*
store double* %28, double** %13
%29 = load double*, double** %6
%30 = load double*, double** %11
%31 = load i32, i32* %9
%32 = call i32 @mtx_chol(double* %29, double* %30, i32 %31)
%33 = load double*, double** %11
%34 = load double*, double** %13
%35 = load double*, double** %8
%36 = load i32, i32* %9
%37 = load i32, i32* %10
%38 = call i32 @lin_solve_triangular_equ(double* %33, double* %34, double* %35, i32 %36, i32 %37, i32 1)
%39 = load double*, double** %11
%40 = load double*, double** %12
%41 = load i32, i32* %9
%42 = load i32, i32* %9
%43 = call i32 @mtx_transpose(double* %39, double* %40, i32 %41, i32 %42)
%44 = load double*, double** %12
%45 = load double*, double** %7
%46 = load double*, double** %13
%47 = load i32, i32* %9
%48 = load i32, i32* %10
%49 = call i32 @lin_solve_triangular_equ(double* %44, double* %45, double* %46, i32 %47, i32 %48, i32 0)
%50 = load double*, double** %11
%51 = call i32 @free(double* %50)
%52 = load double*, double** %12
%53 = call i32 @free(double* %52)
%54 = load double*, double** %13
%55 = call i32 @free(double* %54)
ret void
}

LLVM IR (-O2):
define void @lin_solve_PSD(double* %0, double* %1, double* %2, i32 %3, i32 %4) {
%6 = mul nsw i32 %3, %3
%7 = tail call i64 @calloc(i32 %6, i32 8)
%8 = inttoptr i64 %7 to double*
%9 = tail call i64 @calloc(i32 %6, i32 8)
%10 = inttoptr i64 %9 to double*
%11 = mul nsw i32 %4, %3
%12 = tail call i64 @calloc(i32 %11, i32 8)
%13 = inttoptr i64 %12 to double*
%14 = tail call i32 @mtx_chol(double* %0, double* %8, i32 %3)
%15 = tail call i32 @lin_solve_triangular_equ(double* %8, double* %13, double* %2, i32 %3, i32 %4, i32 1)
%16 = tail call i32 @mtx_transpose(double* %8, double* %10, i32 %3, i32 %3)
%17 = tail call i32 @lin_solve_triangular_equ(double* %10, double* %1, double* %13, i32 %3, i32 %4, i32 0)
%18 = tail call i32 @free(double* %8)
%19 = tail call i32 @free(double* %10)
%20 = tail call i32 @free(double* %13)
ret void
}