#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 funcao_x(double);
double n_simpson(double intervalo_min, double intervalo_max, double h) {
  double xk = intervalo_min + h;
  double soma;
  int i = 1;
  while (xk < intervalo_max) {
    if (i % 2 == 0)
      soma += 2.0 * funcao_x(xk);
    else
      soma += 4.0 * funcao_x(xk);
    xk += h;
    i++;
  }
  soma = h * (funcao_x(intervalo_max) + funcao_x(intervalo_min) + soma) / 3.0;
  return soma;
}


x86 assembly (clang, -O0):
<n_simpson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c7 <n_simpson+0xb7>
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1186 <n_simpson+0x76>
movsd  -0x20(%rbp),%xmm0
call   1030 <funcao_x@plt>
movsd  -0x28(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11aa <n_simpson+0x9a>
movsd  -0x20(%rbp),%xmm0
call   1030 <funcao_x@plt>
movsd  -0x28(%rbp),%xmm1
movsd  0xe6b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113d <n_simpson+0x2d>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <funcao_x@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <funcao_x@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
addsd  %xmm2,%xmm1
addsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdf4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<n_simpson>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
movsd  %xmm2,0x10(%rsp)
movsd  %xmm0,0x20(%rsp)
addsd  %xmm0,%xmm2
ucomisd %xmm2,%xmm1
jbe    119a <n_simpson+0x8a>
mov    $0x1,%ebx
lea    0xec5(%rip),%r14
movsd  %xmm1,0x28(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,0x8(%rsp)
xor    %r15d,%r15d
test   $0x1,%bl
sete   %r15b
movapd %xmm2,%xmm0
call   1030 <funcao_x@plt>
movsd  0x8(%rsp),%xmm2
mulsd  (%r14,%r15,8),%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x28(%rsp),%xmm1
add    $0x1,%ebx
addsd  0x10(%rsp),%xmm2
ucomisd %xmm2,%xmm1
ja     1150 <n_simpson+0x40>
movapd %xmm1,%xmm0
call   1030 <funcao_x@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
call   1030 <funcao_x@plt>
addsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
divsd  0xe42(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @n_simpson(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
%10 = load double, double* %4
%11 = load double, double* %6
%12 = fadd double %10, %11
store double %12, double* %7
store i32 1, i32* %9
br label %13
13: ; preds = %31, %3
%14 = load double, double* %7
%15 = load double, double* %5
%16 = fcmp olt double %14, %15
br i1 %16, label %17, label %37
17: ; preds = %13
%18 = load i32, i32* %9
%19 = srem i32 %18, 2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load double, double* %7
%23 = call double @funcao_x(double %22)
%24 = load double, double* %8
%25 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %23, double %24)
store double %25, double* %8
br label %31
26: ; preds = %17
%27 = load double, double* %7
%28 = call double @funcao_x(double %27)
%29 = load double, double* %8
%30 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %28, double %29)
store double %30, double* %8
br label %31
31: ; preds = %26, %21
%32 = load double, double* %6
%33 = load double, double* %7
%34 = fadd double %33, %32
store double %34, double* %7
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %13
37: ; preds = %13
%38 = load double, double* %6
%39 = load double, double* %5
%40 = call double @funcao_x(double %39)
%41 = load double, double* %4
%42 = call double @funcao_x(double %41)
%43 = fadd double %40, %42
%44 = load double, double* %8
%45 = fadd double %43, %44
%46 = fmul double %38, %45
%47 = fdiv double %46, 3.000000e+00
store double %47, double* %8
%48 = load double, double* %8
ret double %48
}

LLVM IR (-O2):
define double @n_simpson(double %0, double %1, double %2) {
%4 = fadd double %2, %0
%5 = fcmp olt double %4, %1
br i1 %5, label %6, label %19
6: ; preds = %3, %6
%7 = phi double [ %17, %6 ], [ %4, %3 ]
%8 = phi i32 [ %16, %6 ], [ 1, %3 ]
%9 = phi double [ %15, %6 ], [ undef, %3 ]
%10 = and i32 %8, 1
%11 = icmp eq i32 %10, 0
%12 = tail call double @funcao_x(double %7)
%13 = tail call double @llvm.fmuladd.f64(double %12, double 2.000000e+00, double %9)
%14 = tail call double @llvm.fmuladd.f64(double %12, double 4.000000e+00, double %9)
%15 = select i1 %11, double %13, double %14
%16 = add nuw nsw i32 %8, 1
%17 = fadd double %7, %2
%18 = fcmp olt double %17, %1
br i1 %18, label %6, label %19
19: ; preds = %6, %3
%20 = phi double [ undef, %3 ], [ %15, %6 ]
%21 = tail call double @funcao_x(double %1)
%22 = tail call double @funcao_x(double %0)
%23 = fadd double %21, %22
%24 = fadd double %20, %23
%25 = fmul double %24, %2
%26 = fdiv double %25, 3.000000e+00
ret double %26
}