#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 drand48();
int /*<<< orphan*/ srand48(int);
double monteCarloIntegration1D(double (*f)(double), double a, double b, int n) {
  long int i;
  double x, sum = 0;
  srand48(1e3);
  for (i = 0; i < n; i++) {
    x = drand48();
    sum += f(x);
  }
  return (sum / (double)n) * (b - a);
}


x86 assembly (clang, -O0):
<monteCarloIntegration1D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x3e8,%edi
call   1030 <srand48@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
jge    1196 <monteCarloIntegration1D+0x76>
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
call   *%rax
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1153 <monteCarloIntegration1D+0x33>
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monteCarloIntegration1D>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r14d
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
mov    $0x3e8,%edi
call   1030 <srand48@plt>
test   %r14d,%r14d
jle    1171 <monteCarloIntegration1D+0x51>
movslq %r14d,%rbp
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x18(%rsp)
xor    %eax,%eax
call   1040 <drand48@plt>
call   *%rbx
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
add    $0xffffffffffffffff,%rbp
jne    1150 <monteCarloIntegration1D+0x30>
jmp    1175 <monteCarloIntegration1D+0x55>
xorpd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @monteCarloIntegration1D(double (double)* %0, double %1, double %2, i32 %3) {
%5 = alloca double (double)*
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i64
%10 = alloca double
%11 = alloca double
store double (double)* %0, double (double)** %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %11
%12 = call i32 @srand48(i32 1000)
store i64 0, i64* %9
br label %13
13: ; preds = %25, %4
%14 = load i64, i64* %9
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %18, label %28
18: ; preds = %13
%19 = call double (...) @drand48()
store double %19, double* %10
%20 = load double (double)*, double (double)** %5
%21 = load double, double* %10
%22 = call double %20(double %21)
%23 = load double, double* %11
%24 = fadd double %23, %22
store double %24, double* %11
br label %25
25: ; preds = %18
%26 = load i64, i64* %9
%27 = add nsw i64 %26, 1
store i64 %27, i64* %9
br label %13
28: ; preds = %13
%29 = load double, double* %11
%30 = load i32, i32* %8
%31 = sitofp i32 %30 to double
%32 = fdiv double %29, %31
%33 = load double, double* %7
%34 = load double, double* %6
%35 = fsub double %33, %34
%36 = fmul double %32, %35
ret double %36
}

LLVM IR (-O2):
define double @monteCarloIntegration1D(double (double)* nocapture %0, double %1, double %2, i32 %3) {
%5 = tail call i32 @srand48(i32 1000)
%6 = sext i32 %3 to i64
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %16
8: ; preds = %4, %8
%9 = phi double [ %13, %8 ], [ 0.000000e+00, %4 ]
%10 = phi i64 [ %14, %8 ], [ 0, %4 ]
%11 = tail call double (...) @drand48()
%12 = tail call double %0(double %11)
%13 = fadd double %9, %12
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %16, label %8
16: ; preds = %8, %4
%17 = phi double [ 0.000000e+00, %4 ], [ %13, %8 ]
%18 = sitofp i32 %3 to double
%19 = fdiv double %17, %18
%20 = fsub double %2, %1
%21 = fmul double %20, %19
ret double %21
}