#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 double int32_t;

/* Variables and functions */
double integral(double (*f)(double x), double a, double b, int32_t n) {
  double step = (b - a) / (double)n;
  double area = 0.0;
  for (int32_t i = 0; i < n; i++) {
    area += f(a + (i + 0.5) * step) * step;
  }
  return area;
}


x86 assembly (clang, -O0):
<integral>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a6 <integral+0xa6>
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm1
movsd  0xe9c(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe71(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    113f <integral+0x3f>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<integral>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm3,%xmm3
movsd  %xmm2,0x18(%rsp)
ucomisd %xmm3,%xmm2
jbe    11a0 <integral+0xa0>
mov    %rdi,%rbx
subsd  0x10(%rsp),%xmm1
divsd  0x18(%rsp),%xmm1
movsd  %xmm1,0x20(%rsp)
xorps  %xmm0,%xmm0
xorpd  %xmm3,%xmm3
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
movsd  %xmm3,0x28(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xea6(%rip),%xmm0
mulsd  0x20(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
call   *%rbx
movsd  0x28(%rsp),%xmm3
mulsd  0x20(%rsp),%xmm0
addsd  %xmm0,%xmm3
movsd  0x8(%rsp),%xmm0
addsd  0xe82(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
ucomisd 0x8(%rsp),%xmm0
movsd  0x8(%rsp),%xmm0
ja     1140 <integral+0x40>
movapd %xmm3,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @integral(double (double)* %0, double %1, double %2, double %3) {
%5 = alloca double (double)*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double (double)* %0, double (double)** %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%12 = load double, double* %7
%13 = load double, double* %6
%14 = fsub double %12, %13
%15 = load double, double* %8
%16 = fdiv double %14, %15
store double %16, double* %9
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
br label %17
17: ; preds = %32, %4
%18 = load double, double* %11
%19 = load double, double* %8
%20 = fcmp olt double %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load double (double)*, double (double)** %5
%23 = load double, double* %6
%24 = load double, double* %11
%25 = fadd double %24, 5.000000e-01
%26 = load double, double* %9
%27 = call double @llvm.fmuladd.f64(double %25, double %26, double %23)
%28 = call double %22(double %27)
%29 = load double, double* %9
%30 = load double, double* %10
%31 = call double @llvm.fmuladd.f64(double %28, double %29, double %30)
store double %31, double* %10
br label %32
32: ; preds = %21
%33 = load double, double* %11
%34 = fadd double %33, 1.000000e+00
store double %34, double* %11
br label %17
35: ; preds = %17
%36 = load double, double* %10
ret double %36
}

LLVM IR (-O2):
define double @integral(double (double)* nocapture %0, double %1, double %2, double %3) {
%5 = fsub double %2, %1
%6 = fdiv double %5, %3
%7 = fcmp ogt double %3, 0.000000e+00
br i1 %7, label %10, label %8
8: ; preds = %10, %4
%9 = phi double [ 0.000000e+00, %4 ], [ %16, %10 ]
ret double %9
10: ; preds = %4, %10
%11 = phi double [ %17, %10 ], [ 0.000000e+00, %4 ]
%12 = phi double [ %16, %10 ], [ 0.000000e+00, %4 ]
%13 = fadd double %11, 5.000000e-01
%14 = tail call double @llvm.fmuladd.f64(double %13, double %6, double %1)
%15 = tail call double %0(double %14)
%16 = tail call double @llvm.fmuladd.f64(double %15, double %6, double %12)
%17 = fadd double %11, 1.000000e+00
%18 = fcmp olt double %17, %3
br i1 %18, label %10, label %8
}