#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 DMax(double *, int);
scalar_t__ exp(double);
double log(double);
float DLogSum(double *vec, int n) {
  int x;
  double max, sum;
  max = DMax(vec, n);
  sum = 0.0;
  for (x = 0; x < n; x++)
    if (vec[x] > max - 50.)
      sum += exp(vec[x] - max);
  sum = log(sum) + max;
  return sum;
}


x86 assembly (clang, -O0):
<DLogSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <DMax@plt>
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cc <DLogSum+0x9c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe7b(%rip),%xmm2
subsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    11b9 <DLogSum+0x89>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1040 <exp@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11be <DLogSum+0x8e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115f <DLogSum+0x2f>
movsd  -0x20(%rbp),%xmm0
call   1050 <log@plt>
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DLogSum>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
call   1030 <DMax@plt>
test   %ebp,%ebp
movsd  %xmm0,0x8(%rsp)
jle    11b0 <DLogSum+0x80>
movsd  0xeac(%rip),%xmm2
addsd  %xmm0,%xmm2
mov    %ebp,%ebp
xorpd  %xmm1,%xmm1
xor    %ebx,%ebx
movsd  %xmm2,0x10(%rsp)
jmp    1179 <DLogSum+0x49>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11b4 <DLogSum+0x84>
movsd  (%r14,%rbx,8),%xmm0
ucomisd %xmm2,%xmm0
jbe    1170 <DLogSum+0x40>
subsd  0x8(%rsp),%xmm0
movsd  %xmm1,0x18(%rsp)
call   1040 <exp@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
jmp    1170 <DLogSum+0x40>
xorpd  %xmm1,%xmm1
movapd %xmm1,%xmm0
call   1050 <log@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define float @DLogSum(double* %0, i32 %1) {
%3 = tail call double @DMax(double* %0, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %23
5: ; preds = %2
%6 = fadd double %3, -5.000000e+01
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %5, %19
%9 = phi i64 [ 0, %5 ], [ %21, %19 ]
%10 = phi double [ 0.000000e+00, %5 ], [ %20, %19 ]
%11 = getelementptr inbounds double, double* %0, i64 %9
%12 = load double, double* %11
%13 = fcmp ogt double %12, %6
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = fsub double %12, %3
%16 = tail call i64 @exp(double %15)
%17 = sitofp i64 %16 to double
%18 = fadd double %10, %17
br label %19
19: ; preds = %8, %14
%20 = phi double [ %18, %14 ], [ %10, %8 ]
%21 = add nuw nsw i64 %9, 1
%22 = icmp eq i64 %21, %7
br i1 %22, label %23, label %8
23: ; preds = %19, %2
%24 = phi double [ 0.000000e+00, %2 ], [ %20, %19 ]
%25 = tail call double @log(double %24)
%26 = fadd double %3, %25
%27 = fptrunc double %26 to float
ret float %27
}