#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 *calloc(int, int);
int /*<<< orphan*/ free(double *);
double get_time();
int /*<<< orphan*/ manual_dcopy(int, double *, double *);
int /*<<< orphan*/ printf(char *, char const *, double, double);
void bench_manual_dcopy(int n, const char *message, int size, double *x) {
  double *y = calloc(size * size, sizeof(double));
  double k = 0;
  double start = get_time();
  for (int i = 0; i < n; ++i) {
    k += y[0];
    manual_dcopy(size * size, x, y);
  }
  double finish = get_time();
  free(y);
  double ms = (finish - start) / n;
  printf("Benchmark %s: %f ms (_hack: %5.2f)\n", message, ms, k);
}


x86 assembly (clang, -O0):
<bench_manual_dcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1060 <get_time@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d6 <bench_manual_dcopy+0x86>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <manual_dcopy@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1196 <bench_manual_dcopy+0x46>
mov    $0x0,%al
call   1060 <get_time@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x48(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rsi
movsd  -0x50(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bench_manual_dcopy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %edx,%r13d
mov    %rsi,%r14
mov    %edi,%r15d
imul   %edx,%r13d
mov    %r13d,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <get_time@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
test   %r15d,%r15d
jle    11c3 <bench_manual_dcopy+0x73>
movsd  %xmm0,(%rsp)
mov    %r15d,%ebp
nopl   0x0(%rax)
movsd  (%rsp),%xmm0
addsd  (%rbx),%xmm0
movsd  %xmm0,(%rsp)
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <manual_dcopy@plt>
add    $0xffffffff,%ebp
jne    11a0 <bench_manual_dcopy+0x50>
jmp    11c8 <bench_manual_dcopy+0x78>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1060 <get_time@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm1
subsd  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
lea    0xe00(%rip),%rdi
mov    %r14,%rsi
movsd  (%rsp),%xmm1
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Benchmark %s: %f ms (_hack: %5.2f)\0A\00"
define void @bench_manual_dcopy(i32 %0, i8* %1, i32 %2, double* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store double* %3, double** %8
%15 = load i32, i32* %7
%16 = load i32, i32* %7
%17 = mul nsw i32 %15, %16
%18 = call double* @calloc(i32 %17, i32 8)
store double* %18, double** %9
store double 0.000000e+00, double* %10
%19 = call double (...) @get_time()
store double %19, double* %11
store i32 0, i32* %12
br label %20
20: ; preds = %36, %4
%21 = load i32, i32* %12
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load double*, double** %9
%26 = getelementptr inbounds double, double* %25, i64 0
%27 = load double, double* %26
%28 = load double, double* %10
%29 = fadd double %28, %27
store double %29, double* %10
%30 = load i32, i32* %7
%31 = load i32, i32* %7
%32 = mul nsw i32 %30, %31
%33 = load double*, double** %8
%34 = load double*, double** %9
%35 = call i32 @manual_dcopy(i32 %32, double* %33, double* %34)
br label %36
36: ; preds = %24
%37 = load i32, i32* %12
%38 = add nsw i32 %37, 1
store i32 %38, i32* %12
br label %20
39: ; preds = %20
%40 = call double (...) @get_time()
store double %40, double* %13
%41 = load double*, double** %9
%42 = call i32 @free(double* %41)
%43 = load double, double* %13
%44 = load double, double* %11
%45 = fsub double %43, %44
%46 = load i32, i32* %5
%47 = sitofp i32 %46 to double
%48 = fdiv double %45, %47
store double %48, double* %14
%49 = load i8*, i8** %6
%50 = load double, double* %14
%51 = load double, double* %10
%52 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %49, double %50, double %51)
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"Benchmark %s: %f ms (_hack: %5.2f)\0A\00"
define void @bench_manual_dcopy(i32 %0, i8* %1, i32 %2, double* %3) {
%5 = mul nsw i32 %2, %2
%6 = tail call double* @calloc(i32 %5, i32 8)
%7 = tail call double (...) @get_time()
%8 = icmp sgt i32 %0, 0
br i1 %8, label %17, label %9
9: ; preds = %17, %4
%10 = phi double [ 0.000000e+00, %4 ], [ %21, %17 ]
%11 = tail call double (...) @get_time()
%12 = tail call i32 @free(double* %6)
%13 = fsub double %11, %7
%14 = sitofp i32 %0 to double
%15 = fdiv double %13, %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %1, double %15, double %10)
ret void
17: ; preds = %4, %17
%18 = phi double [ %21, %17 ], [ 0.000000e+00, %4 ]
%19 = phi i32 [ %23, %17 ], [ 0, %4 ]
%20 = load double, double* %6
%21 = fadd double %18, %20
%22 = tail call i32 @manual_dcopy(i32 %5, double* %3, double* %6)
%23 = add nuw nsw i32 %19, 1
%24 = icmp eq i32 %23, %0
br i1 %24, label %9, label %17
}