#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*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ randirichlet(double *, double *, int);
int /*<<< orphan*/ ranmultinom(int *, int, double *, int);
void randirmult(double *pp, int *aa, int len, int m) {
  int k;
  double a, b, p;
  double *x;
  if (len == 0)
    return;
  if (len == 1) {
    aa[0] = m;
    return;
  }
  if ((x = (double *)calloc((len), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", len);
  randirichlet(x, pp, len);
  ranmultinom(aa, m, x, len);
  free(x);
}


x86 assembly (clang, -O0):
<randirmult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1175 <randirmult+0x25>
jmp    11e3 <randirmult+0x93>
cmpl   $0x1,-0x14(%rbp)
jne    118d <randirmult+0x3d>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11e3 <randirmult+0x93>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11b7 <randirmult+0x67>
mov    -0x14(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1040 <fatalx@plt>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <randirichlet@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1070 <ranmultinom@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randirmult>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
je     116d <randirmult+0x1d>
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%r12
cmp    $0x1,%edx
jne    1176 <randirmult+0x26>
mov    %r14d,(%r12)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rdi,%r15
mov    %ebp,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119b <randirmult+0x4b>
lea    0xe6c(%rip),%rdi
mov    %ebp,%esi
call   1040 <fatalx@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <randirichlet@plt>
mov    %r12,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1070 <ranmultinom@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
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 @randirmult(double* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double*
store double* %0, double** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
br label %44
17: ; preds = %4
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %8
%22 = load i32*, i32** %6
%23 = getelementptr inbounds i32, i32* %22, i64 0
store i32 %21, i32* %23
br label %44
24: ; preds = %17
%25 = load i32, i32* %7
%26 = call i64 @calloc(i32 %25, i32 8)
%27 = inttoptr i64 %26 to double*
store double* %27, double** %13
%28 = icmp eq double* %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %7
%31 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %24
%33 = load double*, double** %13
%34 = load double*, double** %5
%35 = load i32, i32* %7
%36 = call i32 @randirichlet(double* %33, double* %34, i32 %35)
%37 = load i32*, i32** %6
%38 = load i32, i32* %8
%39 = load double*, double** %13
%40 = load i32, i32* %7
%41 = call i32 @ranmultinom(i32* %37, i32 %38, double* %39, i32 %40)
%42 = load double*, double** %13
%43 = call i32 @free(double* %42)
br label %44
44: ; preds = %32, %20, %16
ret void
}

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