#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 const *argv[]) {
  double pi, x;
  int i, N;
  pi = 0.0;
  N = 1000;
  for (i = 0; i <= N; i++) {
    x = (double)i / N;
    pi += 4 / (1 + x * x);
  }
  pi = pi / N;
  printf("%f\n", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x3e8,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     1199 <main+0x89>
cvtsi2sdl -0x24(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe97(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe83(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113c <main+0x2c>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

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

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

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