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


x86 assembly (clang, -O0):
<bench_morpheus_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   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <get_time@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c9 <bench_morpheus_dcopy+0x79>
cvtsi2sdl -0x34(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x14(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <morpheus_dcopy@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118e <bench_morpheus_dcopy+0x3e>
mov    $0x0,%al
call   1050 <get_time@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rsi
movsd  -0x48(%rbp),%xmm0
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bench_morpheus_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   1060 <calloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <get_time@plt>
movsd  %xmm0,0x10(%rsp)
test   %r15d,%r15d
jle    11cb <bench_morpheus_dcopy+0x7b>
xorpd  %xmm0,%xmm0
mov    %r15d,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
movsd  %xmm0,(%rbx)
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1070 <morpheus_dcopy@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xe3a(%rip),%xmm0
add    $0xffffffff,%ebp
jne    11a0 <bench_morpheus_dcopy+0x50>
xor    %eax,%eax
call   1050 <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    0xe05(%rip),%rdi
mov    %r14,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str = [21 x i8] c"Benchmark %s: %f ms\0A\00"
define void @bench_morpheus_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 %16, label %9
9: ; preds = %16, %4
%10 = tail call double (...) @get_time()
%11 = tail call i32 @free(double* %6)
%12 = fsub double %10, %7
%13 = sitofp i32 %0 to double
%14 = fdiv double %12, %13
%15 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %1, double %14)
ret void
16: ; preds = %4, %16
%17 = phi i32 [ %20, %16 ], [ 0, %4 ]
%18 = sitofp i32 %17 to double
store double %18, double* %6
%19 = tail call i32 @morpheus_dcopy(i32 %5, double* %3, double* %6)
%20 = add nuw nsw i32 %17, 1
%21 = icmp eq i32 %20, %0
br i1 %21, label %9, label %16
}