#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 */
typedef double uint64_t;
struct timespec {
  long tv_sec;
  double tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int atoi(char *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ dgemm2(double *, double *, double *, int, int);
int /*<<< orphan*/ printf(char *, float);
double rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int BLOCK_SIZE = atoi(argv[1]);
  int n = atoi(argv[2]);
  uint64_t t0;
  float t;
  struct timespec begin, end;
  double *a, *b;
  double *c0, *c1, *c2;
  double diff;
  int i;
  srand(time(NULL));
  a = (double *)calloc(sizeof(double), n * n);
  for (i = 0; i < n * n; i++) {
    a[i] = rand() / 1000000.0;
    a[i] = 1;
  }
  b = (double *)calloc(sizeof(double), n * n);
  for (i = 0; i < n * n; i++) {
    b[i] = rand() / 1000000.0;
    b[i] = 1;
  }
  c0 = (double *)calloc(sizeof(double), n * n);
  c1 = (double *)calloc(sizeof(double), n * n);
  c2 = (double *)calloc(sizeof(double), n * n);
  clock_gettime(CLOCK_MONOTONIC, &begin);
  dgemm2(a, b, c2, n, BLOCK_SIZE);
  clock_gettime(CLOCK_MONOTONIC, &end);
  t0 = 1000000000L * (end.tv_sec - begin.tv_sec) + end.tv_nsec - begin.tv_nsec;
  t = t0 / 1000000000.0;
  printf("%f\n", t);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    -0x18(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    -0x18(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    123a <main+0xba>
mov    $0x0,%al
call   10a0 <rand@plt>
movsd  0xe0a(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x50(%rbp),%rax
movslq -0x7c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
movslq -0x7c(%rbp),%rcx
movsd  0xde1(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    11e5 <main+0x65>
mov    -0x18(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    -0x18(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    12ab <main+0x12b>
mov    $0x0,%al
call   10a0 <rand@plt>
movsd  0xd99(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x58(%rbp),%rax
movslq -0x7c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x58(%rbp),%rax
movslq -0x7c(%rbp),%rcx
movsd  0xd70(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    1256 <main+0xd6>
mov    -0x18(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,-0x70(%rbp)
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1080 <dgemm2@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x48(%rbp),%rax
sub    -0x38(%rbp),%rax
imul   $0x3b9aca00,%rax,%rax
cvtsi2sd %rax,%xmm0
addsd  -0x40(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xcaa(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
lea    0xca9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    %ebp,%r12d
imul   %ebp,%r12d
mov    $0x8,%edi
mov    %r12d,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
test   %r12d,%r12d
je     123f <main+0xbf>
mov    %ebp,(%rsp)
mov    %r14d,0x4(%rsp)
mov    %r12d,%ebp
movabs $0x3ff0000000000000,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %r14,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11f0 <main+0x70>
mov    $0x8,%edi
mov    %r12d,%esi
call   1060 <calloc@plt>
mov    %rax,%r13
test   %r12d,%r12d
je     1235 <main+0xb5>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %r14,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1220 <main+0xa0>
mov    0x4(%rsp),%r14d
mov    (%rsp),%ebp
jmp    124f <main+0xcf>
mov    $0x8,%edi
mov    %r12d,%esi
call   1060 <calloc@plt>
mov    %rax,%r13
mov    $0x8,%edi
mov    %r12d,%esi
call   1060 <calloc@plt>
mov    $0x8,%edi
mov    %r12d,%esi
call   1060 <calloc@plt>
mov    $0x8,%edi
mov    %r12d,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
mov    0x2d68(%rip),%rbx
mov    (%rbx),%edi
lea    0x18(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
mov    %r14d,%r8d
call   1080 <dgemm2@plt>
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    0x8(%rsp),%rax
sub    0x18(%rsp),%rax
imul   $0x3b9aca00,%rax,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x10(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
divsd  0xd28(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xd25(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, double }
@CLOCK_MONOTONIC = global i32 0
@.str = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca float
%10 = alloca %struct.timespec
%11 = alloca %struct.timespec
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double*
%17 = alloca double
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %7
%27 = call i32 @time(i32* null)
%28 = call i32 @srand(i32 %27)
%29 = load i32, i32* %7
%30 = load i32, i32* %7
%31 = mul nsw i32 %29, %30
%32 = call i64 @calloc(i32 8, i32 %31)
%33 = inttoptr i64 %32 to double*
store double* %33, double** %12
store i32 0, i32* %18
br label %34
34: ; preds = %51, %2
%35 = load i32, i32* %18
%36 = load i32, i32* %7
%37 = load i32, i32* %7
%38 = mul nsw i32 %36, %37
%39 = icmp slt i32 %35, %38
br i1 %39, label %40, label %54
40: ; preds = %34
%41 = call double (...) @rand()
%42 = fdiv double %41, 1.000000e+06
%43 = load double*, double** %12
%44 = load i32, i32* %18
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
store double %42, double* %46
%47 = load double*, double** %12
%48 = load i32, i32* %18
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
store double 1.000000e+00, double* %50
br label %51
51: ; preds = %40
%52 = load i32, i32* %18
%53 = add nsw i32 %52, 1
store i32 %53, i32* %18
br label %34
54: ; preds = %34
%55 = load i32, i32* %7
%56 = load i32, i32* %7
%57 = mul nsw i32 %55, %56
%58 = call i64 @calloc(i32 8, i32 %57)
%59 = inttoptr i64 %58 to double*
store double* %59, double** %13
store i32 0, i32* %18
br label %60
60: ; preds = %77, %54
%61 = load i32, i32* %18
%62 = load i32, i32* %7
%63 = load i32, i32* %7
%64 = mul nsw i32 %62, %63
%65 = icmp slt i32 %61, %64
br i1 %65, label %66, label %80
66: ; preds = %60
%67 = call double (...) @rand()
%68 = fdiv double %67, 1.000000e+06
%69 = load double*, double** %13
%70 = load i32, i32* %18
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
store double %68, double* %72
%73 = load double*, double** %13
%74 = load i32, i32* %18
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
store double 1.000000e+00, double* %76
br label %77
77: ; preds = %66
%78 = load i32, i32* %18
%79 = add nsw i32 %78, 1
store i32 %79, i32* %18
br label %60
80: ; preds = %60
%81 = load i32, i32* %7
%82 = load i32, i32* %7
%83 = mul nsw i32 %81, %82
%84 = call i64 @calloc(i32 8, i32 %83)
%85 = inttoptr i64 %84 to double*
store double* %85, double** %14
%86 = load i32, i32* %7
%87 = load i32, i32* %7
%88 = mul nsw i32 %86, %87
%89 = call i64 @calloc(i32 8, i32 %88)
%90 = inttoptr i64 %89 to double*
store double* %90, double** %15
%91 = load i32, i32* %7
%92 = load i32, i32* %7
%93 = mul nsw i32 %91, %92
%94 = call i64 @calloc(i32 8, i32 %93)
%95 = inttoptr i64 %94 to double*
store double* %95, double** %16
%96 = load i32, i32* @CLOCK_MONOTONIC
%97 = call i32 @clock_gettime(i32 %96, %struct.timespec* %10)
%98 = load double*, double** %12
%99 = load double*, double** %13
%100 = load double*, double** %16
%101 = load i32, i32* %7
%102 = load i32, i32* %6
%103 = call i32 @dgemm2(double* %98, double* %99, double* %100, i32 %101, i32 %102)
%104 = load i32, i32* @CLOCK_MONOTONIC
%105 = call i32 @clock_gettime(i32 %104, %struct.timespec* %11)
%106 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
%107 = load i64, i64* %106
%108 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%109 = load i64, i64* %108
%110 = sub nsw i64 %107, %109
%111 = mul nsw i64 1000000000, %110
%112 = sitofp i64 %111 to double
%113 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 1
%114 = load double, double* %113
%115 = fadd double %112, %114
%116 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 1
%117 = load double, double* %116
%118 = fsub double %115, %117
store double %118, double* %8
%119 = load double, double* %8
%120 = fdiv double %119, 1.000000e+09
%121 = fptrunc double %120 to float
store float %121, float* %9
%122 = load float, float* %9
%123 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), float %122)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i64, double }
@CLOCK_MONOTONIC = global i32 0
@.str = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = bitcast %struct.timespec* %3 to i8*
%12 = bitcast %struct.timespec* %4 to i8*
%13 = tail call i32 @time(i32* null)
%14 = tail call i32 @srand(i32 %13)
%15 = mul nsw i32 %10, %10
%16 = tail call i64 @calloc(i32 8, i32 %15)
%17 = inttoptr i64 %16 to double*
%18 = icmp eq i32 %15, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = tail call i64 @calloc(i32 8, i32 %15)
%21 = inttoptr i64 %20 to double*
br label %41
22: ; preds = %2
%23 = zext i32 %15 to i64
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ 0, %22 ], [ %28, %24 ]
%26 = tail call double (...) @rand()
%27 = getelementptr inbounds double, double* %17, i64 %25
store double 1.000000e+00, double* %27
%28 = add nuw nsw i64 %25, 1
%29 = icmp eq i64 %28, %23
br i1 %29, label %30, label %24
30: ; preds = %24
%31 = tail call i64 @calloc(i32 8, i32 %15)
%32 = inttoptr i64 %31 to double*
br i1 %18, label %41, label %33
33: ; preds = %30
%34 = zext i32 %15 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %39, %35 ]
%37 = tail call double (...) @rand()
%38 = getelementptr inbounds double, double* %32, i64 %36
store double 1.000000e+00, double* %38
%39 = add nuw nsw i64 %36, 1
%40 = icmp eq i64 %39, %34
br i1 %40, label %41, label %35
41: ; preds = %35, %19, %30
%42 = phi double* [ %21, %19 ], [ %32, %30 ], [ %32, %35 ]
%43 = tail call i64 @calloc(i32 8, i32 %15)
%44 = tail call i64 @calloc(i32 8, i32 %15)
%45 = tail call i64 @calloc(i32 8, i32 %15)
%46 = inttoptr i64 %45 to double*
%47 = load i32, i32* @CLOCK_MONOTONIC
%48 = call i32 @clock_gettime(i32 %47, %struct.timespec* %3)
%49 = call i32 @dgemm2(double* %17, double* %42, double* %46, i32 %10, i32 %7)
%50 = load i32, i32* @CLOCK_MONOTONIC
%51 = call i32 @clock_gettime(i32 %50, %struct.timespec* %4)
%52 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%53 = load i64, i64* %52
%54 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%55 = load i64, i64* %54
%56 = sub nsw i64 %53, %55
%57 = mul nsw i64 %56, 1000000000
%58 = sitofp i64 %57 to double
%59 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%60 = load double, double* %59
%61 = fadd double %60, %58
%62 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%63 = load double, double* %62
%64 = fsub double %61, %63
%65 = fdiv double %64, 1.000000e+09
%66 = fptrunc double %65 to float
%67 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), float %66)
ret i32 0
}