#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*/ eigen_symm(double *, double **, double **, int);
int /*<<< orphan*/ free_matrix2(double **);
int /*<<< orphan*/ mvnrand_pcs(double *, double *, double *, double **, int);
double **new_matrix2(int, int);
double sqrt(double);
void mvnrand(double *x, double *mu, double **S, int d) {
  double z[d], **V = new_matrix2(d, d);
  eigen_symm(z, V, S, d);
  int i;
  for (i = 0; i < d; i++)
    z[i] = sqrt(z[i]);
  mvnrand_pcs(x, mu, z, V, d);
  free_matrix2(V);
}


x86 assembly (clang, -O0):
<mvnrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <new_matrix2@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <eigen_symm@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f1 <mvnrand+0xa1>
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1060 <sqrt@plt>
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11b8 <mvnrand+0x68>
mov    -0x48(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1070 <mvnrand_pcs@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free_matrix2@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvnrand>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,-0x48(%rbp)
mov    %rdi,-0x40(%rbp)
mov    %ecx,%r15d
mov    %rsp,%r12
lea    0xf(,%r15,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %ecx,%edi
mov    %ecx,%esi
call   1050 <new_matrix2@plt>
mov    %r12,%rdi
mov    %rax,-0x38(%rbp)
mov    %rax,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1030 <eigen_symm@plt>
mov    %ebx,-0x2c(%rbp)
test   %ebx,%ebx
jle    11fa <mvnrand+0xaa>
lea    -0x1(%r15),%rax
mov    %r15d,%r14d
and    $0x3,%r14d
cmp    $0x3,%rax
jae    122c <mvnrand+0xdc>
xor    %r13d,%r13d
test   %r14,%r14
je     11fa <mvnrand+0xaa>
lea    (%r12,%r13,8),%r15
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
jmp    11e8 <mvnrand+0x98>
nop
call   1060 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
je     11fa <mvnrand+0xaa>
movsd  (%r15,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     11d0 <mvnrand+0x80>
sqrtsd %xmm0,%xmm0
jmp    11d9 <mvnrand+0x89>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %r12,%rdx
mov    -0x38(%rbp),%rbx
mov    %rbx,%rcx
mov    -0x2c(%rbp),%r8d
call   1070 <mvnrand_pcs@plt>
mov    %rbx,%rdi
call   1040 <free_matrix2@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
and    $0xfffffffc,%r15d
xor    %r13d,%r13d
xorpd  %xmm1,%xmm1
jmp    125d <mvnrand+0x10d>
nopl   0x0(%rax)
call   1060 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x18(%r12,%r13,8)
add    $0x4,%r13
cmp    %r13,%r15
je     11be <mvnrand+0x6e>
movsd  (%r12,%r13,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1270 <mvnrand+0x120>
sqrtsd %xmm0,%xmm0
jmp    1279 <mvnrand+0x129>
nop
call   1060 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,(%r12,%r13,8)
movsd  0x8(%r12,%r13,8),%xmm0
ucomisd %xmm1,%xmm0
jb     12a0 <mvnrand+0x150>
sqrtsd %xmm0,%xmm0
jmp    12a9 <mvnrand+0x159>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1060 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%r12,%r13,8)
movsd  0x10(%r12,%r13,8),%xmm0
ucomisd %xmm1,%xmm0
jb     12d0 <mvnrand+0x180>
sqrtsd %xmm0,%xmm0
jmp    12d9 <mvnrand+0x189>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1060 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x10(%r12,%r13,8)
movsd  0x18(%r12,%r13,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1240 <mvnrand+0xf0>
sqrtsd %xmm0,%xmm0
jmp    1249 <mvnrand+0xf9>

LLVM IR (-O0):
define void @mvnrand(double* %0, double* %1, double** %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca double**
%12 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store double** %2, double*** %7
store i32 %3, i32* %8
%13 = load i32, i32* %8
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca double, i64 %14
store i64 %14, i64* %10
%17 = load i32, i32* %8
%18 = load i32, i32* %8
%19 = call double** @new_matrix2(i32 %17, i32 %18)
store double** %19, double*** %11
%20 = load double**, double*** %11
%21 = load double**, double*** %7
%22 = load i32, i32* %8
%23 = call i32 @eigen_symm(double* %16, double** %20, double** %21, i32 %22)
store i32 0, i32* %12
br label %24
24: ; preds = %37, %4
%25 = load i32, i32* %12
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = load i32, i32* %12
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %16, i64 %30
%32 = load double, double* %31
%33 = call double @sqrt(double %32)
%34 = load i32, i32* %12
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %16, i64 %35
store double %33, double* %36
br label %37
37: ; preds = %28
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 1
store i32 %39, i32* %12
br label %24
40: ; preds = %24
%41 = load double*, double** %5
%42 = load double*, double** %6
%43 = load double**, double*** %11
%44 = load i32, i32* %8
%45 = call i32 @mvnrand_pcs(double* %41, double* %42, double* %16, double** %43, i32 %44)
%46 = load double**, double*** %11
%47 = call i32 @free_matrix2(double** %46)
%48 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
define void @mvnrand(double* %0, double* %1, double** %2, i32 %3) {
%5 = zext i32 %3 to i64
%6 = alloca double, i64 %5
%7 = tail call double** @new_matrix2(i32 %3, i32 %3)
%8 = call i32 @eigen_symm(double* %6, double** %7, double** %2, i32 %3)
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %49
10: ; preds = %4
%11 = add nsw i64 %5, -1
%12 = and i64 %5, 3
%13 = icmp ult i64 %11, 3
br i1 %13, label %37, label %14
14: ; preds = %10
%15 = and i64 %5, 4294967292
br label %16
16: ; preds = %16, %14
%17 = phi i64 [ 0, %14 ], [ %34, %16 ]
%18 = phi i64 [ 0, %14 ], [ %35, %16 ]
%19 = getelementptr inbounds double, double* %6, i64 %17
%20 = load double, double* %19
%21 = call double @sqrt(double %20)
store double %21, double* %19
%22 = or i64 %17, 1
%23 = getelementptr inbounds double, double* %6, i64 %22
%24 = load double, double* %23
%25 = call double @sqrt(double %24)
store double %25, double* %23
%26 = or i64 %17, 2
%27 = getelementptr inbounds double, double* %6, i64 %26
%28 = load double, double* %27
%29 = call double @sqrt(double %28)
store double %29, double* %27
%30 = or i64 %17, 3
%31 = getelementptr inbounds double, double* %6, i64 %30
%32 = load double, double* %31
%33 = call double @sqrt(double %32)
store double %33, double* %31
%34 = add nuw nsw i64 %17, 4
%35 = add i64 %18, 4
%36 = icmp eq i64 %35, %15
br i1 %36, label %37, label %16
37: ; preds = %16, %10
%38 = phi i64 [ 0, %10 ], [ %34, %16 ]
%39 = icmp eq i64 %12, 0
br i1 %39, label %49, label %40
40: ; preds = %37, %40
%41 = phi i64 [ %46, %40 ], [ %38, %37 ]
%42 = phi i64 [ %47, %40 ], [ 0, %37 ]
%43 = getelementptr inbounds double, double* %6, i64 %41
%44 = load double, double* %43
%45 = call double @sqrt(double %44)
store double %45, double* %43
%46 = add nuw nsw i64 %41, 1
%47 = add i64 %42, 1
%48 = icmp eq i64 %47, %12
br i1 %48, label %49, label %40
49: ; preds = %37, %40, %4
%50 = call i32 @mvnrand_pcs(double* %0, double* %1, double* %6, double** %7, i32 %3)
%51 = call i32 @free_matrix2(double** %7)
ret void
}