#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 gsl_sf_lngamma(double);
double vector_betaln(long n, double *a) {
  long i;
  double sum_a = 0, sum_ga = 0;
  for (i = 0; i < n; i++) {
    sum_a += a[i];
    sum_ga += gsl_sf_lngamma(a[i]);
  }
  return sum_ga - gsl_sf_lngamma(sum_a);
}


x86 assembly (clang, -O0):
<vector_betaln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    118a <vector_betaln+0x7a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <gsl_sf_lngamma@plt>
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <vector_betaln+0x28>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <gsl_sf_lngamma@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_betaln>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
jle    1174 <vector_betaln+0x64>
mov    %rsi,%r14
mov    %rdi,%r15
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%r14,%rbx,8),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <gsl_sf_lngamma@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm1
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <vector_betaln+0x30>
jmp    1181 <vector_betaln+0x71>
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
call   1030 <gsl_sf_lngamma@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @vector_betaln(i64 %0, double* %1) {
%3 = alloca i64
%4 = alloca double*
%5 = alloca i64
%6 = alloca double
%7 = alloca double
store i64 %0, i64* %3
store double* %1, double** %4
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store i64 0, i64* %5
br label %8
8: ; preds = %26, %2
%9 = load i64, i64* %5
%10 = load i64, i64* %3
%11 = icmp slt i64 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = load double*, double** %4
%14 = load i64, i64* %5
%15 = getelementptr inbounds double, double* %13, i64 %14
%16 = load double, double* %15
%17 = load double, double* %6
%18 = fadd double %17, %16
store double %18, double* %6
%19 = load double*, double** %4
%20 = load i64, i64* %5
%21 = getelementptr inbounds double, double* %19, i64 %20
%22 = load double, double* %21
%23 = call double @gsl_sf_lngamma(double %22)
%24 = load double, double* %7
%25 = fadd double %24, %23
store double %25, double* %7
br label %26
26: ; preds = %12
%27 = load i64, i64* %5
%28 = add nsw i64 %27, 1
store i64 %28, i64* %5
br label %8
29: ; preds = %8
%30 = load double, double* %7
%31 = load double, double* %6
%32 = call double @gsl_sf_lngamma(double %31)
%33 = fsub double %30, %32
ret double %33
}

LLVM IR (-O2):
define double @vector_betaln(i64 %0, double* nocapture %1) {
%3 = icmp sgt i64 %0, 0
br i1 %3, label %4, label %15
4: ; preds = %2, %4
%5 = phi double [ %12, %4 ], [ 0.000000e+00, %2 ]
%6 = phi double [ %10, %4 ], [ 0.000000e+00, %2 ]
%7 = phi i64 [ %13, %4 ], [ 0, %2 ]
%8 = getelementptr inbounds double, double* %1, i64 %7
%9 = load double, double* %8
%10 = fadd double %6, %9
%11 = tail call double @gsl_sf_lngamma(double %9)
%12 = fadd double %5, %11
%13 = add nuw nsw i64 %7, 1
%14 = icmp eq i64 %13, %0
br i1 %14, label %15, label %4
15: ; preds = %4, %2
%16 = phi double [ 0.000000e+00, %2 ], [ %10, %4 ]
%17 = phi double [ 0.000000e+00, %2 ], [ %12, %4 ]
%18 = tail call double @gsl_sf_lngamma(double %16)
%19 = fsub double %17, %18
ret double %19
}