#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 int /*<<< orphan*/ nobeats;
typedef int /*<<< orphan*/ beats;

/* Variables and functions */
size_t drand48();
double fabs(double const);
double sample(float *, size_t, double);
double autodifference(float nrg[], size_t len, double interval) {
  size_t n;
  double mid, v, diff, total;
  static const double beats[] = {-32, -16, -8, -4, -2, -1, 1, 2, 4, 8, 16, 32},
                      nobeats[] = {-0.5, -0.25, 0.25, 0.5};
  mid = drand48() * len;
  v = sample(nrg, len, mid);
  diff = 0.0;
  total = 0.0;
  for (n = 0; n < (sizeof(beats) / sizeof(*(beats))); n++) {
    double y, w;
    y = sample(nrg, len, mid + beats[n] * interval);
    w = 1.0 / fabs(beats[n]);
    diff += w * fabs(y - v);
    total += w;
  }
  for (n = 0; n < (sizeof(nobeats) / sizeof(*(nobeats))); n++) {
    double y, w;
    y = sample(nrg, len, mid + nobeats[n] * interval);
    w = fabs(nobeats[n]);
    diff -= w * fabs(y - v);
    total += w;
  }
  return diff / total;
}


x86 assembly (clang, -O0):
<autodifference>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
xor    %eax,%eax
call   1040 <drand48@plt>
mov    -0x10(%rbp),%rcx
imul   %rcx,%rax
movq   %rax,%xmm0
movaps 0xeb0(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xeb4(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
call   1030 <sample@plt>
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0xc,-0x20(%rbp)
jae    1256 <autodifference+0x136>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  -0x28(%rbp),%xmm1
mov    -0x20(%rbp),%rcx
lea    0xe7e(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sample@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rcx
lea    0xe57(%rip),%rax
movsd  (%rax,%rcx,8),%xmm1
movaps 0xe2b(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe2f(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
subsd  -0x30(%rbp),%xmm2
movaps 0xe00(%rip),%xmm1
pand   %xmm1,%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    119f <autodifference+0x7f>
movq   $0x0,-0x20(%rbp)
cmpq   $0x4,-0x20(%rbp)
jae    1320 <autodifference+0x200>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  -0x28(%rbp),%xmm1
mov    -0x20(%rbp),%rcx
lea    0xe1f(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sample@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rcx
lea    0xdf8(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movaps 0xd6c(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
subsd  -0x30(%rbp),%xmm2
movaps 0xd4d(%rip),%xmm1
pand   %xmm1,%xmm2
movsd  -0x38(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x60(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    125e <autodifference+0x13e>
movsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<autodifference>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
movsd  %xmm0,0x18(%rsp)
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <drand48@plt>
imul   %r15,%rax
movq   %rax,%xmm1
punpckldq 0xeaf(%rip),%xmm1
subpd  0xeb7(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
movapd %xmm0,0x30(%rsp)
call   1030 <sample@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
lea    0xed3(%rip),%r12
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%r12,1),%xmm0
movapd %xmm0,0x40(%rsp)
mulsd  0x18(%rsp),%xmm0
addsd  0x30(%rsp),%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <sample@plt>
movapd 0xe55(%rip),%xmm2
movapd 0x40(%rsp),%xmm3
andpd  %xmm2,%xmm3
movsd  0xe53(%rip),%xmm1
divsd  %xmm3,%xmm1
subsd  0x10(%rsp),%xmm0
andpd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
movsd  0x20(%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0x8,%rbx
cmp    $0x60,%rbx
jne    11a0 <autodifference+0x80>
movsd  0x18(%rsp),%xmm0
mulsd  0xe11(%rip),%xmm0
addsd  0x30(%rsp),%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <sample@plt>
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
movapd 0xdd6(%rip),%xmm0
andpd  %xmm0,%xmm1
mulsd  0xde2(%rip),%xmm1
addsd  0x20(%rsp),%xmm1
movapd %xmm1,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xdd0(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0xdc4(%rip),%xmm0
addsd  0x30(%rsp),%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <sample@plt>
subsd  0x10(%rsp),%xmm0
andpd  0xd7d(%rip),%xmm0
mulsd  0xd9d(%rip),%xmm0
addsd  0x20(%rsp),%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0xd91(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x30(%rsp),%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <sample@plt>
subsd  0x10(%rsp),%xmm0
andpd  0xd28(%rip),%xmm0
mulsd  0xd48(%rip),%xmm0
addsd  0x20(%rsp),%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xd36(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0xd12(%rip),%xmm0
addsd  0x30(%rsp),%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <sample@plt>
subsd  0x10(%rsp),%xmm0
andpd  0xcd3(%rip),%xmm0
mulsd  0xce3(%rip),%xmm0
addsd  0x20(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  0xcd7(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@autodifference.beats = internal constant [12 x double] [double -3.200000e+01, double -1.600000e+01, double -8.000000e+00, double -4.000000e+00, double -2.000000e+00, double -1.000000e+00, double 1.000000e+00, double 2.000000e+00, double 4.000000e+00, double 8.000000e+00, double 1.600000e+01, double 3.200000e+01]
@autodifference.nobeats = internal constant [4 x double] [double -5.000000e-01, double -2.500000e-01, double 2.500000e-01, double 5.000000e-01]
define double @autodifference(float* %0, i64 %1, double %2) {
%4 = alloca float*
%5 = alloca i64
%6 = alloca double
%7 = alloca i64
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store float* %0, float** %4
store i64 %1, i64* %5
store double %2, double* %6
%16 = call i64 (...) @drand48()
%17 = load i64, i64* %5
%18 = mul i64 %16, %17
%19 = uitofp i64 %18 to double
store double %19, double* %8
%20 = load float*, float** %4
%21 = load i64, i64* %5
%22 = load double, double* %8
%23 = call double @sample(float* %20, i64 %21, double %22)
store double %23, double* %9
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
store i64 0, i64* %7
br label %24
24: ; preds = %52, %3
%25 = load i64, i64* %7
%26 = icmp ult i64 %25, 12
br i1 %26, label %27, label %55
27: ; preds = %24
%28 = load float*, float** %4
%29 = load i64, i64* %5
%30 = load double, double* %8
%31 = load i64, i64* %7
%32 = getelementptr inbounds [12 x double], [12 x double]* @autodifference.beats, i64 0, i64 %31
%33 = load double, double* %32
%34 = load double, double* %6
%35 = call double @llvm.fmuladd.f64(double %33, double %34, double %30)
%36 = call double @sample(float* %28, i64 %29, double %35)
store double %36, double* %12
%37 = load i64, i64* %7
%38 = getelementptr inbounds [12 x double], [12 x double]* @autodifference.beats, i64 0, i64 %37
%39 = load double, double* %38
%40 = call double @llvm.fabs.f64(double %39)
%41 = fdiv double 1.000000e+00, %40
store double %41, double* %13
%42 = load double, double* %13
%43 = load double, double* %12
%44 = load double, double* %9
%45 = fsub double %43, %44
%46 = call double @llvm.fabs.f64(double %45)
%47 = load double, double* %10
%48 = call double @llvm.fmuladd.f64(double %42, double %46, double %47)
store double %48, double* %10
%49 = load double, double* %13
%50 = load double, double* %11
%51 = fadd double %50, %49
store double %51, double* %11
br label %52
52: ; preds = %27
%53 = load i64, i64* %7
%54 = add i64 %53, 1
store i64 %54, i64* %7
br label %24
55: ; preds = %24
store i64 0, i64* %7
br label %56
56: ; preds = %84, %55
%57 = load i64, i64* %7
%58 = icmp ult i64 %57, 4
br i1 %58, label %59, label %87
59: ; preds = %56
%60 = load float*, float** %4
%61 = load i64, i64* %5
%62 = load double, double* %8
%63 = load i64, i64* %7
%64 = getelementptr inbounds [4 x double], [4 x double]* @autodifference.nobeats, i64 0, i64 %63
%65 = load double, double* %64
%66 = load double, double* %6
%67 = call double @llvm.fmuladd.f64(double %65, double %66, double %62)
%68 = call double @sample(float* %60, i64 %61, double %67)
store double %68, double* %14
%69 = load i64, i64* %7
%70 = getelementptr inbounds [4 x double], [4 x double]* @autodifference.nobeats, i64 0, i64 %69
%71 = load double, double* %70
%72 = call double @llvm.fabs.f64(double %71)
store double %72, double* %15
%73 = load double, double* %15
%74 = load double, double* %14
%75 = load double, double* %9
%76 = fsub double %74, %75
%77 = call double @llvm.fabs.f64(double %76)
%78 = load double, double* %10
%79 = fneg double %73
%80 = call double @llvm.fmuladd.f64(double %79, double %77, double %78)
store double %80, double* %10
%81 = load double, double* %15
%82 = load double, double* %11
%83 = fadd double %82, %81
store double %83, double* %11
br label %84
84: ; preds = %59
%85 = load i64, i64* %7
%86 = add i64 %85, 1
store i64 %86, i64* %7
br label %56
87: ; preds = %56
%88 = load double, double* %10
%89 = load double, double* %11
%90 = fdiv double %88, %89
ret double %90
}

LLVM IR (-O2):
@autodifference.beats = internal unnamed_addr constant [12 x double] [double -3.200000e+01, double -1.600000e+01, double -8.000000e+00, double -4.000000e+00, double -2.000000e+00, double -1.000000e+00, double 1.000000e+00, double 2.000000e+00, double 4.000000e+00, double 8.000000e+00, double 1.600000e+01, double 3.200000e+01]
define double @autodifference(float* %0, i64 %1, double %2) {
%4 = tail call i64 (...) @drand48()
%5 = mul i64 %4, %1
%6 = uitofp i64 %5 to double
%7 = tail call double @sample(float* %0, i64 %1, double %6)
br label %8
8: ; preds = %3, %8
%9 = phi i64 [ 0, %3 ], [ %22, %8 ]
%10 = phi double [ 0.000000e+00, %3 ], [ %20, %8 ]
%11 = phi double [ 0.000000e+00, %3 ], [ %21, %8 ]
%12 = getelementptr inbounds [12 x double], [12 x double]* @autodifference.beats, i64 0, i64 %9
%13 = load double, double* %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double %2, double %6)
%15 = tail call double @sample(float* %0, i64 %1, double %14)
%16 = tail call double @llvm.fabs.f64(double %13)
%17 = fdiv double 1.000000e+00, %16
%18 = fsub double %15, %7
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = tail call double @llvm.fmuladd.f64(double %17, double %19, double %10)
%21 = fadd double %11, %17
%22 = add nuw nsw i64 %9, 1
%23 = icmp eq i64 %22, 12
br i1 %23, label %24, label %8
24: ; preds = %8
%25 = tail call double @llvm.fmuladd.f64(double %2, double -5.000000e-01, double %6)
%26 = tail call double @sample(float* %0, i64 %1, double %25)
%27 = fsub double %26, %7
%28 = tail call double @llvm.fabs.f64(double %27)
%29 = tail call double @llvm.fmuladd.f64(double %28, double -5.000000e-01, double %20)
%30 = fadd double %21, 5.000000e-01
%31 = tail call double @llvm.fmuladd.f64(double %2, double -2.500000e-01, double %6)
%32 = tail call double @sample(float* %0, i64 %1, double %31)
%33 = fsub double %32, %7
%34 = tail call double @llvm.fabs.f64(double %33)
%35 = tail call double @llvm.fmuladd.f64(double %34, double -2.500000e-01, double %29)
%36 = fadd double %30, 2.500000e-01
%37 = tail call double @llvm.fmuladd.f64(double %2, double 2.500000e-01, double %6)
%38 = tail call double @sample(float* %0, i64 %1, double %37)
%39 = fsub double %38, %7
%40 = tail call double @llvm.fabs.f64(double %39)
%41 = tail call double @llvm.fmuladd.f64(double %40, double -2.500000e-01, double %35)
%42 = fadd double %36, 2.500000e-01
%43 = tail call double @llvm.fmuladd.f64(double %2, double 5.000000e-01, double %6)
%44 = tail call double @sample(float* %0, i64 %1, double %43)
%45 = fsub double %44, %7
%46 = tail call double @llvm.fabs.f64(double %45)
%47 = tail call double @llvm.fmuladd.f64(double %46, double -5.000000e-01, double %41)
%48 = fadd double %42, 5.000000e-01
%49 = fdiv double %47, %48
ret double %49
}