#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 */
struct timeval {
  double tv_sec;
  double tv_usec;
};

/* Variables and functions */
int atoi(char *);
double drand48();
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ matmat(int, double *, double *, double *);
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char **argv) {
  int i, j, n = 50;
  double *A, *B, *C, time;
  struct timeval t0, t1;
  if (argc == 2) {
    if ((n = atoi(argv[1])) < 0)
      n = 50;
  }
  A = (double *)malloc(n * n * sizeof(double));
  B = (double *)malloc(n * n * sizeof(double));
  C = (double *)malloc(n * n * sizeof(double));
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      A[i + n * j] = drand48();
      B[i + n * j] = drand48();
    }
  }
  gettimeofday(&t0, NULL);
  matmat(n, A, B, C);
  gettimeofday(&t1, NULL);
  printf("1;%f\n",
         (t1.tv_sec - t0.tv_sec) + (t1.tv_usec - t0.tv_usec) / 1000000.0);
  free(A);
  free(B);
  free(C);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x32,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11bc <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11b7 <main+0x47>
movl   $0x32,-0x1c(%rbp)
jmp    11bc <main+0x4c>
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1289 <main+0x119>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1276 <main+0x106>
mov    $0x0,%al
call   1090 <drand48@plt>
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%edx
imul   -0x18(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   1090 <drand48@plt>
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%edx
imul   -0x18(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    121e <main+0xae>
jmp    127b <main+0x10b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    120b <main+0x9b>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
call   1080 <matmat@plt>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x60(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
subsd  -0x48(%rbp),%xmm1
movsd  0xd2d(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
lea    0xd26(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    $0x32,%ebx
cmp    $0x2,%edi
jne    119b <main+0x2b>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
mov    $0x32,%ebx
cmovns %eax,%ebx
mov    %ebx,%ebp
imul   %ebx,%ebp
shl    $0x3,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    %ebx,0xc(%rsp)
test   %ebx,%ebx
je     1239 <main+0xc9>
mov    0xc(%rsp),%ebp
lea    0x0(,%rbp,8),%rbx
mov    0x10(%rsp),%r12
mov    0x18(%rsp),%r14
xor    %r15d,%r15d
mov    %rbp,0x28(%rsp)
nopl   (%rax)
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1090 <drand48@plt>
movsd  %xmm0,(%r14,%r13,1)
xor    %eax,%eax
call   1090 <drand48@plt>
movsd  %xmm0,(%r12,%r13,1)
add    %rbx,%r13
add    $0xffffffffffffffff,%rbp
jne    1200 <main+0x90>
add    $0x1,%r15
add    $0x8,%r14
add    $0x8,%r12
mov    0x28(%rsp),%rbp
cmp    %rbp,%r15
jne    11f0 <main+0x80>
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0xc(%rsp),%edi
mov    0x18(%rsp),%rbx
mov    %rbx,%rsi
mov    0x10(%rsp),%rbp
mov    %rbp,%rdx
mov    0x20(%rsp),%r14
mov    %r14,%rcx
call   1080 <matmat@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movapd 0x30(%rsp),%xmm1
subpd  0x40(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0xd72(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xd6f(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [6 x i8] c"1;%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 i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double
%13 = alloca %struct.timeval
%14 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 50, i32* %8
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 50, i32* %8
br label %24
24: ; preds = %23, %17
br label %25
25: ; preds = %24, %2
%26 = load i32, i32* %8
%27 = load i32, i32* %8
%28 = mul nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to double*
store double* %33, double** %9
%34 = load i32, i32* %8
%35 = load i32, i32* %8
%36 = mul nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 8
%39 = trunc i64 %38 to i32
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to double*
store double* %41, double** %10
%42 = load i32, i32* %8
%43 = load i32, i32* %8
%44 = mul nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 8
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to double*
store double* %49, double** %11
store i32 0, i32* %6
br label %50
50: ; preds = %82, %25
%51 = load i32, i32* %6
%52 = load i32, i32* %8
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %85
54: ; preds = %50
store i32 0, i32* %7
br label %55
55: ; preds = %78, %54
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %81
59: ; preds = %55
%60 = call double (...) @drand48()
%61 = load double*, double** %9
%62 = load i32, i32* %6
%63 = load i32, i32* %8
%64 = load i32, i32* %7
%65 = mul nsw i32 %63, %64
%66 = add nsw i32 %62, %65
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %61, i64 %67
store double %60, double* %68
%69 = call double (...) @drand48()
%70 = load double*, double** %10
%71 = load i32, i32* %6
%72 = load i32, i32* %8
%73 = load i32, i32* %7
%74 = mul nsw i32 %72, %73
%75 = add nsw i32 %71, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %70, i64 %76
store double %69, double* %77
br label %78
78: ; preds = %59
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
br label %55
81: ; preds = %55
br label %82
82: ; preds = %81
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %50
85: ; preds = %50
%86 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%87 = load i32, i32* %8
%88 = load double*, double** %9
%89 = load double*, double** %10
%90 = load double*, double** %11
%91 = call i32 @matmat(i32 %87, double* %88, double* %89, double* %90)
%92 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%93 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%94 = load double, double* %93
%95 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%96 = load double, double* %95
%97 = fsub double %94, %96
%98 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%99 = load double, double* %98
%100 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%101 = load double, double* %100
%102 = fsub double %99, %101
%103 = fdiv double %102, 1.000000e+06
%104 = fadd double %97, %103
%105 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %104)
%106 = load double*, double** %9
%107 = call i32 @free(double* %106)
%108 = load double*, double** %10
%109 = call i32 @free(double* %108)
%110 = load double*, double** %11
%111 = call i32 @free(double* %110)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [6 x i8] c"1;%f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca <2 x double>
%4 = alloca <2 x double>
%5 = bitcast <2 x double>* %3 to i8*
%6 = bitcast <2 x double>* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp slt i32 %11, 0
%13 = select i1 %12, i32 50, i32 %11
br label %14
14: ; preds = %8, %2
%15 = phi i32 [ 50, %2 ], [ %13, %8 ]
%16 = shl i32 %15, 3
%17 = mul i32 %16, %15
%18 = tail call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
%20 = tail call i64 @malloc(i32 %17)
%21 = inttoptr i64 %20 to double*
%22 = tail call i64 @malloc(i32 %17)
%23 = inttoptr i64 %22 to double*
%24 = icmp eq i32 %15, 0
br i1 %24, label %43, label %25
25: ; preds = %14
%26 = zext i32 %15 to i64
%27 = zext i32 %15 to i64
br label %28
28: ; preds = %40, %25
%29 = phi i64 [ 0, %25 ], [ %41, %40 ]
br label %30
30: ; preds = %28, %30
%31 = phi i64 [ 0, %28 ], [ %38, %30 ]
%32 = tail call double (...) @drand48()
%33 = mul nsw i64 %31, %26
%34 = add nuw nsw i64 %33, %29
%35 = getelementptr inbounds double, double* %19, i64 %34
store double %32, double* %35
%36 = tail call double (...) @drand48()
%37 = getelementptr inbounds double, double* %21, i64 %34
store double %36, double* %37
%38 = add nuw nsw i64 %31, 1
%39 = icmp eq i64 %38, %27
br i1 %39, label %40, label %30
40: ; preds = %30
%41 = add nuw nsw i64 %29, 1
%42 = icmp eq i64 %41, %27
br i1 %42, label %43, label %28
43: ; preds = %40, %14
%44 = bitcast <2 x double>* %3 to %struct.timeval*
%45 = bitcast <2 x double>* %4 to %struct.timeval*
%46 = call i32 @gettimeofday(%struct.timeval* %44, i32* null)
%47 = tail call i32 @matmat(i32 %15, double* %19, double* %21, double* %23)
%48 = call i32 @gettimeofday(%struct.timeval* %45, i32* null)
%49 = load <2 x double>, <2 x double>* %4
%50 = load <2 x double>, <2 x double>* %3
%51 = fsub <2 x double> %49, %50
%52 = extractelement <2 x double> %51, i64 1
%53 = fdiv double %52, 1.000000e+06
%54 = extractelement <2 x double> %51, i64 0
%55 = fadd double %54, %53
%56 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %55)
%57 = tail call i32 @free(double* %19)
%58 = tail call i32 @free(double* %21)
%59 = tail call i32 @free(double* %23)
ret i32 0
}