#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*/ _mm_free(double *);
scalar_t__ _mm_malloc(int const, int);
int /*<<< orphan*/ dgemm(int const, int const, unsigned int const, double const,
                         double const *, int const, double const *, int const,
                         double const, double *, unsigned int const);
int /*<<< orphan*/ memcpy(double *, double *, int const);
double mysecond();
double time_dgemm(const int M, const int N, const unsigned K,
                  const double alpha, const double *A, const int lda,
                  const double *B, const int ldb, const double beta, double *C,
                  const unsigned ldc) {
  double mflops, mflop_s;
  double secs = -1;
  int num_iterations = 1;
  int i;
  double *Ca = (double *)_mm_malloc(N * ldc * sizeof(double), 32);
  double cpu_time = 0;
  double last_clock = mysecond();
  for (i = 0; i < num_iterations; ++i) {
    memcpy(Ca, C, N * ldc * sizeof(double));
    cpu_time -= mysecond();
    dgemm(M, N, K, alpha, A, lda, B, ldb, beta, Ca, ldc);
    cpu_time += mysecond();
  }
  mflops = 2.0 * num_iterations * M * N * K / 1.0e6;
  secs = cpu_time;
  mflop_s = mflops / secs;
  memcpy(C, Ca, N * ldc * sizeof(double));
  _mm_free(Ca);
  return mflop_s;
}


