#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*/ printf(char *);
double max_velocity(double *v, long n) {
  long i;
  double x1;
  double max, min;
  max = -1.E15;
  min = 1.E15;
  for (i = 0; i < n; i++) {
    x1 = v[i * 2] - v[i * 2 + 1];
    if (x1 > max) {
      max = x1;
    }
    if (x1 < min) {
      min = x1;
    }
    x1 = v[i * 2] + v[i * 2 + 1];
    if (x1 > max) {
      max = x1;
    }
    if (x1 < min) {
      min = x1;
    }
  }
  if (min <= 0.0) {
    printf("Negative velocities are not supported.\n");
    printf("Write an issue on:\n");
    printf("https://github.com/B0RJA/legendre-1D\n");
    return (0.0);
  }
  return (max);
}


x86 assembly (clang, -O0):
<max_velocity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  0xee0(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1226 <max_velocity+0x116>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
subsd  0x8(%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1192 <max_velocity+0x82>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b0 <max_velocity+0xa0>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
addsd  0x8(%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11f2 <max_velocity+0xe2>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1210 <max_velocity+0x100>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1215 <max_velocity+0x105>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1142 <max_velocity+0x32>
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     1265 <max_velocity+0x155>
lea    0xdd5(%rip),%rdi
call   1030 <printf@plt>
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
lea    0xdf9(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    126f <max_velocity+0x15f>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<max_velocity>:
push   %rax
test   %rsi,%rsi
jle    119f <max_velocity+0x8f>
add    $0x8,%rdi
movsd  0xeda(%rip),%xmm0
movsd  0xeda(%rip),%xmm1
xchg   %ax,%ax
movsd  -0x8(%rdi),%xmm2
movsd  (%rdi),%xmm3
movapd %xmm2,%xmm4
subsd  %xmm3,%xmm4
movapd %xmm4,%xmm5
maxsd  %xmm0,%xmm5
minsd  %xmm1,%xmm4
addsd  %xmm3,%xmm2
movapd %xmm2,%xmm0
maxsd  %xmm5,%xmm0
movapd %xmm2,%xmm1
minsd  %xmm4,%xmm1
add    $0x10,%rdi
add    $0xffffffffffffffff,%rsi
jne    1130 <max_velocity+0x20>
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
jb     119d <max_velocity+0x8d>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm0,%xmm0
pop    %rax
ret
movsd  0xe59(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Negative velocities are not supported.\0A\00"
@.str.1 = [20 x i8] c"Write an issue on:\0A\00"
@.str.2 = [38 x i8] c"https://github.com/B0RJA/legendre-1D\0A\00"
define double @max_velocity(double* %0, i64 %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store i64 %1, i64* %5
store double -1.000000e+15, double* %8
store double 1.000000e+15, double* %9
store i64 0, i64* %6
br label %10
10: ; preds = %63, %2
%11 = load i64, i64* %6
%12 = load i64, i64* %5
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %66
14: ; preds = %10
%15 = load double*, double** %4
%16 = load i64, i64* %6
%17 = mul nsw i64 %16, 2
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = load double*, double** %4
%21 = load i64, i64* %6
%22 = mul nsw i64 %21, 2
%23 = add nsw i64 %22, 1
%24 = getelementptr inbounds double, double* %20, i64 %23
%25 = load double, double* %24
%26 = fsub double %19, %25
store double %26, double* %7
%27 = load double, double* %7
%28 = load double, double* %8
%29 = fcmp ogt double %27, %28
br i1 %29, label %30, label %32
30: ; preds = %14
%31 = load double, double* %7
store double %31, double* %8
br label %32
32: ; preds = %30, %14
%33 = load double, double* %7
%34 = load double, double* %9
%35 = fcmp olt double %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load double, double* %7
store double %37, double* %9
br label %38
38: ; preds = %36, %32
%39 = load double*, double** %4
%40 = load i64, i64* %6
%41 = mul nsw i64 %40, 2
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = load double*, double** %4
%45 = load i64, i64* %6
%46 = mul nsw i64 %45, 2
%47 = add nsw i64 %46, 1
%48 = getelementptr inbounds double, double* %44, i64 %47
%49 = load double, double* %48
%50 = fadd double %43, %49
store double %50, double* %7
%51 = load double, double* %7
%52 = load double, double* %8
%53 = fcmp ogt double %51, %52
br i1 %53, label %54, label %56
54: ; preds = %38
%55 = load double, double* %7
store double %55, double* %8
br label %56
56: ; preds = %54, %38
%57 = load double, double* %7
%58 = load double, double* %9
%59 = fcmp olt double %57, %58
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = load double, double* %7
store double %61, double* %9
br label %62
62: ; preds = %60, %56
br label %63
63: ; preds = %62
%64 = load i64, i64* %6
%65 = add nsw i64 %64, 1
store i64 %65, i64* %6
br label %10
66: ; preds = %10
%67 = load double, double* %9
%68 = fcmp ole double %67, 0.000000e+00
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%71 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%72 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store double 0.000000e+00, double* %3
br label %75
73: ; preds = %66
%74 = load double, double* %8
store double %74, double* %3
br label %75
75: ; preds = %73, %69
%76 = load double, double* %3
ret double %76
}

LLVM IR (-O2):
@str = [39 x i8] c"Negative velocities are not supported.\00"
@str.3 = [19 x i8] c"Write an issue on:\00"
@str.4 = [37 x i8] c"https://github.com/B0RJA/legendre-1D\00"
define double @max_velocity(double* nocapture %0, i64 %1) {
%3 = icmp sgt i64 %1, 0
br i1 %3, label %4, label %32
4: ; preds = %2, %4
%5 = phi double [ %23, %4 ], [ 1.000000e+15, %2 ]
%6 = phi double [ %21, %4 ], [ -1.000000e+15, %2 ]
%7 = phi i64 [ %24, %4 ], [ 0, %2 ]
%8 = shl nuw nsw i64 %7, 1
%9 = getelementptr inbounds double, double* %0, i64 %8
%10 = load double, double* %9
%11 = or i64 %8, 1
%12 = getelementptr inbounds double, double* %0, i64 %11
%13 = load double, double* %12
%14 = fsub double %10, %13
%15 = fcmp ogt double %14, %6
%16 = select i1 %15, double %14, double %6
%17 = fcmp olt double %14, %5
%18 = select i1 %17, double %14, double %5
%19 = fadd double %10, %13
%20 = fcmp ogt double %19, %16
%21 = select i1 %20, double %19, double %16
%22 = fcmp olt double %19, %18
%23 = select i1 %22, double %19, double %18
%24 = add nuw nsw i64 %7, 1
%25 = icmp eq i64 %24, %1
br i1 %25, label %26, label %4
26: ; preds = %4
%27 = fcmp ugt double %23, 0.000000e+00
br i1 %27, label %32, label %28
28: ; preds = %26
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.4, i64 0, i64 0))
br label %32
32: ; preds = %2, %26, %28
%33 = phi double [ 0.000000e+00, %28 ], [ %21, %26 ], [ -1.000000e+15, %2 ]
ret double %33
}