#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 atoi(char *);
double drand48();
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ matmat(int, double *, double *, double *);
int omp_get_max_threads();
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, int, int, double);
int main(int argc, char **argv) {
  int i, j, n = 50;
  double *A, *B, *C, time;
  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();
    }
  }
  time = omp_get_wtime();
  matmat(n, A, B, C);
  time = omp_get_wtime() - time;
  printf("%d;%d;%f\n", omp_get_max_threads(), n, time);
  free(A);
  free(B);
  free(C);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x32,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11cc <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11c7 <main+0x47>
movl   $0x32,-0x1c(%rbp)
jmp    11cc <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    1299 <main+0x119>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1286 <main+0x106>
mov    $0x0,%al
call   10a0 <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   10a0 <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    122e <main+0xae>
jmp    128b <main+0x10b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121b <main+0x9b>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
call   1090 <matmat@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1070 <omp_get_max_threads@plt>
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
movsd  -0x40(%rbp),%xmm0
lea    0xd1e(%rip),%rdi
call   1050 <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    $0x40,%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    $0x32,%ebx
cmp    $0x2,%edi
jne    11ab <main+0x2b>
mov    0x8(%rsi),%rdi
call   1080 <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     1248 <main+0xc8>
mov    0xc(%rsp),%ebp
lea    0x0(,%rbp,8),%rbx
mov    0x10(%rsp),%r15
mov    0x18(%rsp),%r14
xor    %r12d,%r12d
mov    %rbp,(%rsp)
nopl   0x0(%rax)
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   10a0 <drand48@plt>
movsd  %xmm0,(%r14,%r13,1)
xor    %eax,%eax
call   10a0 <drand48@plt>
movsd  %xmm0,(%r15,%r13,1)
add    %rbx,%r13
add    $0xffffffffffffffff,%rbp
jne    1210 <main+0x90>
add    $0x1,%r12
add    $0x8,%r14
add    $0x8,%r15
mov    (%rsp),%rbp
cmp    %rbp,%r12
jne    1200 <main+0x80>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,(%rsp)
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
mov    0x18(%rsp),%rbp
mov    %rbp,%rsi
mov    0x10(%rsp),%r14
mov    %r14,%rdx
mov    0x20(%rsp),%r15
mov    %r15,%rcx
call   1090 <matmat@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1070 <omp_get_max_threads@plt>
lea    0xd6a(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
movsd  (%rsp),%xmm0
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"%d;%d;%f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp slt i32 %7, 0
%9 = select i1 %8, i32 50, i32 %7
br label %10
10: ; preds = %4, %2
%11 = phi i32 [ 50, %2 ], [ %9, %4 ]
%12 = shl i32 %11, 3
%13 = mul i32 %12, %11
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to double*
%16 = tail call i64 @malloc(i32 %13)
%17 = inttoptr i64 %16 to double*
%18 = tail call i64 @malloc(i32 %13)
%19 = inttoptr i64 %18 to double*
%20 = icmp eq i32 %11, 0
br i1 %20, label %39, label %21
21: ; preds = %10
%22 = zext i32 %11 to i64
%23 = zext i32 %11 to i64
br label %24
24: ; preds = %36, %21
%25 = phi i64 [ 0, %21 ], [ %37, %36 ]
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %34, %26 ]
%28 = tail call double (...) @drand48()
%29 = mul nsw i64 %27, %22
%30 = add nuw nsw i64 %29, %25
%31 = getelementptr inbounds double, double* %15, i64 %30
store double %28, double* %31
%32 = tail call double (...) @drand48()
%33 = getelementptr inbounds double, double* %17, i64 %30
store double %32, double* %33
%34 = add nuw nsw i64 %27, 1
%35 = icmp eq i64 %34, %23
br i1 %35, label %36, label %26
36: ; preds = %26
%37 = add nuw nsw i64 %25, 1
%38 = icmp eq i64 %37, %23
br i1 %38, label %39, label %24
39: ; preds = %36, %10
%40 = tail call double (...) @omp_get_wtime()
%41 = tail call i32 @matmat(i32 %11, double* %15, double* %17, double* %19)
%42 = tail call double (...) @omp_get_wtime()
%43 = fsub double %42, %40
%44 = tail call i32 (...) @omp_get_max_threads()
%45 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %44, i32 %11, double %43)
%46 = tail call i32 @free(double* %15)
%47 = tail call i32 @free(double* %17)
%48 = tail call i32 @free(double* %19)
ret i32 0
}