#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() {
  float sum = 0;
  int i, n;
  printf("Enter the value of n\n");
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    sum = sum + (1 / (float)i);
  }
  printf("SUM = %f", 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,-0x8(%rbp)
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1195 <main+0x75>
movss  -0x8(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm2
movss  0xe86(%rip),%xmm1
divss  %xmm2,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115c <main+0x3c>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe78(%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    0xed8(%rip),%rdi
call   1030 <puts@plt>
lea    0xec0(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    116c <main+0x3c>
cmp    $0x1,%eax
jne    1171 <main+0x41>
xorps  %xmm0,%xmm0
movss  0xe9a(%rip),%xmm1
test   $0x1,%al
jne    11c9 <main+0x99>
jmp    11d9 <main+0xa9>
xorps  %xmm0,%xmm0
jmp    11dd <main+0xad>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
xorps  %xmm0,%xmm0
mov    $0x1,%edx
movss  0xe7a(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm2,%xmm2
cvtsi2ss %edx,%xmm2
movaps %xmm1,%xmm3
divss  %xmm2,%xmm3
addss  %xmm0,%xmm3
lea    0x1(%rdx),%esi
xorps  %xmm2,%xmm2
cvtsi2ss %esi,%xmm2
movaps %xmm1,%xmm0
divss  %xmm2,%xmm0
addss  %xmm3,%xmm0
add    $0x2,%edx
cmp    %ecx,%esi
jne    1190 <main+0x60>
xorps  %xmm1,%xmm1
cvtsi2ss %edx,%xmm1
test   $0x1,%al
je     11d9 <main+0xa9>
movss  0xe2f(%rip),%xmm2
divss  %xmm1,%xmm2
addss  %xmm2,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe23(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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