#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*/ free(int *);
int getMaxError(int *, int *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ matrixMulMp(int *, int *, int *, int, int, int);
int /*<<< orphan*/ matrixMulSeq(int *, int *, int *, int, int, int);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ testRand(int *, int *, int, int, int, int);
int main(int argc, char *argv[]) {
  int n = 1000, m = 1000, l = 1000;
  int *A = (int *)malloc(n * l * sizeof(int));
  int *B = (int *)malloc(l * m * sizeof(int));
  int *C = (int *)malloc(n * m * sizeof(int));
  int *Cseq = (int *)malloc(n * m * sizeof(int));
  double _begin, _end;
  _begin = omp_get_wtime();
  (testRand(A, B, n, m, l, 50));
  _end = omp_get_wtime();
  printf("%s done in %f\n", ("Init"), _end - _begin);
  ;
  _begin = omp_get_wtime();
  (matrixMulSeq(A, B, Cseq, n, m, l));
  _end = omp_get_wtime();
  printf("%s done in %f\n", ("Seq "), _end - _begin);
  ;
  _begin = omp_get_wtime();
  (matrixMulMp(A, B, C, n, m, l));
  _end = omp_get_wtime();
  printf("%s done in %f\n", ("MP  "), _end - _begin);
  ;
  printf("Max error: %d\n", getMaxError(C, Cseq, n, m));
  free(A);
  free(B);
  free(C);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
movl   $0x3e8,-0x18(%rbp)
movl   $0x3e8,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    $0x32,%r9d
call   10a0 <testRand@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
lea    0xdaf(%rip),%rdi
lea    0xdb7(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
call   1090 <matrixMulSeq@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
lea    0xd5c(%rip),%rdi
lea    0xd69(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
call   1080 <matrixMulMp@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
lea    0xd09(%rip),%rdi
lea    0xd1b(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1060 <getMaxError@plt>
mov    %eax,%esi
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
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    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x3d0900,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x3d0900,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x3d0900,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    $0x3d0900,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x3e8,%edx
mov    $0x3e8,%ecx
mov    $0x3e8,%r8d
mov    $0x32,%r9d
call   10a0 <testRand@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
lea    0xdfd(%rip),%r13
lea    0xe05(%rip),%rsi
mov    %r13,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    $0x3e8,%ecx
mov    $0x3e8,%r8d
mov    $0x3e8,%r9d
call   1090 <matrixMulSeq@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
lea    0xdc0(%rip),%rsi
mov    %r13,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    $0x3e8,%ecx
mov    $0x3e8,%r8d
mov    $0x3e8,%r9d
call   1080 <matrixMulMp@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
lea    0xd7b(%rip),%rsi
mov    %r13,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x3e8,%edx
mov    $0x3e8,%ecx
call   1060 <getMaxError@plt>
lea    0xd5a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%s done in %f\0A\00"
@.str.1 = [5 x i8] c"Init\00"
@.str.2 = [5 x i8] c"Seq \00"
@.str.3 = [5 x i8] c"MP \00"
@.str.4 = [15 x i8] c"Max error: %d\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 i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca double
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1000, i32* %6
store i32 1000, i32* %7
store i32 1000, i32* %8
%15 = load i32, i32* %6
%16 = load i32, i32* %8
%17 = mul nsw i32 %15, %16
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %9
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = mul nsw i32 %23, %24
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %10
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = mul nsw i32 %31, %32
%34 = sext i32 %33 to i64
%35 = mul i64 %34, 4
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i32*
store i32* %38, i32** %11
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = mul nsw i32 %39, %40
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 4
%44 = trunc i64 %43 to i32
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i32*
store i32* %46, i32** %12
%47 = call double (...) @omp_get_wtime()
store double %47, double* %13
%48 = load i32*, i32** %9
%49 = load i32*, i32** %10
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = load i32, i32* %8
%53 = call i32 @testRand(i32* %48, i32* %49, i32 %50, i32 %51, i32 %52, i32 50)
%54 = call double (...) @omp_get_wtime()
store double %54, double* %14
%55 = load double, double* %14
%56 = load double, double* %13
%57 = fsub double %55, %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %57)
%59 = call double (...) @omp_get_wtime()
store double %59, double* %13
%60 = load i32*, i32** %9
%61 = load i32*, i32** %10
%62 = load i32*, i32** %12
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = load i32, i32* %8
%66 = call i32 @matrixMulSeq(i32* %60, i32* %61, i32* %62, i32 %63, i32 %64, i32 %65)
%67 = call double (...) @omp_get_wtime()
store double %67, double* %14
%68 = load double, double* %14
%69 = load double, double* %13
%70 = fsub double %68, %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %70)
%72 = call double (...) @omp_get_wtime()
store double %72, double* %13
%73 = load i32*, i32** %9
%74 = load i32*, i32** %10
%75 = load i32*, i32** %11
%76 = load i32, i32* %6
%77 = load i32, i32* %7
%78 = load i32, i32* %8
%79 = call i32 @matrixMulMp(i32* %73, i32* %74, i32* %75, i32 %76, i32 %77, i32 %78)
%80 = call double (...) @omp_get_wtime()
store double %80, double* %14
%81 = load double, double* %14
%82 = load double, double* %13
%83 = fsub double %81, %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %83)
%85 = load i32*, i32** %11
%86 = load i32*, i32** %12
%87 = load i32, i32* %6
%88 = load i32, i32* %7
%89 = call i32 @getMaxError(i32* %85, i32* %86, i32 %87, i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %89)
%91 = load i32*, i32** %9
%92 = call i32 @free(i32* %91)
%93 = load i32*, i32** %10
%94 = call i32 @free(i32* %93)
%95 = load i32*, i32** %11
%96 = call i32 @free(i32* %95)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"%s done in %f\0A\00"
@.str.1 = [5 x i8] c"Init\00"
@.str.2 = [5 x i8] c"Seq \00"
@.str.3 = [5 x i8] c"MP \00"
@.str.4 = [15 x i8] c"Max error: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 4000000)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i64 @malloc(i32 4000000)
%6 = inttoptr i64 %5 to i32*
%7 = tail call i64 @malloc(i32 4000000)
%8 = inttoptr i64 %7 to i32*
%9 = tail call i64 @malloc(i32 4000000)
%10 = inttoptr i64 %9 to i32*
%11 = tail call double (...) @omp_get_wtime()
%12 = tail call i32 @testRand(i32* %4, i32* %6, i32 1000, i32 1000, i32 1000, i32 50)
%13 = tail call double (...) @omp_get_wtime()
%14 = fsub double %13, %11
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %14)
%16 = tail call double (...) @omp_get_wtime()
%17 = tail call i32 @matrixMulSeq(i32* %4, i32* %6, i32* %10, i32 1000, i32 1000, i32 1000)
%18 = tail call double (...) @omp_get_wtime()
%19 = fsub double %18, %16
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %19)
%21 = tail call double (...) @omp_get_wtime()
%22 = tail call i32 @matrixMulMp(i32* %4, i32* %6, i32* %8, i32 1000, i32 1000, i32 1000)
%23 = tail call double (...) @omp_get_wtime()
%24 = fsub double %23, %21
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %24)
%26 = tail call i32 @getMaxError(i32* %8, i32* %10, i32 1000, i32 1000)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = tail call i32 @free(i32* %4)
%29 = tail call i32 @free(i32* %6)
%30 = tail call i32 @free(i32* %8)
ret i32 0
}