#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 */
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, double);
double sqrt(int);
int main() {
  double e = 0.0;
  int i;
  for (i = 1; i < 100000; i++) {
    e += pow(i, -2);
  }
  printf("pi is approximate to %f", sqrt(6 * e));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x186a0,-0x14(%rbp)
jge    1185 <main+0x55>
mov    -0x14(%rbp),%edi
mov    $0xfffffffe,%esi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114e <main+0x1e>
movsd  0xe73(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
mov    $0xfffffffe,%esi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x1(%rbx),%edi
mov    $0xfffffffe,%esi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x2(%rbx),%edi
mov    $0xfffffffe,%esi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x3,%ebx
cmp    $0x186a0,%ebx
jne    1140 <main+0x10>
mulsd  0xe4b(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"pi is approximate to %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i32
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store i32 1, i32* %3
br label %4
4: ; preds = %13, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 100000
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = load i32, i32* %3
%9 = call i64 @pow(i32 %8, i32 -2)
%10 = sitofp i64 %9 to double
%11 = load double, double* %2
%12 = fadd double %11, %10
store double %12, double* %2
br label %13
13: ; preds = %7
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %4
16: ; preds = %4
%17 = load double, double* %2
%18 = fmul double 6.000000e+00, %17
%19 = fptosi double %18 to i32
%20 = call double @sqrt(i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %20)
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [24 x i8] c"pi is approximate to %f\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 = tail call i64 @pow(i32 %2, i32 -2)
%5 = sitofp i64 %4 to double
%6 = fadd double %3, %5
%7 = add nuw nsw i32 %2, 1
%8 = tail call i64 @pow(i32 %7, i32 -2)
%9 = sitofp i64 %8 to double
%10 = fadd double %6, %9
%11 = add nuw nsw i32 %2, 2
%12 = tail call i64 @pow(i32 %11, i32 -2)
%13 = sitofp i64 %12 to double
%14 = fadd double %10, %13
%15 = add nuw nsw i32 %2, 3
%16 = icmp eq i32 %15, 100000
br i1 %16, label %17, label %1
17: ; preds = %1
%18 = fmul double %14, 6.000000e+00
%19 = fptosi double %18 to i32
%20 = tail call double @sqrt(i32 %19)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %20)
ret i32 0
}