#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 h_equation(double, double, double);
double sum_function(double a, double b, double n, double (*f)(double)) {
  double sum = 0, h = h_equation(a, b, n), x = h;
  for (n; n > 0; n--) {
    sum = sum + f(a + x);
    x = x + h;
  }
  return 2 * sum;
}


x86 assembly (clang, -O0):
<sum_function>:
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,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1030 <h_equation@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11b9 <sum_function+0xa9>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe5e(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1156 <sum_function+0x46>
movsd  0xe3f(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_function>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x20(%rsp)
call   1030 <h_equation@plt>
movsd  0x8(%rsp),%xmm1
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jbe    11ac <sum_function+0x9c>
movsd  0x18(%rsp),%xmm2
xorpd  %xmm0,%xmm0
nopl   0x0(%rax)
movsd  %xmm2,0x28(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
movapd %xmm2,%xmm0
addsd  0x20(%rsp),%xmm0
call   *%rbx
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  0x28(%rsp),%xmm2
movsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm2
addsd  0xe62(%rip),%xmm1
ucomisd 0xe62(%rip),%xmm1
ja     1150 <sum_function+0x40>
addsd  %xmm0,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @sum_function(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 double
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* %9
%12 = load double, double* %5
%13 = load double, double* %6
%14 = load double, double* %7
%15 = call double @h_equation(double %12, double %13, double %14)
store double %15, double* %10
%16 = load double, double* %10
store double %16, double* %11
%17 = load double, double* %7
br label %18
18: ; preds = %32, %4
%19 = load double, double* %7
%20 = fcmp ogt double %19, 0.000000e+00
br i1 %20, label %21, label %35
21: ; preds = %18
%22 = load double, double* %9
%23 = load double (double)*, double (double)** %8
%24 = load double, double* %5
%25 = load double, double* %11
%26 = fadd double %24, %25
%27 = call double %23(double %26)
%28 = fadd double %22, %27
store double %28, double* %9
%29 = load double, double* %11
%30 = load double, double* %10
%31 = fadd double %29, %30
store double %31, double* %11
br label %32
32: ; preds = %21
%33 = load double, double* %7
%34 = fadd double %33, -1.000000e+00
store double %34, double* %7
br label %18
35: ; preds = %18
%36 = load double, double* %9
%37 = fmul double 2.000000e+00, %36
ret double %37
}

LLVM IR (-O2):
define double @sum_function(double %0, double %1, double %2, double (double)* nocapture %3) {
%5 = tail call double @h_equation(double %0, double %1, double %2)
%6 = fcmp ogt double %2, 0.000000e+00
br i1 %6, label %7, label %19
7: ; preds = %4, %7
%8 = phi double [ %14, %7 ], [ %5, %4 ]
%9 = phi double [ %15, %7 ], [ %2, %4 ]
%10 = phi double [ %13, %7 ], [ 0.000000e+00, %4 ]
%11 = fadd double %8, %0
%12 = tail call double %3(double %11)
%13 = fadd double %10, %12
%14 = fadd double %5, %8
%15 = fadd double %9, -1.000000e+00
%16 = fcmp ogt double %15, 0.000000e+00
br i1 %16, label %7, label %17
17: ; preds = %7
%18 = fmul double %13, 2.000000e+00
br label %19
19: ; preds = %17, %4
%20 = phi double [ 0.000000e+00, %4 ], [ %18, %17 ]
ret double %20
}