#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_s(char *, int *);
int /*<<< orphan*/ system(char *);
main() {
  int number, i;
  double sum = 0;
  printf("Enter a number: ");
  scanf_s("%d", &number);
  for (i = 1; i <= number; i++) {
    sum = sum + (double)i / (double)(i + 1);
  }
  printf("Sum is : %.2f\n", sum);
  printf("\n");
  system("pause");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf_s@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11a7 <main+0x77>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116c <main+0x3c>
movsd  -0x18(%rbp),%xmm0
lea    0xe61(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe54(%rip),%rdi
call   1030 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xebb(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf_s@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1178 <main+0x38>
cmp    $0x1,%eax
jne    117e <main+0x3e>
mov    $0x1,%edx
xorpd  %xmm0,%xmm0
jmp    11cc <main+0x8c>
xorpd  %xmm0,%xmm0
jmp    11e9 <main+0xa9>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
neg    %ecx
mov    $0x1,%esi
xorpd  %xmm1,%xmm1
xchg   %ax,%ax
xorps  %xmm2,%xmm2
cvtsi2sd %esi,%xmm2
lea    0x1(%rsi),%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
divsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
lea    0x2(%rsi),%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
lea    (%rcx,%rsi,1),%edi
add    $0x2,%edi
movapd %xmm0,%xmm1
mov    %edx,%esi
cmp    $0x1,%edi
jne    1190 <main+0x50>
test   $0x1,%al
je     11e9 <main+0xa9>
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
add    $0x1,%edx
xorps  %xmm2,%xmm2
cvtsi2sd %edx,%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
lea    0xe24(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe1b(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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