#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(int argc, char *argv[]) {
  double sum = 0.0;
  int i = 0;
  for (; i <= 10000000; ++i) {
    sum += 1.0 / (1e14 + (i + 0.5) * (i + 0.5));
  }
  sum *= 4.0 * 10000000;
  printf("PI approximately equals to %.8f\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x989680,-0x1c(%rbp)
jg     1198 <main+0x88>
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xec9(%rip),%xmm0
addsd  %xmm0,%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xeb8(%rip),%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm1
movsd  0xea0(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe8c(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <main+0x25>
movsd  0xe60(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xorpd  %xmm1,%xmm1
mov    $0x1,%eax
movsd  0xede(%rip),%xmm2
movsd  0xede(%rip),%xmm3
movsd  0xede(%rip),%xmm4
movsd  0xede(%rip),%xmm5
xorpd  %xmm6,%xmm6
xchg   %ax,%ax
movapd %xmm1,%xmm7
addsd  %xmm2,%xmm7
mulsd  %xmm7,%xmm7
addsd  %xmm3,%xmm7
movapd %xmm4,%xmm0
divsd  %xmm7,%xmm0
addsd  %xmm6,%xmm0
cmp    $0x989681,%eax
je     118f <main+0x7f>
xorps  %xmm6,%xmm6
cvtsi2sd %eax,%xmm6
addsd  %xmm2,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm3,%xmm6
movapd %xmm4,%xmm7
divsd  %xmm6,%xmm7
addsd  %xmm7,%xmm0
addsd  %xmm5,%xmm1
add    $0x2,%eax
movapd %xmm0,%xmm6
jmp    1140 <main+0x30>
mulsd  0xe89(%rip),%xmm0
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"PI approximately equals to %.8f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %6
store i32 0, i32* %7
br label %8
8: ; preds = %22, %2
%9 = load i32, i32* %7
%10 = icmp sle i32 %9, 10000000
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32, i32* %7
%13 = sitofp i32 %12 to double
%14 = fadd double %13, 5.000000e-01
%15 = load i32, i32* %7
%16 = sitofp i32 %15 to double
%17 = fadd double %16, 5.000000e-01
%18 = call double @llvm.fmuladd.f64(double %14, double %17, double 1.000000e+14)
%19 = fdiv double 1.000000e+00, %18
%20 = load double, double* %6
%21 = fadd double %20, %19
store double %21, double* %6
br label %22
22: ; preds = %11
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %8
25: ; preds = %8
%26 = load double, double* %6
%27 = fmul double %26, 4.000000e+07
store double %27, double* %6
%28 = load double, double* %6
%29 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), double %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"PI approximately equals to %.8f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %13, %2
%4 = phi i32 [ 0, %2 ], [ %19, %13 ]
%5 = phi double [ 0.000000e+00, %2 ], [ %18, %13 ]
%6 = sitofp i32 %4 to double
%7 = fadd double %6, 5.000000e-01
%8 = tail call double @llvm.fmuladd.f64(double %7, double %7, double 1.000000e+14)
%9 = fdiv double 1.000000e+00, %8
%10 = fadd double %5, %9
%11 = or i32 %4, 1
%12 = icmp eq i32 %11, 10000001
br i1 %12, label %20, label %13
13: ; preds = %3
%14 = sitofp i32 %11 to double
%15 = fadd double %14, 5.000000e-01
%16 = tail call double @llvm.fmuladd.f64(double %15, double %15, double 1.000000e+14)
%17 = fdiv double 1.000000e+00, %16
%18 = fadd double %10, %17
%19 = add nuw nsw i32 %4, 2
br label %3
20: ; preds = %3
%21 = fmul double %10, 4.000000e+07
%22 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), double %21)
ret i32 0
}