#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 RAND_MAX;
scalar_t__ random();
double integral_monte_carlo(double a, double b, double point_count,
                            double (*f)(double)) {
  double x, y = 0;
  int i;
  for (i = 0; i < point_count; ++i) {
    x = ((b - a) * ((double)random() / RAND_MAX)) + a;
    y += f(x);
  }
  return ((b - a) * (y / point_count));
}


x86 assembly (clang, -O0):
<integral_monte_carlo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ae <integral_monte_carlo+0x9e>
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
movsd  -0x40(%rbp),%xmm0
cvtsi2sd %rax,%xmm2
mov    0x2e73(%rip),%rax
divsd  (%rax),%xmm2
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x28(%rbp),%xmm0
call   *%rax
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    113a <integral_monte_carlo+0x2a>
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<integral_monte_carlo>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm2
movsd  %xmm0,0x10(%rsp)
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
jbe    1197 <integral_monte_carlo+0x87>
mov    %rdi,%rbx
xorpd  %xmm3,%xmm3
mov    $0x1,%ebp
mov    0x2ea4(%rip),%r14
movsd  %xmm2,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm3,0x18(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
mulsd  (%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
call   *%rbx
movsd  0x18(%rsp),%xmm3
movsd  0x8(%rsp),%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
addsd  %xmm0,%xmm3
add    $0x1,%ebp
ucomisd %xmm1,%xmm2
ja     1150 <integral_monte_carlo+0x40>
divsd  %xmm2,%xmm3
movsd  (%rsp),%xmm0
mulsd  %xmm3,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define double @integral_monte_carlo(double %0, double %1, double %2, double (double)* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double (double)*
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double (double)* %3, double (double)** %8
store double 0.000000e+00, double* %10
store i32 0, i32* %11
br label %12
12: ; preds = %32, %4
%13 = load i32, i32* %11
%14 = sitofp i32 %13 to double
%15 = load double, double* %7
%16 = fcmp olt double %14, %15
br i1 %16, label %17, label %35
17: ; preds = %12
%18 = load double, double* %6
%19 = load double, double* %5
%20 = fsub double %18, %19
%21 = call i64 (...) @random()
%22 = sitofp i64 %21 to double
%23 = load double, double* @RAND_MAX
%24 = fdiv double %22, %23
%25 = load double, double* %5
%26 = call double @llvm.fmuladd.f64(double %20, double %24, double %25)
store double %26, double* %9
%27 = load double (double)*, double (double)** %8
%28 = load double, double* %9
%29 = call double %27(double %28)
%30 = load double, double* %10
%31 = fadd double %30, %29
store double %31, double* %10
br label %32
32: ; preds = %17
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 1
store i32 %34, i32* %11
br label %12
35: ; preds = %12
%36 = load double, double* %6
%37 = load double, double* %5
%38 = fsub double %36, %37
%39 = load double, double* %10
%40 = load double, double* %7
%41 = fdiv double %39, %40
%42 = fmul double %38, %41
ret double %42
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define double @integral_monte_carlo(double %0, double %1, double %2, double (double)* nocapture %3) {
%5 = fcmp ogt double %2, 0.000000e+00
%6 = fsub double %1, %0
br i1 %5, label %7, label %20
7: ; preds = %4, %7
%8 = phi i32 [ %17, %7 ], [ 0, %4 ]
%9 = phi double [ %16, %7 ], [ 0.000000e+00, %4 ]
%10 = tail call i64 (...) @random()
%11 = sitofp i64 %10 to double
%12 = load double, double* @RAND_MAX
%13 = fdiv double %11, %12
%14 = tail call double @llvm.fmuladd.f64(double %6, double %13, double %0)
%15 = tail call double %3(double %14)
%16 = fadd double %9, %15
%17 = add nuw nsw i32 %8, 1
%18 = sitofp i32 %17 to double
%19 = fcmp olt double %18, %2
br i1 %19, label %7, label %20
20: ; preds = %7, %4
%21 = phi double [ 0.000000e+00, %4 ], [ %16, %7 ]
%22 = fdiv double %21, %2
%23 = fmul double %6, %22
ret double %23
}