#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_sigmoid(int, double *, double *);
int /*<<< orphan*/ printf(char *, char const *, double);
void bench_sigmoid(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) {
    morpheus_sigmoid(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_sigmoid>:
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    11bc <bench_sigmoid+0x6c>
mov    -0x14(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <morpheus_sigmoid@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118e <bench_sigmoid+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    0xe07(%rip),%rdi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bench_sigmoid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%r15d
imul   %edx,%ebp
mov    %ebp,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1050 <get_time@plt>
movsd  %xmm0,0x10(%rsp)
test   %r15d,%r15d
jle    11a2 <bench_sigmoid+0x52>
mov    %r15d,%ebx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <morpheus_sigmoid@plt>
add    $0xffffffff,%ebx
jne    1190 <bench_sigmoid+0x40>
xor    %eax,%eax
call   1050 <get_time@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r13,%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    0xe26(%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_sigmoid(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 = %30, %4
%20 = load i32, i32* %11
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32, i32* %7
%25 = load i32, i32* %7
%26 = mul nsw i32 %24, %25
%27 = load double*, double** %8
%28 = load double*, double** %9
%29 = call i32 @morpheus_sigmoid(i32 %26, double* %27, double* %28)
br label %30
30: ; preds = %23
%31 = load i32, i32* %11
%32 = add nsw i32 %31, 1
store i32 %32, i32* %11
br label %19
33: ; preds = %19
%34 = call double (...) @get_time()
store double %34, double* %12
%35 = load double*, double** %9
%36 = call i32 @free(double* %35)
%37 = load double, double* %12
%38 = load double, double* %10
%39 = fsub double %37, %38
%40 = load i32, i32* %5
%41 = sitofp i32 %40 to double
%42 = fdiv double %39, %41
store double %42, double* %13
%43 = load i8*, i8** %6
%44 = load double, double* %13
%45 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %43, double %44)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"Benchmark %s: %f ms\0A\00"
define void @bench_sigmoid(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 [ %19, %16 ], [ 0, %4 ]
%18 = tail call i32 @morpheus_sigmoid(i32 %5, double* %3, double* %6)
%19 = add nuw nsw i32 %17, 1
%20 = icmp eq i32 %19, %0
br i1 %20, label %9, label %16
}