#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*/ agbnp3_cspline_interpolate(float, float, int, float *,
                                              float *, float *, float *);
int /*<<< orphan*/ agbnp3_cspline_setup(float, int, float *, float, float,
                                        float *);
float agbnp3_i4(float, float, float, float *);
int /*<<< orphan*/ free(float *);
float *malloc(int);
int /*<<< orphan*/ printf(char *, float, float, float, float);
void agbnp3_test_cspline(void) {
  float x, dx = 0.2;
  int n = 100;
  float dxi = 0.02;
  int ni = 1000;
  float *y = malloc(n * sizeof(float));
  float *y2 = malloc(n * sizeof(float));
  float yp1, ypn = 0.0;
  float f, fp;
  int i;
  float Rj = 2.0, Ri = 1.0, dq;
  float q;
  float fold, xold;
  x = 0.0;
  for (i = 0; i < n; i++) {
    y[i] = agbnp3_i4(x, Ri, Rj, &dq);
    if (i == 0)
      yp1 = dq;
    x += dx;
  }
  agbnp3_cspline_setup(dx, n, y, yp1, ypn, y2);
  x = 0.0;
  for (i = 0; i < ni; i++) {
    agbnp3_cspline_interpolate(x, dx, n, y, y2, &f, &fp);
    if (i > 0) {
      printf("csp: %f %f %f %f\n", x, f, f - fold, fp * dxi);
    }
    fold = f;
    xold = x;
    x += dxi;
  }
  free(y);
  free(y2);
}


