#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, minus = 1;
  float s = 0;
  printf("Please input the value of n:\n");
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    s += minus * (1 / (float)i);
    minus *= -1;
  }
  printf("sum=%f\n", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11ac <main+0x8c>
cvtsi2ssl -0x10(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
movss  0xe7f(%rip),%xmm2
divss  %xmm1,%xmm2
movss  -0x14(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
imul   $0xffffffff,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1163 <main+0x43>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe69(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed7(%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>
movss  0xe9d(%rip),%xmm1
xorps  %xmm0,%xmm0
test   $0x1,%al
jne    11c9 <main+0x99>
jmp    11d9 <main+0xa9>
xorps  %xmm0,%xmm0
jmp    11dd <main+0xad>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
mov    $0x1,%edx
xorps  %xmm0,%xmm0
movss  0xe7a(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm2,%xmm2
cvtsi2ss %edx,%xmm2
movaps %xmm1,%xmm3
divss  %xmm2,%xmm3
addss  %xmm3,%xmm0
lea    0x1(%rdx),%esi
xorps  %xmm2,%xmm2
cvtsi2ss %esi,%xmm2
movaps %xmm1,%xmm3
divss  %xmm2,%xmm3
subss  %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 = [30 x i8] c"Please input the value of n:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"sum=%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
store i32 0, i32* %1
store i32 1, i32* %4
store float 0.000000e+00, float* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = 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 %8
8: ; preds = %22, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i32, i32* %4
%14 = sitofp i32 %13 to float
%15 = load i32, i32* %3
%16 = sitofp i32 %15 to float
%17 = fdiv float 1.000000e+00, %16
%18 = load float, float* %5
%19 = call float @llvm.fmuladd.f32(float %14, float %17, float %18)
store float %19, float* %5
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, -1
store i32 %21, i32* %4
br label %22
22: ; preds = %12
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %8
25: ; preds = %8
%26 = load float, float* %5
%27 = fpext float %26 to double
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %27)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"sum=%f\0A\00"
@str = [29 x i8] c"Please input 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 ([29 x i8], [29 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 float [ 0.000000e+00, %10 ], [ %22, %12 ]
%14 = phi i32 [ 1, %10 ], [ %23, %12 ]
%15 = phi i32 [ 0, %10 ], [ %24, %12 ]
%16 = sitofp i32 %14 to float
%17 = fdiv float 1.000000e+00, %16
%18 = fadd float %17, %13
%19 = add nuw i32 %14, 1
%20 = sitofp i32 %19 to float
%21 = fdiv float 1.000000e+00, %20
%22 = call float @llvm.fmuladd.f32(float %21, float -1.000000e+00, float %18)
%23 = add nuw i32 %14, 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 [ 0.000000e+00, %7 ], [ %22, %26 ]
%31 = phi float [ 1.000000e+00, %7 ], [ %27, %26 ]
%32 = icmp eq i32 %8, 0
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = fdiv float 1.000000e+00, %31
%35 = fadd float %34, %30
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 ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %40)
ret i32 0
}