#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*/ fabs(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int n, i;
  printf("Introduce la precision del calculo (n > 0): ");
  scanf("%i", &n);
  double PI25DT = 3.141592653589793238462643;
  double h = 1.0 / (double)n;
  double sum = 0.0;
#pragma omp parallel for shared(sum)
  for (i = 1; i <= n; i++) {
    double x = h * ((double)i - 0.5);
#pragma omp critical
    sum += (4.0 / (1.0 + x * x));
  }
  double pi = sum * h;
  printf("El valor aproximado de PI es: %.8lf , con un error de %.8lf\n\n", pi,
         fabs(pi - PI25DT));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef2(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
movsd  0xe9c(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe82(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11ff <main+0xcf>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xe64(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe29(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe2d(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1196 <main+0x66>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
movsd  -0x48(%rbp),%xmm0
mov    %eax,%esi
lea    0xe1b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xeed(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe9d(%rip),%xmm1
movapd %xmm1,%xmm6
divsd  %xmm0,%xmm6
test   %eax,%eax
jle    118d <main+0x5d>
cmp    $0x1,%eax
jne    1196 <main+0x66>
xorpd  %xmm0,%xmm0
movsd  0xe88(%rip),%xmm1
test   $0x1,%al
jne    1223 <main+0xf3>
jmp    1243 <main+0x113>
xorpd  %xmm0,%xmm0
jmp    1243 <main+0x113>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
xorpd  %xmm0,%xmm0
mov    $0x1,%edx
movsd  0xe64(%rip),%xmm2
movsd  0xe64(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm4,%xmm4
cvtsi2sd %edx,%xmm4
addsd  %xmm2,%xmm4
mulsd  %xmm6,%xmm4
mulsd  %xmm4,%xmm4
addsd  %xmm1,%xmm4
movapd %xmm3,%xmm5
divsd  %xmm4,%xmm5
addsd  %xmm0,%xmm5
lea    0x1(%rdx),%esi
xorps  %xmm4,%xmm4
cvtsi2sd %esi,%xmm4
addsd  %xmm2,%xmm4
mulsd  %xmm6,%xmm4
mulsd  %xmm4,%xmm4
addsd  %xmm1,%xmm4
movapd %xmm3,%xmm0
divsd  %xmm4,%xmm0
addsd  %xmm5,%xmm0
add    $0x2,%edx
cmp    %ecx,%esi
jne    11c0 <main+0x90>
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
addsd  0xdf1(%rip),%xmm1
test   $0x1,%al
je     1243 <main+0x113>
mulsd  %xmm6,%xmm1
mulsd  %xmm1,%xmm1
addsd  0xdcd(%rip),%xmm1
movsd  0xddd(%rip),%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm6
movsd  %xmm6,0x10(%rsp)
movsd  0xdcb(%rip),%xmm0
addsd  %xmm6,%xmm0
call   1040 <fabs@plt>
lea    0xdf3(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@.str = [45 x i8] c"Introduce la precision del calculo (n > 0): \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [62 x i8] c"El valor aproximado de PI es: %.8lf , con un error de %.8lf\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = sitofp i32 %7 to double
%9 = fdiv double 1.000000e+00, %8
%10 = icmp slt i32 %7, 1
br i1 %10, label %49, label %11
11: ; preds = %2
%12 = and i32 %7, 1
%13 = icmp eq i32 %7, 1
br i1 %13, label %39, label %14
14: ; preds = %11
%15 = and i32 %7, -2
br label %16
16: ; preds = %16, %14
%17 = phi i32 [ 1, %14 ], [ %33, %16 ]
%18 = phi double [ 0.000000e+00, %14 ], [ %32, %16 ]
%19 = phi i32 [ 0, %14 ], [ %34, %16 ]
%20 = sitofp i32 %17 to double
%21 = fadd double %20, -5.000000e-01
%22 = fmul double %9, %21
%23 = call double @llvm.fmuladd.f64(double %22, double %22, double 1.000000e+00)
%24 = fdiv double 4.000000e+00, %23
%25 = fadd double %18, %24
%26 = add nuw i32 %17, 1
%27 = sitofp i32 %26 to double
%28 = fadd double %27, -5.000000e-01
%29 = fmul double %9, %28
%30 = call double @llvm.fmuladd.f64(double %29, double %29, double 1.000000e+00)
%31 = fdiv double 4.000000e+00, %30
%32 = fadd double %25, %31
%33 = add nuw i32 %17, 2
%34 = add i32 %19, 2
%35 = icmp eq i32 %34, %15
br i1 %35, label %36, label %16
36: ; preds = %16
%37 = sitofp i32 %33 to double
%38 = fadd double %37, -5.000000e-01
br label %39
39: ; preds = %36, %11
%40 = phi double [ undef, %11 ], [ %32, %36 ]
%41 = phi double [ 5.000000e-01, %11 ], [ %38, %36 ]
%42 = phi double [ 0.000000e+00, %11 ], [ %32, %36 ]
%43 = icmp eq i32 %12, 0
br i1 %43, label %49, label %44
44: ; preds = %39
%45 = fmul double %9, %41
%46 = call double @llvm.fmuladd.f64(double %45, double %45, double 1.000000e+00)
%47 = fdiv double 4.000000e+00, %46
%48 = fadd double %42, %47
br label %49
49: ; preds = %44, %39, %2
%50 = phi double [ 0.000000e+00, %2 ], [ %40, %39 ], [ %48, %44 ]
%51 = fmul double %9, %50
%52 = fadd double %51, 0xC00921FB54442D18
%53 = call i32 @fabs(double %52)
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), double %51, i32 %53)
ret i32 0
}