#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 sqrt(double);
double rel_error(double *r, double *t, int size) {
  int i;
  double norm_diff = 0, norm_vec = 0;
  for (i = 0; i < size; ++i) {
    norm_diff += (r[i] - t[i]) * (r[i] - t[i]);
    norm_vec += t[i] * t[i];
  }
  return sqrt(norm_diff) / sqrt(norm_vec);
}


x86 assembly (clang, -O0):
<rel_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c6 <rel_error+0xb6>
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
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <rel_error+0x2a>
movsd  -0x20(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rel_error>:
sub    $0x18,%rsp
test   %edx,%edx
jle    112b <rel_error+0x1b>
mov    %edx,%eax
cmp    $0x1,%edx
jne    1131 <rel_error+0x21>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
test   $0x1,%al
jne    118b <rel_error+0x7b>
jmp    11a5 <rel_error+0x95>
xorpd  %xmm4,%xmm4
jmp    11a5 <rel_error+0x95>
mov    %eax,%edx
and    $0xfffffffe,%edx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
nopl   0x0(%rax)
movsd  (%rdi,%rcx,8),%xmm1
movsd  0x8(%rdi,%rcx,8),%xmm4
movsd  (%rsi,%rcx,8),%xmm2
movsd  0x8(%rsi,%rcx,8),%xmm3
subsd  %xmm2,%xmm1
unpcklpd %xmm2,%xmm1
mulpd  %xmm1,%xmm1
addpd  %xmm0,%xmm1
subsd  %xmm3,%xmm4
unpcklpd %xmm3,%xmm4
mulpd  %xmm4,%xmm4
movapd %xmm4,%xmm0
addpd  %xmm1,%xmm0
add    $0x2,%rcx
cmp    %rcx,%rdx
jne    1140 <rel_error+0x30>
addpd  %xmm1,%xmm4
test   $0x1,%al
je     11a5 <rel_error+0x95>
movsd  (%rdi,%rcx,8),%xmm4
movsd  (%rsi,%rcx,8),%xmm1
subsd  %xmm1,%xmm4
unpcklpd %xmm1,%xmm4
mulpd  %xmm4,%xmm4
addpd  %xmm0,%xmm4
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm4
jb     11b8 <rel_error+0xa8>
xorps  %xmm1,%xmm1
sqrtsd %xmm4,%xmm1
jmp    11d3 <rel_error+0xc3>
movapd %xmm4,%xmm0
movapd %xmm4,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm4
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
unpckhpd %xmm4,%xmm4
ucomisd %xmm0,%xmm4
jb     11e6 <rel_error+0xd6>
xorps  %xmm0,%xmm0
sqrtsd %xmm4,%xmm0
jmp    11f9 <rel_error+0xe9>
movapd %xmm4,%xmm0
movsd  %xmm1,(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @rel_error(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 double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
store i32 0, i32* %7
br label %10
10: ; preds = %51, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %54
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 = load double*, double** %4
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = fsub double %30, %35
%37 = load double, double* %8
%38 = call double @llvm.fmuladd.f64(double %25, double %36, double %37)
store double %38, double* %8
%39 = load double*, double** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = load double*, double** %5
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = load double, double* %9
%50 = call double @llvm.fmuladd.f64(double %43, double %48, double %49)
store double %50, double* %9
br label %51
51: ; preds = %14
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %10
54: ; preds = %10
%55 = load double, double* %8
%56 = call double @sqrt(double %55)
%57 = load double, double* %9
%58 = call double @sqrt(double %57)
%59 = fdiv double %56, %58
ret double %59
}

LLVM IR (-O2):
define double @rel_error(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %51
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = and i64 %6, 1
%8 = icmp eq i32 %2, 1
br i1 %8, label %37, 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 <2 x double> [ zeroinitializer, %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 = insertelement <2 x double> poison, double %19, i64 0
%21 = insertelement <2 x double> %20, double %18, i64 1
%22 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %21, <2 x 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 = insertelement <2 x double> poison, double %28, i64 0
%30 = insertelement <2 x double> %29, double %27, i64 1
%31 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %30, <2 x 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
%36 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %30, <2 x double> %22)
br label %37
37: ; preds = %35, %5
%38 = phi <2 x double> [ undef, %5 ], [ %36, %35 ]
%39 = phi i64 [ 0, %5 ], [ %32, %35 ]
%40 = phi <2 x double> [ zeroinitializer, %5 ], [ %31, %35 ]
%41 = icmp eq i64 %7, 0
br i1 %41, label %51, label %42
42: ; preds = %37
%43 = getelementptr inbounds double, double* %0, i64 %39
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %1, i64 %39
%46 = load double, double* %45
%47 = fsub double %44, %46
%48 = insertelement <2 x double> poison, double %47, i64 0
%49 = insertelement <2 x double> %48, double %46, i64 1
%50 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %49, <2 x double> %49, <2 x double> %40)
br label %51
51: ; preds = %42, %37, %3
%52 = phi <2 x double> [ zeroinitializer, %3 ], [ %38, %37 ], [ %50, %42 ]
%53 = extractelement <2 x double> %52, i64 0
%54 = tail call double @sqrt(double %53)
%55 = extractelement <2 x double> %52, i64 1
%56 = tail call double @sqrt(double %55)
%57 = fdiv double %54, %56
ret double %57
}