#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i;
  float sum = 0;
  printf("Enter the length of the series: ");
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    printf("%d/%d ", i, i + 1);
    if (i < n)
      printf("+ ");
    sum += ((float)i) / (i + 1);
  }
  printf("= %.4f\n", sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11c4 <main+0xa4>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1199 <main+0x79>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cvtsi2ssl -0xc(%rbp),%xmm0
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115c <main+0x3c>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe5a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
cmpl   $0x0,(%rsp)
jle    11c8 <main+0xa8>
mov    $0x1,%ebx
xorps  %xmm0,%xmm0
lea    0xecb(%rip),%r14
lea    0xecb(%rip),%r15
jmp    1195 <main+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %ebp,%xmm1
divss  %xmm1,%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,%xmm0
cmp    %eax,%ebx
mov    %ebp,%ebx
jge    11c2 <main+0xa2>
movss  %xmm0,0x4(%rsp)
lea    0x1(%rbx),%ebp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%eax
cmp    %eax,%ebx
jge    1170 <main+0x50>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%eax
jmp    1170 <main+0x50>
cvtss2sd %xmm0,%xmm0
jmp    11cb <main+0xab>
xorps  %xmm0,%xmm0
lea    0xe5c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [33 x i8] c"Enter the length of the series: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [7 x i8] c"%d/%d \00"
@.str.3 = [3 x i8] c"+ \00"
@.str.4 = [8 x i8] c"= %.4f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
br i1 %6, label %26, label %7
7: ; preds = %0, %17
%8 = phi float [ %22, %17 ], [ 0.000000e+00, %0 ]
%9 = phi i32 [ %10, %17 ], [ 1, %0 ]
%10 = add nuw nsw i32 %9, 1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %10)
%12 = load i32, i32* %1
%13 = icmp slt i32 %9, %12
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* %1
br label %17
17: ; preds = %14, %7
%18 = phi i32 [ %16, %14 ], [ %12, %7 ]
%19 = sitofp i32 %9 to float
%20 = sitofp i32 %10 to float
%21 = fdiv float %19, %20
%22 = fadd float %8, %21
%23 = icmp slt i32 %9, %18
br i1 %23, label %7, label %24
24: ; preds = %17
%25 = fpext float %22 to double
br label %26
26: ; preds = %24, %0
%27 = phi double [ 0.000000e+00, %0 ], [ %25, %24 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %27)
ret i32 0
}