#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 */
float cos(float);
int /*<<< orphan*/ free_vector(float *, int, int);
int /*<<< orphan*/ printf(char *, ...);
double sin(float);
int /*<<< orphan*/ spline(float *, float *, int, float, float, float *);
float *vector(int, int);
int main(void) {
  int i;
  float yp1, ypn, *x, *y, *y2;
  x = vector(1, 20);
  y = vector(1, 20);
  y2 = vector(1, 20);
  printf("\nsecond-derivatives for sin(x) from 0 to pi\n");
  for (i = 1; i <= 20; i++) {
    x[i] = i * 3.1415926 / 20;
    y[i] = sin(x[i]);
  }
  yp1 = cos(x[1]);
  ypn = cos(x[20]);
  spline(x, y, 20, yp1, ypn, y2);
  printf("%23s %16s\n", "spline", "actual");
  printf("%11s %14s %16s\n", "angle", "2nd deriv", "2nd deriv");
  for (i = 1; i <= 20; i++)
    printf("%10.2f %16.6f %16.6f\n", x[i], y2[i], -sin(x[i]));
  free_vector(y2, 1, 20);
  free_vector(y, 1, 20);
  free_vector(x, 1, 20);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x14,%esi
call   1060 <vector@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
mov    $0x14,%esi
call   1060 <vector@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1,%edi
mov    $0x14,%esi
call   1060 <vector@plt>
mov    %rax,-0x28(%rbp)
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jg     1226 <main+0xc6>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe34(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe20(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1050 <sin@plt>
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11bd <main+0x5d>
mov    -0x18(%rbp),%rax
movss  0x4(%rax),%xmm0
call   1070 <cos@plt>
movss  %xmm0,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movss  0x50(%rax),%xmm0
call   1070 <cos@plt>
movss  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
mov    -0x28(%rbp),%rcx
mov    $0x14,%edx
call   1080 <spline@plt>
lea    0xdca(%rip),%rdi
lea    0xdce(%rip),%rsi
lea    0xdce(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdc7(%rip),%rdi
lea    0xdd0(%rip),%rsi
lea    0xdcf(%rip),%rcx
mov    %rcx,%rdx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jg     1336 <main+0x1d6>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1050 <sin@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
lea    0xd55(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12ae <main+0x14e>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0x14,%edx
call   1040 <free_vector@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0x14,%edx
call   1040 <free_vector@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0x14,%edx
call   1040 <free_vector@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%edi
mov    $0x14,%esi
call   1070 <vector@plt>
mov    %rax,%r13
mov    $0x1,%edi
mov    $0x14,%esi
call   1070 <vector@plt>
mov    %rax,%r14
mov    $0x1,%edi
mov    $0x14,%esi
call   1070 <vector@plt>
mov    %rax,%r15
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0xe21(%rip),%xmm0
divsd  0xe21(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x0(%r13,%rbx,4)
call   1060 <sin@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0x15,%rbx
jne    11d0 <main+0x60>
movss  0x4(%r13),%xmm0
call   1080 <cos@plt>
movss  %xmm0,(%rsp)
movss  0x50(%r13),%xmm0
call   1080 <cos@plt>
movaps %xmm0,%xmm1
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x14,%edx
movss  (%rsp),%xmm0
mov    %r15,%rcx
call   1090 <spline@plt>
lea    0xdd8(%rip),%rdi
lea    0xddc(%rip),%rsi
lea    0xddc(%rip),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd5(%rip),%rdi
lea    0xdde(%rip),%rsi
lea    0xddd(%rip),%rcx
mov    %rcx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
lea    0xdd1(%rip),%r12
nopl   0x0(%rax,%rax,1)
movss  0x0(%r13,%rbx,4),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movss  (%r15,%rbx,4),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1060 <sin@plt>
movaps %xmm0,%xmm2
xorps  0xd4e(%rip),%xmm2
mov    %r12,%rdi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x3,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x15,%rbx
jne    1290 <main+0x120>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x14,%edx
call   1050 <free_vector@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x14,%edx
call   1050 <free_vector@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x14,%edx
call   1050 <free_vector@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [45 x i8] c"\0Asecond-derivatives for sin(x) from 0 to pi\0A\00"
@.str.1 = [11 x i8] c"%23s %16s\0A\00"
@.str.2 = [7 x i8] c"spline\00"
@.str.3 = [7 x i8] c"actual\00"
@.str.4 = [16 x i8] c"%11s %14s %16s\0A\00"
@.str.5 = [6 x i8] c"angle\00"
@.str.6 = [10 x i8] c"2nd deriv\00"
@.str.7 = [22 x i8] c"%10.2f %16.6f %16.6f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float*
%6 = alloca float*
%7 = alloca float*
store i32 0, i32* %1
%8 = call float* @vector(i32 1, i32 20)
store float* %8, float** %5
%9 = call float* @vector(i32 1, i32 20)
store float* %9, float** %6
%10 = call float* @vector(i32 1, i32 20)
store float* %10, float** %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %12
12: ; preds = %36, %0
%13 = load i32, i32* %2
%14 = icmp sle i32 %13, 20
br i1 %14, label %15, label %39
15: ; preds = %12
%16 = load i32, i32* %2
%17 = sitofp i32 %16 to double
%18 = fmul double %17, 0x400921FB4D12D84A
%19 = fdiv double %18, 2.000000e+01
%20 = fptrunc double %19 to float
%21 = load float*, float** %5
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds float, float* %21, i64 %23
store float %20, float* %24
%25 = load float*, float** %5
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds float, float* %25, i64 %27
%29 = load float, float* %28
%30 = call double @sin(float %29)
%31 = fptrunc double %30 to float
%32 = load float*, float** %6
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds float, float* %32, i64 %34
store float %31, float* %35
br label %36
36: ; preds = %15
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %12
39: ; preds = %12
%40 = load float*, float** %5
%41 = getelementptr inbounds float, float* %40, i64 1
%42 = load float, float* %41
%43 = call float @cos(float %42)
store float %43, float* %3
%44 = load float*, float** %5
%45 = getelementptr inbounds float, float* %44, i64 20
%46 = load float, float* %45
%47 = call float @cos(float %46)
store float %47, float* %4
%48 = load float*, float** %5
%49 = load float*, float** %6
%50 = load float, float* %3
%51 = load float, float* %4
%52 = load float*, float** %7
%53 = call i32 @spline(float* %48, float* %49, i32 20, float %50, float %51, float* %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %2
br label %56
56: ; preds = %80, %39
%57 = load i32, i32* %2
%58 = icmp sle i32 %57, 20
br i1 %58, label %59, label %83
59: ; preds = %56
%60 = load float*, float** %5
%61 = load i32, i32* %2
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds float, float* %60, i64 %62
%64 = load float, float* %63
%65 = fpext float %64 to double
%66 = load float*, float** %7
%67 = load i32, i32* %2
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds float, float* %66, i64 %68
%70 = load float, float* %69
%71 = fpext float %70 to double
%72 = load float*, float** %5
%73 = load i32, i32* %2
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds float, float* %72, i64 %74
%76 = load float, float* %75
%77 = call double @sin(float %76)
%78 = fneg double %77
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), double %65, double %71, double %78)
br label %80
80: ; preds = %59
%81 = load i32, i32* %2
%82 = add nsw i32 %81, 1
store i32 %82, i32* %2
br label %56
83: ; preds = %56
%84 = load float*, float** %7
%85 = call i32 @free_vector(float* %84, i32 1, i32 20)
%86 = load float*, float** %6
%87 = call i32 @free_vector(float* %86, i32 1, i32 20)
%88 = load float*, float** %5
%89 = call i32 @free_vector(float* %88, i32 1, i32 20)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"%23s %16s\0A\00"
@.str.2 = [7 x i8] c"spline\00"
@.str.3 = [7 x i8] c"actual\00"
@.str.4 = [16 x i8] c"%11s %14s %16s\0A\00"
@.str.5 = [6 x i8] c"angle\00"
@.str.6 = [10 x i8] c"2nd deriv\00"
@.str.7 = [22 x i8] c"%10.2f %16.6f %16.6f\0A\00"
@str = [44 x i8] c"\0Asecond-derivatives for sin(x) from 0 to pi\00"
define i32 @main() {
%1 = tail call float* @vector(i32 1, i32 20)
%2 = tail call float* @vector(i32 1, i32 20)
%3 = tail call float* @vector(i32 1, i32 20)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 1, %0 ], [ %16, %5 ]
%7 = trunc i64 %6 to i32
%8 = sitofp i32 %7 to double
%9 = fmul double %8, 0x400921FB4D12D84A
%10 = fdiv double %9, 2.000000e+01
%11 = fptrunc double %10 to float
%12 = getelementptr inbounds float, float* %1, i64 %6
store float %11, float* %12
%13 = tail call double @sin(float %11)
%14 = fptrunc double %13 to float
%15 = getelementptr inbounds float, float* %2, i64 %6
store float %14, float* %15
%16 = add nuw nsw i64 %6, 1
%17 = icmp eq i64 %16, 21
br i1 %17, label %18, label %5
18: ; preds = %5
%19 = getelementptr inbounds float, float* %1, i64 1
%20 = load float, float* %19
%21 = tail call float @cos(float %20)
%22 = getelementptr inbounds float, float* %1, i64 20
%23 = load float, float* %22
%24 = tail call float @cos(float %23)
%25 = tail call i32 @spline(float* %1, float* %2, i32 20, float %21, float %24, float* %3)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %28
28: ; preds = %18, %28
%29 = phi i64 [ 1, %18 ], [ %39, %28 ]
%30 = getelementptr inbounds float, float* %1, i64 %29
%31 = load float, float* %30
%32 = fpext float %31 to double
%33 = getelementptr inbounds float, float* %3, i64 %29
%34 = load float, float* %33
%35 = fpext float %34 to double
%36 = tail call double @sin(float %31)
%37 = fneg double %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), double %32, double %35, double %37)
%39 = add nuw nsw i64 %29, 1
%40 = icmp eq i64 %39, 21
br i1 %40, label %41, label %28
41: ; preds = %28
%42 = tail call i32 @free_vector(float* %3, i32 1, i32 20)
%43 = tail call i32 @free_vector(float* %2, i32 1, i32 20)
%44 = tail call i32 @free_vector(float* %1, i32 1, i32 20)
ret i32 0
}