#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(void) {
  int n;
  float sum = 0.0;
  printf("Enter the no of terms: ");
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    sum += (1.0 / i);
  }
  printf("The sum of series is %.2f", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     119d <main+0x7d>
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xe8b(%rip),%xmm1
divsd  %xmm0,%xmm1
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115c <main+0x3c>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe76(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeea(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1162 <main+0x42>
cmp    $0x1,%eax
jne    116a <main+0x4a>
xorpd  %xmm0,%xmm0
movsd  0xea7(%rip),%xmm1
test   $0x1,%al
jne    11d1 <main+0xb1>
jmp    11e9 <main+0xc9>
xorps  %xmm0,%xmm0
jmp    11e9 <main+0xc9>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
xorpd  %xmm0,%xmm0
mov    $0x1,%edx
movsd  0xe80(%rip),%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %edx,%xmm2
movapd %xmm1,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm0,%xmm3
xorps  %xmm0,%xmm0
cvtsd2ss %xmm3,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x1(%rdx),%esi
xorps  %xmm2,%xmm2
cvtsi2sd %esi,%xmm2
movapd %xmm1,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm0,%xmm3
xorps  %xmm0,%xmm0
cvtsd2ss %xmm3,%xmm0
add    $0x2,%edx
cvtss2sd %xmm0,%xmm0
cmp    %ecx,%esi
jne    1180 <main+0x60>
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
test   $0x1,%al
je     11e9 <main+0xc9>
movsd  0xe27(%rip),%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
cvtsd2ss %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe33(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter the no of terms: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"The sum of series is %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca i32
store i32 0, i32* %1
store float 0.000000e+00, float* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 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* %4
br label %7
7: ; preds = %19, %0
%8 = load i32, i32* %4
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %22
11: ; preds = %7
%12 = load i32, i32* %4
%13 = sitofp i32 %12 to double
%14 = fdiv double 1.000000e+00, %13
%15 = load float, float* %3
%16 = fpext float %15 to double
%17 = fadd double %16, %14
%18 = fptrunc double %17 to float
store float %18, float* %3
br label %19
19: ; preds = %11
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %7
22: ; preds = %7
%23 = load float, float* %3
%24 = fpext float %23 to double
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter the no of terms: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"The sum of series is %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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 %24, label %7
7: ; preds = %0
%8 = and i32 %5, 1
%9 = icmp eq i32 %5, 1
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = and i32 %5, -2
br label %27
12: ; preds = %27
%13 = sitofp i32 %41 to double
br label %14
14: ; preds = %12, %7
%15 = phi double [ undef, %7 ], [ %42, %12 ]
%16 = phi double [ 1.000000e+00, %7 ], [ %13, %12 ]
%17 = phi double [ 0.000000e+00, %7 ], [ %42, %12 ]
%18 = icmp eq i32 %8, 0
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = fdiv double 1.000000e+00, %16
%21 = fadd double %17, %20
%22 = fptrunc double %21 to float
%23 = fpext float %22 to double
br label %24
24: ; preds = %19, %14, %0
%25 = phi double [ 0.000000e+00, %0 ], [ %15, %14 ], [ %23, %19 ]
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %25)
ret i32 0
27: ; preds = %27, %10
%28 = phi i32 [ 1, %10 ], [ %41, %27 ]
%29 = phi double [ 0.000000e+00, %10 ], [ %42, %27 ]
%30 = phi i32 [ 0, %10 ], [ %43, %27 ]
%31 = sitofp i32 %28 to double
%32 = fdiv double 1.000000e+00, %31
%33 = fadd double %29, %32
%34 = fptrunc double %33 to float
%35 = add nuw i32 %28, 1
%36 = fpext float %34 to double
%37 = sitofp i32 %35 to double
%38 = fdiv double 1.000000e+00, %37
%39 = fadd double %38, %36
%40 = fptrunc double %39 to float
%41 = add nuw i32 %28, 2
%42 = fpext float %40 to double
%43 = add i32 %30, 2
%44 = icmp eq i32 %43, %11
br i1 %44, label %12, label %27
}