x86 assembly (clang, -O0):
<time_dgemm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movsd  %xmm1,-0x38(%rbp)
movsd  0xe74(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x8(%rbp),%eax
imul   0x20(%rbp),%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edi
mov    $0x20,%esi
call   1060 <_mm_malloc@plt>
mov    %rax,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    $0x0,%al
call   1030 <mysecond@plt>
movsd  %xmm0,-0x70(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    126b <time_dgemm+0x11b>
mov    -0x60(%rbp),%rdi
mov    0x18(%rbp),%rsi
mov    -0x8(%rbp),%eax
imul   0x20(%rbp),%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    $0x0,%al
call   1030 <mysecond@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x30(%rbp),%r9
mov    0x10(%rbp),%r11d
movsd  -0x38(%rbp),%xmm1
mov    -0x60(%rbp),%r10
mov    0x20(%rbp),%eax
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <dgemm@plt>
mov    $0x0,%al
call   1030 <mysecond@plt>
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11d0 <time_dgemm+0x80>
cvtsi2sdl -0x54(%rbp),%xmm0
addsd  %xmm0,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd6e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x18(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x8(%rbp),%eax
imul   0x20(%rbp),%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x60(%rbp),%rdi
call   1070 <_mm_free@plt>
movsd  -0x48(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_dgemm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,0x8(%rsp)
mov    %r9,0x30(%rsp)
mov    %r8d,0x14(%rsp)
mov    %rcx,0x28(%rsp)
movsd  %xmm0,0x20(%rsp)
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%r13d
mov    0x78(%rsp),%r14
mov    0x80(%rsp),%eax
mov    %esi,%ebp
imul   %eax,%ebp
shl    $0x3,%ebp
mov    %ebp,%edi
mov    $0x20,%esi
call   1060 <_mm_malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <mysecond@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
xor    %eax,%eax
call   1030 <mysecond@plt>
xorpd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
sub    $0x8,%rsp
mov    %r13d,%edi
mov    %r12d,%esi
mov    %r15d,%edx
movsd  0x28(%rsp),%xmm0
mov    0x30(%rsp),%rcx
mov    0x1c(%rsp),%r8d
mov    0x38(%rsp),%r9
movsd  0x10(%rsp),%xmm1
mov    0x88(%rsp),%eax
push   %rax
push   %rbx
mov    0x88(%rsp),%eax
push   %rax
call   1040 <dgemm@plt>
add    $0x20,%rsp
xor    %eax,%eax
call   1030 <mysecond@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r13d,%xmm1
addsd  0x18(%rsp),%xmm0
addsd  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm2
mulsd  %xmm1,%xmm2
mov    %r15d,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mulsd  %xmm2,%xmm1
divsd  0xdb7(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
call   1070 <_mm_free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @time_dgemm(i32 %0, i32 %1, i32 %2, double %3, double* %4, i32 %5, double* %6, i32 %7, double %8, double* %9, i32 %10) {
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double*
%17 = alloca i32
%18 = alloca double*
%19 = alloca i32
%20 = alloca double
%21 = alloca double*
%22 = alloca i32
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca i32
%27 = alloca i32
%28 = alloca double*
%29 = alloca double
%30 = alloca double
store i32 %0, i32* %12
store i32 %1, i32* %13
store i32 %2, i32* %14
store double %3, double* %15
store double* %4, double** %16
store i32 %5, i32* %17
store double* %6, double** %18
store i32 %7, i32* %19
store double %8, double* %20
store double* %9, double** %21
store i32 %10, i32* %22
store double -1.000000e+00, double* %25
store i32 1, i32* %26
%31 = load i32, i32* %13
%32 = load i32, i32* %22
%33 = mul i32 %31, %32
%34 = zext i32 %33 to i64
%35 = mul i64 %34, 8
%36 = trunc i64 %35 to i32
%37 = call i64 @_mm_malloc(i32 %36, i32 32)
%38 = inttoptr i64 %37 to double*
store double* %38, double** %28
store double 0.000000e+00, double* %29
%39 = call double (...) @mysecond()
store double %39, double* %30
store i32 0, i32* %27
br label %40
40: ; preds = %72, %11
%41 = load i32, i32* %27
%42 = load i32, i32* %26
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %75
44: ; preds = %40
%45 = load double*, double** %28
%46 = load double*, double** %21
%47 = load i32, i32* %13
%48 = load i32, i32* %22
%49 = mul i32 %47, %48
%50 = zext i32 %49 to i64
%51 = mul i64 %50, 8
%52 = trunc i64 %51 to i32
%53 = call i32 @memcpy(double* %45, double* %46, i32 %52)
%54 = call double (...) @mysecond()
%55 = load double, double* %29
%56 = fsub double %55, %54
store double %56, double* %29
%57 = load i32, i32* %12
%58 = load i32, i32* %13
%59 = load i32, i32* %14
%60 = load double, double* %15
%61 = load double*, double** %16
%62 = load i32, i32* %17
%63 = load double*, double** %18
%64 = load i32, i32* %19
%65 = load double, double* %20
%66 = load double*, double** %28
%67 = load i32, i32* %22
%68 = call i32 @dgemm(i32 %57, i32 %58, i32 %59, double %60, double* %61, i32 %62, double* %63, i32 %64, double %65, double* %66, i32 %67)
%69 = call double (...) @mysecond()
%70 = load double, double* %29
%71 = fadd double %70, %69
store double %71, double* %29
br label %72
72: ; preds = %44
%73 = load i32, i32* %27
%74 = add nsw i32 %73, 1
store i32 %74, i32* %27
br label %40
75: ; preds = %40
%76 = load i32, i32* %26
%77 = sitofp i32 %76 to double
%78 = fmul double 2.000000e+00, %77
%79 = load i32, i32* %12
%80 = sitofp i32 %79 to double
%81 = fmul double %78, %80
%82 = load i32, i32* %13
%83 = sitofp i32 %82 to double
%84 = fmul double %81, %83
%85 = load i32, i32* %14
%86 = uitofp i32 %85 to double
%87 = fmul double %84, %86
%88 = fdiv double %87, 1.000000e+06
store double %88, double* %23
%89 = load double, double* %29
store double %89, double* %25
%90 = load double, double* %23
%91 = load double, double* %25
%92 = fdiv double %90, %91
store double %92, double* %24
%93 = load double*, double** %21
%94 = load double*, double** %28
%95 = load i32, i32* %13
%96 = load i32, i32* %22
%97 = mul i32 %95, %96
%98 = zext i32 %97 to i64
%99 = mul i64 %98, 8
%100 = trunc i64 %99 to i32
%101 = call i32 @memcpy(double* %93, double* %94, i32 %100)
%102 = load double*, double** %28
%103 = call i32 @_mm_free(double* %102)
%104 = load double, double* %24
ret double %104
}

LLVM IR (-O2):
define double @time_dgemm(i32 %0, i32 %1, i32 %2, double %3, double* %4, i32 %5, double* %6, i32 %7, double %8, double* %9, i32 %10) {
%12 = shl i32 %1, 3
%13 = mul i32 %12, %10
%14 = tail call i64 @_mm_malloc(i32 %13, i32 32)
%15 = inttoptr i64 %14 to double*
%16 = tail call double (...) @mysecond()
%17 = tail call i32 @memcpy(double* %15, double* %9, i32 %13)
%18 = tail call double (...) @mysecond()
%19 = fsub double 0.000000e+00, %18
%20 = tail call i32 @dgemm(i32 %0, i32 %1, i32 %2, double %3, double* %4, i32 %5, double* %6, i32 %7, double %8, double* %15, i32 %10)
%21 = tail call double (...) @mysecond()
%22 = fadd double %19, %21
%23 = sitofp i32 %0 to double
%24 = fmul double %23, 2.000000e+00
%25 = sitofp i32 %1 to double
%26 = fmul double %24, %25
%27 = uitofp i32 %2 to double
%28 = fmul double %26, %27
%29 = fdiv double %28, 1.000000e+06
%30 = fdiv double %29, %22
%31 = tail call i32 @memcpy(double* %9, double* %15, i32 %13)
%32 = tail call i32 @_mm_free(double* %15)
ret double %30
}