#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 */
double **AllocateRandomMatrix(unsigned int);
double **AllocateValueMatrix(unsigned int, double);
int EXIT_SUCCESS;
int /*<<< orphan*/ FreeMatrix(double **, unsigned int);
scalar_t__ atoi(char *);
int /*<<< orphan*/ omp_set_num_threads(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
int main(int argc, char *argv[]) {
  unsigned int threads = 8u;
  unsigned int N = 1024u;
  if (argc > 1) {
    threads = (unsigned int)atoi(argv[1]);
  }
  if (argc > 2) {
    N = (unsigned int)atoi(argv[2]);
  }
  double **A;
  double **B;
  double **C;
  A = AllocateRandomMatrix(N);
  B = AllocateRandomMatrix(N);
  C = AllocateValueMatrix(N, 0.0);
  omp_set_num_threads(threads);
#pragma omp parallel for
  for (unsigned int i = 0u; i < N; ++i) {
    for (unsigned int j = 0u; j < N; ++j) {
      for (unsigned int k = 0u; k < N; ++k) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  printf("Threads\t%d\n", threads);
  printf("Size\t%dx%d\n", N, N);
  FreeMatrix(A, N);
  FreeMatrix(B, N);
  FreeMatrix(C, N);
  return EXIT_SUCCESS;
}


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   $0x8,-0x14(%rbp)
movl   $0x400,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    119e <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11b8 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <AllocateRandomMatrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <AllocateRandomMatrix@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
xorps  %xmm0,%xmm0
call   1030 <AllocateValueMatrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <omp_set_num_threads@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    129a <main+0x13a>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1287 <main+0x127>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1274 <main+0x114>
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x3c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x38(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x38(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1214 <main+0xb4>
jmp    1279 <main+0x119>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1201 <main+0xa1>
jmp    128c <main+0x12c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ee <main+0x8e>
mov    -0x14(%rbp),%esi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <FreeMatrix@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <FreeMatrix@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <FreeMatrix@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x400,%r12d
mov    $0x8,%r14d
cmp    $0x2,%edi
jl     119e <main+0x3e>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rax,%r14
cmp    $0x2,%ebp
je     119e <main+0x3e>
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    %rax,%r12
mov    %r12d,%edi
call   1050 <AllocateRandomMatrix@plt>
mov    %rax,%r15
mov    %r12d,%edi
call   1050 <AllocateRandomMatrix@plt>
mov    %rax,%rbx
xorpd  %xmm0,%xmm0
mov    %r12d,%edi
call   1030 <AllocateValueMatrix@plt>
mov    %rax,%r13
mov    %r14d,%edi
call   1060 <omp_set_num_threads@plt>
test   %r12d,%r12d
je     1288 <main+0x128>
mov    %r12d,%r9d
mov    %r9d,%ecx
and    $0xfffffffe,%ecx
xor    %r8d,%r8d
jmp    11fd <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r8
cmp    %r9,%r8
je     1288 <main+0x128>
mov    (%r15,%r8,8),%rsi
mov    0x0(%r13,%r8,8),%rdi
xor    %ebp,%ebp
jmp    1219 <main+0xb9>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %r9,%rbp
je     11f0 <main+0x90>
movsd  (%rdi,%rbp,8),%xmm0
xor    %edx,%edx
cmp    $0x1,%r12d
je     1269 <main+0x109>
cs nopw 0x0(%rax,%rax,1)
movsd  (%rsi,%rdx,8),%xmm1
mov    (%rbx,%rdx,8),%rax
mulsd  (%rax,%rbp,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi,%rbp,8)
movsd  0x8(%rsi,%rdx,8),%xmm0
mov    0x8(%rbx,%rdx,8),%rax
mulsd  (%rax,%rbp,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rdi,%rbp,8)
add    $0x2,%rdx
cmp    %rdx,%rcx
jne    1230 <main+0xd0>
test   $0x1,%r9b
je     1210 <main+0xb0>
movsd  (%rsi,%rdx,8),%xmm1
mov    (%rbx,%rdx,8),%rdx
mulsd  (%rdx,%rbp,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi,%rbp,8)
jmp    1210 <main+0xb0>
lea    0xd71(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd6c(%rip),%rdi
mov    %r12d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   1080 <FreeMatrix@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1080 <FreeMatrix@plt>
mov    %r13,%rdi
mov    %r12d,%esi
call   1080 <FreeMatrix@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Threads\09%d\0A\00"
@.str.1 = [12 x i8] c"Size\09%dx%d\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 double**
%9 = alloca double**
%10 = alloca double**
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 8, i32* %6
store i32 1024, i32* %7
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @atoi(i8* %19)
%21 = trunc i64 %20 to i32
store i32 %21, i32* %6
br label %22
22: ; preds = %16, %2
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 2
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i64 @atoi(i8* %28)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %7
br label %31
31: ; preds = %25, %22
%32 = load i32, i32* %7
%33 = call double** @AllocateRandomMatrix(i32 %32)
store double** %33, double*** %8
%34 = load i32, i32* %7
%35 = call double** @AllocateRandomMatrix(i32 %34)
store double** %35, double*** %9
%36 = load i32, i32* %7
%37 = call double** @AllocateValueMatrix(i32 %36, double 0.000000e+00)
store double** %37, double*** %10
%38 = load i32, i32* %6
%39 = call i32 @omp_set_num_threads(i32 %38)
store i32 0, i32* %11
br label %40
40: ; preds = %91, %31
%41 = load i32, i32* %11
%42 = load i32, i32* %7
%43 = icmp ult i32 %41, %42
br i1 %43, label %44, label %94
44: ; preds = %40
store i32 0, i32* %12
br label %45
45: ; preds = %87, %44
%46 = load i32, i32* %12
%47 = load i32, i32* %7
%48 = icmp ult i32 %46, %47
br i1 %48, label %49, label %90
49: ; preds = %45
store i32 0, i32* %13
br label %50
50: ; preds = %83, %49
%51 = load i32, i32* %13
%52 = load i32, i32* %7
%53 = icmp ult i32 %51, %52
br i1 %53, label %54, label %86
54: ; preds = %50
%55 = load double**, double*** %8
%56 = load i32, i32* %11
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds double*, double** %55, i64 %57
%59 = load double*, double** %58
%60 = load i32, i32* %13
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double, double* %62
%64 = load double**, double*** %9
%65 = load i32, i32* %13
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds double*, double** %64, i64 %66
%68 = load double*, double** %67
%69 = load i32, i32* %12
%70 = zext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
%72 = load double, double* %71
%73 = load double**, double*** %10
%74 = load i32, i32* %11
%75 = zext i32 %74 to i64
%76 = getelementptr inbounds double*, double** %73, i64 %75
%77 = load double*, double** %76
%78 = load i32, i32* %12
%79 = zext i32 %78 to i64
%80 = getelementptr inbounds double, double* %77, i64 %79
%81 = load double, double* %80
%82 = call double @llvm.fmuladd.f64(double %63, double %72, double %81)
store double %82, double* %80
br label %83
83: ; preds = %54
%84 = load i32, i32* %13
%85 = add i32 %84, 1
store i32 %85, i32* %13
br label %50
86: ; preds = %50
br label %87
87: ; preds = %86
%88 = load i32, i32* %12
%89 = add i32 %88, 1
store i32 %89, i32* %12
br label %45
90: ; preds = %45
br label %91
91: ; preds = %90
%92 = load i32, i32* %11
%93 = add i32 %92, 1
store i32 %93, i32* %11
br label %40
94: ; preds = %40
%95 = load i32, i32* %6
%96 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %95)
%97 = load i32, i32* %7
%98 = load i32, i32* %7
%99 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %97, i32 %98)
%100 = load double**, double*** %8
%101 = load i32, i32* %7
%102 = call i32 @FreeMatrix(double** %100, i32 %101)
%103 = load double**, double*** %9
%104 = load i32, i32* %7
%105 = call i32 @FreeMatrix(double** %103, i32 %104)
%106 = load double**, double*** %10
%107 = load i32, i32* %7
%108 = call i32 @FreeMatrix(double** %106, i32 %107)
%109 = load i32, i32* @EXIT_SUCCESS
ret i32 %109
}

LLVM IR (-O2):
@.str = [12 x i8] c"Threads\09%d\0A\00"
@.str.1 = [12 x i8] c"Size\09%dx%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @atoi(i8* %6)
%8 = trunc i64 %7 to i32
%9 = icmp eq i32 %0, 2
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i64 @atoi(i8* %12)
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %2, %10, %4
%16 = phi i32 [ %8, %10 ], [ %8, %4 ], [ 8, %2 ]
%17 = phi i32 [ %14, %10 ], [ 1024, %4 ], [ 1024, %2 ]
%18 = tail call double** @AllocateRandomMatrix(i32 %17)
%19 = tail call double** @AllocateRandomMatrix(i32 %17)
%20 = tail call double** @AllocateValueMatrix(i32 %17, double 0.000000e+00)
%21 = tail call i32 @omp_set_num_threads(i32 %16)
%22 = icmp eq i32 %17, 0
br i1 %22, label %35, label %23
23: ; preds = %15
%24 = zext i32 %17 to i64
%25 = and i64 %24, 1
%26 = icmp eq i32 %17, 1
%27 = and i64 %24, 4294967294
%28 = icmp eq i64 %25, 0
br label %29
29: ; preds = %23, %46
%30 = phi i64 [ 0, %23 ], [ %47, %46 ]
%31 = getelementptr inbounds double*, double** %18, i64 %30
%32 = load double*, double** %31
%33 = getelementptr inbounds double*, double** %20, i64 %30
%34 = load double*, double** %33
br label %42
35: ; preds = %46, %15
%36 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %16)
%37 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %17)
%38 = tail call i32 @FreeMatrix(double** %18, i32 %17)
%39 = tail call i32 @FreeMatrix(double** %19, i32 %17)
%40 = tail call i32 @FreeMatrix(double** %20, i32 %17)
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
42: ; preds = %29, %60
%43 = phi i64 [ 0, %29 ], [ %61, %60 ]
%44 = getelementptr inbounds double, double* %34, i64 %43
%45 = load double, double* %44
br i1 %26, label %49, label %63
46: ; preds = %60
%47 = add nuw nsw i64 %30, 1
%48 = icmp eq i64 %47, %24
br i1 %48, label %35, label %29
49: ; preds = %63, %42
%50 = phi double [ %45, %42 ], [ %81, %63 ]
%51 = phi i64 [ 0, %42 ], [ %82, %63 ]
br i1 %28, label %60, label %52
52: ; preds = %49
%53 = getelementptr inbounds double, double* %32, i64 %51
%54 = load double, double* %53
%55 = getelementptr inbounds double*, double** %19, i64 %51
%56 = load double*, double** %55
%57 = getelementptr inbounds double, double* %56, i64 %43
%58 = load double, double* %57
%59 = tail call double @llvm.fmuladd.f64(double %54, double %58, double %50)
store double %59, double* %44
br label %60
60: ; preds = %49, %52
%61 = add nuw nsw i64 %43, 1
%62 = icmp eq i64 %61, %24
br i1 %62, label %46, label %42
63: ; preds = %42, %63
%64 = phi double [ %81, %63 ], [ %45, %42 ]
%65 = phi i64 [ %82, %63 ], [ 0, %42 ]
%66 = phi i64 [ %83, %63 ], [ 0, %42 ]
%67 = getelementptr inbounds double, double* %32, i64 %65
%68 = load double, double* %67
%69 = getelementptr inbounds double*, double** %19, i64 %65
%70 = load double*, double** %69
%71 = getelementptr inbounds double, double* %70, i64 %43
%72 = load double, double* %71
%73 = tail call double @llvm.fmuladd.f64(double %68, double %72, double %64)
store double %73, double* %44
%74 = or i64 %65, 1
%75 = getelementptr inbounds double, double* %32, i64 %74
%76 = load double, double* %75
%77 = getelementptr inbounds double*, double** %19, i64 %74
%78 = load double*, double** %77
%79 = getelementptr inbounds double, double* %78, i64 %43
%80 = load double, double* %79
%81 = tail call double @llvm.fmuladd.f64(double %76, double %80, double %73)
store double %81, double* %44
%82 = add nuw nsw i64 %65, 2
%83 = add i64 %66, 2
%84 = icmp eq i64 %83, %27
br i1 %84, label %49, label %63
}