x86 assembly (clang, -O0):
<agbnp3_test_cspline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movss  0xe9c(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
movss  0xe84(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  0xe3e(%rip),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  0xe2d(%rip),%xmm0
movss  %xmm0,-0x44(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1249 <agbnp3_test_cspline+0xe9>
movss  -0x4(%rbp),%xmm0
movss  -0x44(%rbp),%xmm1
movss  -0x40(%rbp),%xmm2
lea    -0x48(%rbp),%rdi
call   1040 <agbnp3_i4@plt>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
cmpl   $0x0,-0x3c(%rbp)
jne    122c <agbnp3_test_cspline+0xcc>
movss  -0x48(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e7 <agbnp3_test_cspline+0x87>
movss  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
movss  -0x2c(%rbp),%xmm1
movss  -0x30(%rbp),%xmm2
mov    -0x28(%rbp),%rdx
call   1070 <agbnp3_cspline_setup@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    130a <agbnp3_test_cspline+0x1aa>
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x34(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1080 <agbnp3_cspline_interpolate@plt>
cmpl   $0x0,-0x3c(%rbp)
jle    12d9 <agbnp3_test_cspline+0x179>
movss  -0x4(%rbp),%xmm0
movss  -0x34(%rbp),%xmm1
movss  -0x34(%rbp),%xmm2
subss  -0x50(%rbp),%xmm2
movss  -0x38(%rbp),%xmm3
mulss  -0x10(%rbp),%xmm3
lea    0xd3c(%rip),%rdi
call   1050 <printf@plt>
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x10(%rbp),%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1277 <agbnp3_test_cspline+0x117>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<agbnp3_test_cspline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x190,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    $0x190,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xorps  %xmm1,%xmm1
xor    %ebx,%ebx
lea    0x10(%rsp),%r15
jmp    11b8 <agbnp3_test_cspline+0x58>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  0x4(%rsp),%xmm1
addss  0xe5a(%rip),%xmm1
add    $0x1,%rbx
cmp    $0x64,%rbx
je     11f2 <agbnp3_test_cspline+0x92>
movss  %xmm1,0x4(%rsp)
movaps %xmm1,%xmm0
movss  0xe37(%rip),%xmm1
movss  0xe33(%rip),%xmm2
mov    %r15,%rdi
call   1040 <agbnp3_i4@plt>
movss  %xmm0,0x0(%rbp,%rbx,4)
test   %rbx,%rbx
jne    11a0 <agbnp3_test_cspline+0x40>
movss  0x10(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
jmp    11a0 <agbnp3_test_cspline+0x40>
movss  0xe0e(%rip),%xmm0
xorps  %xmm2,%xmm2
mov    $0x64,%edi
mov    %rbp,%rsi
movss  0x8(%rsp),%xmm1
mov    %r14,%rdx
call   1070 <agbnp3_cspline_setup@plt>
lea    0xc(%rsp),%r15
lea    0x14(%rsp),%r12
xorps  %xmm0,%xmm0
movss  0xde0(%rip),%xmm1
mov    $0x64,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1080 <agbnp3_cspline_interpolate@plt>
movss  0xdc6(%rip),%xmm0
mov    $0x3e7,%ebx
lea    0xdbe(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  %xmm0,0x4(%rsp)
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
movss  0x4(%rsp),%xmm0
movss  0xd88(%rip),%xmm1
mov    $0x64,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1080 <agbnp3_cspline_interpolate@plt>
movss  0xc(%rsp),%xmm1
movaps %xmm1,%xmm2
subss  0x8(%rsp),%xmm2
movss  0x14(%rsp),%xmm3
movss  0xd59(%rip),%xmm0
mulss  %xmm0,%xmm3
mov    %r13,%rdi
movss  0x4(%rsp),%xmm0
call   1050 <printf@plt>
movss  0x4(%rsp),%xmm0
addss  0xd39(%rip),%xmm0
add    $0xffffffff,%ebx
jne    1260 <agbnp3_test_cspline+0x100>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"csp: %f %f %f %f\0A\00"
define void @agbnp3_test_cspline() {
%1 = alloca float
%2 = alloca float
%3 = alloca i32
%4 = alloca float
%5 = alloca i32
%6 = alloca float*
%7 = alloca float*
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca i32
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca float
%17 = alloca float
%18 = alloca float
store float 0x3FC99999A0000000, float* %2
store i32 100, i32* %3
store float 0x3F947AE140000000, float* %4
store i32 1000, i32* %5
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4
%22 = trunc i64 %21 to i32
%23 = call float* @malloc(i32 %22)
store float* %23, float** %6
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call float* @malloc(i32 %27)
store float* %28, float** %7
store float 0.000000e+00, float* %9
store float 2.000000e+00, float* %13
store float 1.000000e+00, float* %14
store float 0.000000e+00, float* %1
store i32 0, i32* %12
br label %29
29: ; preds = %50, %0
%30 = load i32, i32* %12
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %53
33: ; preds = %29
%34 = load float, float* %1
%35 = load float, float* %14
%36 = load float, float* %13
%37 = call float @agbnp3_i4(float %34, float %35, float %36, float* %15)
%38 = load float*, float** %6
%39 = load i32, i32* %12
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %38, i64 %40
store float %37, float* %41
%42 = load i32, i32* %12
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %33
%45 = load float, float* %15
store float %45, float* %8
br label %46
46: ; preds = %44, %33
%47 = load float, float* %2
%48 = load float, float* %1
%49 = fadd float %48, %47
store float %49, float* %1
br label %50
50: ; preds = %46
%51 = load i32, i32* %12
%52 = add nsw i32 %51, 1
store i32 %52, i32* %12
br label %29
53: ; preds = %29
%54 = load float, float* %2
%55 = load i32, i32* %3
%56 = load float*, float** %6
%57 = load float, float* %8
%58 = load float, float* %9
%59 = load float*, float** %7
%60 = call i32 @agbnp3_cspline_setup(float %54, i32 %55, float* %56, float %57, float %58, float* %59)
store float 0.000000e+00, float* %1
store i32 0, i32* %12
br label %61
61: ; preds = %90, %53
%62 = load i32, i32* %12
%63 = load i32, i32* %5
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %93
65: ; preds = %61
%66 = load float, float* %1
%67 = load float, float* %2
%68 = load i32, i32* %3
%69 = load float*, float** %6
%70 = load float*, float** %7
%71 = call i32 @agbnp3_cspline_interpolate(float %66, float %67, i32 %68, float* %69, float* %70, float* %10, float* %11)
%72 = load i32, i32* %12
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %84
74: ; preds = %65
%75 = load float, float* %1
%76 = load float, float* %10
%77 = load float, float* %10
%78 = load float, float* %17
%79 = fsub float %77, %78
%80 = load float, float* %11
%81 = load float, float* %4
%82 = fmul float %80, %81
%83 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), float %75, float %76, float %79, float %82)
br label %84
84: ; preds = %74, %65
%85 = load float, float* %10
store float %85, float* %17
%86 = load float, float* %1
store float %86, float* %18
%87 = load float, float* %4
%88 = load float, float* %1
%89 = fadd float %88, %87
store float %89, float* %1
br label %90
90: ; preds = %84
%91 = load i32, i32* %12
%92 = add nsw i32 %91, 1
store i32 %92, i32* %12
br label %61
93: ; preds = %61
%94 = load float*, float** %6
%95 = call i32 @free(float* %94)
%96 = load float*, float** %7
%97 = call i32 @free(float* %96)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"csp: %f %f %f %f\0A\00"
define void @agbnp3_test_cspline() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = tail call float* @malloc(i32 400)
%5 = tail call float* @malloc(i32 400)
%6 = bitcast float* %1 to i8*
%7 = bitcast float* %2 to i8*
%8 = bitcast float* %3 to i8*
br label %9
9: ; preds = %0, %9
%10 = phi i64 [ 0, %0 ], [ %19, %9 ]
%11 = phi float [ 0.000000e+00, %0 ], [ %18, %9 ]
%12 = phi float [ undef, %0 ], [ %17, %9 ]
%13 = call float @agbnp3_i4(float %11, float 1.000000e+00, float 2.000000e+00, float* %3)
%14 = getelementptr inbounds float, float* %4, i64 %10
store float %13, float* %14
%15 = icmp eq i64 %10, 0
%16 = load float, float* %3
%17 = select i1 %15, float %16, float %12
%18 = fadd float %11, 0x3FC99999A0000000
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, 100
br i1 %20, label %21, label %9
21: ; preds = %9
%22 = call i32 @agbnp3_cspline_setup(float 0x3FC99999A0000000, i32 100, float* %4, float %17, float 0.000000e+00, float* %5)
%23 = call i32 @agbnp3_cspline_interpolate(float 0.000000e+00, float 0x3FC99999A0000000, i32 100, float* %4, float* %5, float* %1, float* %2)
br label %24
24: ; preds = %21, %24
%25 = phi float [ 0x3F947AE140000000, %21 ], [ %34, %24 ]
%26 = phi i32 [ 1, %21 ], [ %35, %24 ]
%27 = load float, float* %1
%28 = call i32 @agbnp3_cspline_interpolate(float %25, float 0x3FC99999A0000000, i32 100, float* %4, float* %5, float* %1, float* %2)
%29 = load float, float* %1
%30 = fsub float %29, %27
%31 = load float, float* %2
%32 = fmul float %31, 0x3F947AE140000000
%33 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), float %25, float %29, float %30, float %32)
%34 = fadd float %25, 0x3F947AE140000000
%35 = add nuw nsw i32 %26, 1
%36 = icmp eq i32 %35, 1000
br i1 %36, label %37, label %24
37: ; preds = %24
%38 = call i32 @free(float* %4)
%39 = call i32 @free(float* %5)
ret void
}