#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 */
double asum(double *, int);
int intsum(int *, int);
scalar_t__ lgamma(double);
double dirmult(double *pp, int *aa, int len) {
  int t, i, m;
  double y1, y2, ysum;
  double top, bot;
  m = len;
  t = intsum(aa, m);
  if (t < 1)
    return 0.0;
  top = bot = 0.0;
  ysum = asum(pp, m);
  for (i = 0; i < m; i++) {
    top += lgamma(pp[i] + (double)aa[i]);
    bot += lgamma(pp[i]);
  }
  top += lgamma(ysum);
  bot += lgamma(ysum + (double)t);
  y1 = top - bot;
  return y1 - y2;
}


x86 assembly (clang, -O0):
<dirmult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1030 <intsum@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jge    116f <dirmult+0x3f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125d <dirmult+0x12d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1040 <asum@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1204 <dirmult+0xd4>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm1
addsd  %xmm1,%xmm0
call   1050 <lgamma@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <lgamma@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1197 <dirmult+0x67>
movsd  -0x40(%rbp),%xmm0
call   1050 <lgamma@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
call   1050 <lgamma@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirmult>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %edx,%esi
call   1030 <intsum@plt>
test   %eax,%eax
jle    11bf <dirmult+0x8f>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <asum@plt>
movsd  %xmm0,0x8(%rsp)
test   %ebp,%ebp
jle    1196 <dirmult+0x66>
mov    %ebp,%r12d
xor    %ebp,%ebp
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sdl (%r14,%rbp,4),%xmm0
addsd  (%rbx,%rbp,8),%xmm0
call   1050 <lgamma@plt>
movsd  (%rbx,%rbp,8),%xmm0
call   1050 <lgamma@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1170 <dirmult+0x40>
movsd  0x8(%rsp),%xmm0
call   1050 <lgamma@plt>
cvtsi2sd %r15d,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
call   1050 <lgamma@plt>
movsd  0xe43(%rip),%xmm0
jmp    11c2 <dirmult+0x92>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @dirmult(double* %0, i32* %1, i32 %2) {
%4 = alloca double
%5 = alloca double*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double* %0, double** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%16 = load i32, i32* %7
store i32 %16, i32* %10
%17 = load i32*, i32** %6
%18 = load i32, i32* %10
%19 = call i32 @intsum(i32* %17, i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %3
store double 0.000000e+00, double* %4
br label %80
23: ; preds = %3
store double 0.000000e+00, double* %15
store double 0.000000e+00, double* %14
%24 = load double*, double** %5
%25 = load i32, i32* %10
%26 = call double @asum(double* %24, i32 %25)
store double %26, double* %13
store i32 0, i32* %9
br label %27
27: ; preds = %57, %23
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %60
31: ; preds = %27
%32 = load double*, double** %5
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = load i32*, i32** %6
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = sitofp i32 %41 to double
%43 = fadd double %36, %42
%44 = call i64 @lgamma(double %43)
%45 = sitofp i64 %44 to double
%46 = load double, double* %14
%47 = fadd double %46, %45
store double %47, double* %14
%48 = load double*, double** %5
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
%53 = call i64 @lgamma(double %52)
%54 = sitofp i64 %53 to double
%55 = load double, double* %15
%56 = fadd double %55, %54
store double %56, double* %15
br label %57
57: ; preds = %31
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %27
60: ; preds = %27
%61 = load double, double* %13
%62 = call i64 @lgamma(double %61)
%63 = sitofp i64 %62 to double
%64 = load double, double* %14
%65 = fadd double %64, %63
store double %65, double* %14
%66 = load double, double* %13
%67 = load i32, i32* %8
%68 = sitofp i32 %67 to double
%69 = fadd double %66, %68
%70 = call i64 @lgamma(double %69)
%71 = sitofp i64 %70 to double
%72 = load double, double* %15
%73 = fadd double %72, %71
store double %73, double* %15
%74 = load double, double* %14
%75 = load double, double* %15
%76 = fsub double %74, %75
store double %76, double* %11
%77 = load double, double* %11
%78 = load double, double* %12
%79 = fsub double %77, %78
store double %79, double* %4
br label %80
80: ; preds = %60, %22
%81 = load double, double* %4
ret double %81
}

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