#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 */
int /*<<< orphan*/ copy_vndb_vnfl(double *, float const *, int const);
int curve_fit_cubic_to_points_refit_db(double *, unsigned int const,
                                       unsigned int const, float const,
                                       unsigned int const, unsigned int const *,
                                       unsigned int, float const, double **,
                                       int *, unsigned int **, unsigned int **,
                                       unsigned int *);
int /*<<< orphan*/ free(double *);
void *malloc(int);
int curve_fit_cubic_to_points_refit_fl(
    const float *points, const unsigned int points_len, const unsigned int dims,
    const float error_threshold, const unsigned int calc_flag,
    const unsigned int *corners, unsigned int corners_len,
    const float corner_angle, float **r_cubic_array,
    unsigned int *r_cubic_array_len, unsigned int **r_cubic_orig_index,
    unsigned int **r_corner_index_array, unsigned int *r_corner_index_len) {
  const uint points_flat_len = points_len * dims;
  double *points_db = malloc(sizeof(double) * points_flat_len);
  copy_vndb_vnfl(points_db, points, points_flat_len);
  double *cubic_array_db = NULL;
  float *cubic_array_fl = NULL;
  uint cubic_array_len = 0;
  int result = curve_fit_cubic_to_points_refit_db(
      points_db, points_len, dims, error_threshold, calc_flag, corners,
      corners_len, corner_angle, &cubic_array_db, &cubic_array_len,
      r_cubic_orig_index, r_corner_index_array, r_corner_index_len);
  free(points_db);
  if (!result) {
    uint cubic_array_flat_len = cubic_array_len * 3 * dims;
    cubic_array_fl = malloc(sizeof(float) * cubic_array_flat_len);
    for (uint i = 0; i < cubic_array_flat_len; ++i) {
      cubic_array_fl[i] = (float)cubic_array_db[i];
    }
    free(cubic_array_db);
  }
  *r_cubic_array = cubic_array_fl;
  *r_cubic_array_len = cubic_array_len;
  return result;
}


