#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 /*<<< orphan*/ DymosimError(char *);
int SearchGrid(double, double const *, int);
void Interpolate1DerS(double *res, double *res_d, double x, const double xval[],
                      int Mxval, int Nxval, const double yval[], int Myval,
                      int Nyval, double dx) {
  int below;
  int Kxval, Kyval;
  *res = 0;
  *res_d = 0;
  if ((Mxval != 1 && Nxval != 1) || (Myval != 1 && Nyval != 1)) {
    DymosimError("Arguments to Interpolate1 must be vectors.");
    return;
  }
  Kxval = Mxval > 1 ? Mxval : Nxval;
  Kyval = Myval > 1 ? Myval : Nyval;
  if (Kxval != Kyval) {
    DymosimError(
        "The x and y vectors must have the same length in Interpolate1.");
    return;
  } else if (x <= xval[0]) {
    *res = (yval[0]);
    *res_d = 0;
  } else if (x >= xval[Kxval - 1]) {
    *res = (yval[Kxval - 1]);
    *res_d = 0;
  } else {
    below = SearchGrid(x, xval, Kxval);
    *res = (yval[below] + (yval[below + 1] - yval[below]) * (x - xval[below]) /
                              (xval[below + 1] - xval[below]));
    *res_d = ((yval[below + 1] - yval[below]) * dx /
              (xval[below + 1] - xval[below]));
  }
}


