#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 int64_t;

/* Variables and functions */
scalar_t__ stdlib_base_is_nan(double);
scalar_t__ stdlib_base_is_positive_zero(double);
double stdlib_strided_dmaxsorted(const int64_t N, const double *X,
                                 const int64_t stride) {
  double v1;
  double v2;
  if (N <= 0) {
    return 0.0 / 0.0;
  }
  if (N == 1 || stride == 0) {
    return X[0];
  }
  if (stride < 0) {
    v1 = X[(1 - N) * stride];
    v2 = X[0];
  } else {
    v1 = X[0];
    v2 = X[(N - 1) * stride];
  }
  if (stdlib_base_is_nan(v1) || stdlib_base_is_nan(v2)) {
    return 0.0 / 0.0;
  }
  if (v1 == v2) {
    if (stdlib_base_is_positive_zero(v1) || stdlib_base_is_positive_zero(v2)) {
      return 0.0;
    }
    return v1;
  }
  if (v1 > v2) {
    return v1;
  }
  return v2;
}


x86 assembly (clang, -O0):
<stdlib_strided_dmaxsorted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     114e <stdlib_strided_dmaxsorted+0x2e>
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1292 <stdlib_strided_dmaxsorted+0x172>
cmpl   $0x1,-0xc(%rbp)
je     1162 <stdlib_strided_dmaxsorted+0x42>
cmpl   $0x0,-0x1c(%rbp)
jne    1174 <stdlib_strided_dmaxsorted+0x54>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1292 <stdlib_strided_dmaxsorted+0x172>
cmpl   $0x0,-0x1c(%rbp)
jge    11ad <stdlib_strided_dmaxsorted+0x8d>
mov    -0x18(%rbp),%rax
mov    $0x1,%ecx
sub    -0xc(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11d5 <stdlib_strided_dmaxsorted+0xb5>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <stdlib_base_is_nan@plt>
cmp    $0x0,%rax
jne    11fd <stdlib_strided_dmaxsorted+0xdd>
movsd  -0x30(%rbp),%xmm0
call   1040 <stdlib_base_is_nan@plt>
cmp    $0x0,%rax
je     120f <stdlib_strided_dmaxsorted+0xef>
movsd  0xdfb(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1292 <stdlib_strided_dmaxsorted+0x172>
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jne    1269 <stdlib_strided_dmaxsorted+0x149>
jp     1269 <stdlib_strided_dmaxsorted+0x149>
movsd  -0x28(%rbp),%xmm0
call   1030 <stdlib_base_is_positive_zero@plt>
cmp    $0x0,%rax
jne    124d <stdlib_strided_dmaxsorted+0x12d>
movsd  -0x30(%rbp),%xmm0
call   1030 <stdlib_base_is_positive_zero@plt>
cmp    $0x0,%rax
je     125a <stdlib_strided_dmaxsorted+0x13a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1292 <stdlib_strided_dmaxsorted+0x172>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1292 <stdlib_strided_dmaxsorted+0x172>
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1288 <stdlib_strided_dmaxsorted+0x168>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1292 <stdlib_strided_dmaxsorted+0x172>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdlib_strided_dmaxsorted>:
sub    $0x18,%rsp
movsd  0xed4(%rip),%xmm0
test   %edi,%edi
jle    11a9 <stdlib_strided_dmaxsorted+0x89>
cmp    $0x1,%edi
je     114d <stdlib_strided_dmaxsorted+0x2d>
test   %edx,%edx
je     114d <stdlib_strided_dmaxsorted+0x2d>
js     1156 <stdlib_strided_dmaxsorted+0x36>
add    $0xffffffff,%edi
imul   %edx,%edi
movslq %edi,%rcx
mov    %rsi,%rax
lea    (%rsi,%rcx,8),%rsi
jmp    1166 <stdlib_strided_dmaxsorted+0x46>
movsd  (%rsi),%xmm0
add    $0x18,%rsp
ret
mov    $0x1,%eax
sub    %edi,%eax
imul   %edx,%eax
cltq
lea    (%rsi,%rax,8),%rax
movsd  (%rsi),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rax),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <stdlib_base_is_nan@plt>
test   %rax,%rax
je     1191 <stdlib_strided_dmaxsorted+0x71>
movsd  0xe74(%rip),%xmm0
add    $0x18,%rsp
ret
movsd  0x8(%rsp),%xmm0
call   1040 <stdlib_base_is_nan@plt>
test   %rax,%rax
movsd  0xe59(%rip),%xmm0
je     11ae <stdlib_strided_dmaxsorted+0x8e>
add    $0x18,%rsp
ret
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jne    11ef <stdlib_strided_dmaxsorted+0xcf>
jp     11ef <stdlib_strided_dmaxsorted+0xcf>
call   1030 <stdlib_base_is_positive_zero@plt>
xorpd  %xmm0,%xmm0
test   %rax,%rax
jne    11a9 <stdlib_strided_dmaxsorted+0x89>
movsd  0x8(%rsp),%xmm0
call   1030 <stdlib_base_is_positive_zero@plt>
test   %rax,%rax
movsd  0x10(%rsp),%xmm0
je     11a9 <stdlib_strided_dmaxsorted+0x89>
xorpd  %xmm0,%xmm0
add    $0x18,%rsp
ret
maxsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

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

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