#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);
scalar_t__ memcmp(double const *, double const *, size_t);
int memcmp_double(const double *p1, const double *p2, size_t num_elements) {
  if (memcmp(p1, p2, num_elements * sizeof *p1) == 0)
    return 0;
  else {
    const double abs_epsilon = 1e-8;
    const double rel_epsilon = 1e-5;
    size_t index;
    for (index = 0; index < num_elements; index++) {
      double diff = fabs(p1[index] - p2[index]);
      if (diff > abs_epsilon) {
        double sum = fabs(p1[index]) + fabs(p2[index]);
        if (diff > sum * rel_epsilon)
          return 1;
      }
    }
    return 0;
  }
}


x86 assembly (clang, -O0):
<memcmp_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
shl    $0x3,%rdx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    114f <memcmp_double+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1243 <memcmp_double+0x133>
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe9c(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    123c <memcmp_double+0x12c>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xe70(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xe52(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1226 <memcmp_double+0x116>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe3c(%rip),%xmm1
pand   %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movaps 0xe24(%rip),%xmm2
pand   %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xdfa(%rip),%xmm1
mulsd  -0x48(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1221 <memcmp_double+0x111>
movl   $0x1,-0x4(%rbp)
jmp    1243 <memcmp_double+0x133>
jmp    1226 <memcmp_double+0x116>
jmp    122b <memcmp_double+0x11b>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1171 <memcmp_double+0x61>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcmp_double>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rdx,8),%rdx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     11a6 <memcmp_double+0x96>
test   %rbx,%rbx
je     11a6 <memcmp_double+0x96>
xor    %eax,%eax
movapd 0xebc(%rip),%xmm0
movsd  0xec4(%rip),%xmm1
movapd 0xeac(%rip),%xmm2
movsd  0xebc(%rip),%xmm3
jmp    1169 <memcmp_double+0x59>
xchg   %ax,%ax
add    $0x1,%rax
cmp    %rax,%rbx
je     11a4 <memcmp_double+0x94>
movsd  (%r15,%rax,8),%xmm6
movsd  (%r14,%rax,8),%xmm4
movapd %xmm6,%xmm5
subsd  %xmm4,%xmm5
andpd  %xmm0,%xmm5
ucomisd %xmm1,%xmm5
jbe    1160 <memcmp_double+0x50>
andpd  %xmm2,%xmm6
andpd  %xmm2,%xmm4
addsd  %xmm6,%xmm4
mulsd  %xmm3,%xmm4
ucomisd %xmm4,%xmm5
jbe    1160 <memcmp_double+0x50>
mov    $0x1,%eax
jmp    11a6 <memcmp_double+0x96>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @memcmp_double(double* %0, double* %1, i64 %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i64
%8 = alloca double
%9 = alloca double
%10 = alloca i64
%11 = alloca double
%12 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store i64 %2, i64* %7
%13 = load double*, double** %5
%14 = load double*, double** %6
%15 = load i64, i64* %7
%16 = mul i64 %15, 8
%17 = call i64 @memcmp(double* %13, double* %14, i64 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 0, i32* %4
br label %61
20: ; preds = %3
store double 1.000000e-08, double* %8
store double 1.000000e-05, double* %9
store i64 0, i64* %10
br label %21
21: ; preds = %57, %20
%22 = load i64, i64* %10
%23 = load i64, i64* %7
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %60
25: ; preds = %21
%26 = load double*, double** %5
%27 = load i64, i64* %10
%28 = getelementptr inbounds double, double* %26, i64 %27
%29 = load double, double* %28
%30 = load double*, double** %6
%31 = load i64, i64* %10
%32 = getelementptr inbounds double, double* %30, i64 %31
%33 = load double, double* %32
%34 = fsub double %29, %33
%35 = call double @llvm.fabs.f64(double %34)
store double %35, double* %11
%36 = load double, double* %11
%37 = fcmp ogt double %36, 1.000000e-08
br i1 %37, label %38, label %56
38: ; preds = %25
%39 = load double*, double** %5
%40 = load i64, i64* %10
%41 = getelementptr inbounds double, double* %39, i64 %40
%42 = load double, double* %41
%43 = call double @llvm.fabs.f64(double %42)
%44 = load double*, double** %6
%45 = load i64, i64* %10
%46 = getelementptr inbounds double, double* %44, i64 %45
%47 = load double, double* %46
%48 = call double @llvm.fabs.f64(double %47)
%49 = fadd double %43, %48
store double %49, double* %12
%50 = load double, double* %11
%51 = load double, double* %12
%52 = fmul double %51, 1.000000e-05
%53 = fcmp ogt double %50, %52
br i1 %53, label %54, label %55
54: ; preds = %38
store i32 1, i32* %4
br label %61
55: ; preds = %38
br label %56
56: ; preds = %55, %25
br label %57
57: ; preds = %56
%58 = load i64, i64* %10
%59 = add i64 %58, 1
store i64 %59, i64* %10
br label %21
60: ; preds = %21
store i32 0, i32* %4
br label %61
61: ; preds = %60, %54, %19
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
define i32 @memcmp_double(double* %0, double* %1, i64 %2) {
%4 = shl i64 %2, 3
%5 = tail call i64 @memcmp(double* %0, double* %1, i64 %4)
%6 = icmp ne i64 %5, 0
%7 = icmp ne i64 %2, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %27
9: ; preds = %3, %24
%10 = phi i64 [ %25, %24 ], [ 0, %3 ]
%11 = getelementptr inbounds double, double* %0, i64 %10
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %1, i64 %10
%14 = load double, double* %13
%15 = fsub double %12, %14
%16 = tail call double @llvm.fabs.f64(double %15)
%17 = fcmp ogt double %16, 1.000000e-08
br i1 %17, label %18, label %24
18: ; preds = %9
%19 = tail call double @llvm.fabs.f64(double %12)
%20 = tail call double @llvm.fabs.f64(double %14)
%21 = fadd double %19, %20
%22 = fmul double %21, 1.000000e-05
%23 = fcmp ogt double %16, %22
br i1 %23, label %27, label %24
24: ; preds = %18, %9
%25 = add nuw i64 %10, 1
%26 = icmp eq i64 %25, %2
br i1 %26, label %27, label %9
27: ; preds = %18, %24, %3
%28 = phi i32 [ 0, %3 ], [ 1, %18 ], [ 0, %24 ]
ret i32 %28
}