#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 */
scalar_t__ fabs(double);
double interpolate_stepwise_nearest(int tCount, double *tValues,
                                    double *yValues, double t) {
  int i, prevI = 0, nextI = 0;
  double prevT = tValues[0], nextT = 0;
  if (tCount == 1) {
    return yValues[0];
  }
  for (i = 1; i < tCount; i++) {
    nextI = i;
    nextT = tValues[i];
    if (t >= prevT && t <= nextT)
      break;
    prevT = nextT;
    prevI = nextI;
  }
  if (fabs(t - nextT) < fabs(t - prevT)) {
    return yValues[nextI];
  } else {
    return yValues[prevI];
  }
}


x86 assembly (clang, -O0):
<interpolate_stepwise_nearest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1167 <interpolate_stepwise_nearest+0x57>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1234 <interpolate_stepwise_nearest+0x124>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d9 <interpolate_stepwise_nearest+0xc9>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     11bb <interpolate_stepwise_nearest+0xab>
movsd  -0x28(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11bb <interpolate_stepwise_nearest+0xab>
jmp    11d9 <interpolate_stepwise_nearest+0xc9>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116e <interpolate_stepwise_nearest+0x5e>
movsd  -0x28(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jge    1222 <interpolate_stepwise_nearest+0x112>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1234 <interpolate_stepwise_nearest+0x124>
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpolate_stepwise_nearest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
cmp    $0x1,%edi
je     11d8 <interpolate_stepwise_nearest+0xc8>
mov    %edi,%ebp
movsd  (%rsi),%xmm2
xorpd  %xmm1,%xmm1
xor    %ebx,%ebx
cmp    $0x2,%edi
jl     1155 <interpolate_stepwise_nearest+0x45>
movsd  0x8(%rsi),%xmm1
ucomisd %xmm2,%xmm0
jb     115f <interpolate_stepwise_nearest+0x4f>
ucomisd %xmm0,%xmm1
jb     115f <interpolate_stepwise_nearest+0x4f>
movsd  %xmm2,0x8(%rsp)
mov    $0x1,%ebp
jmp    11a6 <interpolate_stepwise_nearest+0x96>
movsd  %xmm2,0x8(%rsp)
xor    %ebp,%ebp
jmp    11a6 <interpolate_stepwise_nearest+0x96>
mov    %ebp,%eax
add    $0xffffffff,%ebp
add    $0xfffffffffffffffe,%rax
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movapd %xmm1,%xmm2
cmp    %rbx,%rax
je     119a <interpolate_stepwise_nearest+0x8a>
movsd  0x10(%rsi,%rbx,8),%xmm1
add    $0x1,%rbx
ucomisd %xmm2,%xmm0
jb     1170 <interpolate_stepwise_nearest+0x60>
ucomisd %xmm0,%xmm1
jb     1170 <interpolate_stepwise_nearest+0x60>
movsd  %xmm2,0x8(%rsp)
lea    0x1(%rbx),%ebp
jmp    11a6 <interpolate_stepwise_nearest+0x96>
mov    %ebp,%ebx
movsd  %xmm2,0x8(%rsp)
movapd %xmm2,%xmm1
movsd  %xmm0,0x10(%rsp)
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %rax,%r15
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%r15
jge    11d2 <interpolate_stepwise_nearest+0xc2>
mov    %ebp,%eax
jmp    11d4 <interpolate_stepwise_nearest+0xc4>
mov    %ebx,%eax
lea    (%r14,%rax,8),%r14
movsd  (%r14),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @interpolate_stepwise_nearest(i32 %0, double* %1, double* %2, double %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32 %0, i32* %6
store double* %1, double** %7
store double* %2, double** %8
store double %3, double* %9
store i32 0, i32* %11
store i32 0, i32* %12
%15 = load double*, double** %7
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
store double %17, double* %13
store double 0.000000e+00, double* %14
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %4
%21 = load double*, double** %8
%22 = getelementptr inbounds double, double* %21, i64 0
%23 = load double, double* %22
store double %23, double* %5
br label %72
24: ; preds = %4
store i32 1, i32* %10
br label %25
25: ; preds = %47, %24
%26 = load i32, i32* %10
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %50
29: ; preds = %25
%30 = load i32, i32* %10
store i32 %30, i32* %12
%31 = load double*, double** %7
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
store double %35, double* %14
%36 = load double, double* %9
%37 = load double, double* %13
%38 = fcmp oge double %36, %37
br i1 %38, label %39, label %44
39: ; preds = %29
%40 = load double, double* %9
%41 = load double, double* %14
%42 = fcmp ole double %40, %41
br i1 %42, label %43, label %44
43: ; preds = %39
br label %50
44: ; preds = %39, %29
%45 = load double, double* %14
store double %45, double* %13
%46 = load i32, i32* %12
store i32 %46, i32* %11
br label %47
47: ; preds = %44
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
br label %25
50: ; preds = %43, %25
%51 = load double, double* %9
%52 = load double, double* %14
%53 = fsub double %51, %52
%54 = call i64 @fabs(double %53)
%55 = load double, double* %9
%56 = load double, double* %13
%57 = fsub double %55, %56
%58 = call i64 @fabs(double %57)
%59 = icmp slt i64 %54, %58
br i1 %59, label %60, label %66
60: ; preds = %50
%61 = load double*, double** %8
%62 = load i32, i32* %12
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
store double %65, double* %5
br label %72
66: ; preds = %50
%67 = load double*, double** %8
%68 = load i32, i32* %11
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
%71 = load double, double* %70
store double %71, double* %5
br label %72
72: ; preds = %66, %60, %20
%73 = load double, double* %5
ret double %73
}

LLVM IR (-O2):
define double @interpolate_stepwise_nearest(i32 %0, double* nocapture %1, double* nocapture %2, double %3) {
%5 = icmp eq i32 %0, 1
br i1 %5, label %47, label %6
6: ; preds = %4
%7 = load double, double* %1
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %31
9: ; preds = %6
%10 = add nsw i32 %0, -1
%11 = zext i32 %0 to i64
%12 = getelementptr inbounds double, double* %1, i64 1
%13 = load double, double* %12
%14 = fcmp ugt double %7, %3
%15 = fcmp ult double %13, %3
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %23, label %31
17: ; preds = %23
%18 = getelementptr inbounds double, double* %1, i64 %26
%19 = load double, double* %18
%20 = fcmp ugt double %24, %3
%21 = fcmp ult double %19, %3
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %23, label %28
23: ; preds = %9, %17
%24 = phi double [ %19, %17 ], [ %13, %9 ]
%25 = phi i64 [ %26, %17 ], [ 1, %9 ]
%26 = add nuw nsw i64 %25, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %31, label %17
28: ; preds = %17
%29 = trunc i64 %25 to i32
%30 = trunc i64 %26 to i32
br label %31
31: ; preds = %23, %9, %28, %6
%32 = phi i32 [ 0, %6 ], [ %29, %28 ], [ 0, %9 ], [ %10, %23 ]
%33 = phi double [ %7, %6 ], [ %24, %28 ], [ %7, %9 ], [ %24, %23 ]
%34 = phi i32 [ 0, %6 ], [ %30, %28 ], [ 1, %9 ], [ %10, %23 ]
%35 = phi double [ 0.000000e+00, %6 ], [ %19, %28 ], [ %13, %9 ], [ %24, %23 ]
%36 = fsub double %3, %35
%37 = tail call i64 @fabs(double %36)
%38 = fsub double %3, %33
%39 = tail call i64 @fabs(double %38)
%40 = icmp slt i64 %37, %39
br i1 %40, label %41, label %44
41: ; preds = %31
%42 = zext i32 %34 to i64
%43 = getelementptr inbounds double, double* %2, i64 %42
br label %47
44: ; preds = %31
%45 = zext i32 %32 to i64
%46 = getelementptr inbounds double, double* %2, i64 %45
br label %47
47: ; preds = %4, %44, %41
%48 = phi double* [ %43, %41 ], [ %46, %44 ], [ %2, %4 ]
%49 = load double, double* %48
ret double %49
}