#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 intsum(int *, int);
double logbino(int, int);
double logmultinom(int *cc, int n) {
  int t, k, i;
  double y, ytot;
  if (n <= 1)
    return 0.0;
  t = intsum(cc, n);
  if (t == 0)
    return 0.0;
  ytot = 0;
  for (i = 0; i < n - 1; i++) {
    k = cc[i];
    y = logbino(t, k);
    ytot += y;
    t -= k;
  }
  return ytot;
}


x86 assembly (clang, -O0):
<logmultinom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jg     1146 <logmultinom+0x26>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11dc <logmultinom+0xbc>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <intsum@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    116c <logmultinom+0x4c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11dc <logmultinom+0xbc>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d2 <logmultinom+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <logbino@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117b <logmultinom+0x5b>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logmultinom>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm0,%xmm0
cmp    $0x2,%esi
jl     1196 <logmultinom+0x76>
mov    %esi,%r15d
mov    %rdi,%r14
call   1030 <intsum@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
je     1196 <logmultinom+0x76>
mov    %eax,%ebp
add    $0xffffffff,%r15d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
mov    (%r14,%rbx,4),%r12d
mov    %ebp,%edi
mov    %r12d,%esi
call   1040 <logbino@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
sub    %r12d,%ebp
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <logmultinom+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @logmultinom(i32* %0, i32 %1) {
%3 = alloca double
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i32* %0, i32** %4
store i32 %1, i32* %5
%11 = load i32, i32* %5
%12 = icmp sle i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
store double 0.000000e+00, double* %3
br label %47
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = load i32, i32* %5
%17 = call i32 @intsum(i32* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store double 0.000000e+00, double* %3
br label %47
21: ; preds = %14
store double 0.000000e+00, double* %10
store i32 0, i32* %8
br label %22
22: ; preds = %42, %21
%23 = load i32, i32* %8
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %45
27: ; preds = %22
%28 = load i32*, i32** %4
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
store i32 %32, i32* %7
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call double @logbino(i32 %33, i32 %34)
store double %35, double* %9
%36 = load double, double* %9
%37 = load double, double* %10
%38 = fadd double %37, %36
store double %38, double* %10
%39 = load i32, i32* %7
%40 = load i32, i32* %6
%41 = sub nsw i32 %40, %39
store i32 %41, i32* %6
br label %42
42: ; preds = %27
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %22
45: ; preds = %22
%46 = load double, double* %10
store double %46, double* %3
br label %47
47: ; preds = %45, %20, %13
%48 = load double, double* %3
ret double %48
}

LLVM IR (-O2):
define double @logmultinom(i32* %0, i32 %1) {
%3 = icmp slt i32 %1, 2
br i1 %3, label %21, label %4
4: ; preds = %2
%5 = tail call i32 @intsum(i32* %0, i32 %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = add nsw i32 %1, -1
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %19, %10 ]
%12 = phi double [ 0.000000e+00, %7 ], [ %17, %10 ]
%13 = phi i32 [ %5, %7 ], [ %18, %10 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %11
%15 = load i32, i32* %14
%16 = tail call double @logbino(i32 %13, i32 %15)
%17 = fadd double %12, %16
%18 = sub nsw i32 %13, %15
%19 = add nuw nsw i64 %11, 1
%20 = icmp eq i64 %19, %9
br i1 %20, label %21, label %10
21: ; preds = %10, %4, %2
%22 = phi double [ 0.000000e+00, %2 ], [ 0.000000e+00, %4 ], [ %17, %10 ]
ret double %22
}