#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 pow(double, int);
int /*<<< orphan*/ printf(char *);
double inc_list_sum(double base, double inc, int len) {
  if (inc < 0) {
    printf("[Error] Bad arguments!\n");
    return -1;
  }
  if (inc == 1) {
    return (base * len);
  } else {
    return (base * (1 - pow(inc, len)) / (1 - inc));
  }
}


x86 assembly (clang, -O0):
<inc_list_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1161 <inc_list_sum+0x41>
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d9 <inc_list_sum+0xb9>
movsd  -0x18(%rbp),%xmm0
movsd  0xe92(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1196 <inc_list_sum+0x76>
jp     1196 <inc_list_sum+0x76>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d9 <inc_list_sum+0xb9>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
call   1040 <pow@plt>
movsd  -0x28(%rbp),%xmm0
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe35(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inc_list_sum>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    114b <inc_list_sum+0x2b>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
movsd  0xec2(%rip),%xmm0
add    $0x18,%rsp
ret
ucomisd 0xead(%rip),%xmm1
jne    1167 <inc_list_sum+0x47>
jp     1167 <inc_list_sum+0x47>
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
mulsd  %xmm2,%xmm0
add    $0x18,%rsp
ret
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
call   1040 <pow@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  0xe68(%rip),%xmm1
subsd  0x10(%rsp),%xmm1
divsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"[Error] Bad arguments!\0A\00"
define double @inc_list_sum(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
%8 = load double, double* %6
%9 = fcmp olt double %8, 0.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store double -1.000000e+00, double* %4
br label %31
12: ; preds = %3
%13 = load double, double* %6
%14 = fcmp oeq double %13, 1.000000e+00
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load double, double* %5
%17 = load i32, i32* %7
%18 = sitofp i32 %17 to double
%19 = fmul double %16, %18
store double %19, double* %4
br label %31
20: ; preds = %12
%21 = load double, double* %5
%22 = load double, double* %6
%23 = load i32, i32* %7
%24 = call i32 @pow(double %22, i32 %23)
%25 = sub nsw i32 1, %24
%26 = sitofp i32 %25 to double
%27 = fmul double %21, %26
%28 = load double, double* %6
%29 = fsub double 1.000000e+00, %28
%30 = fdiv double %27, %29
store double %30, double* %4
br label %31
31: ; preds = %20, %15, %10
%32 = load double, double* %4
ret double %32
}

LLVM IR (-O2):
@str = [23 x i8] c"[Error] Bad arguments!\00"
define double @inc_list_sum(double %0, double %1, i32 %2) {
%4 = fcmp olt double %1, 0.000000e+00
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %19
7: ; preds = %3
%8 = fcmp oeq double %1, 1.000000e+00
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = sitofp i32 %2 to double
%11 = fmul double %10, %0
br label %19
12: ; preds = %7
%13 = tail call i32 @pow(double %1, i32 %2)
%14 = sub nsw i32 1, %13
%15 = sitofp i32 %14 to double
%16 = fmul double %15, %0
%17 = fsub double 1.000000e+00, %1
%18 = fdiv double %16, %17
br label %19
19: ; preds = %12, %9, %5
%20 = phi double [ -1.000000e+00, %5 ], [ %11, %9 ], [ %18, %12 ]
ret double %20
}