#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 pow(int, int);
int /*<<< orphan*/ printf(char *, float);
void ex5() {
  float sum = 0;
  int n = 1;
  while (n < 101) {
    sum += pow(-1, n + 1) * 1 / n;
    n++;
  }
  printf("%f", sum);
}


x86 assembly (clang, -O0):
<ex5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x65,-0x8(%rbp)
jge    1174 <ex5+0x54>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    $0xffffffff,%edi
call   1040 <pow@plt>
shl    $0x0,%eax
cltd
idivl  -0x8(%rbp)
cvtsi2ss %eax,%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1137 <ex5+0x17>
movss  -0x4(%rbp),%xmm0
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex5>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
mov    $0x3,%ebx
movss  %xmm0,0xc(%rsp)
lea    -0x2(%rbx),%r14d
lea    -0x1(%rbx),%ebp
mov    $0xffffffff,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
cltd
idiv   %r14d
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
mov    $0xffffffff,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
cltd
idiv   %ebp
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  0xc(%rsp),%xmm0
add    $0x2,%ebx
cmp    $0x67,%ebx
jne    1130 <ex5+0x10>
lea    0xe75(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%f\00"
define void @ex5() {
%1 = alloca float
%2 = alloca i32
store float 0.000000e+00, float* %1
store i32 1, i32* %2
br label %3
3: ; preds = %6, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 101
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 1
%9 = call i32 @pow(i32 -1, i32 %8)
%10 = mul nsw i32 %9, 1
%11 = load i32, i32* %2
%12 = sdiv i32 %10, %11
%13 = sitofp i32 %12 to float
%14 = load float, float* %1
%15 = fadd float %14, %13
store float %15, float* %1
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %3
18: ; preds = %3
%19 = load float, float* %1
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %19)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%f\00"
define void @ex5() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 1, %0 ], [ %9, %1 ]
%3 = phi float [ 0.000000e+00, %0 ], [ %13, %1 ]
%4 = add nuw nsw i32 %2, 1
%5 = tail call i32 @pow(i32 -1, i32 %4)
%6 = sdiv i32 %5, %2
%7 = sitofp i32 %6 to float
%8 = fadd float %3, %7
%9 = add nuw nsw i32 %2, 2
%10 = tail call i32 @pow(i32 -1, i32 %9)
%11 = sdiv i32 %10, %4
%12 = sitofp i32 %11 to float
%13 = fadd float %8, %12
%14 = icmp eq i32 %9, 101
br i1 %14, label %15, label %1
15: ; preds = %1
%16 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %13)
ret void
}