#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);
double ComputeNorm(double *x, long n) {
  double tmp = 0.0;
  long i;
  for (i = 0; i < n; i++)
    if (fabs(x[i] - 1.0) > tmp)
      tmp = fabs(x[i] - 1.0);
  return (tmp);
}


x86 assembly (clang, -O0):
<ComputeNorm>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1198 <ComputeNorm+0x98>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xed1(%rip),%xmm1
subsd  %xmm1,%xmm0
movaps 0xeb6(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1182 <ComputeNorm+0x82>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xea2(%rip),%xmm1
subsd  %xmm1,%xmm0
movaps 0xe87(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1187 <ComputeNorm+0x87>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    111c <ComputeNorm+0x1c>
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<ComputeNorm>:
test   %rsi,%rsi
jle    1113 <ComputeNorm+0x13>
cmp    $0x1,%rsi
jne    1117 <ComputeNorm+0x17>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
jmp    116c <ComputeNorm+0x6c>
xorps  %xmm0,%xmm0
ret
mov    %rsi,%rcx
and    $0xfffffffffffffffe,%rcx
xorpd  %xmm0,%xmm0
xor    %eax,%eax
movsd  0xed4(%rip),%xmm1
movapd 0xedc(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rdi,%rax,8),%xmm3
addsd  %xmm1,%xmm3
andpd  %xmm2,%xmm3
maxsd  %xmm0,%xmm3
movsd  0x8(%rdi,%rax,8),%xmm0
addsd  %xmm1,%xmm0
andpd  %xmm2,%xmm0
maxsd  %xmm3,%xmm0
add    $0x2,%rax
cmp    %rax,%rcx
jne    1140 <ComputeNorm+0x40>
test   $0x1,%sil
je     118f <ComputeNorm+0x8f>
movsd  (%rdi,%rax,8),%xmm1
addsd  0xe81(%rip),%xmm1
andpd  0xe89(%rip),%xmm1
maxsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
ret

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

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