#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 /*<<< orphan*/ exit(int);
scalar_t__ fabs(float);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(float *);
double max(scalar_t__, double);
int /*<<< orphan*/ printf(char *, double, double, size_t);
float *read_raw(char *, size_t *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  size_t frame1, frame2;
  float *data1, *data2;
  size_t i, n, changed;
  double diff = 0;
  double maxdiff = 0;
  if (argc != 3) {
    fprintf(stderr, "usage: cmpraw 1.raw 2.raw\n");
    exit(1);
  }
  data1 = read_raw(argv[1], &frame1);
  data2 = read_raw(argv[2], &frame2);
  if (frame1 != frame2) {
    fprintf(stderr, "mismatch size (%zu vs %zu)\n", frame1, frame2);
    exit(1);
  }
  n = frame1 * 2;
  changed = 0;
  for (i = 0; i < n; i++) {
    if (data1[i] != data2[i]) {
      changed++;
      diff += fabs(data1[i] - data2[i]);
      maxdiff = max(fabs(data1[i] - data2[i]), maxdiff);
    }
  }
  printf("avg diff = %g, max diff = %g, changed = %.3f%%\n", diff / n,
         maxdiff * 32768, changed * 100.0f / n);
  free(data1);
  free(data2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c4 <main+0x54>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <read_raw@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <read_raw@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1225 <main+0xb5>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    12fa <main+0x18a>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
ucomiss (%rax,%rcx,4),%xmm0
jne    1279 <main+0x109>
jp     1279 <main+0x109>
jmp    12e4 <main+0x174>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
subss  (%rax,%rcx,4),%xmm0
call   1070 <fabs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
subss  (%rax,%rcx,4),%xmm0
call   1070 <fabs@plt>
mov    %rax,%rdi
movsd  -0x58(%rbp),%xmm0
call   1060 <max@plt>
movsd  %xmm0,-0x58(%rbp)
jmp    12e9 <main+0x179>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1241 <main+0xd1>
movsd  -0x50(%rbp),%xmm0
mov    -0x40(%rbp),%rax
mov    %rax,-0x78(%rbp)
movq   %rax,%xmm1
movaps 0xced(%rip),%xmm2
punpckldq %xmm2,%xmm1
movapd 0xcf1(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  0xcdc(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x60(%rbp)
test   %rax,%rax
movss  %xmm0,-0x5c(%rbp)
js     138a <main+0x21a>
movss  -0x60(%rbp),%xmm0
movss  %xmm0,-0x5c(%rbp)
mov    -0x78(%rbp),%rax
movss  -0x5c(%rbp),%xmm0
movss  0xc8d(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x84(%rbp)
ff
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x80(%rbp)
test   %rax,%rax
movss  %xmm0,-0x7c(%rbp)
js     13e0 <main+0x270>
movss  -0x80(%rbp),%xmm0
movss  %xmm0,-0x7c(%rbp)
movsd  -0x68(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm0
movss  -0x84(%rbp),%xmm2
ff
movss  -0x7c(%rbp),%xmm3
divss  %xmm3,%xmm2
movaps %xmm2,%xmm3
cvttss2si %xmm3,%rsi
mov    %rsi,%rcx
sar    $0x3f,%rcx
movss  0xc1a(%rip),%xmm3
subss  %xmm3,%xmm2
cvttss2si %xmm2,%rax
and    %rcx,%rax
or     %rax,%rsi
lea    0xc3f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
cmp    $0x3,%edi
jne    133e <main+0x1ce>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x18(%rsp),%rsi
call   1040 <read_raw@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0x10(%rsp),%rsi
call   1040 <read_raw@plt>
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%rcx
cmp    %rcx,%r15
jne    135f <main+0x1ef>
mov    %rax,%r12
add    %r15,%r15
je     1249 <main+0xd9>
xorps  %xmm3,%xmm3
xor    %r13d,%r13d
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
jmp    11e9 <main+0x79>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1257 <main+0xe7>
movss  (%r14,%rbx,4),%xmm0
movss  (%r12,%rbx,4),%xmm1
ucomiss %xmm1,%xmm0
jne    11fc <main+0x8c>
jnp    11e0 <main+0x70>
add    $0x1,%r13
subss  %xmm1,%xmm0
movsd  %xmm3,0x8(%rsp)
call   1070 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movss  (%r14,%rbx,4),%xmm0
subss  (%r12,%rbx,4),%xmm0
call   1070 <fabs@plt>
mov    %rax,%rdi
movsd  0x8(%rsp),%xmm0
call   1060 <max@plt>
movaps %xmm0,%xmm3
jmp    11e0 <main+0x70>
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %r13d,%r13d
xorps  %xmm3,%xmm3
movq   %r15,%xmm0
punpckldq 0xd9c(%rip),%xmm0
subpd  0xda4(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
test   %r13,%r13
js     1287 <main+0x117>
xorps  %xmm0,%xmm0
cvtsi2ss %r13,%xmm0
jmp    12a0 <main+0x130>
mov    %r13,%rax
shr    %rax
and    $0x1,%r13d
or     %rax,%r13
xorps  %xmm0,%xmm0
cvtsi2ss %r13,%xmm0
addss  %xmm0,%xmm0
mulsd  0xd78(%rip),%xmm3
movsd  (%rsp),%xmm2
divsd  %xmm1,%xmm2
movsd  %xmm2,(%rsp)
mulss  0xd6a(%rip),%xmm0
test   %r15,%r15
js     12cd <main+0x15d>
xorps  %xmm1,%xmm1
cvtsi2ss %r15,%xmm1
jmp    12e6 <main+0x176>
mov    %r15,%rax
shr    %rax
and    $0x1,%r15d
or     %rax,%r15
xorps  %xmm1,%xmm1
cvtsi2ss %r15,%xmm1
addss  %xmm1,%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subss  0xd2e(%rip),%xmm0
cvttss2si %xmm0,%rsi
and    %rcx,%rsi
or     %rax,%rsi
lea    0xd57(%rip),%rdi
movsd  (%rsp),%xmm0
movapd %xmm3,%xmm1
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
lea    0xce2(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"usage: cmpraw 1.raw 2.raw\0A\00"
@.str.1 = [28 x i8] c"mismatch size (%zu vs %zu)\0A\00"
@.str.2 = [48 x i8] c"avg diff = %g, max diff = %g, changed = %.3f%%\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca float*
%9 = alloca float*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca double
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call float* @read_raw(i8* %24, i64* %6)
store float* %25, float** %8
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call float* @read_raw(i8* %28, i64* %7)
store float* %29, float** %9
%30 = load i64, i64* %6
%31 = load i64, i64* %7
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %39
33: ; preds = %21
%34 = load i32, i32* @stderr
%35 = load i64, i64* %6
%36 = load i64, i64* %7
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %35, i64 %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %21
%40 = load i64, i64* %6
%41 = mul i64 %40, 2
store i64 %41, i64* %11
store i64 0, i64* %12
store i64 0, i64* %10
br label %42
42: ; preds = %85, %39
%43 = load i64, i64* %10
%44 = load i64, i64* %11
%45 = icmp ult i64 %43, %44
br i1 %45, label %46, label %88
46: ; preds = %42
%47 = load float*, float** %8
%48 = load i64, i64* %10
%49 = getelementptr inbounds float, float* %47, i64 %48
%50 = load float, float* %49
%51 = load float*, float** %9
%52 = load i64, i64* %10
%53 = getelementptr inbounds float, float* %51, i64 %52
%54 = load float, float* %53
%55 = fcmp une float %50, %54
br i1 %55, label %56, label %84
56: ; preds = %46
%57 = load i64, i64* %12
%58 = add i64 %57, 1
store i64 %58, i64* %12
%59 = load float*, float** %8
%60 = load i64, i64* %10
%61 = getelementptr inbounds float, float* %59, i64 %60
%62 = load float, float* %61
%63 = load float*, float** %9
%64 = load i64, i64* %10
%65 = getelementptr inbounds float, float* %63, i64 %64
%66 = load float, float* %65
%67 = fsub float %62, %66
%68 = call i64 @fabs(float %67)
%69 = sitofp i64 %68 to double
%70 = load double, double* %13
%71 = fadd double %70, %69
store double %71, double* %13
%72 = load float*, float** %8
%73 = load i64, i64* %10
%74 = getelementptr inbounds float, float* %72, i64 %73
%75 = load float, float* %74
%76 = load float*, float** %9
%77 = load i64, i64* %10
%78 = getelementptr inbounds float, float* %76, i64 %77
%79 = load float, float* %78
%80 = fsub float %75, %79
%81 = call i64 @fabs(float %80)
%82 = load double, double* %14
%83 = call double @max(i64 %81, double %82)
store double %83, double* %14
br label %84
84: ; preds = %56, %46
br label %85
85: ; preds = %84
%86 = load i64, i64* %10
%87 = add i64 %86, 1
store i64 %87, i64* %10
br label %42
88: ; preds = %42
%89 = load double, double* %13
%90 = load i64, i64* %11
%91 = uitofp i64 %90 to double
%92 = fdiv double %89, %91
%93 = load double, double* %14
%94 = fmul double %93, 3.276800e+04
%95 = load i64, i64* %12
%96 = uitofp i64 %95 to float
%97 = fmul float %96, 1.000000e+02
%98 = load i64, i64* %11
%99 = uitofp i64 %98 to float
%100 = fdiv float %97, %99
%101 = fptoui float %100 to i64
%102 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), double %92, double %94, i64 %101)
%103 = load float*, float** %8
%104 = call i32 @free(float* %103)
%105 = load float*, float** %9
%106 = call i32 @free(float* %105)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"usage: cmpraw 1.raw 2.raw\0A\00"
@.str.1 = [28 x i8] c"mismatch size (%zu vs %zu)\0A\00"
@.str.2 = [48 x i8] c"avg diff = %g, max diff = %g, changed = %.3f%%\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i64* %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call float* @read_raw(i8* %14, i64* %3)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = call float* @read_raw(i8* %17, i64* %4)
%19 = load i64, i64* %3
%20 = load i64, i64* %4
%21 = icmp eq i64 %19, %20
br i1 %21, label %26, label %22
22: ; preds = %12
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %19, i64 %20)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %12
%27 = shl i64 %19, 1
%28 = icmp eq i64 %27, 0
br i1 %28, label %56, label %29
29: ; preds = %26, %50
%30 = phi double [ %53, %50 ], [ 0.000000e+00, %26 ]
%31 = phi double [ %52, %50 ], [ 0.000000e+00, %26 ]
%32 = phi i64 [ %51, %50 ], [ 0, %26 ]
%33 = phi i64 [ %54, %50 ], [ 0, %26 ]
%34 = getelementptr inbounds float, float* %15, i64 %33
%35 = load float, float* %34
%36 = getelementptr inbounds float, float* %18, i64 %33
%37 = load float, float* %36
%38 = fcmp une float %35, %37
br i1 %38, label %39, label %50
39: ; preds = %29
%40 = add i64 %32, 1
%41 = fsub float %35, %37
%42 = call i64 @fabs(float %41)
%43 = sitofp i64 %42 to double
%44 = fadd double %31, %43
%45 = load float, float* %34
%46 = load float, float* %36
%47 = fsub float %45, %46
%48 = call i64 @fabs(float %47)
%49 = call double @max(i64 %48, double %30)
br label %50
50: ; preds = %29, %39
%51 = phi i64 [ %40, %39 ], [ %32, %29 ]
%52 = phi double [ %44, %39 ], [ %31, %29 ]
%53 = phi double [ %49, %39 ], [ %30, %29 ]
%54 = add nuw i64 %33, 1
%55 = icmp eq i64 %54, %27
br i1 %55, label %56, label %29
56: ; preds = %50, %26
%57 = phi i64 [ 0, %26 ], [ %51, %50 ]
%58 = phi double [ 0.000000e+00, %26 ], [ %52, %50 ]
%59 = phi double [ 0.000000e+00, %26 ], [ %53, %50 ]
%60 = uitofp i64 %27 to double
%61 = fdiv double %58, %60
%62 = fmul double %59, 3.276800e+04
%63 = uitofp i64 %57 to float
%64 = fmul float %63, 1.000000e+02
%65 = uitofp i64 %27 to float
%66 = fdiv float %64, %65
%67 = fptoui float %66 to i64
%68 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), double %61, double %62, i64 %67)
%69 = call i32 @free(float* %15)
%70 = call i32 @free(float* %18)
ret i32 0
}