#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
double func(double);
scalar_t__ malloc(int);
int /*<<< orphan*/ nAleatorios(double *);
int /*<<< orphan*/ srand48(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  FILE *fout;
  fout = fopen("resultados.txt", "w+");
  srand48(time(NULL));
  double *nums = (double *)malloc(1000000 * sizeof(double));
  double *x = (double *)malloc(1000000 * sizeof(double));
  double dx = 0;
  dx = 1.0 / 1000000;
  x[0] = 0.0;
  nAleatorios(nums);
  int i;
  int cuenta = 0;
  if (nums[0] < func(x[0])) {
    cuenta += 1;
  }
  for (i = 1; i < 1000000; i++) {
    x[i] = x[i - 1] + dx;
    if (nums[i] < func(x[i])) {
      cuenta += 1;
    }
  }
  double integral = 0;
  integral = (double)cuenta / 1000000;
  fprintf(fout, "El valor de la integral es : %lf\n", integral);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe82(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1090 <srand48@plt>
mov    $0x7a1200,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x7a1200,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe1e(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <nAleatorios@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
call   1070 <func@plt>
movsd  -0x40(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1234 <main+0xb4>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
movl   $0x1,-0x2c(%rbp)
cmpl   $0xf4240,-0x2c(%rbp)
jge    12bb <main+0x13b>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1070 <func@plt>
movsd  -0x48(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    12a8 <main+0x128>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12ad <main+0x12d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    123b <main+0xbb>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x30(%rbp),%xmm0
movsd  0xd38(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xd39(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe7d(%rip),%rdi
lea    0xe85(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1090 <srand48@plt>
mov    $0x7a1200,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    $0x7a1200,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
movq   $0x0,(%rax)
mov    %r15,%rdi
call   1030 <nAleatorios@plt>
movsd  (%r15),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%r12),%xmm0
call   1070 <func@plt>
xor    %ebp,%ebp
ucomisd 0x8(%rsp),%xmm0
seta   %bpl
mov    $0x1,%ebx
movsd  -0x8(%r12,%rbx,8),%xmm0
addsd  0xdf1(%rip),%xmm0
movsd  %xmm0,(%r12,%rbx,8)
movsd  (%r15,%rbx,8),%xmm1
movsd  %xmm1,0x8(%rsp)
call   1070 <func@plt>
xor    %eax,%eax
ucomisd 0x8(%rsp),%xmm0
seta   %al
add    %eax,%ebp
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    1200 <main+0x80>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  0xdb9(%rip),%xmm0
lea    0xdcc(%rip),%rsi
mov    %r14,%rdi
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"resultados.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [34 x i8] c"El valor de la integral 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 ([3 x i8], [3 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*
store double 0.000000e+00, double* %7
%8 = tail call i32 @nAleatorios(double* %5)
%9 = load double, double* %5
%10 = load double, double* %7
%11 = tail call double @func(double %10)
%12 = fcmp olt double %9, %11
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %0, %14
%15 = phi i64 [ 1, %0 ], [ %28, %14 ]
%16 = phi i32 [ %13, %0 ], [ %27, %14 ]
%17 = add nsw i64 %15, -1
%18 = getelementptr inbounds double, double* %7, i64 %17
%19 = load double, double* %18
%20 = fadd double %19, 0x3EB0C6F7A0B5ED8D
%21 = getelementptr inbounds double, double* %7, i64 %15
store double %20, double* %21
%22 = getelementptr inbounds double, double* %5, i64 %15
%23 = load double, double* %22
%24 = tail call double @func(double %20)
%25 = fcmp olt double %23, %24
%26 = zext i1 %25 to i32
%27 = add nuw nsw i32 %16, %26
%28 = add nuw nsw i64 %15, 1
%29 = icmp eq i64 %28, 1000000
br i1 %29, label %30, label %14
30: ; preds = %14
%31 = sitofp i32 %27 to double
%32 = fdiv double %31, 1.000000e+06
%33 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), double %32)
%34 = tail call i32 @fclose(i32* %1)
ret i32 0
}