#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 *);
int /*<<< orphan*/ freematrix(int, int **);
int **mkmatrix(int, int);
int **mmult(int, int, int **, int **, int **);
int /*<<< orphan*/ printf(char *, int, int, int, int);
int main(int argc, char *argv[]) {
  int i, n = ((argc == 2) ? atoi(argv[1]) : 300000);
  int **m1 = mkmatrix(10, 10);
  int **m2 = mkmatrix(10, 10);
  int **mm = mkmatrix(10, 10);
  for (i = 0; i < n; i++) {
    mm = mmult(10, 10, m1, m2, mm);
  }
  printf("%d %d %d %d\n", mm[0][0], mm[2][3], mm[3][2], mm[4][4]);
  freematrix(10, m1);
  freematrix(10, m2);
  freematrix(10, mm);
  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)
cmpl   $0x2,-0x8(%rbp)
jne    1185 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x34(%rbp)
jmp    1192 <main+0x42>
mov    $0x493e0,%eax
mov    %eax,-0x34(%rbp)
jmp    1192 <main+0x42>
mov    -0x34(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0xa,%esi
mov    %esi,%edi
call   1030 <mkmatrix@plt>
mov    %rax,-0x20(%rbp)
mov    $0xa,%esi
mov    %esi,%edi
call   1030 <mkmatrix@plt>
mov    %rax,-0x28(%rbp)
mov    $0xa,%esi
mov    %esi,%edi
call   1030 <mkmatrix@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1205 <main+0xb5>
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    $0xa,%esi
mov    %esi,%edi
call   1040 <mmult@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cf <main+0x7f>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    0xc(%rax),%edx
mov    -0x30(%rbp),%rax
mov    0x18(%rax),%rax
mov    0x8(%rax),%ecx
mov    -0x30(%rbp),%rax
mov    0x20(%rax),%rax
mov    0x10(%rax),%r8d
lea    0xdc9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    $0xa,%edi
call   1060 <freematrix@plt>
mov    -0x28(%rbp),%rsi
mov    $0xa,%edi
call   1060 <freematrix@plt>
mov    -0x30(%rbp),%rsi
mov    $0xa,%edi
call   1060 <freematrix@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x493e0,%ebp
cmp    $0x2,%edi
jne    116c <main+0x1c>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    $0xa,%edi
mov    $0xa,%esi
call   1030 <mkmatrix@plt>
mov    %rax,%r14
mov    $0xa,%edi
mov    $0xa,%esi
call   1030 <mkmatrix@plt>
mov    %rax,%r15
mov    $0xa,%edi
mov    $0xa,%esi
call   1030 <mkmatrix@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    11d0 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    $0xa,%esi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1040 <mmult@plt>
mov    %rax,%rbx
add    $0xffffffff,%ebp
jne    11b0 <main+0x60>
mov    (%rbx),%rax
mov    0x10(%rbx),%rcx
mov    (%rax),%esi
mov    0xc(%rcx),%edx
mov    0x18(%rbx),%rax
mov    0x8(%rax),%ecx
mov    0x20(%rbx),%rax
mov    0x10(%rax),%r8d
lea    0xe0e(%rip),%rdi
call   1050 <printf@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   1060 <freematrix@plt>
mov    $0xa,%edi
mov    %r15,%rsi
call   1060 <freematrix@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <freematrix@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%d %d %d %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**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
br label %19
18: ; preds = %2
br label %19
19: ; preds = %18, %13
%20 = phi i32 [ %17, %13 ], [ 300000, %18 ]
store i32 %20, i32* %7
%21 = call i32** @mkmatrix(i32 10, i32 10)
store i32** %21, i32*** %8
%22 = call i32** @mkmatrix(i32 10, i32 10)
store i32** %22, i32*** %9
%23 = call i32** @mkmatrix(i32 10, i32 10)
store i32** %23, i32*** %10
store i32 0, i32* %6
br label %24
24: ; preds = %33, %19
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %36
28: ; preds = %24
%29 = load i32**, i32*** %8
%30 = load i32**, i32*** %9
%31 = load i32**, i32*** %10
%32 = call i32** @mmult(i32 10, i32 10, i32** %29, i32** %30, i32** %31)
store i32** %32, i32*** %10
br label %33
33: ; preds = %28
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %24
36: ; preds = %24
%37 = load i32**, i32*** %10
%38 = getelementptr inbounds i32*, i32** %37, i64 0
%39 = load i32*, i32** %38
%40 = getelementptr inbounds i32, i32* %39, i64 0
%41 = load i32, i32* %40
%42 = load i32**, i32*** %10
%43 = getelementptr inbounds i32*, i32** %42, i64 2
%44 = load i32*, i32** %43
%45 = getelementptr inbounds i32, i32* %44, i64 3
%46 = load i32, i32* %45
%47 = load i32**, i32*** %10
%48 = getelementptr inbounds i32*, i32** %47, i64 3
%49 = load i32*, i32** %48
%50 = getelementptr inbounds i32, i32* %49, i64 2
%51 = load i32, i32* %50
%52 = load i32**, i32*** %10
%53 = getelementptr inbounds i32*, i32** %52, i64 4
%54 = load i32*, i32** %53
%55 = getelementptr inbounds i32, i32* %54, i64 4
%56 = load i32, i32* %55
%57 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %46, i32 %51, i32 %56)
%58 = load i32**, i32*** %8
%59 = call i32 @freematrix(i32 10, i32** %58)
%60 = load i32**, i32*** %9
%61 = call i32 @freematrix(i32 10, i32** %60)
%62 = load i32**, i32*** %10
%63 = call i32 @freematrix(i32 10, i32** %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"%d %d %d %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 300000, %2 ]
%10 = tail call i32** @mkmatrix(i32 10, i32 10)
%11 = tail call i32** @mkmatrix(i32 10, i32 10)
%12 = tail call i32** @mkmatrix(i32 10, i32 10)
%13 = icmp sgt i32 %9, 0
br i1 %13, label %14, label %20
14: ; preds = %8, %14
%15 = phi i32** [ %17, %14 ], [ %12, %8 ]
%16 = phi i32 [ %18, %14 ], [ 0, %8 ]
%17 = tail call i32** @mmult(i32 10, i32 10, i32** %10, i32** %11, i32** %15)
%18 = add nuw nsw i32 %16, 1
%19 = icmp eq i32 %18, %9
br i1 %19, label %20, label %14
20: ; preds = %14, %8
%21 = phi i32** [ %12, %8 ], [ %17, %14 ]
%22 = load i32*, i32** %21
%23 = load i32, i32* %22
%24 = getelementptr inbounds i32*, i32** %21, i64 2
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds i32*, i32** %21, i64 3
%29 = load i32*, i32** %28
%30 = getelementptr inbounds i32, i32* %29, i64 2
%31 = load i32, i32* %30
%32 = getelementptr inbounds i32*, i32** %21, i64 4
%33 = load i32*, i32** %32
%34 = getelementptr inbounds i32, i32* %33, i64 4
%35 = load i32, i32* %34
%36 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %27, i32 %31, i32 %35)
%37 = tail call i32 @freematrix(i32 10, i32** %10)
%38 = tail call i32 @freematrix(i32 10, i32** %11)
%39 = tail call i32 @freematrix(i32 10, i32** %21)
ret i32 0
}