#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 */
int DBL_MAX;
scalar_t__ match(double *, double *, int, double);
int /*<<< orphan*/ printf(char *);
int main() {
  int bins = 4;
  double reference[4] = {5.00, 6.00, 3.00, 8.00};
  double test1[4] = {1.00, 2.00, 3.00, 4.00};
  double test2[4] = {5.01, 5.99, 3.02, 7.98};
  double dorked[4] = {1, 2, DBL_MAX, 4};
  double threshold = 0.95;
  printf("Test1 v Reference:     ");
  match(test1, reference, bins, threshold) ? printf("MATCH\n")
                                           : printf("NO_MATCH\n");
  printf("Test2 v Reference:     ");
  match(test2, reference, bins, threshold) ? printf("MATCH\n")
                                           : printf("NO_MATCH\n");
  printf("Dorked v Reference:    ");
  match(dorked, reference, bins, threshold) ? printf("MATCH\n")
                                            : printf("NO_MATCH\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
mov    0xee0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xedd(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed4(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xed1(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xec5(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0xec2(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xebf(%rip),%rax
mov    %rax,-0x58(%rbp)
movsd  0xe53(%rip),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xe3b(%rip),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    0x2dfc(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  0xe13(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xdfe(%rip),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edx
movsd  -0x98(%rbp),%xmm0
ff
call   1040 <match@plt>
cmp    $0x0,%rax
je     1249 <main+0x129>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
jmp    1255 <main+0x135>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edx
movsd  -0x98(%rbp),%xmm0
ff
call   1040 <match@plt>
cmp    $0x0,%rax
je     1294 <main+0x174>
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
jmp    12a0 <main+0x180>
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edx
movsd  -0x98(%rbp),%xmm0
ff
call   1040 <match@plt>
cmp    $0x0,%rax
je     12e2 <main+0x1c2>
lea    0xdc3(%rip),%rdi
call   1030 <printf@plt>
jmp    12ee <main+0x1ce>
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
movaps 0xeed(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xed1(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xef5(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xefd(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe75(%rip),%xmm0
mov    0x2e4e(%rip),%rax
cvtsi2sdl (%rax),%xmm1
movaps %xmm0,(%rsp)
movsd  %xmm1,0x10(%rsp)
movabs $0x4010000000000000,%rax
mov    %rax,0x18(%rsp)
lea    0xeca(%rip),%rdi
call   1040 <printf@plt>
lea    0x40(%rsp),%rdi
lea    0x60(%rsp),%r14
movsd  0xe43(%rip),%xmm0
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <match@plt>
test   %rax,%rax
lea    0xee4(%rip),%r15
lea    0xee0(%rip),%rbx
mov    %rbx,%rdi
cmove  %r15,%rdi
call   1030 <puts@plt>
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0x20(%rsp),%rdi
mov    %r14,%rsi
mov    $0x4,%edx
movsd  0xdf8(%rip),%xmm0
call   1050 <match@plt>
test   %rax,%rax
mov    %rbx,%rdi
cmove  %r15,%rdi
call   1030 <puts@plt>
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
movsd  0xdc5(%rip),%xmm0
call   1050 <match@plt>
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.reference = [4 x double] [double 5.000000e+00, double 6.000000e+00, double 3.000000e+00, double 8.000000e+00]
@__const.main.test1 = [4 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00]
@__const.main.test2 = [4 x double] [double 5.010000e+00, double 5.990000e+00, double 3.020000e+00, double 7.980000e+00]
@DBL_MAX = global i32 0
@.str = [24 x i8] c"Test1 v Reference: \00"
@.str.1 = [7 x i8] c"MATCH\0A\00"
@.str.2 = [10 x i8] c"NO_MATCH\0A\00"
@.str.3 = [24 x i8] c"Test2 v Reference: \00"
@.str.4 = [24 x i8] c"Dorked v Reference: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x double]
%4 = alloca [4 x double]
%5 = alloca [4 x double]
%6 = alloca [4 x double]
%7 = alloca double
store i32 0, i32* %1
store i32 4, i32* %2
%8 = bitcast [4 x double]* %3 to i8*
%9 = bitcast [4 x double]* %4 to i8*
%10 = bitcast [4 x double]* %5 to i8*
%11 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
store double 1.000000e+00, double* %11
%12 = getelementptr inbounds double, double* %11, i64 1
store double 2.000000e+00, double* %12
%13 = getelementptr inbounds double, double* %12, i64 1
%14 = load i32, i32* @DBL_MAX
%15 = sitofp i32 %14 to double
store double %15, double* %13
%16 = getelementptr inbounds double, double* %13, i64 1
store double 4.000000e+00, double* %16
store double 0x3FEE666666666666, double* %7
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%19 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%20 = load i32, i32* %2
%21 = load double, double* %7
%22 = call i64 @match(double* %18, double* %19, i32 %20, double %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %0
%25 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %28
26: ; preds = %0
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %24
%29 = phi i32 [ %25, %24 ], [ %27, %26 ]
%30 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%31 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%32 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%33 = load i32, i32* %2
%34 = load double, double* %7
%35 = call i64 @match(double* %31, double* %32, i32 %33, double %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %41
39: ; preds = %28
%40 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
%42 = phi i32 [ %38, %37 ], [ %40, %39 ]
%43 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%44 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%45 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%46 = load i32, i32* %2
%47 = load double, double* %7
%48 = call i64 @match(double* %44, double* %45, i32 %46, double %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %54
52: ; preds = %41
%53 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %52, %50
%55 = phi i32 [ %51, %50 ], [ %53, %52 ]
ret i32 0
}

LLVM IR (-O2):
@__const.main.reference = [4 x double] [double 5.000000e+00, double 6.000000e+00, double 3.000000e+00, double 8.000000e+00]
@__const.main.test1 = [4 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00]
@__const.main.test2 = [4 x double] [double 5.010000e+00, double 5.990000e+00, double 3.020000e+00, double 7.980000e+00]
@DBL_MAX = global i32 0
@.str = [24 x i8] c"Test1 v Reference: \00"
@.str.3 = [24 x i8] c"Test2 v Reference: \00"
@.str.4 = [24 x i8] c"Dorked v Reference: \00"
@str.6 = [9 x i8] c"NO_MATCH\00"
@str.9 = [6 x i8] c"MATCH\00"
define i32 @main() {
%1 = alloca [4 x double]
%2 = alloca [4 x double]
%3 = alloca [4 x double]
%4 = alloca [4 x double]
%5 = bitcast [4 x double]* %1 to i8*
%6 = bitcast [4 x double]* %2 to i8*
%7 = bitcast [4 x double]* %3 to i8*
%8 = bitcast [4 x double]* %4 to i8*
%9 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%10 = bitcast [4 x double]* %4 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 2.000000e+00>, <2 x double>* %10
%11 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%12 = load i32, i32* @DBL_MAX
%13 = sitofp i32 %12 to double
store double %13, double* %11
%14 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
store double 4.000000e+00, double* %14
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%17 = getelementptr inbounds [4 x double], [4 x double]* %1, i64 0, i64 0
%18 = call i64 @match(double* %16, double* %17, i32 4, double 0x3FEE666666666666)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0)
%21 = call i32 @puts(i8* dereferenceable(1) %20)
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%23 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%24 = call i64 @match(double* %23, double* %17, i32 4, double 0x3FEE666666666666)
%25 = icmp eq i64 %24, 0
%26 = select i1 %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0)
%27 = call i32 @puts(i8* dereferenceable(1) %26)
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%29 = call i64 @match(double* %9, double* %17, i32 4, double 0x3FEE666666666666)
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0)
%32 = call i32 @puts(i8* dereferenceable(1) %31)
ret i32 0
}