#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 log10(int);
double reduce_factorial(int l, int i) {
  double factorial;
  int x;
  factorial = log10(1.0);
  for (x = l - (i - 1); x < l + 1; x++) {
    factorial = factorial + log10(x);
  }
  return factorial;
}


x86 assembly (clang, -O0):
<reduce_factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x1,%edi
call   1030 <log10@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    117d <reduce_factorial+0x6d>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <reduce_factorial+0x2b>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reduce_factorial>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
mov    $0x1,%edi
call   1030 <log10@plt>
lea    0x1(%r14),%r15d
mov    %r15d,%eax
sub    %ebx,%eax
cmp    %r14d,%eax
jg     1169 <reduce_factorial+0x59>
neg    %ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
lea    (%r15,%rbx,1),%edi
call   1030 <log10@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
inc    %ebx
jne    1140 <reduce_factorial+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @reduce_factorial(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call double @log10(i32 1)
store double %7, double* %5
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = sub nsw i32 %8, %10
store i32 %11, i32* %6
br label %12
12: ; preds = %22, %2
%13 = load i32, i32* %6
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = load double, double* %5
%19 = load i32, i32* %6
%20 = call double @log10(i32 %19)
%21 = fadd double %18, %20
store double %21, double* %5
br label %22
22: ; preds = %17
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %12
25: ; preds = %12
%26 = load double, double* %5
ret double %26
}

LLVM IR (-O2):
define double @reduce_factorial(i32 %0, i32 %1) {
%3 = tail call double @log10(i32 1)
%4 = add i32 %0, 1
%5 = sub i32 %4, %1
%6 = icmp sgt i32 %5, %0
br i1 %6, label %14, label %7
7: ; preds = %2, %7
%8 = phi i32 [ %12, %7 ], [ %5, %2 ]
%9 = phi double [ %11, %7 ], [ %3, %2 ]
%10 = tail call double @log10(i32 %8)
%11 = fadd double %9, %10
%12 = add i32 %8, 1
%13 = icmp eq i32 %8, %0
br i1 %13, label %14, label %7
14: ; preds = %7, %2
%15 = phi double [ %3, %2 ], [ %11, %7 ]
ret double %15
}