#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*/ adrand(double *, size_t);
int /*<<< orphan*/ assert(int);
double drand48();
int fabs(double);
double filter1(double *, double *, size_t);
double filter2(double *, double *, size_t, size_t);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ sample1(double *, size_t, double);
int /*<<< orphan*/ sample2(double *, size_t, double, size_t *);
double *xcalloc(size_t, int);
void test(size_t n) {
  double *a, *x1, *x2, v1, v2, r;
  size_t i, l, xp;
  a = xcalloc(n, sizeof(*a));
  x1 = xcalloc(n, sizeof(*x1));
  x2 = xcalloc(n, sizeof(*x2));
  xp = 0;
  adrand(a, n);
  l = n * 100;
  for (i = 0; i < l; i++) {
    r = drand48();
    sample1(x1, n, r);
    sample2(x2, n, r, &xp);
    v1 = filter1(x1, a, n);
    v2 = filter2(x2, a, n, xp);
    assert(fabs(v2 - v1) < 1e-6);
  }
  free(a);
  free(x1);
  free(x2);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <xcalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <xcalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <xcalloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <adrand@plt>
imul   $0x64,-0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    12b7 <test+0x117>
mov    $0x0,%al
call   10c0 <drand48@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsd  -0x38(%rbp),%xmm0
call   1050 <sample1@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsd  -0x38(%rbp),%xmm0
lea    -0x50(%rbp),%rdx
call   10a0 <sample2@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1090 <filter1@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x50(%rbp),%rcx
call   1040 <filter2@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
call   1060 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd6b(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1208 <test+0x68>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    $0x8,%esi
call   10b0 <xcalloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x8,%esi
call   10b0 <xcalloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x8,%esi
call   10b0 <xcalloc@plt>
mov    %rax,%r12
movq   $0x0,0x10(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <adrand@plt>
imul   $0x64,%rbx,%rbp
test   %rbp,%rbp
je     1271 <test+0xd1>
lea    0x10(%rsp),%r13
xor    %eax,%eax
call   10c0 <drand48@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <sample1@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
movsd  0x8(%rsp),%xmm0
mov    %r13,%rdx
call   10a0 <sample2@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1090 <filter1@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x10(%rsp),%rcx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <filter2@plt>
subsd  0x8(%rsp),%xmm0
call   1060 <fabs@plt>
xor    %edi,%edi
test   %eax,%eax
setle  %dil
call   1080 <assert@plt>
add    $0xffffffffffffffff,%rbp
jne    1200 <test+0x60>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @test(i64 %0) {
%2 = alloca i64
%3 = alloca double*
%4 = alloca double*
%5 = alloca double*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i64 %0, i64* %2
%12 = load i64, i64* %2
%13 = call double* @xcalloc(i64 %12, i32 8)
store double* %13, double** %3
%14 = load i64, i64* %2
%15 = call double* @xcalloc(i64 %14, i32 8)
store double* %15, double** %4
%16 = load i64, i64* %2
%17 = call double* @xcalloc(i64 %16, i32 8)
store double* %17, double** %5
store i64 0, i64* %11
%18 = load double*, double** %3
%19 = load i64, i64* %2
%20 = call i32 @adrand(double* %18, i64 %19)
%21 = load i64, i64* %2
%22 = mul i64 %21, 100
store i64 %22, i64* %10
store i64 0, i64* %9
br label %23
23: ; preds = %54, %1
%24 = load i64, i64* %9
%25 = load i64, i64* %10
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %57
27: ; preds = %23
%28 = call double (...) @drand48()
store double %28, double* %8
%29 = load double*, double** %4
%30 = load i64, i64* %2
%31 = load double, double* %8
%32 = call i32 @sample1(double* %29, i64 %30, double %31)
%33 = load double*, double** %5
%34 = load i64, i64* %2
%35 = load double, double* %8
%36 = call i32 @sample2(double* %33, i64 %34, double %35, i64* %11)
%37 = load double*, double** %4
%38 = load double*, double** %3
%39 = load i64, i64* %2
%40 = call double @filter1(double* %37, double* %38, i64 %39)
store double %40, double* %6
%41 = load double*, double** %5
%42 = load double*, double** %3
%43 = load i64, i64* %2
%44 = load i64, i64* %11
%45 = call double @filter2(double* %41, double* %42, i64 %43, i64 %44)
store double %45, double* %7
%46 = load double, double* %7
%47 = load double, double* %6
%48 = fsub double %46, %47
%49 = call i32 @fabs(double %48)
%50 = sitofp i32 %49 to double
%51 = fcmp olt double %50, 0x3EB0C6F7A0B5ED8D
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
br label %54
54: ; preds = %27
%55 = load i64, i64* %9
%56 = add i64 %55, 1
store i64 %56, i64* %9
br label %23
57: ; preds = %23
%58 = load double*, double** %3
%59 = call i32 @free(double* %58)
%60 = load double*, double** %4
%61 = call i32 @free(double* %60)
%62 = load double*, double** %5
%63 = call i32 @free(double* %62)
ret void
}

LLVM IR (-O2):
define void @test(i64 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = tail call double* @xcalloc(i64 %0, i32 8)
%5 = tail call double* @xcalloc(i64 %0, i32 8)
%6 = tail call double* @xcalloc(i64 %0, i32 8)
store i64 0, i64* %2
%7 = tail call i32 @adrand(double* %4, i64 %0)
%8 = mul i64 %0, 100
%9 = icmp eq i64 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %1, %10
%11 = phi i64 [ %23, %10 ], [ 0, %1 ]
%12 = call double (...) @drand48()
%13 = call i32 @sample1(double* %5, i64 %0, double %12)
%14 = call i32 @sample2(double* %6, i64 %0, double %12, i64* %2)
%15 = call double @filter1(double* %5, double* %4, i64 %0)
%16 = load i64, i64* %2
%17 = call double @filter2(double* %6, double* %4, i64 %0, i64 %16)
%18 = fsub double %17, %15
%19 = call i32 @fabs(double %18)
%20 = icmp slt i32 %19, 1
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = add nuw i64 %11, 1
%24 = icmp eq i64 %23, %8
br i1 %24, label %25, label %10
25: ; preds = %10, %1
%26 = call i32 @free(double* %4)
%27 = call i32 @free(double* %5)
%28 = call i32 @free(double* %6)
ret void
}