x86 assembly (clang, -O0):
<curve_fit_cubic_to_points_refit_fl>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
movss  %xmm0,-0x24(%rbp)
mov    %ecx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
movss  %xmm1,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <copy_vndb_vnfl@plt>
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
movss  -0x24(%rbp),%xmm0
mov    -0x28(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    -0x34(%rbp),%r9d
movss  -0x38(%rbp),%xmm1
mov    0x20(%rbp),%r11
mov    0x28(%rbp),%r10
mov    0x30(%rbp),%rax
lea    -0x50(%rbp),%r14
lea    -0x5c(%rbp),%rbx
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1050 <curve_fit_cubic_to_points_refit_db@plt>
mov    %eax,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x60(%rbp)
jne    1291 <curve_fit_cubic_to_points_refit_fl+0x151>
imul   $0x3,-0x5c(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x64(%rbp)
movslq -0x64(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    1288 <curve_fit_cubic_to_points_refit_fl+0x148>
mov    -0x50(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x58(%rbp),%rax
movslq -0x68(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1250 <curve_fit_cubic_to_points_refit_fl+0x110>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rcx
mov    0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x5c(%rbp),%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x60(%rbp),%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<curve_fit_cubic_to_points_refit_fl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movss  %xmm1,0x34(%rsp)
mov    %r9d,0x30(%rsp)
mov    %r8,0x40(%rsp)
mov    %ecx,%r12d
movss  %xmm0,0x2c(%rsp)
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r13
mov    %edx,%ebx
imul   %esi,%ebx
lea    0x0(,%rbx,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1060 <copy_vndb_vnfl@plt>
movq   $0x0,0x38(%rsp)
movl   $0x0,0x28(%rsp)
mov    0xa0(%rsp),%rax
mov    %rax,0x20(%rsp)
movaps 0x90(%rsp),%xmm0
movups %xmm0,0x10(%rsp)
lea    0x28(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0x38(%rsp),%rax
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
movss  0x2c(%rsp),%xmm0
mov    %r12d,%ecx
mov    0x40(%rsp),%r8
mov    0x30(%rsp),%r9d
movss  0x34(%rsp),%xmm1
call   1050 <curve_fit_cubic_to_points_refit_db@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1030 <free@plt>
test   %r12d,%r12d
je     120b <curve_fit_cubic_to_points_refit_fl+0xcb>
xor    %ebx,%ebx
jmp    12fc <curve_fit_cubic_to_points_refit_fl+0x1bc>
imul   0x28(%rsp),%r14d
lea    (%r14,%r14,2),%ebp
lea    0x0(,%rbp,4),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    0x38(%rsp),%rdi
test   %ebp,%ebp
jle    12f7 <curve_fit_cubic_to_points_refit_fl+0x1b7>
mov    %ebp,%eax
cmp    $0x4,%ebp
jae    123f <curve_fit_cubic_to_points_refit_fl+0xff>
xor    %ecx,%ecx
jmp    12e0 <curve_fit_cubic_to_points_refit_fl+0x1a0>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdx
mov    %rdx,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rdx,%rdx
je     1327 <curve_fit_cubic_to_points_refit_fl+0x1e7>
mov    %r8,%rdx
and    $0xfffffffffffffffe,%rdx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nop
movupd (%rdi,%rsi,8),%xmm0
movupd 0x10(%rdi,%rsi,8),%xmm1
cvtpd2ps %xmm0,%xmm0
cvtpd2ps %xmm1,%xmm1
unpcklpd %xmm1,%xmm0
movupd %xmm0,(%rbx,%rsi,4)
movupd 0x20(%rdi,%rsi,8),%xmm0
movupd 0x30(%rdi,%rsi,8),%xmm1
cvtpd2ps %xmm0,%xmm0
cvtpd2ps %xmm1,%xmm1
unpcklpd %xmm1,%xmm0
movupd %xmm0,0x10(%rbx,%rsi,4)
add    $0x8,%rsi
add    $0xfffffffffffffffe,%rdx
jne    1270 <curve_fit_cubic_to_points_refit_fl+0x130>
test   $0x1,%r8b
je     12d6 <curve_fit_cubic_to_points_refit_fl+0x196>
movupd (%rdi,%rsi,8),%xmm0
movupd 0x10(%rdi,%rsi,8),%xmm1
cvtpd2ps %xmm0,%xmm0
cvtpd2ps %xmm1,%xmm1
unpcklpd %xmm1,%xmm0
movupd %xmm0,(%rbx,%rsi,4)
cmp    %rax,%rcx
je     12f7 <curve_fit_cubic_to_points_refit_fl+0x1b7>
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rcx,8),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    12e0 <curve_fit_cubic_to_points_refit_fl+0x1a0>
call   1030 <free@plt>
mov    0x88(%rsp),%rcx
mov    0x80(%rsp),%rax
mov    %rbx,(%rax)
mov    0x28(%rsp),%eax
mov    %eax,(%rcx)
mov    %r12d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %esi,%esi
test   $0x1,%r8b
jne    12ba <curve_fit_cubic_to_points_refit_fl+0x17a>
jmp    12d6 <curve_fit_cubic_to_points_refit_fl+0x196>

LLVM IR (-O0):
define i32 @curve_fit_cubic_to_points_refit_fl(float* %0, i32 %1, i32 %2, float %3, i32 %4, i32* %5, i32 %6, float %7, float** %8, i32* %9, i32** %10, i32** %11, i32* %12) {
%14 = alloca float*
%15 = alloca i32
%16 = alloca i32
%17 = alloca float
%18 = alloca i32
%19 = alloca i32*
%20 = alloca i32
%21 = alloca float
%22 = alloca float**
%23 = alloca i32*
%24 = alloca i32**
%25 = alloca i32**
%26 = alloca i32*
%27 = alloca i32
%28 = alloca double*
%29 = alloca double*
%30 = alloca float*
%31 = alloca i32
%32 = alloca i32
%33 = alloca i32
%34 = alloca i32
store float* %0, float** %14
store i32 %1, i32* %15
store i32 %2, i32* %16
store float %3, float* %17
store i32 %4, i32* %18
store i32* %5, i32** %19
store i32 %6, i32* %20
store float %7, float* %21
store float** %8, float*** %22
store i32* %9, i32** %23
store i32** %10, i32*** %24
store i32** %11, i32*** %25
store i32* %12, i32** %26
%35 = load i32, i32* %15
%36 = load i32, i32* %16
%37 = mul i32 %35, %36
store i32 %37, i32* %27
%38 = load i32, i32* %27
%39 = sext i32 %38 to i64
%40 = mul i64 8, %39
%41 = trunc i64 %40 to i32
%42 = call i8* @malloc(i32 %41)
%43 = bitcast i8* %42 to double*
store double* %43, double** %28
%44 = load double*, double** %28
%45 = load float*, float** %14
%46 = load i32, i32* %27
%47 = call i32 @copy_vndb_vnfl(double* %44, float* %45, i32 %46)
store double* null, double** %29
store float* null, float** %30
store i32 0, i32* %31
%48 = load double*, double** %28
%49 = load i32, i32* %15
%50 = load i32, i32* %16
%51 = load float, float* %17
%52 = load i32, i32* %18
%53 = load i32*, i32** %19
%54 = load i32, i32* %20
%55 = load float, float* %21
%56 = load i32**, i32*** %24
%57 = load i32**, i32*** %25
%58 = load i32*, i32** %26
%59 = call i32 @curve_fit_cubic_to_points_refit_db(double* %48, i32 %49, i32 %50, float %51, i32 %52, i32* %53, i32 %54, float %55, double** %29, i32* %31, i32** %56, i32** %57, i32* %58)
store i32 %59, i32* %32
%60 = load double*, double** %28
%61 = call i32 @free(double* %60)
%62 = load i32, i32* %32
%63 = icmp ne i32 %62, 0
br i1 %63, label %96, label %64
64: ; preds = %13
%65 = load i32, i32* %31
%66 = mul nsw i32 %65, 3
%67 = load i32, i32* %16
%68 = mul i32 %66, %67
store i32 %68, i32* %33
%69 = load i32, i32* %33
%70 = sext i32 %69 to i64
%71 = mul i64 4, %70
%72 = trunc i64 %71 to i32
%73 = call i8* @malloc(i32 %72)
%74 = bitcast i8* %73 to float*
store float* %74, float** %30
store i32 0, i32* %34
br label %75
75: ; preds = %90, %64
%76 = load i32, i32* %34
%77 = load i32, i32* %33
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %93
79: ; preds = %75
%80 = load double*, double** %29
%81 = load i32, i32* %34
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %80, i64 %82
%84 = load double, double* %83
%85 = fptrunc double %84 to float
%86 = load float*, float** %30
%87 = load i32, i32* %34
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds float, float* %86, i64 %88
store float %85, float* %89
br label %90
90: ; preds = %79
%91 = load i32, i32* %34
%92 = add nsw i32 %91, 1
store i32 %92, i32* %34
br label %75
93: ; preds = %75
%94 = load double*, double** %29
%95 = call i32 @free(double* %94)
br label %96
96: ; preds = %93, %13
%97 = load float*, float** %30
%98 = load float**, float*** %22
store float* %97, float** %98
%99 = load i32, i32* %31
%100 = load i32*, i32** %23
store i32 %99, i32* %100
%101 = load i32, i32* %32
ret i32 %101
}

LLVM IR (-O2):
define i32 @curve_fit_cubic_to_points_refit_fl(float* %0, i32 %1, i32 %2, float %3, i32 %4, i32* %5, i32 %6, float %7, float** nocapture writeonly %8, i32* nocapture writeonly %9, i32** %10, i32** %11, i32* %12) {
%14 = alloca double*
%15 = alloca i32
%16 = mul i32 %2, %1
%17 = shl i32 %16, 3
%18 = tail call i8* @malloc(i32 %17)
%19 = bitcast i8* %18 to double*
%20 = tail call i32 @copy_vndb_vnfl(double* %19, float* %0, i32 %16)
%21 = bitcast double** %14 to i8*
store double* null, double** %14
%22 = bitcast i32* %15 to i8*
store i32 0, i32* %15
%23 = call i32 @curve_fit_cubic_to_points_refit_db(double* %19, i32 %1, i32 %2, float %3, i32 %4, i32* %5, i32 %6, float %7, double** %14, i32* %15, i32** %10, i32** %11, i32* %12)
%24 = call i32 @free(double* %19)
%25 = icmp eq i32 %23, 0
br i1 %25, label %26, label %108
26: ; preds = %13
%27 = load i32, i32* %15
%28 = mul i32 %2, 3
%29 = mul i32 %28, %27
%30 = shl i32 %29, 2
%31 = call i8* @malloc(i32 %30)
%32 = bitcast i8* %31 to float*
%33 = icmp sgt i32 %29, 0
%34 = load double*, double** %14
br i1 %33, label %35, label %98
35: ; preds = %26
%36 = zext i32 %29 to i64
%37 = icmp ult i32 %29, 4
br i1 %37, label %96, label %38
38: ; preds = %35
%39 = and i64 %36, 4294967292
%40 = add nsw i64 %39, -4
%41 = lshr exact i64 %40, 2
%42 = add nuw nsw i64 %41, 1
%43 = and i64 %42, 1
%44 = icmp eq i64 %40, 0
br i1 %44, label %78, label %45
45: ; preds = %38
%46 = and i64 %42, 9223372036854775806
br label %47
47: ; preds = %47, %45
%48 = phi i64 [ 0, %45 ], [ %75, %47 ]
%49 = phi i64 [ 0, %45 ], [ %76, %47 ]
%50 = getelementptr inbounds double, double* %34, i64 %48
%51 = bitcast double* %50 to <2 x double>*
%52 = load <2 x double>, <2 x double>* %51
%53 = getelementptr inbounds double, double* %50, i64 2
%54 = bitcast double* %53 to <2 x double>*
%55 = load <2 x double>, <2 x double>* %54
%56 = fptrunc <2 x double> %52 to <2 x float>
%57 = fptrunc <2 x double> %55 to <2 x float>
%58 = getelementptr inbounds float, float* %32, i64 %48
%59 = bitcast float* %58 to <2 x float>*
store <2 x float> %56, <2 x float>* %59
%60 = getelementptr inbounds float, float* %58, i64 2
%61 = bitcast float* %60 to <2 x float>*
store <2 x float> %57, <2 x float>* %61
%62 = or i64 %48, 4
%63 = getelementptr inbounds double, double* %34, i64 %62
%64 = bitcast double* %63 to <2 x double>*
%65 = load <2 x double>, <2 x double>* %64
%66 = getelementptr inbounds double, double* %63, i64 2
%67 = bitcast double* %66 to <2 x double>*
%68 = load <2 x double>, <2 x double>* %67
%69 = fptrunc <2 x double> %65 to <2 x float>
%70 = fptrunc <2 x double> %68 to <2 x float>
%71 = getelementptr inbounds float, float* %32, i64 %62
%72 = bitcast float* %71 to <2 x float>*
store <2 x float> %69, <2 x float>* %72
%73 = getelementptr inbounds float, float* %71, i64 2
%74 = bitcast float* %73 to <2 x float>*
store <2 x float> %70, <2 x float>* %74
%75 = add nuw i64 %48, 8
%76 = add i64 %49, 2
%77 = icmp eq i64 %76, %46
br i1 %77, label %78, label %47
78: ; preds = %47, %38
%79 = phi i64 [ 0, %38 ], [ %75, %47 ]
%80 = icmp eq i64 %43, 0
br i1 %80, label %94, label %81
81: ; preds = %78
%82 = getelementptr inbounds double, double* %34, i64 %79
%83 = bitcast double* %82 to <2 x double>*
%84 = load <2 x double>, <2 x double>* %83
%85 = getelementptr inbounds double, double* %82, i64 2
%86 = bitcast double* %85 to <2 x double>*
%87 = load <2 x double>, <2 x double>* %86
%88 = fptrunc <2 x double> %84 to <2 x float>
%89 = fptrunc <2 x double> %87 to <2 x float>
%90 = getelementptr inbounds float, float* %32, i64 %79
%91 = bitcast float* %90 to <2 x float>*
store <2 x float> %88, <2 x float>* %91
%92 = getelementptr inbounds float, float* %90, i64 2
%93 = bitcast float* %92 to <2 x float>*
store <2 x float> %89, <2 x float>* %93
br label %94
94: ; preds = %78, %81
%95 = icmp eq i64 %39, %36
br i1 %95, label %98, label %96
96: ; preds = %35, %94
%97 = phi i64 [ 0, %35 ], [ %39, %94 ]
br label %100
98: ; preds = %100, %94, %26
%99 = call i32 @free(double* %34)
br label %108
100: ; preds = %96, %100
%101 = phi i64 [ %106, %100 ], [ %97, %96 ]
%102 = getelementptr inbounds double, double* %34, i64 %101
%103 = load double, double* %102
%104 = fptrunc double %103 to float
%105 = getelementptr inbounds float, float* %32, i64 %101
store float %104, float* %105
%106 = add nuw nsw i64 %101, 1
%107 = icmp eq i64 %106, %36
br i1 %107, label %98, label %100
108: ; preds = %98, %13
%109 = phi float* [ null, %13 ], [ %32, %98 ]
store float* %109, float** %8
%110 = load i32, i32* %15
store i32 %110, i32* %9
ret i32 %23
}