#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 choldcmp(double **, int, double *);
double *dvector(int /*<<< orphan*/, int);
int /*<<< orphan*/ free_dvector(double *, int /*<<< orphan*/);
int /*<<< orphan*/ matvec(double **, int, int, double *, double *);
int /*<<< orphan*/ mexErrMsgTxt(char *);
double snorm();
void normal_rndc(double **vcov, int k, double *randvec) {
  int i, j;
  double *rvec, *xpxd;
  int invt;
  rvec = dvector(0, k - 1);
  xpxd = dvector(0, k - 1);
  invt = choldcmp(vcov, k, xpxd);
  if (invt != 1)
    mexErrMsgTxt("cholesky error in normal_rnd \n");
  for (i = 0; i < k; i++) {
    for (j = i; j < k; j++)
      vcov[i][j] = 0.0;
    vcov[i][i] = xpxd[i];
  }
  for (i = 0; i < k; i++)
    rvec[i] = snorm();
  matvec(vcov, k, k, rvec, randvec);
  free_dvector(rvec, 0);
  free_dvector(xpxd, 0);
}


x86 assembly (clang, -O0):
<normal_rndc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
xor    %edi,%edi
call   1050 <dvector@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
xor    %edi,%edi
call   1050 <dvector@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1040 <choldcmp@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
je     11be <normal_rndc+0x5e>
lea    0xe47(%rip),%rdi
call   1060 <mexErrMsgTxt@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1239 <normal_rndc+0xd9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1209 <normal_rndc+0xa9>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d7 <normal_rndc+0x77>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c5 <normal_rndc+0x65>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126e <normal_rndc+0x10e>
mov    $0x0,%al
call   1030 <snorm@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1240 <normal_rndc+0xe0>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1080 <matvec@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1070 <free_dvector@plt>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1070 <free_dvector@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normal_rndc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
lea    -0x1(%r15),%ebp
xor    %edi,%edi
mov    %ebp,%esi
call   1060 <dvector@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %ebp,%esi
call   1060 <dvector@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %r15d,%esi
mov    %rax,%rdx
call   1040 <choldcmp@plt>
cmp    $0x1,%eax
je     11c2 <normal_rndc+0x52>
lea    0xe43(%rip),%rdi
call   1070 <mexErrMsgTxt@plt>
test   %r15d,%r15d
jle    12e7 <normal_rndc+0x177>
mov    %rbp,0x10(%rsp)
mov    %r13,%rax
mov    %r12,%r13
mov    %rbx,0x18(%rsp)
mov    %r14,0x28(%rsp)
mov    %r15d,%ecx
cmp    $0x1,%r15d
mov    %rcx,0x8(%rsp)
mov    %r15,0x20(%rsp)
jne    1200 <normal_rndc+0x90>
xor    %ebp,%ebp
mov    %r13,%r14
mov    %rax,%r13
jmp    1284 <normal_rndc+0x114>
and    $0xfffffffe,%ecx
mov    %rcx,0x30(%rsp)
lea    -0x2(%r15),%r12d
xor    %ebp,%ebp
mov    %r13,%r14
mov    %rax,%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%r12),%eax
lea    0x8(,%rax,8),%rdx
mov    (%r14,%rbp,8),%r15
lea    (%r15,%rbp,8),%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movsd  0x0(%r13,%rbp,8),%xmm0
movsd  %xmm0,(%r15,%rbp,8)
mov    %r12d,%eax
lea    0x8(,%rax,8),%rdx
mov    0x8(%r14,%rbp,8),%rbx
lea    (%rbx,%rbp,8),%rdi
add    $0x8,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movsd  0x8(%r13,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rbp,8)
add    $0x2,%rbp
add    $0xfffffffe,%r12d
cmp    %rbp,0x30(%rsp)
jne    1220 <normal_rndc+0xb0>
testb  $0x1,0x8(%rsp)
mov    %r14,%r12
je     12b9 <normal_rndc+0x149>
mov    0x10(%rsp),%rax
sub    %ebp,%eax
lea    0x8(,%rax,8),%rdx
mov    (%r12,%rbp,8),%r14
lea    (%r14,%rbp,8),%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movsd  0x0(%r13,%rbp,8),%xmm0
movsd  %xmm0,(%r14,%rbp,8)
mov    0x20(%rsp),%r15
test   %r15d,%r15d
mov    0x28(%rsp),%r14
mov    0x18(%rsp),%rbx
jle    12e7 <normal_rndc+0x177>
xor    %ebp,%ebp
nop
xor    %eax,%eax
call   1030 <snorm@plt>
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,0x8(%rsp)
jne    12d0 <normal_rndc+0x160>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
mov    %r14,%r8
call   1090 <matvec@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <free_dvector@plt>
mov    %r13,%rdi
xor    %esi,%esi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <free_dvector@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"cholesky error in normal_rnd \0A\00"
define void @normal_rndc(double** %0, i32 %1, double* %2) {
%4 = alloca double**
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
store double** %0, double*** %4
store i32 %1, i32* %5
store double* %2, double** %6
%12 = load i32, i32* %5
%13 = sub nsw i32 %12, 1
%14 = call double* @dvector(i32 0, i32 %13)
store double* %14, double** %9
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
%17 = call double* @dvector(i32 0, i32 %16)
store double* %17, double** %10
%18 = load double**, double*** %4
%19 = load i32, i32* %5
%20 = load double*, double** %10
%21 = call i32 @choldcmp(double** %18, i32 %19, double* %20)
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %3
%25 = call i32 @mexErrMsgTxt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %3
store i32 0, i32* %7
br label %27
27: ; preds = %63, %26
%28 = load i32, i32* %7
%29 = load i32, i32* %5
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %66
31: ; preds = %27
%32 = load i32, i32* %7
store i32 %32, i32* %8
br label %33
33: ; preds = %46, %31
%34 = load i32, i32* %8
%35 = load i32, i32* %5
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = load double**, double*** %4
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double*, double** %38, i64 %40
%42 = load double*, double** %41
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
store double 0.000000e+00, double* %45
br label %46
46: ; preds = %37
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %33
49: ; preds = %33
%50 = load double*, double** %10
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = load double**, double*** %4
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double*, double** %55, i64 %57
%59 = load double*, double** %58
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
store double %54, double* %62
br label %63
63: ; preds = %49
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %27
66: ; preds = %27
store i32 0, i32* %7
br label %67
67: ; preds = %77, %66
%68 = load i32, i32* %7
%69 = load i32, i32* %5
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %80
71: ; preds = %67
%72 = call double (...) @snorm()
%73 = load double*, double** %9
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
store double %72, double* %76
br label %77
77: ; preds = %71
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
br label %67
80: ; preds = %67
%81 = load double**, double*** %4
%82 = load i32, i32* %5
%83 = load i32, i32* %5
%84 = load double*, double** %9
%85 = load double*, double** %6
%86 = call i32 @matvec(double** %81, i32 %82, i32 %83, double* %84, double* %85)
%87 = load double*, double** %9
%88 = call i32 @free_dvector(double* %87, i32 0)
%89 = load double*, double** %10
%90 = call i32 @free_dvector(double* %89, i32 0)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"cholesky error in normal_rnd \0A\00"
define void @normal_rndc(double** %0, i32 %1, double* %2) {
%4 = add i32 %1, -1
%5 = tail call double* @dvector(i32 0, i32 %4)
%6 = tail call double* @dvector(i32 0, i32 %4)
%7 = tail call i32 @choldcmp(double** %0, i32 %1, double* %6)
%8 = icmp eq i32 %7, 1
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @mexErrMsgTxt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %75
13: ; preds = %11
%14 = zext i32 %1 to i64
%15 = and i64 %14, 1
%16 = icmp eq i32 %1, 1
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = and i64 %14, 4294967294
br label %38
19: ; preds = %38, %13
%20 = phi i64 [ 0, %13 ], [ %66, %38 ]
%21 = icmp eq i64 %15, 0
br i1 %21, label %35, label %22
22: ; preds = %19
%23 = trunc i64 %20 to i32
%24 = sub i32 %4, %23
%25 = zext i32 %24 to i64
%26 = shl nuw nsw i64 %25, 3
%27 = add nuw nsw i64 %26, 8
%28 = getelementptr inbounds double*, double** %0, i64 %20
%29 = load double*, double** %28
%30 = getelementptr double, double* %29, i64 %20
%31 = bitcast double* %30 to i8*
%32 = getelementptr inbounds double, double* %6, i64 %20
%33 = load double, double* %32
%34 = getelementptr inbounds double, double* %29, i64 %20
store double %33, double* %34
br label %35
35: ; preds = %19, %22
br i1 %12, label %36, label %75
36: ; preds = %35
%37 = zext i32 %1 to i64
br label %69
38: ; preds = %38, %17
%39 = phi i64 [ 0, %17 ], [ %66, %38 ]
%40 = phi i64 [ 0, %17 ], [ %67, %38 ]
%41 = trunc i64 %39 to i32
%42 = sub i32 %4, %41
%43 = zext i32 %42 to i64
%44 = shl nuw nsw i64 %43, 3
%45 = add nuw nsw i64 %44, 8
%46 = getelementptr inbounds double*, double** %0, i64 %39
%47 = load double*, double** %46
%48 = getelementptr double, double* %47, i64 %39
%49 = bitcast double* %48 to i8*
%50 = getelementptr inbounds double, double* %6, i64 %39
%51 = load double, double* %50
%52 = getelementptr inbounds double, double* %47, i64 %39
store double %51, double* %52
%53 = or i64 %39, 1
%54 = trunc i64 %53 to i32
%55 = sub i32 %4, %54
%56 = zext i32 %55 to i64
%57 = shl nuw nsw i64 %56, 3
%58 = add nuw nsw i64 %57, 8
%59 = getelementptr inbounds double*, double** %0, i64 %53
%60 = load double*, double** %59
%61 = getelementptr double, double* %60, i64 %53
%62 = bitcast double* %61 to i8*
%63 = getelementptr inbounds double, double* %6, i64 %53
%64 = load double, double* %63
%65 = getelementptr inbounds double, double* %60, i64 %53
store double %64, double* %65
%66 = add nuw nsw i64 %39, 2
%67 = add i64 %40, 2
%68 = icmp eq i64 %67, %18
br i1 %68, label %19, label %38
69: ; preds = %36, %69
%70 = phi i64 [ 0, %36 ], [ %73, %69 ]
%71 = tail call double (...) @snorm()
%72 = getelementptr inbounds double, double* %5, i64 %70
store double %71, double* %72
%73 = add nuw nsw i64 %70, 1
%74 = icmp eq i64 %73, %37
br i1 %74, label %75, label %69
75: ; preds = %69, %11, %35
%76 = tail call i32 @matvec(double** %0, i32 %1, i32 %1, double* %5, double* %2)
%77 = tail call i32 @free_dvector(double* %5, i32 0)
%78 = tail call i32 @free_dvector(double* %6, i32 0)
ret void
}