#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double);
int /*<<< orphan*/ stderr;
void trav_time(double d, double *tv, double *dv, int nd, double *P_tt,
               int *ierror) {
  int i, flag = 1;
  for (i = 0; i < nd; i++) {
    if ((d >= dv[i]) && (d <= dv[i + 1])) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    if (*ierror == 1) {
      fprintf(stderr, "Error: distance: %f out of range\n", d);
      exit(1);
    }
    fprintf(stderr, "WARNING : distance: %f out of range; extrapolating ... \n",
            d);
    i--;
  }
  *P_tt = tv[i] + (tv[i + 1] - tv[i]) * (d - dv[i]) / (dv[i + 1] - dv[i]);
}


x86 assembly (clang, -O0):
<trav_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x1,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b2 <trav_time+0x92>
movsd  -0x8(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jb     119f <trav_time+0x7f>
movsd  -0x8(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     119f <trav_time+0x7f>
movl   $0x0,-0x38(%rbp)
jmp    11b2 <trav_time+0x92>
jmp    11a4 <trav_time+0x84>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    114e <trav_time+0x2e>
cmpl   $0x0,-0x38(%rbp)
je     1210 <trav_time+0xf0>
mov    -0x30(%rbp),%rax
cmpl   $0x1,(%rax)
jne    11ed <trav_time+0xcd>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
movsd  -0x8(%rbp),%xmm0
lea    0xe22(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
movsd  -0x8(%rbp),%xmm0
lea    0xe20(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
movsd  -0x8(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm1
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trav_time>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
test   %edx,%edx
jle    1165 <trav_time+0x45>
mov    %edx,%ebp
mov    %edx,%ecx
xor    %eax,%eax
jmp    1149 <trav_time+0x29>
nopl   0x0(%rax)
add    $0x1,%rax
cmp    %rax,%rcx
je     1160 <trav_time+0x40>
ucomisd (%rbx,%rax,8),%xmm0
jb     1140 <trav_time+0x20>
movsd  0x8(%rbx,%rax,8),%xmm1
ucomisd %xmm0,%xmm1
jb     1140 <trav_time+0x20>
mov    %eax,%ebp
jmp    118f <trav_time+0x6f>
add    $0xffffffff,%ebp
jmp    116a <trav_time+0x4a>
mov    $0xffffffff,%ebp
cmpl   $0x1,(%r8)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
je     11d2 <trav_time+0xb2>
lea    0xea2(%rip),%rsi
movsd  %xmm0,(%rsp)
call   1030 <fprintf@plt>
movsd  (%rsp),%xmm0
movslq %ebp,%rax
movsd  (%r15,%rax,8),%xmm4
movsd  0x8(%r15,%rax,8),%xmm1
subsd  %xmm4,%xmm1
movsd  (%rbx,%rax,8),%xmm2
movsd  0x8(%rbx,%rax,8),%xmm3
subsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
subsd  %xmm2,%xmm3
divsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe27(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Error: distance: %f out of range\0A\00"
@.str.1 = [57 x i8] c"WARNING : distance: %f out of range; extrapolating ... \0A\00"
define void @trav_time(double %0, double* %1, double* %2, i32 %3, double* %4, i32* %5) {
%7 = alloca double
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca double*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store double %0, double* %7
store double* %1, double** %8
store double* %2, double** %9
store i32 %3, i32* %10
store double* %4, double** %11
store i32* %5, i32** %12
store i32 1, i32* %14
store i32 0, i32* %13
br label %15
15: ; preds = %38, %6
%16 = load i32, i32* %13
%17 = load i32, i32* %10
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %41
19: ; preds = %15
%20 = load double, double* %7
%21 = load double*, double** %9
%22 = load i32, i32* %13
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = fcmp oge double %20, %25
br i1 %26, label %27, label %37
27: ; preds = %19
%28 = load double, double* %7
%29 = load double*, double** %9
%30 = load i32, i32* %13
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %29, i64 %32
%34 = load double, double* %33
%35 = fcmp ole double %28, %34
br i1 %35, label %36, label %37
36: ; preds = %27
store i32 0, i32* %14
br label %41
37: ; preds = %27, %19
br label %38
38: ; preds = %37
%39 = load i32, i32* %13
%40 = add nsw i32 %39, 1
store i32 %40, i32* %13
br label %15
41: ; preds = %36, %15
%42 = load i32, i32* %14
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %59
44: ; preds = %41
%45 = load i32*, i32** %12
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = load double, double* %7
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), double %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %44
%54 = load i32, i32* @stderr
%55 = load double, double* %7
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), double %55)
%57 = load i32, i32* %13
%58 = add nsw i32 %57, -1
store i32 %58, i32* %13
br label %59
59: ; preds = %53, %41
%60 = load double*, double** %8
%61 = load i32, i32* %13
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = load double*, double** %8
%66 = load i32, i32* %13
%67 = add nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %65, i64 %68
%70 = load double, double* %69
%71 = load double*, double** %8
%72 = load i32, i32* %13
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
%75 = load double, double* %74
%76 = fsub double %70, %75
%77 = load double, double* %7
%78 = load double*, double** %9
%79 = load i32, i32* %13
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double, double* %78, i64 %80
%82 = load double, double* %81
%83 = fsub double %77, %82
%84 = fmul double %76, %83
%85 = load double*, double** %9
%86 = load i32, i32* %13
%87 = add nsw i32 %86, 1
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %85, i64 %88
%90 = load double, double* %89
%91 = load double*, double** %9
%92 = load i32, i32* %13
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds double, double* %91, i64 %93
%95 = load double, double* %94
%96 = fsub double %90, %95
%97 = fdiv double %84, %96
%98 = fadd double %64, %97
%99 = load double*, double** %11
store double %98, double* %99
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Error: distance: %f out of range\0A\00"
@.str.1 = [57 x i8] c"WARNING : distance: %f out of range; extrapolating ... \0A\00"
define void @trav_time(double %0, double* nocapture %1, double* nocapture %2, i32 %3, double* nocapture writeonly %4, i32* nocapture %5) {
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %24
8: ; preds = %6
%9 = zext i32 %3 to i64
br label %10
10: ; preds = %8, %20
%11 = phi i64 [ 0, %8 ], [ %15, %20 ]
%12 = getelementptr inbounds double, double* %2, i64 %11
%13 = load double, double* %12
%14 = fcmp ugt double %13, %0
%15 = add nuw nsw i64 %11, 1
br i1 %14, label %20, label %16
16: ; preds = %10
%17 = getelementptr inbounds double, double* %2, i64 %15
%18 = load double, double* %17
%19 = fcmp ult double %18, %0
br i1 %19, label %20, label %34
20: ; preds = %10, %16
%21 = icmp eq i64 %15, %9
br i1 %21, label %22, label %10
22: ; preds = %20
%23 = add i32 %3, -1
br label %24
24: ; preds = %22, %6
%25 = phi i32 [ -1, %6 ], [ %23, %22 ]
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 1
%28 = load i32, i32* @stderr
br i1 %27, label %29, label %32
29: ; preds = %24
%30 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), double %0)
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %24
%33 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), double %0)
br label %36
34: ; preds = %16
%35 = trunc i64 %11 to i32
br label %36
36: ; preds = %34, %32
%37 = phi i32 [ %25, %32 ], [ %35, %34 ]
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %1, i64 %38
%40 = load double, double* %39
%41 = add nsw i32 %37, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %1, i64 %42
%44 = load double, double* %43
%45 = fsub double %44, %40
%46 = getelementptr inbounds double, double* %2, i64 %38
%47 = load double, double* %46
%48 = fsub double %0, %47
%49 = fmul double %45, %48
%50 = getelementptr inbounds double, double* %2, i64 %42
%51 = load double, double* %50
%52 = fsub double %51, %47
%53 = fdiv double %49, %52
%54 = fadd double %40, %53
store double %54, double* %4
ret void
}