#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 calc_max_spectral_difference(double *, double *);
int /*<<< orphan*/ dft_magnitude(double const *, double *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ oct_save_double(double const *, double const *, int);
int /*<<< orphan*/ printf(char *, int, ...);
double dft_cmp_double(int linenum, const double *orig, const double *test,
                      int len, double target_snr, int allow_exit) {
  static double orig_spec[((8192) / 2)];
  static double test_spec[((8192) / 2)];
  double snr;
  if (!orig || !test) {
    printf("Error (line %d) : dft_cmp_double : Bad input arrays.\n", linenum);
    return 1;
  };
  if (len != (8192)) {
    printf("Error (line %d) : dft_cmp_double : Bad input array length.\n",
           linenum);
    return 1;
  };
  dft_magnitude(orig, orig_spec);
  dft_magnitude(test, test_spec);
  snr = calc_max_spectral_difference(orig_spec, test_spec);
  if (snr > target_snr) {
    printf("\n\nLine %d: Actual SNR (% 4.1f) > target SNR (% 4.1f).\n\n",
           linenum, snr, target_snr);
    oct_save_double(orig, test, len);
    if (allow_exit)
      exit(1);
  };
  if (snr < -500.0)
    snr = -500.0;
  return snr;
}


x86 assembly (clang, -O0):
<dft_cmp_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movsd  %xmm0,-0x30(%rbp)
mov    %r8d,-0x34(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1185 <dft_cmp_double+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <dft_cmp_double+0x58>
mov    -0xc(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  0xe62(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128e <dft_cmp_double+0x13e>
cmpl   $0x2000,-0x24(%rbp)
je     11d8 <dft_cmp_double+0x88>
mov    -0xc(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  0xe32(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128e <dft_cmp_double+0x13e>
mov    -0x18(%rbp),%rdi
lea    0x2e7d(%rip),%rsi
call   1040 <dft_magnitude@plt>
mov    -0x20(%rbp),%rdi
lea    0xae6d(%rip),%rsi
call   1040 <dft_magnitude@plt>
lea    0x2e61(%rip),%rdi
lea    0xae5a(%rip),%rsi
call   1050 <calc_max_spectral_difference@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1264 <dft_cmp_double+0x114>
mov    -0xc(%rbp),%esi
movsd  -0x40(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xe4e(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1070 <oct_save_double@plt>
cmpl   $0x0,-0x34(%rbp)
je     125f <dft_cmp_double+0x10f>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1264 <dft_cmp_double+0x114>
movsd  0xd9c(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1284 <dft_cmp_double+0x134>
movsd  0xd89(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dft_cmp_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
test   %rsi,%rsi
je     120a <dft_cmp_double+0xba>
mov    %rdx,%rbx
test   %rdx,%rdx
je     120a <dft_cmp_double+0xba>
cmp    $0x2000,%ecx
jne    1213 <dft_cmp_double+0xc3>
mov    %r8d,%r14d
mov    %rsi,%rbp
lea    0x2ed4(%rip),%r12
mov    %rsi,%rdi
mov    %r12,%rsi
movsd  %xmm0,(%rsp)
call   1040 <dft_magnitude@plt>
lea    0xaebd(%rip),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <dft_magnitude@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <calc_max_spectral_difference@plt>
movsd  (%rsp),%xmm1
movapd %xmm0,%xmm2
ucomisd %xmm1,%xmm0
jbe    11fc <dft_cmp_double+0xac>
lea    0xeb3(%rip),%rdi
mov    %r15d,%esi
movapd %xmm2,%xmm0
mov    $0x2,%al
movsd  %xmm2,(%rsp)
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2000,%edx
call   1070 <oct_save_double@plt>
movsd  (%rsp),%xmm2
test   %r14d,%r14d
jne    123b <dft_cmp_double+0xeb>
movsd  0xe04(%rip),%xmm0
maxsd  %xmm2,%xmm0
jmp    122c <dft_cmp_double+0xdc>
lea    0xdff(%rip),%rdi
jmp    121a <dft_cmp_double+0xca>
lea    0xe2c(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movsd  0xdd4(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@dft_cmp_double.orig_spec = internal global [4096 x double] zeroinitializer
@dft_cmp_double.test_spec = internal global [4096 x double] zeroinitializer
@.str = [54 x i8] c"Error (line %d) : dft_cmp_double : Bad input arrays.\0A\00"
@.str.1 = [60 x i8] c"Error (line %d) : dft_cmp_double : Bad input array length.\0A\00"
@.str.2 = [56 x i8] c"\0A\0ALine %d: Actual SNR (% 4.1f) > target SNR (% 4.1f).\0A\0A\00"
define double @dft_cmp_double(i32 %0, double* %1, double* %2, i32 %3, double %4, i32 %5) {
%7 = alloca double
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca double
%13 = alloca i32
%14 = alloca double
store i32 %0, i32* %8
store double* %1, double** %9
store double* %2, double** %10
store i32 %3, i32* %11
store double %4, double* %12
store i32 %5, i32* %13
%15 = load double*, double** %9
%16 = icmp ne double* %15, null
br i1 %16, label %17, label %20
17: ; preds = %6
%18 = load double*, double** %10
%19 = icmp ne double* %18, null
br i1 %19, label %23, label %20
20: ; preds = %17, %6
%21 = load i32, i32* %8
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %21)
store double 1.000000e+00, double* %7
br label %58
23: ; preds = %17
%24 = load i32, i32* %11
%25 = icmp ne i32 %24, 8192
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %8
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %27)
store double 1.000000e+00, double* %7
br label %58
29: ; preds = %23
%30 = load double*, double** %9
%31 = call i32 @dft_magnitude(double* %30, double* getelementptr inbounds ([4096 x double], [4096 x double]* @dft_cmp_double.orig_spec, i64 0, i64 0))
%32 = load double*, double** %10
%33 = call i32 @dft_magnitude(double* %32, double* getelementptr inbounds ([4096 x double], [4096 x double]* @dft_cmp_double.test_spec, i64 0, i64 0))
%34 = call double @calc_max_spectral_difference(double* getelementptr inbounds ([4096 x double], [4096 x double]* @dft_cmp_double.orig_spec, i64 0, i64 0), double* getelementptr inbounds ([4096 x double], [4096 x double]* @dft_cmp_double.test_spec, i64 0, i64 0))
store double %34, double* %14
%35 = load double, double* %14
%36 = load double, double* %12
%37 = fcmp ogt double %35, %36
br i1 %37, label %38, label %52
38: ; preds = %29
%39 = load i32, i32* %8
%40 = load double, double* %14
%41 = load double, double* %12
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %39, double %40, double %41)
%43 = load double*, double** %9
%44 = load double*, double** %10
%45 = load i32, i32* %11
%46 = call i32 @oct_save_double(double* %43, double* %44, i32 %45)
%47 = load i32, i32* %13
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %38
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %38
br label %52
52: ; preds = %51, %29
%53 = load double, double* %14
%54 = fcmp olt double %53, -5.000000e+02
br i1 %54, label %55, label %56
55: ; preds = %52
store double -5.000000e+02, double* %14
br label %56
56: ; preds = %55, %52
%57 = load double, double* %14
store double %57, double* %7
br label %58
58: ; preds = %56, %26, %20
%59 = load double, double* %7
ret double %59
}

LLVM IR (-O2):
@dft_cmp_double.orig_spec = internal global [4096 x double] zeroinitializer
@dft_cmp_double.test_spec = internal global [4096 x double] zeroinitializer
@.str = [54 x i8] c"Error (line %d) : dft_cmp_double : Bad input arrays.\0A\00"
@.str.1 = [60 x i8] c"Error (line %d) : dft_cmp_double : Bad input array length.\0A\00"
@.str.2 = [56 x i8] c"\0A\0ALine %d: Actual SNR (% 4.1f) > target SNR (% 4.1f).\0A\0A\00"
define double @dft_cmp_double(i32 %0, double* %1, double* %2, i32 %3, double %4, i32 %5) {
%7 = icmp ne double* %1, null
%8 = icmp ne double* %2, null
%9 = and i1 %7, %8
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %30
12: ; preds = %6
%13 = icmp eq i32 %3, 8192
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %30
16: ; preds = %12
%17 = tail call i32 @dft_magnitude(double* %1, double* getelementptr inbounds ([4096 x double], [4096 x double]* @dft_cmp_double.orig_spec, i64 0, i64 0))
%18 = tail call i32 @dft_magnitude(double* %2, double* getelementptr inbounds ([4096 x double], [4096 x double]* @dft_cmp_double.test_spec, i64 0, i64 0))
%19 = tail call double @calc_max_spectral_difference(double* getelementptr inbounds ([4096 x double], [4096 x double]* @dft_cmp_double.orig_spec, i64 0, i64 0), double* getelementptr inbounds ([4096 x double], [4096 x double]* @dft_cmp_double.test_spec, i64 0, i64 0))
%20 = fcmp ogt double %19, %4
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %0, double %19, double %4)
%23 = tail call i32 @oct_save_double(double* %1, double* %2, i32 8192)
%24 = icmp eq i32 %5, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %21, %16
%28 = fcmp olt double %19, -5.000000e+02
%29 = select i1 %28, double -5.000000e+02, double %19
br label %30
30: ; preds = %27, %14, %10
%31 = phi double [ 1.000000e+00, %14 ], [ %29, %27 ], [ 1.000000e+00, %10 ]
ret double %31
}