#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 uint;

/* Variables and functions */
double DBL_MAX;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ curve_fit_cubic_to_points_single_db(
    double const *, int const, double const *, int const, double,
    double const *, double const *, double *, double *, double *, int *);
double dot_vnvn(double const *, double *, int const);
int /*<<< orphan*/ isub_vnvn(double *, double const *, int const);
double knot_remove_error_value(const double *tan_l, const double *tan_r,
                               const double *points_offset,
                               const uint points_offset_len,
                               const double *points_offset_length_cache,
                               const uint dims, double r_handle_factors[2],
                               uint *r_error_index) {
  double error_sq = DBL_MAX;
  double handle_factor_l[dims];
  double handle_factor_r[dims];
  curve_fit_cubic_to_points_single_db(
      points_offset, points_offset_len, points_offset_length_cache, dims, 0.0,
      tan_l, tan_r, handle_factor_l, handle_factor_r, &error_sq, r_error_index);
  assert(error_sq != DBL_MAX);
  isub_vnvn(handle_factor_l, points_offset, dims);
  r_handle_factors[0] = dot_vnvn(tan_l, handle_factor_l, dims);
  isub_vnvn(handle_factor_r, &points_offset[(points_offset_len - 1) * dims],
            dims);
  r_handle_factors[1] = dot_vnvn(tan_r, handle_factor_r, dims);
  return error_sq;
}


