#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 */
double fabs(double const);
double chebyshev_distance(const double *u, const double *v, int n) {
  int i = 0;
  double d, maxv = 0.0;
  for (i = 0; i < n; i++) {
    d = fabs(u[i] - v[i]);
    if (d > maxv) {
      maxv = d;
    }
  }
  return maxv;
}


x86 assembly (clang, -O0):
<chebyshev_distance>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1188 <chebyshev_distance+0x88>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xeae(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1175 <chebyshev_distance+0x75>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    117a <chebyshev_distance+0x7a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1125 <chebyshev_distance+0x25>
movsd  -0x28(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<chebyshev_distance>:
test   %edx,%edx
jle    1113 <chebyshev_distance+0x13>
mov    %edx,%eax
cmp    $0x1,%edx
jne    1117 <chebyshev_distance+0x17>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    1163 <chebyshev_distance+0x63>
xorps  %xmm0,%xmm0
ret
mov    %eax,%edx
and    $0xfffffffe,%edx
xorpd  %xmm2,%xmm2
xor    %ecx,%ecx
movapd 0xed6(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
movsd  (%rdi,%rcx,8),%xmm3
movsd  0x8(%rdi,%rcx,8),%xmm0
subsd  (%rsi,%rcx,8),%xmm3
andpd  %xmm1,%xmm3
maxsd  %xmm2,%xmm3
subsd  0x8(%rsi,%rcx,8),%xmm0
andpd  %xmm1,%xmm0
maxsd  %xmm3,%xmm0
add    $0x2,%rcx
movapd %xmm0,%xmm2
cmp    %rcx,%rdx
jne    1130 <chebyshev_distance+0x30>
test   $0x1,%al
je     1181 <chebyshev_distance+0x81>
movsd  (%rdi,%rcx,8),%xmm1
subsd  (%rsi,%rcx,8),%xmm1
andpd  0xe87(%rip),%xmm1
maxsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @chebyshev_distance(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store double 0.000000e+00, double* %9
store i32 0, i32* %7
br label %10
10: ; preds = %33, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load double*, double** %4
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = load double*, double** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = fsub double %19, %24
%26 = call double @llvm.fabs.f64(double %25)
store double %26, double* %8
%27 = load double, double* %8
%28 = load double, double* %9
%29 = fcmp ogt double %27, %28
br i1 %29, label %30, label %32
30: ; preds = %14
%31 = load double, double* %8
store double %31, double* %9
br label %32
32: ; preds = %30, %14
br label %33
33: ; preds = %32
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %10
36: ; preds = %10
%37 = load double, double* %9
ret double %37
}

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