#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ log10(double);
int /*<<< orphan*/ stderr;
double log_kai1(int n) {
  int i;
  double k;
  if (n < 0) {
    fprintf(stderr, "Error : n < 0  in log_kai1()\n");
    return 0.;
  }
  k = 0.;
  if (n <= 1)
    return k;
  for (i = 2; i <= n; i++)
    k += log10((double)i);
  return k;
}


x86 assembly (clang, -O0):
<log_kai1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1157 <log_kai1+0x37>
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
lea    0xebb(%rip),%rsi
call   1030 <fprintf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11bc <log_kai1+0x9c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jg     1178 <log_kai1+0x58>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11bc <log_kai1+0x9c>
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b2 <log_kai1+0x92>
cvtsi2sdl -0x10(%rbp),%xmm0
call   1040 <log10@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117f <log_kai1+0x5f>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_kai1>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
js     1181 <log_kai1+0x61>
mov    %edi,%r14d
xorps  %xmm0,%xmm0
cmp    $0x2,%edi
jb     1199 <log_kai1+0x79>
neg    %r14d
mov    $0x2,%ebx
xorps  %xmm0,%xmm0
xchg   %ax,%ax
movsd  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
call   1040 <log10@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1140 <log_kai1+0x20>
jmp    1199 <log_kai1+0x79>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
call   1030 <fprintf@plt>
xorps  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Error : n < 0 in log_kai1()\0A\00"
define double @log_kai1(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %2
br label %33
11: ; preds = %1
store double 0.000000e+00, double* %5
%12 = load i32, i32* %3
%13 = icmp sle i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = load double, double* %5
store double %15, double* %2
br label %33
16: ; preds = %11
store i32 2, i32* %4
br label %17
17: ; preds = %28, %16
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32, i32* %4
%23 = sitofp i32 %22 to double
%24 = call i64 @log10(double %23)
%25 = sitofp i64 %24 to double
%26 = load double, double* %5
%27 = fadd double %26, %25
store double %27, double* %5
br label %28
28: ; preds = %21
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %17
31: ; preds = %17
%32 = load double, double* %5
store double %32, double* %2
br label %33
33: ; preds = %31, %14, %8
%34 = load double, double* %2
ret double %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Error : n < 0 in log_kai1()\0A\00"
define double @log_kai1(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %17
6: ; preds = %1
%7 = icmp ult i32 %0, 2
br i1 %7, label %17, label %8
8: ; preds = %6, %8
%9 = phi double [ %14, %8 ], [ 0.000000e+00, %6 ]
%10 = phi i32 [ %15, %8 ], [ 2, %6 ]
%11 = sitofp i32 %10 to double
%12 = tail call i64 @log10(double %11)
%13 = sitofp i64 %12 to double
%14 = fadd double %9, %13
%15 = add nuw i32 %10, 1
%16 = icmp eq i32 %10, %0
br i1 %16, label %17, label %8
17: ; preds = %8, %6, %3
%18 = phi double [ 0.000000e+00, %3 ], [ 0.000000e+00, %6 ], [ %14, %8 ]
ret double %18
}