#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, double);
char *SeriesSum(int times) {
  char *result = (char *)malloc(3 * sizeof(char));
  int denominator = 1;
  double sum = 0.0;
  while (times--) {
    sum += 1.0 / denominator;
    denominator += 3;
  }
  sprintf(result, "%.2f", sum);
  return result;
}


x86 assembly (clang, -O0):
<SeriesSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x3,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     1185 <SeriesSum+0x65>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe97(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <SeriesSum+0x28>
mov    -0x10(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
lea    0xe73(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SeriesSum>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x3,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
je     114f <SeriesSum+0x2f>
cmp    $0x1,%ebp
jne    1155 <SeriesSum+0x35>
movsd  0xebd(%rip),%xmm1
xorpd  %xmm0,%xmm0
test   $0x1,%bpl
jne    11bb <SeriesSum+0x9b>
jmp    11cb <SeriesSum+0xab>
xorpd  %xmm0,%xmm0
jmp    11cb <SeriesSum+0xab>
mov    %ebp,%eax
and    $0xfffffffe,%eax
movsd  0xe9e(%rip),%xmm1
xorpd  %xmm0,%xmm0
mov    $0x4,%ecx
movsd  0xe95(%rip),%xmm2
movapd %xmm1,%xmm3
nopw   0x0(%rax,%rax,1)
movapd %xmm1,%xmm4
divsd  %xmm3,%xmm4
addsd  %xmm0,%xmm4
xorps  %xmm5,%xmm5
cvtsi2sd %ecx,%xmm5
movapd %xmm1,%xmm0
divsd  %xmm5,%xmm0
addsd  %xmm4,%xmm0
addsd  %xmm2,%xmm3
add    $0x6,%ecx
add    $0xfffffffe,%eax
jne    1180 <SeriesSum+0x60>
add    $0xfffffffd,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
test   $0x1,%bpl
je     11cb <SeriesSum+0xab>
movsd  0xe3d(%rip),%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%.2f\00"
define i8* @SeriesSum(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %2
%6 = call i64 @malloc(i32 3)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
store i32 1, i32* %4
store double 0.000000e+00, double* %5
br label %8
8: ; preds = %12, %1
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i32, i32* %4
%14 = sitofp i32 %13 to double
%15 = fdiv double 1.000000e+00, %14
%16 = load double, double* %5
%17 = fadd double %16, %15
store double %17, double* %5
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 3
store i32 %19, i32* %4
br label %8
20: ; preds = %8
%21 = load i8*, i8** %3
%22 = load double, double* %5
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %22)
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.2f\00"
define i8* @SeriesSum(i32 %0) {
%2 = tail call i64 @malloc(i32 3)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i32 %0, 0
br i1 %4, label %34, label %5
5: ; preds = %1
%6 = and i32 %0, 1
%7 = icmp eq i32 %0, 1
br i1 %7, label %26, label %8
8: ; preds = %5
%9 = and i32 %0, -2
br label %10
10: ; preds = %10, %8
%11 = phi double [ 0.000000e+00, %8 ], [ %20, %10 ]
%12 = phi i32 [ 1, %8 ], [ %21, %10 ]
%13 = phi i32 [ 0, %8 ], [ %22, %10 ]
%14 = sitofp i32 %12 to double
%15 = fdiv double 1.000000e+00, %14
%16 = fadd double %11, %15
%17 = add nuw nsw i32 %12, 3
%18 = sitofp i32 %17 to double
%19 = fdiv double 1.000000e+00, %18
%20 = fadd double %16, %19
%21 = add nuw nsw i32 %12, 6
%22 = add i32 %13, 2
%23 = icmp eq i32 %22, %9
br i1 %23, label %24, label %10
24: ; preds = %10
%25 = sitofp i32 %21 to double
br label %26
26: ; preds = %24, %5
%27 = phi double [ undef, %5 ], [ %20, %24 ]
%28 = phi double [ 0.000000e+00, %5 ], [ %20, %24 ]
%29 = phi double [ 1.000000e+00, %5 ], [ %25, %24 ]
%30 = icmp eq i32 %6, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = fdiv double 1.000000e+00, %29
%33 = fadd double %28, %32
br label %34
34: ; preds = %31, %26, %1
%35 = phi double [ 0.000000e+00, %1 ], [ %27, %26 ], [ %33, %31 ]
%36 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %35)
ret i8* %3
}