#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
scalar_t__ malloc(int);
int /*<<< orphan*/ nAleatorios(double *);
double promedio(double *, int);
int /*<<< orphan*/ srand48(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  FILE *fout;
  fout = fopen("resultados.txt", "a");
  srand48(time(NULL));
  double *x = (double *)malloc(1000000 * sizeof(double));
  double *y = (double *)malloc(1000000 * sizeof(double));
  double *valores = (double *)malloc(100 * sizeof(double));
  int j = 0, k = 0;
  int cuenta = 0;
  double pi = 0;
  while (k < 100) {
    nAleatorios(x);
    nAleatorios(y);
    while (j < 1000000) {
      if (x[j] * x[j] + y[j] * y[j] < 1.0) {
        cuenta += 1;
      }
      j += 1;
    }
    valores[k] = (double)4 * cuenta / 1000000;
    k += 1;
  }
  pi = promedio(valores, 100);
  fprintf(fout, "El valor de la constante pi es: %lf\n", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe92(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1070 <srand48@plt>
mov    $0x7a1200,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x7a1200,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x320,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
cmpl   $0x64,-0x30(%rbp)
jge    12b3 <main+0x143>
mov    -0x18(%rbp),%rdi
call   1030 <nAleatorios@plt>
mov    -0x20(%rbp),%rdi
call   1030 <nAleatorios@plt>
cmpl   $0xf4240,-0x2c(%rbp)
jge    127b <main+0x10b>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xdb6(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    126d <main+0xfd>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1209 <main+0x99>
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  0xd80(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd6c(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11ed <main+0x7d>
mov    -0x28(%rbp),%rdi
mov    $0x64,%esi
call   1090 <promedio@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
lea    0xd53(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xea3(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,(%rsp)
xor    %r13d,%r13d
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1070 <srand48@plt>
mov    $0x7a1200,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x7a1200,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x320,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rax
add    $0x10,%rax
mov    %rax,0x10(%rsp)
mov    %rbx,%rax
add    $0x10,%rax
mov    %rax,0x8(%rsp)
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    121b <main+0xab>
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe19(%rip),%xmm0
divsd  0xe19(%rip),%xmm0
movsd  %xmm0,(%r12,%r13,8)
add    $0x1,%r13
cmp    $0x64,%r13
je     1359 <main+0x1e9>
mov    %r15,%rdi
call   1030 <nAleatorios@plt>
mov    %rbx,%rdi
call   1030 <nAleatorios@plt>
cmp    $0xf423f,%r14d
ja     11f0 <main+0x80>
mov    %r14d,%edi
mov    $0xf4240,%ecx
sub    %rdi,%rcx
cmp    $0x4,%rcx
jae    1260 <main+0xf0>
mov    %rdi,%rax
movsd  0xdc0(%rip),%xmm2
jmp    1320 <main+0x1b0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rcx,%rdx
and    $0xfffffffffffffffc,%rdx
lea    (%rdx,%rdi,1),%rax
movd   %ebp,%xmm0
mov    0x10(%rsp),%rsi
lea    (%rsi,%rdi,8),%rsi
mov    0x8(%rsp),%rbp
lea    0x0(,%rdi,8),%rdi
add    %rbp,%rdi
pxor   %xmm1,%xmm1
xor    %ebp,%ebp
movapd 0xd6a(%rip),%xmm6
cs nopw 0x0(%rax,%rax,1)
movupd -0x10(%rsi,%rbp,8),%xmm2
movupd (%rsi,%rbp,8),%xmm3
movupd -0x10(%rdi,%rbp,8),%xmm4
movupd (%rdi,%rbp,8),%xmm5
mulpd  %xmm4,%xmm4
mulpd  %xmm5,%xmm5
mulpd  %xmm2,%xmm2
addpd  %xmm4,%xmm2
mulpd  %xmm3,%xmm3
addpd  %xmm5,%xmm3
cmpltpd %xmm6,%xmm2
shufps $0xe8,%xmm2,%xmm2
psubd  %xmm2,%xmm0
cmpltpd %xmm6,%xmm3
shufps $0xe8,%xmm3,%xmm3
psubd  %xmm3,%xmm1
add    $0x4,%rbp
cmp    %rbp,%rdx
jne    12a0 <main+0x130>
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ebp
mov    $0xf4240,%r14d
cmp    %rdx,%rcx
movsd  0xcfd(%rip),%xmm2
je     11f0 <main+0x80>
nopl   0x0(%rax)
movsd  (%r15,%rax,8),%xmm0
movsd  (%rbx,%rax,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xor    %ecx,%ecx
ucomisd %xmm0,%xmm2
seta   %cl
add    %ecx,%ebp
add    $0x1,%rax
cmp    $0xf4240,%rax
jne    1320 <main+0x1b0>
mov    $0xf4240,%r14d
jmp    11f0 <main+0x80>
mov    %r12,%rdi
mov    $0x64,%esi
call   1090 <promedio@plt>
lea    0xccc(%rip),%rsi
mov    (%rsp),%rdi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"resultados.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [37 x i8] c"El valor de la constante pi es: %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca double*
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store i32 0, i32* %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = call i32 @time(i32* null)
%12 = call i32 @srand48(i32 %11)
%13 = call i64 @malloc(i32 8000000)
%14 = inttoptr i64 %13 to double*
store double* %14, double** %3
%15 = call i64 @malloc(i32 8000000)
%16 = inttoptr i64 %15 to double*
store double* %16, double** %4
%17 = call i64 @malloc(i32 800)
%18 = inttoptr i64 %17 to double*
store double* %18, double** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store double 0.000000e+00, double* %9
br label %19
19: ; preds = %60, %0
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 100
br i1 %21, label %22, label %71
22: ; preds = %19
%23 = load double*, double** %3
%24 = call i32 @nAleatorios(double* %23)
%25 = load double*, double** %4
%26 = call i32 @nAleatorios(double* %25)
br label %27
27: ; preds = %57, %22
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 1000000
br i1 %29, label %30, label %60
30: ; preds = %27
%31 = load double*, double** %3
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = load double*, double** %3
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = load double*, double** %4
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = load double, double* %44
%46 = load double*, double** %4
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = fmul double %45, %50
%52 = call double @llvm.fmuladd.f64(double %35, double %40, double %51)
%53 = fcmp olt double %52, 1.000000e+00
br i1 %53, label %54, label %57
54: ; preds = %30
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %57
57: ; preds = %54, %30
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
br label %27
60: ; preds = %27
%61 = load i32, i32* %8
%62 = sitofp i32 %61 to double
%63 = fmul double 4.000000e+00, %62
%64 = fdiv double %63, 1.000000e+06
%65 = load double*, double** %5
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
store double %64, double* %68
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %19
71: ; preds = %19
%72 = load double*, double** %5
%73 = call double @promedio(double* %72, i32 100)
store double %73, double* %9
%74 = load i32*, i32** %2
%75 = load double, double* %9
%76 = call i32 @fprintf(i32* %74, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), double %75)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"resultados.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [37 x i8] c"El valor de la constante pi es: %lf\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand48(i32 %2)
%4 = tail call i64 @malloc(i32 8000000)
%5 = inttoptr i64 %4 to double*
%6 = tail call i64 @malloc(i32 8000000)
%7 = inttoptr i64 %6 to double*
%8 = tail call i64 @malloc(i32 800)
%9 = inttoptr i64 %8 to double*
br label %10
10: ; preds = %0, %75
%11 = phi i64 [ 0, %0 ], [ %82, %75 ]
%12 = phi i32 [ 0, %0 ], [ %77, %75 ]
%13 = phi i32 [ 0, %0 ], [ %76, %75 ]
%14 = tail call i32 @nAleatorios(double* %5)
%15 = tail call i32 @nAleatorios(double* %7)
%16 = icmp ult i32 %13, 1000000
br i1 %16, label %17, label %75
17: ; preds = %10
%18 = zext i32 %13 to i64
%19 = sub nsw i64 1000000, %18
%20 = icmp ult i64 %19, 4
br i1 %20, label %58, label %21
21: ; preds = %17
%22 = and i64 %19, -4
%23 = add nsw i64 %22, %18
%24 = insertelement <2 x i32> <i32 poison, i32 0>, i32 %12, i64 0
br label %25
25: ; preds = %25, %21
%26 = phi i64 [ 0, %21 ], [ %52, %25 ]
%27 = phi <2 x i32> [ %24, %21 ], [ %50, %25 ]
%28 = phi <2 x i32> [ zeroinitializer, %21 ], [ %51, %25 ]
%29 = add i64 %26, %18
%30 = getelementptr inbounds double, double* %5, i64 %29
%31 = bitcast double* %30 to <2 x double>*
%32 = load <2 x double>, <2 x double>* %31
%33 = getelementptr inbounds double, double* %30, i64 2
%34 = bitcast double* %33 to <2 x double>*
%35 = load <2 x double>, <2 x double>* %34
%36 = getelementptr inbounds double, double* %7, i64 %29
%37 = bitcast double* %36 to <2 x double>*
%38 = load <2 x double>, <2 x double>* %37
%39 = getelementptr inbounds double, double* %36, i64 2
%40 = bitcast double* %39 to <2 x double>*
%41 = load <2 x double>, <2 x double>* %40
%42 = fmul <2 x double> %38, %38
%43 = fmul <2 x double> %41, %41
%44 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %32, <2 x double> %32, <2 x double> %42)
%45 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %35, <2 x double> %35, <2 x double> %43)
%46 = fcmp olt <2 x double> %44, <double 1.000000e+00, double 1.000000e+00>
%47 = fcmp olt <2 x double> %45, <double 1.000000e+00, double 1.000000e+00>
%48 = zext <2 x i1> %46 to <2 x i32>
%49 = zext <2 x i1> %47 to <2 x i32>
%50 = add <2 x i32> %27, %48
%51 = add <2 x i32> %28, %49
%52 = add nuw i64 %26, 4
%53 = icmp eq i64 %52, %22
br i1 %53, label %54, label %25
54: ; preds = %25
%55 = add <2 x i32> %51, %50
%56 = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %55)
%57 = icmp eq i64 %19, %22
br i1 %57, label %75, label %58
58: ; preds = %17, %54
%59 = phi i64 [ %18, %17 ], [ %23, %54 ]
%60 = phi i32 [ %12, %17 ], [ %56, %54 ]
br label %61
61: ; preds = %58, %61
%62 = phi i64 [ %73, %61 ], [ %59, %58 ]
%63 = phi i32 [ %72, %61 ], [ %60, %58 ]
%64 = getelementptr inbounds double, double* %5, i64 %62
%65 = load double, double* %64
%66 = getelementptr inbounds double, double* %7, i64 %62
%67 = load double, double* %66
%68 = fmul double %67, %67
%69 = tail call double @llvm.fmuladd.f64(double %65, double %65, double %68)
%70 = fcmp olt double %69, 1.000000e+00
%71 = zext i1 %70 to i32
%72 = add nsw i32 %63, %71
%73 = add nuw nsw i64 %62, 1
%74 = icmp eq i64 %73, 1000000
br i1 %74, label %75, label %61
75: ; preds = %61, %54, %10
%76 = phi i32 [ %13, %10 ], [ 1000000, %54 ], [ 1000000, %61 ]
%77 = phi i32 [ %12, %10 ], [ %56, %54 ], [ %72, %61 ]
%78 = sitofp i32 %77 to double
%79 = fmul double %78, 4.000000e+00
%80 = fdiv double %79, 1.000000e+06
%81 = getelementptr inbounds double, double* %9, i64 %11
store double %80, double* %81
%82 = add nuw nsw i64 %11, 1
%83 = icmp eq i64 %82, 100
br i1 %83, label %84, label %10
84: ; preds = %75
%85 = tail call double @promedio(double* %9, i32 100)
%86 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), double %85)
ret i32 0
}