#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 relative_error(const int n, const double *const a,
                      const double *const b) {
  double sum;
  double d;
  double max = 0.0;
  int i;
  for (i = 0; i < n; i++) {
    sum = 0.5 * (a[i] + b[i]);
    if (sum > 0) {
      d = fabs((a[i] - b[i]) / sum);
      if (d > max)
        max = d;
    }
  }
  return max;
}


x86 assembly (clang, -O0):
<relative_error>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c8 <relative_error+0xc8>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm1
movsd  0xeb4(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11b5 <relative_error+0xb5>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
divsd  -0x20(%rbp),%xmm0
movaps 0xe83(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11b0 <relative_error+0xb0>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11b5 <relative_error+0xb5>
jmp    11ba <relative_error+0xba>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    111e <relative_error+0x1e>
movsd  -0x30(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<relative_error>:
test   %edi,%edi
jle    116e <relative_error+0x6e>
mov    %edi,%eax
xorpd  %xmm1,%xmm1
xor    %ecx,%ecx
movsd  0xeec(%rip),%xmm2
movapd 0xef4(%rip),%xmm3
xorpd  %xmm0,%xmm0
jmp    1139 <relative_error+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rcx
cmp    %rcx,%rax
je     116d <relative_error+0x6d>
movsd  (%rsi,%rcx,8),%xmm4
movsd  (%rdx,%rcx,8),%xmm6
movapd %xmm4,%xmm5
addsd  %xmm6,%xmm5
mulsd  %xmm2,%xmm5
ucomisd %xmm1,%xmm5
jbe    1130 <relative_error+0x30>
subsd  %xmm6,%xmm4
divsd  %xmm5,%xmm4
andpd  %xmm3,%xmm4
ucomisd %xmm0,%xmm4
jbe    1130 <relative_error+0x30>
movapd %xmm4,%xmm0
jmp    1130 <relative_error+0x30>
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @relative_error(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
store double 0.000000e+00, double* %9
store i32 0, i32* %10
br label %11
11: ; preds = %52, %3
%12 = load i32, i32* %10
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %55
15: ; preds = %11
%16 = load double*, double** %5
%17 = load i32, i32* %10
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = load double*, double** %6
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = fadd double %20, %25
%27 = fmul double 5.000000e-01, %26
store double %27, double* %7
%28 = load double, double* %7
%29 = fcmp ogt double %28, 0.000000e+00
br i1 %29, label %30, label %51
30: ; preds = %15
%31 = load double*, double** %5
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = load double*, double** %6
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = fsub double %35, %40
%42 = load double, double* %7
%43 = fdiv double %41, %42
%44 = call double @llvm.fabs.f64(double %43)
store double %44, double* %8
%45 = load double, double* %8
%46 = load double, double* %9
%47 = fcmp ogt double %45, %46
br i1 %47, label %48, label %50
48: ; preds = %30
%49 = load double, double* %8
store double %49, double* %9
br label %50
50: ; preds = %48, %30
br label %51
51: ; preds = %50, %15
br label %52
52: ; preds = %51
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %11
55: ; preds = %11
%56 = load double, double* %9
ret double %56
}

LLVM IR (-O2):
define double @relative_error(i32 %0, double* nocapture %1, double* nocapture %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %27
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %23
%8 = phi i64 [ 0, %5 ], [ %25, %23 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %24, %23 ]
%10 = getelementptr inbounds double, double* %1, i64 %8
%11 = load double, double* %10
%12 = getelementptr inbounds double, double* %2, i64 %8
%13 = load double, double* %12
%14 = fadd double %11, %13
%15 = fmul double %14, 5.000000e-01
%16 = fcmp ogt double %15, 0.000000e+00
br i1 %16, label %17, label %23
17: ; preds = %7
%18 = fsub double %11, %13
%19 = fdiv double %18, %15
%20 = tail call double @llvm.fabs.f64(double %19)
%21 = fcmp ogt double %20, %9
br i1 %21, label %22, label %23
22: ; preds = %17
br label %23
23: ; preds = %7, %22, %17
%24 = phi double [ %20, %22 ], [ %9, %17 ], [ %9, %7 ]
%25 = add nuw nsw i64 %8, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %27, label %7
27: ; preds = %23, %3
%28 = phi double [ 0.000000e+00, %3 ], [ %24, %23 ]
ret double %28
}