#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 */
long indexxd(double, double *, long);
double interpxyd(double x0, double *x, double *y, long n) {
  long i;
  i = indexxd(x0, x, n);
  if (i < 0)
    return (y[0]);
  if (i >= n - 1)
    return (y[n - 1]);
  return (y[i] + (x0 - x[i]) * (y[i + 1] - y[i]) / (x[i + 1] - x[i]));
}


x86 assembly (clang, -O0):
<interpxyd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <indexxd@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    115c <interpxyd+0x4c>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f2 <interpxyd+0xe2>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jl     118c <interpxyd+0x7c>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f2 <interpxyd+0xe2>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x10(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm1
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpxyd>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
movsd  %xmm0,0x8(%rsp)
mov    %rdx,%rsi
call   1030 <indexxd@plt>
test   %rax,%rax
js     1178 <interpxyd+0x68>
lea    -0x1(%rbx),%rcx
cmp    %rcx,%rax
jge    117f <interpxyd+0x6f>
movsd  (%r15,%rax,8),%xmm1
movsd  0x8(%r15,%rax,8),%xmm2
movsd  0x8(%rsp),%xmm4
subsd  %xmm1,%xmm4
movsd  (%r14,%rax,8),%xmm3
movsd  0x8(%r14,%rax,8),%xmm0
subsd  %xmm3,%xmm0
mulsd  %xmm4,%xmm0
subsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
jmp    1186 <interpxyd+0x76>
movsd  (%r14),%xmm0
jmp    1186 <interpxyd+0x76>
movsd  -0x8(%r14,%rbx,8),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @interpxyd(double %0, double* %1, double* %2, i64 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca i64
%10 = alloca i64
store double %0, double* %6
store double* %1, double** %7
store double* %2, double** %8
store i64 %3, i64* %9
%11 = load double, double* %6
%12 = load double*, double** %7
%13 = load i64, i64* %9
%14 = call i64 @indexxd(double %11, double* %12, i64 %13)
store i64 %14, i64* %10
%15 = load i64, i64* %10
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load double*, double** %8
%19 = getelementptr inbounds double, double* %18, i64 0
%20 = load double, double* %19
store double %20, double* %5
br label %66
21: ; preds = %4
%22 = load i64, i64* %10
%23 = load i64, i64* %9
%24 = sub nsw i64 %23, 1
%25 = icmp sge i64 %22, %24
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load double*, double** %8
%28 = load i64, i64* %9
%29 = sub nsw i64 %28, 1
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
store double %31, double* %5
br label %66
32: ; preds = %21
%33 = load double*, double** %8
%34 = load i64, i64* %10
%35 = getelementptr inbounds double, double* %33, i64 %34
%36 = load double, double* %35
%37 = load double, double* %6
%38 = load double*, double** %7
%39 = load i64, i64* %10
%40 = getelementptr inbounds double, double* %38, i64 %39
%41 = load double, double* %40
%42 = fsub double %37, %41
%43 = load double*, double** %8
%44 = load i64, i64* %10
%45 = add nsw i64 %44, 1
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = load double*, double** %8
%49 = load i64, i64* %10
%50 = getelementptr inbounds double, double* %48, i64 %49
%51 = load double, double* %50
%52 = fsub double %47, %51
%53 = fmul double %42, %52
%54 = load double*, double** %7
%55 = load i64, i64* %10
%56 = add nsw i64 %55, 1
%57 = getelementptr inbounds double, double* %54, i64 %56
%58 = load double, double* %57
%59 = load double*, double** %7
%60 = load i64, i64* %10
%61 = getelementptr inbounds double, double* %59, i64 %60
%62 = load double, double* %61
%63 = fsub double %58, %62
%64 = fdiv double %53, %63
%65 = fadd double %36, %64
store double %65, double* %5
br label %66
66: ; preds = %32, %26, %17
%67 = load double, double* %5
ret double %67
}

LLVM IR (-O2):
define double @interpxyd(double %0, double* %1, double* nocapture %2, i64 %3) {
%5 = tail call i64 @indexxd(double %0, double* %1, i64 %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load double, double* %2
br label %31
9: ; preds = %4
%10 = add nsw i64 %3, -1
%11 = icmp slt i64 %5, %10
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = getelementptr inbounds double, double* %2, i64 %10
%14 = load double, double* %13
br label %31
15: ; preds = %9
%16 = getelementptr inbounds double, double* %2, i64 %5
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %1, i64 %5
%19 = load double, double* %18
%20 = fsub double %0, %19
%21 = add nuw nsw i64 %5, 1
%22 = getelementptr inbounds double, double* %2, i64 %21
%23 = load double, double* %22
%24 = fsub double %23, %17
%25 = fmul double %20, %24
%26 = getelementptr inbounds double, double* %1, i64 %21
%27 = load double, double* %26
%28 = fsub double %27, %19
%29 = fdiv double %25, %28
%30 = fadd double %17, %29
br label %31
31: ; preds = %15, %12, %7
%32 = phi double [ %8, %7 ], [ %14, %12 ], [ %30, %15 ]
ret double %32
}