#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);
void v_compare(int n, const double *v0, const double *v1, double *amax_ptr,
               double *rmax_ptr) {
  double amax = 0.0, rmax = 0.0;
  int j;
  for (j = 0; j < n; ++j) {
    double a0 = v0[j];
    double a1 = v1[j];
    double q = fabs(a0);
    double adif = fabs(a1 - a0);
    double rdif = (q > 0.0 ? adif / q : adif);
    amax = ((amax) >= (adif) ? (amax) : (adif));
    rmax = ((rmax) >= (rdif) ? (rmax) : (rdif));
  }
  if (rmax_ptr != NULL)
    *rmax_ptr = rmax;
  if (amax_ptr != NULL)
    *amax_ptr = amax;
}


x86 assembly (clang, -O0):
<v_compare>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    123b <v_compare+0x13b>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movaps 0xe96(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movaps 0xe7c(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11b3 <v_compare+0xb3>
movsd  -0x60(%rbp),%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    11bd <v_compare+0xbd>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x60(%rbp),%xmm0
jb     11e6 <v_compare+0xe6>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    11f0 <v_compare+0xf0>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x68(%rbp),%xmm0
jb     1219 <v_compare+0x119>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    1223 <v_compare+0x123>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    112e <v_compare+0x2e>
cmpq   $0x0,-0x28(%rbp)
je     1253 <v_compare+0x153>
movsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     126b <v_compare+0x16b>
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<v_compare>:
test   %edi,%edi
jle    1181 <v_compare+0x81>
mov    %edi,%eax
xorpd  %xmm2,%xmm2
xor    %edi,%edi
movapd 0xeec(%rip),%xmm3
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
jmp    1153 <v_compare+0x53>
xchg   %ax,%ax
movapd %xmm4,%xmm6
cmplesd %xmm0,%xmm6
andpd  %xmm6,%xmm0
andnpd %xmm4,%xmm6
orpd   %xmm6,%xmm0
movapd %xmm5,%xmm4
cmplesd %xmm1,%xmm4
andpd  %xmm4,%xmm1
andnpd %xmm5,%xmm4
orpd   %xmm4,%xmm1
add    $0x1,%rdi
cmp    %rdi,%rax
je     1189 <v_compare+0x89>
movsd  (%rsi,%rdi,8),%xmm7
movsd  (%rdx,%rdi,8),%xmm6
subsd  %xmm7,%xmm6
movapd %xmm6,%xmm4
andpd  %xmm3,%xmm4
ucomisd %xmm7,%xmm2
movapd %xmm4,%xmm5
je     1120 <v_compare+0x20>
divsd  %xmm7,%xmm6
andpd  %xmm3,%xmm6
movapd %xmm6,%xmm5
jmp    1120 <v_compare+0x20>
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
test   %r8,%r8
je     1193 <v_compare+0x93>
movsd  %xmm1,(%r8)
test   %rcx,%rcx
je     119c <v_compare+0x9c>
movsd  %xmm0,(%rcx)
ret

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

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