#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 timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int EXIT_SUCCESS;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int *create_random_matrix(int const, int const);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ ms_diff(struct timespec, struct timespec);
int *multithreaded_matrix_product(int *, int *, int const, int const,
                                  int const);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  srand(time(NULL));
  const int r = 5;
  const int s = 2;
  const int t = 4;
  int *A = create_random_matrix(r, s);
  int *B = create_random_matrix(s, t);
  struct timespec start;
  clock_gettime(CLOCK_REALTIME, &start);
  int *C = multithreaded_matrix_product(A, B, r, s, t);
  struct timespec stop;
  clock_gettime(CLOCK_REALTIME, &stop);
  printf("%ld ms elapsed.\n", ms_diff(start, stop));
  free(A);
  free(B);
  free(C);
  return EXIT_SUCCESS;
}


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)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
movl   $0x5,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    $0x5,%edi
mov    $0x2,%esi
call   10a0 <create_random_matrix@plt>
mov    %rax,-0x28(%rbp)
mov    $0x2,%edi
mov    $0x4,%esi
call   10a0 <create_random_matrix@plt>
mov    %rax,-0x30(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x5,%edx
mov    $0x2,%ecx
mov    $0x4,%r8d
call   1050 <multithreaded_matrix_product@plt>
mov    %rax,-0x40(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x38(%rbp),%edi
mov    -0x48(%rbp),%esi
call   1090 <ms_diff@plt>
mov    %eax,%esi
lea    0xdc6(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    $0x5,%edi
mov    $0x2,%esi
call   10a0 <create_random_matrix@plt>
mov    %rax,%r14
mov    $0x2,%edi
mov    $0x4,%esi
call   10a0 <create_random_matrix@plt>
mov    %rax,%rbx
mov    0x2e1c(%rip),%r12
mov    (%r12),%edi
lea    0x10(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
mov    $0x2,%ecx
mov    $0x4,%r8d
call   1050 <multithreaded_matrix_product@plt>
mov    %rax,%r15
mov    (%r12),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0x10(%rsp),%edi
mov    0x8(%rsp),%esi
call   1090 <ms_diff@plt>
lea    0xdee(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [17 x i8] c"%ld ms elapsed.\0A\00"
@EXIT_SUCCESS = global i32 0
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 %struct.timespec
%12 = alloca i32*
%13 = alloca %struct.timespec
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 @time(i32* null)
%15 = call i32 @srand(i32 %14)
store i32 5, i32* %6
store i32 2, i32* %7
store i32 4, i32* %8
%16 = call i32* @create_random_matrix(i32 5, i32 2)
store i32* %16, i32** %9
%17 = call i32* @create_random_matrix(i32 2, i32 4)
store i32* %17, i32** %10
%18 = load i32, i32* @CLOCK_REALTIME
%19 = call i32 @clock_gettime(i32 %18, %struct.timespec* %11)
%20 = load i32*, i32** %9
%21 = load i32*, i32** %10
%22 = call i32* @multithreaded_matrix_product(i32* %20, i32* %21, i32 5, i32 2, i32 4)
store i32* %22, i32** %12
%23 = load i32, i32* @CLOCK_REALTIME
%24 = call i32 @clock_gettime(i32 %23, %struct.timespec* %13)
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @ms_diff(i32 %26, i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %9
%32 = call i32 @free(i32* %31)
%33 = load i32*, i32** %10
%34 = call i32 @free(i32* %33)
%35 = load i32*, i32** %12
%36 = call i32 @free(i32* %35)
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [17 x i8] c"%ld ms elapsed.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = tail call i32* @create_random_matrix(i32 5, i32 2)
%8 = tail call i32* @create_random_matrix(i32 2, i32 4)
%9 = bitcast %struct.timespec* %3 to i8*
%10 = load i32, i32* @CLOCK_REALTIME
%11 = call i32 @clock_gettime(i32 %10, %struct.timespec* %3)
%12 = call i32* @multithreaded_matrix_product(i32* %7, i32* %8, i32 5, i32 2, i32 4)
%13 = bitcast %struct.timespec* %4 to i8*
%14 = load i32, i32* @CLOCK_REALTIME
%15 = call i32 @clock_gettime(i32 %14, %struct.timespec* %4)
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @ms_diff(i32 %17, i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 @free(i32* %7)
%23 = call i32 @free(i32* %8)
%24 = call i32 @free(i32* %12)
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}