#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*/ create_spline(double *, int, double *);
int /*<<< orphan*/ eval_spline(double *, double *, int, double, double *);
double *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int test_spline(void) {
  int i;
  double *data;
  double *spline;
  int size = 10;
  double ans;
  printf("Testing the spline function.\n\n");
  data = malloc(2 * size * sizeof(double));
  spline = malloc(size * sizeof(double));
  data[0] = 0;
  data[1] = 55;
  data[2] = 5;
  data[3] = 60;
  data[4] = 10;
  data[5] = 58;
  data[6] = 15;
  data[7] = 54;
  data[8] = 20;
  data[9] = 55;
  data[10] = 25;
  data[11] = 60;
  data[12] = 30;
  data[13] = 54;
  data[14] = 35;
  data[15] = 57;
  data[16] = 40;
  data[17] = 52;
  data[18] = 45;
  data[19] = 49;
  create_spline(data, size, spline);
  for (i = 0; i < 45; i++) {
    eval_spline(data, spline, size, (double)i, &ans);
    printf("%d %f\n", i, ans);
  }
  printf("Spline test finish\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_spline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0xa,-0x1c(%rbp)
lea    0xf2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe80(%rip),%xmm0
movsd  %xmm0,0x18(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe9f(%rip),%xmm0
movsd  %xmm0,0x20(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,0x28(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe6d(%rip),%xmm0
movsd  %xmm0,0x30(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe2c(%rip),%xmm0
movsd  %xmm0,0x38(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe43(%rip),%xmm0
movsd  %xmm0,0x40(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe2a(%rip),%xmm0
movsd  %xmm0,0x48(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe11(%rip),%xmm0
movsd  %xmm0,0x50(%rax)
mov    -0x10(%rbp),%rax
movsd  0xdf8(%rip),%xmm0
movsd  %xmm0,0x58(%rax)
mov    -0x10(%rbp),%rax
movsd  0xddf(%rip),%xmm0
movsd  %xmm0,0x60(%rax)
mov    -0x10(%rbp),%rax
movsd  0xdc6(%rip),%xmm0
movsd  %xmm0,0x68(%rax)
mov    -0x10(%rbp),%rax
movsd  0xdad(%rip),%xmm0
movsd  %xmm0,0x70(%rax)
mov    -0x10(%rbp),%rax
movsd  0xd94(%rip),%xmm0
movsd  %xmm0,0x78(%rax)
mov    -0x10(%rbp),%rax
movsd  0xd7b(%rip),%xmm0
movsd  %xmm0,0x80(%rax)
mov    -0x10(%rbp),%rax
movsd  0xd5f(%rip),%xmm0
movsd  %xmm0,0x88(%rax)
mov    -0x10(%rbp),%rax
movsd  0xd43(%rip),%xmm0
movsd  %xmm0,0x90(%rax)
mov    -0x10(%rbp),%rax
movsd  0xd27(%rip),%xmm0
movsd  %xmm0,0x98(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <create_spline@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x2d,-0x4(%rbp)
jge    133f <test_spline+0x1ff>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
cvtsi2sdl -0x4(%rbp),%xmm0
lea    -0x28(%rbp),%rcx
call   1050 <eval_spline@plt>
mov    -0x4(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
lea    0xd75(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12f8 <test_spline+0x1b8>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_spline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xf44(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa0,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x50,%edi
call   1070 <malloc@plt>
xorps  %xmm0,%xmm0
movhps 0xe77(%rip),%xmm0
mov    %rax,%r14
movups %xmm0,(%rbx)
movaps 0xe7a(%rip),%xmm0
movups %xmm0,0x10(%rbx)
movaps 0xe7f(%rip),%xmm0
movups %xmm0,0x20(%rbx)
movaps 0xe84(%rip),%xmm0
movups %xmm0,0x30(%rbx)
movaps 0xe89(%rip),%xmm0
movups %xmm0,0x40(%rbx)
movaps 0xe8e(%rip),%xmm0
movups %xmm0,0x50(%rbx)
movaps 0xe93(%rip),%xmm0
movups %xmm0,0x60(%rbx)
movaps 0xe98(%rip),%xmm0
movups %xmm0,0x70(%rbx)
movaps 0xe9d(%rip),%xmm0
movups %xmm0,0x80(%rbx)
movapd 0xe9e(%rip),%xmm0
movupd %xmm0,0x90(%rbx)
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %rax,%rdx
call   1050 <create_spline@plt>
xor    %ebp,%ebp
xorpd  %xmm0,%xmm0
lea    0x8(%rsp),%r15
lea    0xe84(%rip),%r12
nopl   0x0(%rax)
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
movsd  (%rsp),%xmm0
mov    %r15,%rcx
call   1060 <eval_spline@plt>
movsd  0x8(%rsp),%xmm0
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
addsd  0xdac(%rip),%xmm0
add    $0x1,%ebp
cmp    $0x2d,%ebp
jne    1220 <test_spline+0xd0>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Testing the spline function.\0A\0A\00"
@.str.1 = [7 x i8] c"%d %f\0A\00"
@.str.2 = [20 x i8] c"Spline test finish\0A\00"
define i32 @test_spline() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
store i32 10, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %4
%8 = mul nsw i32 2, %7
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call double* @malloc(i32 %11)
store double* %12, double** %2
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = trunc i64 %15 to i32
%17 = call double* @malloc(i32 %16)
store double* %17, double** %3
%18 = load double*, double** %2
%19 = getelementptr inbounds double, double* %18, i64 0
store double 0.000000e+00, double* %19
%20 = load double*, double** %2
%21 = getelementptr inbounds double, double* %20, i64 1
store double 5.500000e+01, double* %21
%22 = load double*, double** %2
%23 = getelementptr inbounds double, double* %22, i64 2
store double 5.000000e+00, double* %23
%24 = load double*, double** %2
%25 = getelementptr inbounds double, double* %24, i64 3
store double 6.000000e+01, double* %25
%26 = load double*, double** %2
%27 = getelementptr inbounds double, double* %26, i64 4
store double 1.000000e+01, double* %27
%28 = load double*, double** %2
%29 = getelementptr inbounds double, double* %28, i64 5
store double 5.800000e+01, double* %29
%30 = load double*, double** %2
%31 = getelementptr inbounds double, double* %30, i64 6
store double 1.500000e+01, double* %31
%32 = load double*, double** %2
%33 = getelementptr inbounds double, double* %32, i64 7
store double 5.400000e+01, double* %33
%34 = load double*, double** %2
%35 = getelementptr inbounds double, double* %34, i64 8
store double 2.000000e+01, double* %35
%36 = load double*, double** %2
%37 = getelementptr inbounds double, double* %36, i64 9
store double 5.500000e+01, double* %37
%38 = load double*, double** %2
%39 = getelementptr inbounds double, double* %38, i64 10
store double 2.500000e+01, double* %39
%40 = load double*, double** %2
%41 = getelementptr inbounds double, double* %40, i64 11
store double 6.000000e+01, double* %41
%42 = load double*, double** %2
%43 = getelementptr inbounds double, double* %42, i64 12
store double 3.000000e+01, double* %43
%44 = load double*, double** %2
%45 = getelementptr inbounds double, double* %44, i64 13
store double 5.400000e+01, double* %45
%46 = load double*, double** %2
%47 = getelementptr inbounds double, double* %46, i64 14
store double 3.500000e+01, double* %47
%48 = load double*, double** %2
%49 = getelementptr inbounds double, double* %48, i64 15
store double 5.700000e+01, double* %49
%50 = load double*, double** %2
%51 = getelementptr inbounds double, double* %50, i64 16
store double 4.000000e+01, double* %51
%52 = load double*, double** %2
%53 = getelementptr inbounds double, double* %52, i64 17
store double 5.200000e+01, double* %53
%54 = load double*, double** %2
%55 = getelementptr inbounds double, double* %54, i64 18
store double 4.500000e+01, double* %55
%56 = load double*, double** %2
%57 = getelementptr inbounds double, double* %56, i64 19
store double 4.900000e+01, double* %57
%58 = load double*, double** %2
%59 = load i32, i32* %4
%60 = load double*, double** %3
%61 = call i32 @create_spline(double* %58, i32 %59, double* %60)
store i32 0, i32* %1
br label %62
62: ; preds = %75, %0
%63 = load i32, i32* %1
%64 = icmp slt i32 %63, 45
br i1 %64, label %65, label %78
65: ; preds = %62
%66 = load double*, double** %2
%67 = load double*, double** %3
%68 = load i32, i32* %4
%69 = load i32, i32* %1
%70 = sitofp i32 %69 to double
%71 = call i32 @eval_spline(double* %66, double* %67, i32 %68, double %70, double* %5)
%72 = load i32, i32* %1
%73 = load double, double* %5
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %72, double %73)
br label %75
75: ; preds = %65
%76 = load i32, i32* %1
%77 = add nsw i32 %76, 1
store i32 %77, i32* %1
br label %62
78: ; preds = %62
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%d %f\0A\00"
@str = [30 x i8] c"Testing the spline function.\0A\00"
@str.3 = [19 x i8] c"Spline test finish\00"
define i32 @test_spline() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%4 = tail call double* @malloc(i32 160)
%5 = tail call double* @malloc(i32 80)
%6 = bitcast double* %4 to <2 x double>*
store <2 x double> <double 0.000000e+00, double 5.500000e+01>, <2 x double>* %6
%7 = getelementptr inbounds double, double* %4, i64 2
%8 = bitcast double* %7 to <2 x double>*
store <2 x double> <double 5.000000e+00, double 6.000000e+01>, <2 x double>* %8
%9 = getelementptr inbounds double, double* %4, i64 4
%10 = bitcast double* %9 to <2 x double>*
store <2 x double> <double 1.000000e+01, double 5.800000e+01>, <2 x double>* %10
%11 = getelementptr inbounds double, double* %4, i64 6
%12 = bitcast double* %11 to <2 x double>*
store <2 x double> <double 1.500000e+01, double 5.400000e+01>, <2 x double>* %12
%13 = getelementptr inbounds double, double* %4, i64 8
%14 = bitcast double* %13 to <2 x double>*
store <2 x double> <double 2.000000e+01, double 5.500000e+01>, <2 x double>* %14
%15 = getelementptr inbounds double, double* %4, i64 10
%16 = bitcast double* %15 to <2 x double>*
store <2 x double> <double 2.500000e+01, double 6.000000e+01>, <2 x double>* %16
%17 = getelementptr inbounds double, double* %4, i64 12
%18 = bitcast double* %17 to <2 x double>*
store <2 x double> <double 3.000000e+01, double 5.400000e+01>, <2 x double>* %18
%19 = getelementptr inbounds double, double* %4, i64 14
%20 = bitcast double* %19 to <2 x double>*
store <2 x double> <double 3.500000e+01, double 5.700000e+01>, <2 x double>* %20
%21 = getelementptr inbounds double, double* %4, i64 16
%22 = bitcast double* %21 to <2 x double>*
store <2 x double> <double 4.000000e+01, double 5.200000e+01>, <2 x double>* %22
%23 = getelementptr inbounds double, double* %4, i64 18
%24 = bitcast double* %23 to <2 x double>*
store <2 x double> <double 4.500000e+01, double 4.900000e+01>, <2 x double>* %24
%25 = tail call i32 @create_spline(double* %4, i32 10, double* %5)
br label %26
26: ; preds = %0, %26
%27 = phi i32 [ 0, %0 ], [ %32, %26 ]
%28 = sitofp i32 %27 to double
%29 = call i32 @eval_spline(double* %4, double* %5, i32 10, double %28, double* %1)
%30 = load double, double* %1
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %27, double %30)
%32 = add nuw nsw i32 %27, 1
%33 = icmp eq i32 %32, 45
br i1 %33, label %34, label %26
34: ; preds = %26
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}