#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, counter;
  float sum = 0;
  printf("Enter the length of the series: ");
  scanf("%d", &n);
  for (counter = 1; counter <= n; counter++) {
    sum += (1.0 / counter);
    printf("(1/%d) ", counter);
    if (counter < n)
      printf("+ ");
  }
  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    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedd(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11cd <main+0xad>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe8b(%rip),%xmm1
divsd  %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ba <main+0x9a>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <main+0x9f>
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   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11c6 <main+0xa6>
xorps  %xmm0,%xmm0
lea    0xed4(%rip),%rbx
lea    0xed5(%rip),%r14
xor    %ebp,%ebp
jmp    1199 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  0xe81(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
cmp    %eax,%ebp
jge    11c9 <main+0xa9>
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%eax
cmp    %eax,%ebp
jge    1170 <main+0x50>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%eax
jmp    1170 <main+0x50>
xorps  %xmm0,%xmm0
lea    0xe67(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
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 = [8 x i8] c"(1/%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 = %27, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %30
11: ; preds = %7
%12 = load i32, i32* %3
%13 = sitofp i32 %12 to double
%14 = fdiv double 1.000000e+00, %13
%15 = load float, float* %4
%16 = fpext float %15 to double
%17 = fadd double %16, %14
%18 = fptrunc double %17 to float
store float %18, float* %4
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %3
%22 = load i32, i32* %2
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %11
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %11
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %7
30: ; preds = %7
%31 = load float, float* %4
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %32)
%34 = load i32, i32* %1
ret i32 %34
}

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 = [8 x i8] c"(1/%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 %25, label %7
7: ; preds = %0, %20
%8 = phi double [ %23, %20 ], [ 0.000000e+00, %0 ]
%9 = phi i32 [ %22, %20 ], [ 1, %0 ]
%10 = sitofp i32 %9 to double
%11 = fdiv double 1.000000e+00, %10
%12 = fadd double %8, %11
%13 = fptrunc double %12 to float
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%15 = load i32, i32* %1
%16 = icmp slt i32 %9, %15
br i1 %16, label %17, label %20
17: ; preds = %7
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* %1
br label %20
20: ; preds = %7, %17
%21 = phi i32 [ %15, %7 ], [ %19, %17 ]
%22 = add nuw nsw i32 %9, 1
%23 = fpext float %13 to double
%24 = icmp slt i32 %9, %21
br i1 %24, label %7, label %25
25: ; preds = %20, %0
%26 = phi double [ 0.000000e+00, %0 ], [ %23, %20 ]
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %26)
ret i32 0
}