#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 log10(double);
double calc_max_spectral_difference(const double *orig, const double *test) {
  double orig_max = 0.0, max_diff = 0.0;
  int k;
  for (k = 0; k < ((8192) / 2); k++) {
    if (orig_max < orig[k])
      orig_max = orig[k];
    if (max_diff < fabs(orig[k] - test[k]))
      max_diff = fabs(orig[k] - test[k]);
  };
  if (max_diff < 1e-25)
    return -500.0;
  return 20.0 * log10(max_diff / orig_max);
}


x86 assembly (clang, -O0):
<calc_max_spectral_difference>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1000,-0x2c(%rbp)
jge    11e3 <calc_max_spectral_difference+0xd3>
movsd  -0x20(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1172 <calc_max_spectral_difference+0x62>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xe88(%rip),%xmm2
pand   %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    11d0 <calc_max_spectral_difference+0xc0>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xe59(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11d5 <calc_max_spectral_difference+0xc5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1137 <calc_max_spectral_difference+0x27>
movsd  0xe15(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1208 <calc_max_spectral_difference+0xf8>
movsd  0xe12(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122b <calc_max_spectral_difference+0x11b>
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <log10@plt>
movaps %xmm0,%xmm1
movsd  0xde6(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_max_spectral_difference>:
push   %rax
xorpd  %xmm0,%xmm0
xor    %eax,%eax
movapd 0xee1(%rip),%xmm2
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rdi,%rax,8),%xmm3
movapd %xmm3,%xmm4
subsd  (%rsi,%rax,8),%xmm3
andpd  %xmm2,%xmm3
maxsd  %xmm0,%xmm3
movsd  0x8(%rdi,%rax,8),%xmm0
maxsd  %xmm1,%xmm4
movapd %xmm0,%xmm1
maxsd  %xmm4,%xmm1
subsd  0x8(%rsi,%rax,8),%xmm0
andpd  %xmm2,%xmm0
maxsd  %xmm3,%xmm0
add    $0x2,%rax
cmp    $0x1000,%rax
jne    1130 <calc_max_spectral_difference+0x20>
movsd  0xe9e(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    118a <calc_max_spectral_difference+0x7a>
movsd  0xe88(%rip),%xmm0
pop    %rax
ret
divsd  %xmm1,%xmm0
call   1030 <log10@plt>
mulsd  0xe85(%rip),%xmm0
pop    %rax
ret

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

LLVM IR (-O2):
define double @calc_max_spectral_difference(double* nocapture %0, double* nocapture %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ 0, %2 ], [ %28, %3 ]
%5 = phi double [ 0.000000e+00, %2 ], [ %27, %3 ]
%6 = phi double [ 0.000000e+00, %2 ], [ %21, %3 ]
%7 = getelementptr inbounds double, double* %0, i64 %4
%8 = load double, double* %7
%9 = fcmp olt double %6, %8
%10 = select i1 %9, double %8, double %6
%11 = getelementptr inbounds double, double* %1, i64 %4
%12 = load double, double* %11
%13 = fsub double %8, %12
%14 = tail call double @llvm.fabs.f64(double %13)
%15 = fcmp olt double %5, %14
%16 = select i1 %15, double %14, double %5
%17 = or i64 %4, 1
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = load double, double* %18
%20 = fcmp olt double %10, %19
%21 = select i1 %20, double %19, double %10
%22 = getelementptr inbounds double, double* %1, i64 %17
%23 = load double, double* %22
%24 = fsub double %19, %23
%25 = tail call double @llvm.fabs.f64(double %24)
%26 = fcmp olt double %16, %25
%27 = select i1 %26, double %25, double %16
%28 = add nuw nsw i64 %4, 2
%29 = icmp eq i64 %28, 4096
br i1 %29, label %30, label %3
30: ; preds = %3
%31 = fcmp olt double %27, 1.000000e-25
br i1 %31, label %36, label %32
32: ; preds = %30
%33 = fdiv double %27, %21
%34 = tail call double @log10(double %33)
%35 = fmul double %34, 2.000000e+01
br label %36
36: ; preds = %30, %32
%37 = phi double [ %35, %32 ], [ -5.000000e+02, %30 ]
ret double %37
}