#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 *, double);
int main(void) {
  double v, i;
  for (v = 0, i = 1; i < 1000000000; i++) {
    v += 1.0 / i;
  }
  printf("lim (n-> infinity) (1/n) = %f\n", v);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xed1(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xecc(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1175 <main+0x65>
movsd  0xeb1(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe9a(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1134 <main+0x24>
movsd  -0x10(%rbp),%xmm0
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xorpd  %xmm0,%xmm0
movsd  0xee3(%rip),%xmm1
mov    $0x3,%eax
movsd  0xede(%rip),%xmm2
movapd %xmm1,%xmm3
xchg   %ax,%ax
movapd %xmm1,%xmm4
divsd  %xmm3,%xmm4
addsd  %xmm0,%xmm4
lea    -0x1(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movapd %xmm1,%xmm5
divsd  %xmm0,%xmm5
addsd  %xmm4,%xmm5
xorps  %xmm4,%xmm4
cvtsi2sd %eax,%xmm4
movapd %xmm1,%xmm0
divsd  %xmm4,%xmm0
addsd  %xmm5,%xmm0
addsd  %xmm2,%xmm3
add    $0x3,%eax
cmp    $0x3b9aca02,%eax
jne    1130 <main+0x20>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"lim (n-> infinity) (1/n) = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 1.000000e+00, double* %3
br label %4
4: ; preds = %12, %0
%5 = load double, double* %3
%6 = fcmp olt double %5, 1.000000e+09
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load double, double* %3
%9 = fdiv double 1.000000e+00, %8
%10 = load double, double* %2
%11 = fadd double %10, %9
store double %11, double* %2
br label %12
12: ; preds = %7
%13 = load double, double* %3
%14 = fadd double %13, 1.000000e+00
store double %14, double* %3
br label %4
15: ; preds = %4
%16 = load double, double* %2
%17 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"lim (n-> infinity) (1/n) = %f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 1, %0 ], [ %15, %1 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %14, %1 ]
%4 = sitofp i32 %2 to double
%5 = fdiv double 1.000000e+00, %4
%6 = fadd double %3, %5
%7 = add nuw nsw i32 %2, 1
%8 = sitofp i32 %7 to double
%9 = fdiv double 1.000000e+00, %8
%10 = fadd double %6, %9
%11 = add nuw nsw i32 %2, 2
%12 = sitofp i32 %11 to double
%13 = fdiv double 1.000000e+00, %12
%14 = fadd double %10, %13
%15 = add nuw nsw i32 %2, 3
%16 = icmp eq i32 %15, 1000000000
br i1 %16, label %17, label %1
17: ; preds = %1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %14)
ret i32 0
}