#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 gsw_indx(double *, int, double);
double gsw_xinterp1(double *x, double *y, int n, double x0) {
  int k;
  double r;
  k = gsw_indx(x, n, x0);
  r = (x0 - x[k]) / (x[k + 1] - x[k]);
  return (y[k] + r * (y[k + 1] - y[k]));
}


x86 assembly (clang, -O0):
<gsw_xinterp1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
call   1030 <gsw_indx@plt>
mov    %eax,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsw_xinterp1>:
push   %r14
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%esi
call   1030 <gsw_indx@plt>
cltq
movsd  (%rbx,%rax,8),%xmm0
movsd  0x8(%rbx,%rax,8),%xmm1
movsd  (%rsp),%xmm2
subsd  %xmm0,%xmm2
subsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
movsd  (%r14,%rax,8),%xmm1
movsd  0x8(%r14,%rax,8),%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @gsw_xinterp1(double* %0, double* %1, i32 %2, double %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store double %3, double* %8
%11 = load double*, double** %5
%12 = load i32, i32* %7
%13 = load double, double* %8
%14 = call i32 @gsw_indx(double* %11, i32 %12, double %13)
store i32 %14, i32* %9
%15 = load double, double* %8
%16 = load double*, double** %5
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = fsub double %15, %20
%22 = load double*, double** %5
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %22, i64 %25
%27 = load double, double* %26
%28 = load double*, double** %5
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = fsub double %27, %32
%34 = fdiv double %21, %33
store double %34, double* %10
%35 = load double*, double** %6
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load double, double* %10
%41 = load double*, double** %6
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %41, i64 %44
%46 = load double, double* %45
%47 = load double*, double** %6
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = fsub double %46, %51
%53 = call double @llvm.fmuladd.f64(double %40, double %52, double %39)
ret double %53
}

LLVM IR (-O2):
define double @gsw_xinterp1(double* %0, double* nocapture %1, i32 %2, double %3) {
%5 = tail call i32 @gsw_indx(double* %0, i32 %2, double %3)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds double, double* %0, i64 %6
%8 = load double, double* %7
%9 = fsub double %3, %8
%10 = add nsw i32 %5, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds double, double* %0, i64 %11
%13 = load double, double* %12
%14 = fsub double %13, %8
%15 = fdiv double %9, %14
%16 = getelementptr inbounds double, double* %1, i64 %6
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %1, i64 %11
%19 = load double, double* %18
%20 = fsub double %19, %17
%21 = tail call double @llvm.fmuladd.f64(double %15, double %20, double %17)
ret double %21
}