#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 */
typedef int int32_t;

/* Variables and functions */
int UniformInterp1Index(float, int, float *);
int /*<<< orphan*/ assert(int);
float UniformInterp1(const float y[], int32_t n, float xi) {
  assert(y != NULL);
  assert(n >= 2);
  float frac;
  int32_t index = UniformInterp1Index(xi, n, &frac);
  return y[index] + frac * (y[index + 1] - y[index]);
}


x86 assembly (clang, -O0):
<UniformInterp1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movss  %xmm0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x2,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movss  -0x10(%rbp),%xmm0
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <UniformInterp1Index@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
movss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
subss  (%rax,%rcx,4),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UniformInterp1>:
push   %rbp
push   %rbx
push   %rax
movss  %xmm0,(%rsp)
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x2,%ebp
setge  %dil
call   1030 <assert@plt>
lea    0x4(%rsp),%rsi
movss  (%rsp),%xmm0
mov    %ebp,%edi
call   1040 <UniformInterp1Index@plt>
cltq
movss  (%rbx,%rax,4),%xmm1
movss  0x4(%rbx,%rax,4),%xmm0
subss  %xmm1,%xmm0
mulss  0x4(%rsp),%xmm0
addss  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define float @UniformInterp1(float* %0, i32 %1, float %2) {
%4 = alloca float*
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca i32
store float* %0, float** %4
store i32 %1, i32* %5
store float %2, float* %6
%9 = load float*, float** %4
%10 = icmp ne float* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 2
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load float, float* %6
%18 = load i32, i32* %5
%19 = call i32 @UniformInterp1Index(float %17, i32 %18, float* %7)
store i32 %19, i32* %8
%20 = load float*, float** %4
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds float, float* %20, i64 %22
%24 = load float, float* %23
%25 = load float, float* %7
%26 = load float*, float** %4
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds float, float* %26, i64 %29
%31 = load float, float* %30
%32 = load float*, float** %4
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds float, float* %32, i64 %34
%36 = load float, float* %35
%37 = fsub float %31, %36
%38 = call float @llvm.fmuladd.f32(float %25, float %37, float %24)
ret float %38
}

LLVM IR (-O2):
define float @UniformInterp1(float* %0, i32 %1, float %2) {
%4 = alloca float
%5 = icmp ne float* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp sgt i32 %1, 1
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = bitcast float* %4 to i8*
%12 = call i32 @UniformInterp1Index(float %2, i32 %1, float* %4)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds float, float* %0, i64 %13
%15 = load float, float* %14
%16 = load float, float* %4
%17 = add nsw i32 %12, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds float, float* %0, i64 %18
%20 = load float, float* %19
%21 = fsub float %20, %15
%22 = call float @llvm.fmuladd.f32(float %16, float %21, float %15)
ret float %22
}