x86 assembly (clang, -O0):
<Interpolate1DerS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movsd  %xmm1,-0x38(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
cmpl   $0x1,-0x24(%rbp)
je     1179 <Interpolate1DerS+0x59>
cmpl   $0x1,-0x28(%rbp)
jne    118d <Interpolate1DerS+0x6d>
cmpl   $0x1,0x10(%rbp)
je     119e <Interpolate1DerS+0x7e>
cmpl   $0x1,0x18(%rbp)
je     119e <Interpolate1DerS+0x7e>
lea    0xe6c(%rip),%rdi
call   1040 <DymosimError@plt>
jmp    1359 <Interpolate1DerS+0x239>
cmpl   $0x1,-0x24(%rbp)
jle    11b3 <Interpolate1DerS+0x93>
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    11b9 <Interpolate1DerS+0x99>
mov    -0x28(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x1,0x10(%rbp)
jle    11d4 <Interpolate1DerS+0xb4>
mov    0x10(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    11da <Interpolate1DerS+0xba>
mov    0x18(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x44(%rbp),%eax
je     11fd <Interpolate1DerS+0xdd>
lea    0xe38(%rip),%rdi
call   1040 <DymosimError@plt>
jmp    1359 <Interpolate1DerS+0x239>
movsd  -0x18(%rbp),%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jb     1234 <Interpolate1DerS+0x114>
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    1354 <Interpolate1DerS+0x234>
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
ucomisd (%rax,%rcx,8),%xmm0
jb     127b <Interpolate1DerS+0x15b>
mov    -0x30(%rbp),%rax
mov    -0x40(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    134f <Interpolate1DerS+0x22f>
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1030 <SearchGrid@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm1
mov    -0x20(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1354 <Interpolate1DerS+0x234>
jmp    1359 <Interpolate1DerS+0x239>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Interpolate1DerS>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x48(%rsp),%eax
mov    0x40(%rsp),%edx
movq   $0x0,(%rdi)
movq   $0x0,(%rsi)
cmp    $0x1,%ecx
je     1158 <Interpolate1DerS+0x38>
cmp    $0x1,%r8d
jne    1162 <Interpolate1DerS+0x42>
cmp    $0x1,%edx
je     1179 <Interpolate1DerS+0x59>
cmp    $0x1,%eax
je     1179 <Interpolate1DerS+0x59>
lea    0xe97(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <DymosimError@plt>
cmp    $0x2,%ecx
cmovge %ecx,%r8d
cmp    $0x2,%edx
cmovge %edx,%eax
cmp    %eax,%r8d
jne    122f <Interpolate1DerS+0x10f>
movsd  (%r15),%xmm2
ucomisd %xmm0,%xmm2
jae    123b <Interpolate1DerS+0x11b>
movslq %r8d,%rax
ucomisd -0x8(%r15,%rax,8),%xmm0
jae    1242 <Interpolate1DerS+0x122>
mov    %r15,%rdi
mov    %r8d,%esi
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1030 <SearchGrid@plt>
cltq
movsd  (%r14,%rax,8),%xmm0
movsd  0x8(%r14,%rax,8),%xmm1
subsd  %xmm0,%xmm1
movsd  (%r15,%rax,8),%xmm2
movsd  0x8(%r15,%rax,8),%xmm3
movsd  0x8(%rsp),%xmm4
subsd  %xmm2,%xmm4
mulsd  %xmm1,%xmm4
subsd  %xmm2,%xmm3
divsd  %xmm3,%xmm4
addsd  %xmm0,%xmm4
movsd  %xmm4,(%rbx)
movsd  0x8(%r14,%rax,8),%xmm0
subsd  (%r14,%rax,8),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%r15,%rax,8),%xmm1
subsd  (%r15,%rax,8),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r12)
jmp    1258 <Interpolate1DerS+0x138>
lea    0xdf5(%rip),%rdi
jmp    1169 <Interpolate1DerS+0x49>
movsd  (%r14),%xmm0
jmp    124c <Interpolate1DerS+0x12c>
add    $0xffffffffffffffff,%rax
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rbx)
movq   $0x0,(%r12)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Arguments to Interpolate1 must be vectors.\00"
@.str.1 = [63 x i8] c"The x and y vectors must have the same length in Interpolate1.\00"
define void @Interpolate1DerS(double* %0, double* %1, double %2, double* %3, i32 %4, i32 %5, double* %6, i32 %7, i32 %8, double %9) {
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
%17 = alloca double*
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store double* %0, double** %11
store double* %1, double** %12
store double %2, double* %13
store double* %3, double** %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store double* %6, double** %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store double %9, double* %20
%24 = load double*, double** %11
store double 0.000000e+00, double* %24
%25 = load double*, double** %12
store double 0.000000e+00, double* %25
%26 = load i32, i32* %15
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %10
%29 = load i32, i32* %16
%30 = icmp ne i32 %29, 1
br i1 %30, label %37, label %31
31: ; preds = %28, %10
%32 = load i32, i32* %18
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32, i32* %19
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %39
37: ; preds = %34, %28
%38 = call i32 @DymosimError(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %166
39: ; preds = %34, %31
%40 = load i32, i32* %15
%41 = icmp sgt i32 %40, 1
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = load i32, i32* %15
br label %46
44: ; preds = %39
%45 = load i32, i32* %16
br label %46
46: ; preds = %44, %42
%47 = phi i32 [ %43, %42 ], [ %45, %44 ]
store i32 %47, i32* %22
%48 = load i32, i32* %18
%49 = icmp sgt i32 %48, 1
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = load i32, i32* %18
br label %54
52: ; preds = %46
%53 = load i32, i32* %19
br label %54
54: ; preds = %52, %50
%55 = phi i32 [ %51, %50 ], [ %53, %52 ]
store i32 %55, i32* %23
%56 = load i32, i32* %22
%57 = load i32, i32* %23
%58 = icmp ne i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = call i32 @DymosimError(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
br label %166
61: ; preds = %54
%62 = load double, double* %13
%63 = load double*, double** %14
%64 = getelementptr inbounds double, double* %63, i64 0
%65 = load double, double* %64
%66 = fcmp ole double %62, %65
br i1 %66, label %67, label %73
67: ; preds = %61
%68 = load double*, double** %17
%69 = getelementptr inbounds double, double* %68, i64 0
%70 = load double, double* %69
%71 = load double*, double** %11
store double %70, double* %71
%72 = load double*, double** %12
store double 0.000000e+00, double* %72
br label %165
73: ; preds = %61
%74 = load double, double* %13
%75 = load double*, double** %14
%76 = load i32, i32* %22
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %75, i64 %78
%80 = load double, double* %79
%81 = fcmp oge double %74, %80
br i1 %81, label %82, label %91
82: ; preds = %73
%83 = load double*, double** %17
%84 = load i32, i32* %22
%85 = sub nsw i32 %84, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %83, i64 %86
%88 = load double, double* %87
%89 = load double*, double** %11
store double %88, double* %89
%90 = load double*, double** %12
store double 0.000000e+00, double* %90
br label %164
91: ; preds = %73
%92 = load double, double* %13
%93 = load double*, double** %14
%94 = load i32, i32* %22
%95 = call i32 @SearchGrid(double %92, double* %93, i32 %94)
store i32 %95, i32* %21
%96 = load double*, double** %17
%97 = load i32, i32* %21
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
%100 = load double, double* %99
%101 = load double*, double** %17
%102 = load i32, i32* %21
%103 = add nsw i32 %102, 1
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double, double* %101, i64 %104
%106 = load double, double* %105
%107 = load double*, double** %17
%108 = load i32, i32* %21
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
%111 = load double, double* %110
%112 = fsub double %106, %111
%113 = load double, double* %13
%114 = load double*, double** %14
%115 = load i32, i32* %21
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds double, double* %114, i64 %116
%118 = load double, double* %117
%119 = fsub double %113, %118
%120 = fmul double %112, %119
%121 = load double*, double** %14
%122 = load i32, i32* %21
%123 = add nsw i32 %122, 1
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds double, double* %121, i64 %124
%126 = load double, double* %125
%127 = load double*, double** %14
%128 = load i32, i32* %21
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds double, double* %127, i64 %129
%131 = load double, double* %130
%132 = fsub double %126, %131
%133 = fdiv double %120, %132
%134 = fadd double %100, %133
%135 = load double*, double** %11
store double %134, double* %135
%136 = load double*, double** %17
%137 = load i32, i32* %21
%138 = add nsw i32 %137, 1
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds double, double* %136, i64 %139
%141 = load double, double* %140
%142 = load double*, double** %17
%143 = load i32, i32* %21
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds double, double* %142, i64 %144
%146 = load double, double* %145
%147 = fsub double %141, %146
%148 = load double, double* %20
%149 = fmul double %147, %148
%150 = load double*, double** %14
%151 = load i32, i32* %21
%152 = add nsw i32 %151, 1
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds double, double* %150, i64 %153
%155 = load double, double* %154
%156 = load double*, double** %14
%157 = load i32, i32* %21
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds double, double* %156, i64 %158
%160 = load double, double* %159
%161 = fsub double %155, %160
%162 = fdiv double %149, %161
%163 = load double*, double** %12
store double %162, double* %163
br label %164
164: ; preds = %91, %82
br label %165
165: ; preds = %164, %67
br label %166
166: ; preds = %37, %59, %165
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"Arguments to Interpolate1 must be vectors.\00"
@.str.1 = [63 x i8] c"The x and y vectors must have the same length in Interpolate1.\00"
define void @Interpolate1DerS(double* nocapture writeonly %0, double* nocapture writeonly %1, double %2, double* %3, i32 %4, i32 %5, double* nocapture %6, i32 %7, i32 %8, double %9) {
store double 0.000000e+00, double* %0
store double 0.000000e+00, double* %1
%11 = icmp ne i32 %4, 1
%12 = icmp ne i32 %5, 1
%13 = and i1 %11, %12
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = icmp ne i32 %7, 1
%16 = icmp ne i32 %8, 1
%17 = and i1 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14, %10
%19 = tail call i32 @DymosimError(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %69
20: ; preds = %14
%21 = icmp sgt i32 %4, 1
%22 = select i1 %21, i32 %4, i32 %5
%23 = icmp sgt i32 %7, 1
%24 = select i1 %23, i32 %7, i32 %8
%25 = icmp eq i32 %22, %24
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = tail call i32 @DymosimError(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
br label %69
28: ; preds = %20
%29 = load double, double* %3
%30 = fcmp ult double %29, %2
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = load double, double* %6
store double %32, double* %0
store double 0.000000e+00, double* %1
br label %69
33: ; preds = %28
%34 = add nsw i32 %22, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %3, i64 %35
%37 = load double, double* %36
%38 = fcmp ugt double %37, %2
br i1 %38, label %42, label %39
39: ; preds = %33
%40 = getelementptr inbounds double, double* %6, i64 %35
%41 = load double, double* %40
store double %41, double* %0
store double 0.000000e+00, double* %1
br label %69
42: ; preds = %33
%43 = tail call i32 @SearchGrid(double %2, double* %3, i32 %22)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %6, i64 %44
%46 = load double, double* %45
%47 = add nsw i32 %43, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %6, i64 %48
%50 = load double, double* %49
%51 = fsub double %50, %46
%52 = getelementptr inbounds double, double* %3, i64 %44
%53 = load double, double* %52
%54 = fsub double %2, %53
%55 = fmul double %51, %54
%56 = getelementptr inbounds double, double* %3, i64 %48
%57 = load double, double* %56
%58 = fsub double %57, %53
%59 = fdiv double %55, %58
%60 = fadd double %46, %59
store double %60, double* %0
%61 = load double, double* %49
%62 = load double, double* %45
%63 = fsub double %61, %62
%64 = fmul double %63, %9
%65 = load double, double* %56
%66 = load double, double* %52
%67 = fsub double %65, %66
%68 = fdiv double %64, %67
store double %68, double* %1
br label %69
69: ; preds = %39, %42, %31, %26, %18
ret void
}