x86 assembly (clang, -O0):
<knot_remove_error_value>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    0x2e71(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x34(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,-0x68(%rbp)
mov    %rbx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x34(%rbp),%eax
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r11
sub    %rcx,%r11
mov    %r11,-0x60(%rbp)
mov    %r11,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    0x18(%rbp),%rax
xorps  %xmm0,%xmm0
lea    -0x40(%rbp),%r10
sub    $0x20,%rsp
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1050 <curve_fit_cubic_to_points_single_db@plt>
add    $0x20,%rsp
movsd  -0x40(%rbp),%xmm0
mov    0x2dd4(%rip),%rax
ucomisd (%rax),%xmm0
setne  %al
setp   %cl
or     %cl,%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x68(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <isub_vnvn@plt>
mov    -0x68(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%edx
call   1030 <dot_vnvn@plt>
mov    -0x60(%rbp),%rdi
mov    0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
imul   -0x34(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x34(%rbp),%edx
call   1040 <isub_vnvn@plt>
mov    -0x60(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%edx
call   1030 <dot_vnvn@plt>
mov    0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<knot_remove_error_value>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r13d
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%r9
mov    %rsi,-0x40(%rbp)
mov    %rdi,%rax
mov    %rdi,-0x38(%rbp)
mov    %rsp,-0x48(%rbp)
mov    0x18(%rbp),%r10
mov    0x2e69(%rip),%rcx
movsd  (%rcx),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    %r13d,%ecx
mov    %rsp,%r14
lea    0xf(,%rcx,8),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r14
mov    %r14,%rsp
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    -0x30(%rbp),%r11
xorps  %xmm0,%xmm0
mov    %rdx,%rdi
mov    %r12d,%esi
mov    %r8,%rdx
mov    %r13d,%ecx
mov    %rax,%r8
push   %r10
push   %r11
push   %rbx
push   %r14
call   1050 <curve_fit_cubic_to_points_single_db@plt>
add    $0x20,%rsp
mov    0x2e12(%rip),%rax
movsd  (%rax),%xmm0
cmpneqsd -0x30(%rbp),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1060 <assert@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1040 <isub_vnvn@plt>
mov    -0x38(%rbp),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1030 <dot_vnvn@plt>
mov    0x10(%rbp),%r14
movsd  %xmm0,(%r14)
add    $0xffffffff,%r12d
imul   %r13d,%r12d
movslq %r12d,%rax
lea    (%r15,%rax,8),%rsi
mov    %rbx,%rdi
mov    %r13d,%edx
call   1040 <isub_vnvn@plt>
mov    -0x40(%rbp),%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1030 <dot_vnvn@plt>
movsd  %xmm0,0x8(%r14)
movsd  -0x30(%rbp),%xmm0
mov    -0x48(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DBL_MAX = global double 0.000000e+00
define double @knot_remove_error_value(double* %0, double* %1, double* %2, i32 %3, double* %4, i32 %5, double* %6, i32* %7) {
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32
%13 = alloca double*
%14 = alloca i32
%15 = alloca double*
%16 = alloca i32*
%17 = alloca double
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i64
store double* %0, double** %9
store double* %1, double** %10
store double* %2, double** %11
store i32 %3, i32* %12
store double* %4, double** %13
store i32 %5, i32* %14
store double* %6, double** %15
store i32* %7, i32** %16
%21 = load double, double* @DBL_MAX
store double %21, double* %17
%22 = load i32, i32* %14
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %18
%25 = alloca double, i64 %23
store i64 %23, i64* %19
%26 = load i32, i32* %14
%27 = zext i32 %26 to i64
%28 = alloca double, i64 %27
store i64 %27, i64* %20
%29 = load double*, double** %11
%30 = load i32, i32* %12
%31 = load double*, double** %13
%32 = load i32, i32* %14
%33 = load double*, double** %9
%34 = load double*, double** %10
%35 = load i32*, i32** %16
%36 = call i32 @curve_fit_cubic_to_points_single_db(double* %29, i32 %30, double* %31, i32 %32, double 0.000000e+00, double* %33, double* %34, double* %25, double* %28, double* %17, i32* %35)
%37 = load double, double* %17
%38 = load double, double* @DBL_MAX
%39 = fcmp une double %37, %38
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load double*, double** %11
%43 = load i32, i32* %14
%44 = call i32 @isub_vnvn(double* %25, double* %42, i32 %43)
%45 = load double*, double** %9
%46 = load i32, i32* %14
%47 = call double @dot_vnvn(double* %45, double* %25, i32 %46)
%48 = load double*, double** %15
%49 = getelementptr inbounds double, double* %48, i64 0
store double %47, double* %49
%50 = load double*, double** %11
%51 = load i32, i32* %12
%52 = sub nsw i32 %51, 1
%53 = load i32, i32* %14
%54 = mul nsw i32 %52, %53
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %50, i64 %55
%57 = load i32, i32* %14
%58 = call i32 @isub_vnvn(double* %28, double* %56, i32 %57)
%59 = load double*, double** %10
%60 = load i32, i32* %14
%61 = call double @dot_vnvn(double* %59, double* %28, i32 %60)
%62 = load double*, double** %15
%63 = getelementptr inbounds double, double* %62, i64 1
store double %61, double* %63
%64 = load double, double* %17
%65 = load i8*, i8** %18
ret double %64
}

LLVM IR (-O2):
@DBL_MAX = global double 0.000000e+00
define double @knot_remove_error_value(double* %0, double* %1, double* %2, i32 %3, double* %4, i32 %5, double* nocapture writeonly %6, i32* %7) {
%9 = alloca double
%10 = bitcast double* %9 to i8*
%11 = load double, double* @DBL_MAX
store double %11, double* %9
%12 = zext i32 %5 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca double, i64 %12
%15 = alloca double, i64 %12
%16 = call i32 @curve_fit_cubic_to_points_single_db(double* %2, i32 %3, double* %4, i32 %5, double 0.000000e+00, double* %0, double* %1, double* %14, double* %15, double* %9, i32* %7)
%17 = load double, double* %9
%18 = load double, double* @DBL_MAX
%19 = fcmp une double %17, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = call i32 @isub_vnvn(double* %14, double* %2, i32 %5)
%23 = call double @dot_vnvn(double* %0, double* %14, i32 %5)
store double %23, double* %6
%24 = add nsw i32 %3, -1
%25 = mul nsw i32 %24, %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %2, i64 %26
%28 = call i32 @isub_vnvn(double* %15, double* %27, i32 %5)
%29 = call double @dot_vnvn(double* %1, double* %15, i32 %5)
%30 = getelementptr inbounds double, double* %6, i64 1
store double %29, double* %30
%31 = load double, double* %9
ret double %31
}