#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[]) {
  int n = 1000;
  double h = 1.0 / (double)n;
  double sum = 0.0;
  for (int i = 1; i <= n; i++) {
    double x = h * ((double)i - 0.5);
    sum += (4.0 / (1.0 + x * x));
  }
  double pi = sum * h;
  printf("El valor aproximado de PI es: %.16f", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xec6(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11bb <main+0xab>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xea0(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe6d(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe69(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1152 <main+0x42>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movsd  0xee7(%rip),%xmm1
xorpd  %xmm0,%xmm0
mov    $0x2,%eax
movsd  0xede(%rip),%xmm2
movsd  0xede(%rip),%xmm3
movsd  0xede(%rip),%xmm5
movsd  0xedd(%rip),%xmm8
movapd %xmm1,%xmm6
nopw   0x0(%rax,%rax,1)
movapd %xmm6,%xmm7
addsd  %xmm2,%xmm7
mulsd  %xmm3,%xmm7
mulsd  %xmm7,%xmm7
addsd  %xmm1,%xmm7
movapd %xmm5,%xmm4
divsd  %xmm7,%xmm4
addsd  %xmm0,%xmm4
xorps  %xmm7,%xmm7
cvtsi2sd %eax,%xmm7
addsd  %xmm2,%xmm7
mulsd  %xmm3,%xmm7
mulsd  %xmm7,%xmm7
addsd  %xmm1,%xmm7
movapd %xmm5,%xmm0
divsd  %xmm7,%xmm0
addsd  %xmm4,%xmm0
addsd  %xmm8,%xmm6
add    $0x2,%eax
cmp    $0x3ea,%eax
jne    1150 <main+0x40>
mulsd  0xe66(%rip),%xmm0
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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