#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*/ DiscreteGamma(double *, double, double, int,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  double *gammaRates, alpha;
  int i, numCategories;
  alpha = 0.42;
  numCategories = 3;
  gammaRates = (double *)calloc(numCategories, sizeof(double));
  if (gammaRates == NULL) {
    fprintf(stderr, "Could not allocate %s (%zu bytes)", "gammaRates",
            numCategories * sizeof(double));
    exit(EXIT_FAILURE);
  }
  DiscreteGamma(gammaRates, alpha, alpha, numCategories, 0);
  printf("Givens: alpha = %.2f; numCategories = %d\n\n", alpha, numCategories);
  printf("Rates as calculated by this prog:\n");
  printf("--------------------------------\n");
  for (i = 0; i < numCategories; i++)
    printf(" %.4f", gammaRates[i]);
  printf("\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xe92(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x3,-0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ca <main+0x7a>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%ecx
lea    0xe58(%rip),%rsi
lea    0xe73(%rip),%rdx
call   1050 <fprintf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x28(%rbp),%esi
xor    %edx,%edx
call   1060 <DiscreteGamma@plt>
movsd  -0x20(%rbp),%xmm0
mov    -0x28(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1250 <main+0x100>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe6a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    121b <main+0xcb>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x3,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     1223 <main+0xb3>
mov    %rax,%rbx
movsd  0xe69(%rip),%xmm0
mov    %rax,%rdi
movaps %xmm0,%xmm1
mov    $0x3,%esi
xor    %edx,%edx
call   1080 <DiscreteGamma@plt>
lea    0xe85(%rip),%rdi
movsd  0xe48(%rip),%xmm0
mov    $0x3,%esi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb1(%rip),%rdi
call   1040 <puts@plt>
movsd  (%rbx),%xmm0
lea    0xe79(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x10(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
lea    0xdf0(%rip),%rdx
mov    $0x18,%ecx
call   1070 <fprintf@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Could not allocate %s (%zu bytes)\00"
@.str.1 = [11 x i8] c"gammaRates\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [43 x i8] c"Givens: alpha = %.2f; numCategories = %d\0A\0A\00"
@.str.3 = [35 x i8] c"Rates as calculated by this prog:\0A\00"
@.str.4 = [34 x i8] c"--------------------------------\0A\00"
@.str.5 = [6 x i8] c" %.4f\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double*
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 4.200000e-01, double* %7
store i32 3, i32* %9
%10 = load i32, i32* %9
%11 = call i64 @calloc(i32 %10, i32 8)
%12 = inttoptr i64 %11 to double*
store double* %12, double** %6
%13 = load double*, double** %6
%14 = icmp eq double* %13, null
br i1 %14, label %15, label %24
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 8
%20 = trunc i64 %19 to i32
%21 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load double*, double** %6
%26 = load double, double* %7
%27 = load double, double* %7
%28 = load i32, i32* %9
%29 = call i32 @DiscreteGamma(double* %25, double %26, double %27, i32 %28, i32 0)
%30 = load double, double* %7
%31 = load i32, i32* %9
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), double %30, i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %8
br label %35
35: ; preds = %46, %24
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %49
39: ; preds = %35
%40 = load double*, double** %6
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %44)
br label %46
46: ; preds = %39
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %35
49: ; preds = %35
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Could not allocate %s (%zu bytes)\00"
@.str.1 = [11 x i8] c"gammaRates\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [43 x i8] c"Givens: alpha = %.2f; numCategories = %d\0A\0A\00"
@.str.5 = [6 x i8] c" %.4f\00"
@str = [34 x i8] c"Rates as calculated by this prog:\00"
@str.7 = [33 x i8] c"--------------------------------\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @calloc(i32 3, i32 8)
%4 = inttoptr i64 %3 to double*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 24)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = tail call i32 @DiscreteGamma(double* %4, double 4.200000e-01, double 4.200000e-01, i32 3, i32 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), double 4.200000e-01, i32 3)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0))
%16 = load double, double* %4
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %16)
%18 = getelementptr inbounds double, double* %4, i64 1
%19 = load double, double* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %19)
%21 = getelementptr inbounds double, double* %4, i64 2
%22 = load double, double* %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %22)
%24 = tail call i32 @putchar(i32 10)
ret i32 0
}