#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*/ printf(char *, ...);
void series4(int n) {
  int i;
  double sum = 0.0;
  for (i = 1; i <= n; i++) {
    printf("1/%d", i);
    i != n ? printf("+") : printf(".");
    sum += 1.0 / i;
  }
  printf("\nSum of the above series is %f\n", sum);
}


x86 assembly (clang, -O0):
<series4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     119d <series4+0x8d>
mov    -0x8(%rbp),%esi
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     1166 <series4+0x56>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1174 <series4+0x64>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe7f(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112a <series4+0x1a>
movsd  -0x10(%rbp),%xmm0
lea    0xe68(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<series4>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
jle    11a9 <series4+0x89>
mov    %edi,%r15d
neg    %r15d
mov    $0x1,%ebx
xorpd  %xmm0,%xmm0
lea    0xec5(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
mov    %r15d,%ecx
add    %ebx,%ecx
sete   %al
lea    (%rax,%rax,2),%edi
add    $0x2b,%edi
call   1030 <putchar@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xe7a(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1150 <series4+0x30>
jmp    11ad <series4+0x8d>
xorpd  %xmm0,%xmm0
lea    0xe59(%rip),%rdi
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"1/%d\00"
@.str.1 = [2 x i8] c"+\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [32 x i8] c"\0ASum of the above series is %f\0A\00"
define void @series4(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
store i32 %0, i32* %2
store double 0.000000e+00, double* %4
store i32 1, i32* %3
br label %5
5: ; preds = %26, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp sle i32 %6, %7
br i1 %8, label %9, label %29
9: ; preds = %5
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
%13 = load i32, i32* %2
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
17: ; preds = %9
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ %16, %15 ], [ %18, %17 ]
%21 = load i32, i32* %3
%22 = sitofp i32 %21 to double
%23 = fdiv double 1.000000e+00, %22
%24 = load double, double* %4
%25 = fadd double %24, %23
store double %25, double* %4
br label %26
26: ; preds = %19
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %5
29: ; preds = %5
%30 = load double, double* %4
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), double %30)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"1/%d\00"
@.str.3 = [32 x i8] c"\0ASum of the above series is %f\0A\00"
define void @series4(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %15, label %3
3: ; preds = %1, %3
%4 = phi double [ %12, %3 ], [ 0.000000e+00, %1 ]
%5 = phi i32 [ %13, %3 ], [ 1, %1 ]
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %5, %0
%8 = select i1 %7, i32 46, i32 43
%9 = tail call i32 @putchar(i32 %8)
%10 = sitofp i32 %5 to double
%11 = fdiv double 1.000000e+00, %10
%12 = fadd double %4, %11
%13 = add nuw i32 %5, 1
%14 = icmp eq i32 %5, %0
br i1 %14, label %15, label %3
15: ; preds = %3, %1
%16 = phi double [ 0.000000e+00, %1 ], [ %12, %3 ]
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), double %16)
ret void
}