#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 */
int /*<<< orphan*/ printf(char *, double, double, double);
double stub1(double, void *);
double stub2(double, void *);
double derivative(double x0, double h, double (*my_func)(double, void *),
                  void *params) {
  double ans;
  ans = ((*my_func)(x0 + h, params) - (*my_func)(x0 - h, params)) / (2.0 * h);
  printf("DE:%lf, %lf, %lf\n", x0, h, ans);
  return ans;
}


x86 assembly (clang, -O0):
<derivative>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rdi
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xe95(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<derivative>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
addsd  %xmm1,%xmm0
mov    %rsi,%rdi
call   *%r14
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
call   *%r14
movsd  (%rsp),%xmm2
subsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
lea    0xe8f(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"DE:%lf, %lf, %lf\0A\00"
define double @derivative(double %0, double %1, double (double, i8*)* %2, i8* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double (double, i8*)*
%8 = alloca i8*
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store double (double, i8*)* %2, double (double, i8*)** %7
store i8* %3, i8** %8
%10 = load double (double, i8*)*, double (double, i8*)** %7
%11 = load double, double* %5
%12 = load double, double* %6
%13 = fadd double %11, %12
%14 = load i8*, i8** %8
%15 = call double %10(double %13, i8* %14)
%16 = load double (double, i8*)*, double (double, i8*)** %7
%17 = load double, double* %5
%18 = load double, double* %6
%19 = fsub double %17, %18
%20 = load i8*, i8** %8
%21 = call double %16(double %19, i8* %20)
%22 = fsub double %15, %21
%23 = load double, double* %6
%24 = fmul double 2.000000e+00, %23
%25 = fdiv double %22, %24
store double %25, double* %9
%26 = load double, double* %5
%27 = load double, double* %6
%28 = load double, double* %9
%29 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %26, double %27, double %28)
%30 = load double, double* %9
ret double %30
}

LLVM IR (-O2):
@.str = [18 x i8] c"DE:%lf, %lf, %lf\0A\00"
define double @derivative(double %0, double %1, double (double, i8*)* nocapture %2, i8* %3) {
%5 = fadd double %0, %1
%6 = tail call double %2(double %5, i8* %3)
%7 = fsub double %0, %1
%8 = tail call double %2(double %7, i8* %3)
%9 = fsub double %6, %8
%10 = fmul double %1, 2.000000e+00
%11 = fdiv double %9, %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %0, double %1, double %11)
ret double %11
}