#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*/ cholesky(double *, double *, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ gaussa(double *, int);
int /*<<< orphan*/ mulmat(double *, double *, double *, int, int, int);
int /*<<< orphan*/ transpose(double *, double *, int, int);
void genmultgauss(double *rvec, int num, int n, double *covar) {
  double *cf;
  if ((cf = (double *)calloc((n * n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n * n);
  cholesky(cf, covar, n);
  transpose(cf, cf, n, n);
  gaussa(rvec, num * n);
  mulmat(rvec, rvec, cf, num, n, n);
  free(cf);
}


x86 assembly (clang, -O0):
<genmultgauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%edi
imul   -0x10(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b8 <genmultgauss+0x48>
mov    -0x10(%rbp),%esi
imul   -0x10(%rbp),%esi
lea    0xe4d(%rip),%rdi
call   1040 <fatalx@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1050 <cholesky@plt>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1070 <transpose@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
imul   -0x10(%rbp),%esi
call   1080 <gaussa@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x10(%rbp),%r9d
call   1090 <mulmat@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genmultgauss>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
mov    %edx,%r13d
imul   %edx,%r13d
mov    %r13d,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11b1 <genmultgauss+0x41>
lea    0xe57(%rip),%rdi
mov    %r13d,%esi
call   1040 <fatalx@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <cholesky@plt>
mov    %rbp,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
mov    %ebx,%ecx
call   1070 <transpose@plt>
mov    %ebx,%esi
imul   %r14d,%esi
mov    %r15,%rdi
call   1080 <gaussa@plt>
mov    %r15,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
mov    %ebx,%r8d
mov    %ebx,%r9d
call   1090 <mulmat@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define void @genmultgauss(double* %0, i32 %1, i32 %2, double* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
store double* %0, double** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store double* %3, double** %8
%10 = load i32, i32* %7
%11 = load i32, i32* %7
%12 = mul nsw i32 %10, %11
%13 = call i64 @calloc(i32 %12, i32 8)
%14 = inttoptr i64 %13 to double*
store double* %14, double** %9
%15 = icmp eq double* %14, null
br i1 %15, label %16, label %21
16: ; preds = %4
%17 = load i32, i32* %7
%18 = load i32, i32* %7
%19 = mul nsw i32 %17, %18
%20 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %16, %4
%22 = load double*, double** %9
%23 = load double*, double** %8
%24 = load i32, i32* %7
%25 = call i32 @cholesky(double* %22, double* %23, i32 %24)
%26 = load double*, double** %9
%27 = load double*, double** %9
%28 = load i32, i32* %7
%29 = load i32, i32* %7
%30 = call i32 @transpose(double* %26, double* %27, i32 %28, i32 %29)
%31 = load double*, double** %5
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = mul nsw i32 %32, %33
%35 = call i32 @gaussa(double* %31, i32 %34)
%36 = load double*, double** %5
%37 = load double*, double** %5
%38 = load double*, double** %9
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = load i32, i32* %7
%42 = call i32 @mulmat(double* %36, double* %37, double* %38, i32 %39, i32 %40, i32 %41)
%43 = load double*, double** %9
%44 = call i32 @free(double* %43)
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define void @genmultgauss(double* %0, i32 %1, i32 %2, double* %3) {
%5 = mul nsw i32 %2, %2
%6 = tail call i64 @calloc(i32 %5, i32 8)
%7 = inttoptr i64 %6 to double*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %11
11: ; preds = %9, %4
%12 = tail call i32 @cholesky(double* %7, double* %3, i32 %2)
%13 = tail call i32 @transpose(double* %7, double* %7, i32 %2, i32 %2)
%14 = mul nsw i32 %2, %1
%15 = tail call i32 @gaussa(double* %0, i32 %14)
%16 = tail call i32 @mulmat(double* %0, double* %0, double* %7, i32 %1, i32 %2, i32 %2)
%17 = tail call i32 @free(double* %7)
ret void
}