#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 diff_buffer(int, double *, double *);
int /*<<< orphan*/ printf(char *, char *, ...);
void test_buffer_diff(int size, double *a, double *b, char *test_name) {
  double diff = diff_buffer(size, a, b);
  if (diff != 0.0) {
    printf("\n\nERROR in %s: diff = %f\n\n", test_name, diff);
  } else {
    printf("%s PASSED\n", test_name);
  }
}


x86 assembly (clang, -O0):
<test_buffer_diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <diff_buffer@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1169 <test_buffer_diff+0x49>
jp     1169 <test_buffer_diff+0x49>
jmp    1185 <test_buffer_diff+0x65>
mov    -0x20(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
lea    0xe87(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1197 <test_buffer_diff+0x77>
mov    -0x20(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_buffer_diff>:
push   %rbx
mov    %rcx,%rbx
call   1040 <diff_buffer@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1135 <test_buffer_diff+0x15>
jnp    1147 <test_buffer_diff+0x27>
lea    0xec4(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%al
pop    %rbx
jmp    1030 <printf@plt>
lea    0xecd(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"\0A\0AERROR in %s: diff = %f\0A\0A\00"
@.str.1 = [11 x i8] c"%s PASSED\0A\00"
define void @test_buffer_diff(i32 %0, double* %1, double* %2, i8* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca i8*
%9 = alloca double
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store i8* %3, i8** %8
%10 = load i32, i32* %5
%11 = load double*, double** %6
%12 = load double*, double** %7
%13 = call double @diff_buffer(i32 %10, double* %11, double* %12)
store double %13, double* %9
%14 = load double, double* %9
%15 = fcmp une double %14, 0.000000e+00
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i8*, i8** %8
%18 = load double, double* %9
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %17, double %18)
br label %23
20: ; preds = %4
%21 = load i8*, i8** %8
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %16
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"\0A\0AERROR in %s: diff = %f\0A\0A\00"
@.str.1 = [11 x i8] c"%s PASSED\0A\00"
define void @test_buffer_diff(i32 %0, double* %1, double* %2, i8* %3) {
%5 = tail call double @diff_buffer(i32 %0, double* %1, double* %2)
%6 = fcmp une double %5, 0.000000e+00
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %3, double %5)
br label %11
9: ; preds = %4
%10 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %11
11: ; preds = %9, %7
ret void
}