#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 */
double f(double);
int /*<<< orphan*/ printf(char *, ...);
double rnd(long *);
int /*<<< orphan*/ scanf(char *, double *);
void main() {
  double x = 0, res = 0, cont;
  unsigned long dentro = 0, fuera = 0;
  long random = 0;
  printf("Introduzca un valor para x: ");
  scanf("%lf", &x);
  if (x >= 0) {
    for (cont = 0; cont < 10000; cont++) {
      if (f(rnd(&random) * x) > rnd(&random))
        dentro++;
    }
    res = x * dentro / 10000;
  } else
    res = 0;
  printf("El resultado es:  %lf\n", res);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     125c <main+0x11c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe50(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1216 <main+0xd6>
lea    -0x30(%rbp),%rdi
call   1050 <rnd@plt>
mulsd  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <rnd@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11fa <main+0xba>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ff <main+0xbf>
movsd  0xe01(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11a8 <main+0x68>
movsd  -0x8(%rbp),%xmm0
movaps 0xdee(%rip),%xmm2
movq   -0x20(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xded(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1264 <main+0x124>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xde1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xec7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed6(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
movsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     1207 <main+0xc7>
mov    $0x2710,%ebp
xor    %ebx,%ebx
lea    0x18(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1050 <rnd@plt>
mulsd  0x8(%rsp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
call   1050 <rnd@plt>
xor    %eax,%eax
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
add    %rax,%rbx
add    $0xffffffff,%ebp
jne    11a0 <main+0x60>
movq   %rbx,%xmm1
punpckldq 0xe1b(%rip),%xmm1
subpd  0xe23(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0x8(%rsp),%xmm0
divsd  0xe19(%rip),%xmm0
lea    0xe3b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Introduzca un valor para x: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [23 x i8] c"El resultado es: %lf\0A\00"
define void @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store double 0.000000e+00, double* %1
store double 0.000000e+00, double* %2
store i64 0, i64* %4
store i64 0, i64* %5
store i64 0, i64* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%9 = load double, double* %1
%10 = fcmp oge double %9, 0.000000e+00
br i1 %10, label %11, label %35
11: ; preds = %0
store double 0.000000e+00, double* %3
br label %12
12: ; preds = %26, %11
%13 = load double, double* %3
%14 = fcmp olt double %13, 1.000000e+04
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = call double @rnd(i64* %6)
%17 = load double, double* %1
%18 = fmul double %16, %17
%19 = call double @f(double %18)
%20 = call double @rnd(i64* %6)
%21 = fcmp ogt double %19, %20
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i64, i64* %4
%24 = add i64 %23, 1
store i64 %24, i64* %4
br label %25
25: ; preds = %22, %15
br label %26
26: ; preds = %25
%27 = load double, double* %3
%28 = fadd double %27, 1.000000e+00
store double %28, double* %3
br label %12
29: ; preds = %12
%30 = load double, double* %1
%31 = load i64, i64* %4
%32 = uitofp i64 %31 to double
%33 = fmul double %30, %32
%34 = fdiv double %33, 1.000000e+04
store double %34, double* %2
br label %36
35: ; preds = %0
store double 0.000000e+00, double* %2
br label %36
36: ; preds = %35, %29
%37 = load double, double* %2
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %37)
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Introduzca un valor para x: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [23 x i8] c"El resultado es: %lf\0A\00"
define void @main() {
%1 = alloca double
%2 = alloca i64
%3 = bitcast double* %1 to i8*
store double 0.000000e+00, double* %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%7 = load double, double* %1
%8 = fcmp ult double %7, 0.000000e+00
br i1 %8, label %27, label %9
9: ; preds = %0, %9
%10 = phi i64 [ %19, %9 ], [ 0, %0 ]
%11 = phi i32 [ %20, %9 ], [ 0, %0 ]
%12 = call double @rnd(i64* %2)
%13 = load double, double* %1
%14 = fmul double %12, %13
%15 = call double @f(double %14)
%16 = call double @rnd(i64* %2)
%17 = fcmp ogt double %15, %16
%18 = zext i1 %17 to i64
%19 = add i64 %10, %18
%20 = add nuw nsw i32 %11, 1
%21 = icmp eq i32 %20, 10000
br i1 %21, label %22, label %9
22: ; preds = %9
%23 = load double, double* %1
%24 = uitofp i64 %19 to double
%25 = fmul double %23, %24
%26 = fdiv double %25, 1.000000e+04
br label %27
27: ; preds = %0, %22
%28 = phi double [ %26, %22 ], [ 0.000000e+00, %0 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %28)
ret void
}