#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*/ imprimeMatriz(int *, int, int);
int /*<<< orphan*/ multMatrizes(int *, int *, int *, int);
size_t pos(int, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ produtoEscalar(int *, int, int);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int matrix[10 * 10] = {0};
  int matrixSize;
  do {
    printf("Tamanho do lado da matriz: ");
    scanf("%d", &matrixSize);
  } while (matrixSize > 10);
  for (int y = 0; y < matrixSize; ++y) {
    for (int x = 0; x < matrixSize; ++x) {
      matrix[pos(x, y, matrixSize)] = rand() % 40;
    }
  }
  imprimeMatriz(matrix, matrixSize, matrixSize);
  produtoEscalar(matrix, matrixSize, 2);
  imprimeMatriz(matrix, matrixSize, matrixSize);
  int mult[10];
  int resultado[10];
  for (int i = 0; i < matrixSize; ++i) {
    mult[i] = rand() % 10;
  }
  imprimeMatriz(mult, matrixSize, 1);
  multMatrizes(matrix, mult, resultado, matrixSize);
  imprimeMatriz(resultado, matrixSize, 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x190,%edx
call   1050 <memset@plt>
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1080 <scanf@plt>
cmpl   $0xa,-0x1a4(%rbp)
jg     11a5 <main+0x25>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    126f <main+0xef>
movl   $0x0,-0x1ac(%rbp)
mov    -0x1ac(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    1256 <main+0xd6>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x28,%ecx
cltd
idiv   %ecx
mov    %edx,-0x218(%rbp)
mov    -0x1ac(%rbp),%edi
mov    -0x1a8(%rbp),%esi
mov    -0x1a4(%rbp),%edx
call   1090 <pos@plt>
mov    -0x218(%rbp),%edx
mov    %edx,-0x1a0(%rbp,%rax,4)
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    11f7 <main+0x77>
jmp    125b <main+0xdb>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    11db <main+0x5b>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
mov    -0x1a4(%rbp),%edx
call   1060 <imprimeMatriz@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
mov    $0x2,%edx
call   1030 <produtoEscalar@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
mov    -0x1a4(%rbp),%edx
call   1060 <imprimeMatriz@plt>
movl   $0x0,-0x214(%rbp)
mov    -0x214(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    1303 <main+0x183>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq -0x214(%rbp),%rax
mov    %edx,-0x1e0(%rbp,%rax,4)
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    12c0 <main+0x140>
lea    -0x1e0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
mov    $0x1,%edx
call   1060 <imprimeMatriz@plt>
lea    -0x1a0(%rbp),%rdi
lea    -0x1e0(%rbp),%rsi
lea    -0x210(%rbp),%rdx
mov    -0x1a4(%rbp),%ecx
call   1070 <multMatrizes@plt>
lea    -0x210(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
mov    $0x1,%edx
call   1060 <imprimeMatriz@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
lea    0x70(%rsp),%rdi
mov    $0x190,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe5d(%rip),%r14
lea    0xe72(%rip),%rbp
lea    0xc(%rsp),%rbx
nop
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%edx
cmp    $0xa,%edx
jg     11b0 <main+0x30>
test   %edx,%edx
jle    1235 <main+0xb5>
xor    %r14d,%r14d
jmp    11e9 <main+0x69>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14d
cmp    %edx,%r14d
jge    1235 <main+0xb5>
test   %edx,%edx
jle    11e0 <main+0x60>
xor    %ebp,%ebp
nop
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x24,%rax
add    %ecx,%eax
shl    $0x3,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %r14d,%esi
call   1090 <pos@plt>
mov    %ebx,0x70(%rsp,%rax,4)
add    $0x1,%ebp
mov    0xc(%rsp),%edx
cmp    %edx,%ebp
jl     11f0 <main+0x70>
jmp    11e0 <main+0x60>
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    %edx,%esi
call   1060 <imprimeMatriz@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <produtoEscalar@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %edx,%esi
call   1060 <imprimeMatriz@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    12a6 <main+0x126>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
movslq 0xc(%rsp),%rsi
cmp    %rsi,%rbx
jl     1270 <main+0xf0>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1060 <imprimeMatriz@plt>
mov    0xc(%rsp),%ecx
lea    0x70(%rsp),%rdi
lea    0x40(%rsp),%rbp
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1070 <multMatrizes@plt>
mov    0xc(%rsp),%esi
mov    %rbp,%rdi
mov    $0x1,%edx
call   1060 <imprimeMatriz@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Tamanho do lado da matriz: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i32]
%7 = alloca [10 x i32]
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [100 x i32]* %2 to i8*
br label %10
10: ; preds = %13, %0
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %13
13: ; preds = %10
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 10
br i1 %15, label %10, label %16
16: ; preds = %13
store i32 0, i32* %4
br label %17
17: ; preds = %38, %16
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %41
21: ; preds = %17
store i32 0, i32* %5
br label %22
22: ; preds = %34, %21
%23 = load i32, i32* %5
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = call i32 (...) @rand()
%28 = srem i32 %27, 40
%29 = load i32, i32* %5
%30 = load i32, i32* %4
%31 = load i32, i32* %3
%32 = call i64 @pos(i32 %29, i32 %30, i32 %31)
%33 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %32
store i32 %28, i32* %33
br label %34
34: ; preds = %26
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %22
37: ; preds = %22
br label %38
38: ; preds = %37
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %17
41: ; preds = %17
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%43 = load i32, i32* %3
%44 = load i32, i32* %3
%45 = call i32 @imprimeMatriz(i32* %42, i32 %43, i32 %44)
%46 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%47 = load i32, i32* %3
%48 = call i32 @produtoEscalar(i32* %46, i32 %47, i32 2)
%49 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%50 = load i32, i32* %3
%51 = load i32, i32* %3
%52 = call i32 @imprimeMatriz(i32* %49, i32 %50, i32 %51)
store i32 0, i32* %8
br label %53
53: ; preds = %63, %41
%54 = load i32, i32* %8
%55 = load i32, i32* %3
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %66
57: ; preds = %53
%58 = call i32 (...) @rand()
%59 = srem i32 %58, 10
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %61
store i32 %59, i32* %62
br label %63
63: ; preds = %57
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %53
66: ; preds = %53
%67 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%68 = load i32, i32* %3
%69 = call i32 @imprimeMatriz(i32* %67, i32 %68, i32 1)
%70 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%71 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%72 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%73 = load i32, i32* %3
%74 = call i32 @multMatrizes(i32* %70, i32* %71, i32* %72, i32 %73)
%75 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%76 = load i32, i32* %3
%77 = call i32 @imprimeMatriz(i32* %75, i32 %76, i32 1)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Tamanho do lado da matriz: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = alloca [10 x i32]
%4 = alloca [10 x i32]
%5 = bitcast [100 x i32]* %1 to i8*
%6 = bitcast i32* %2 to i8*
br label %7
7: ; preds = %7, %0
%8 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 10
br i1 %11, label %7, label %12
12: ; preds = %7
%13 = icmp sgt i32 %10, 0
br i1 %13, label %14, label %18
14: ; preds = %12, %30
%15 = phi i32 [ %31, %30 ], [ %10, %12 ]
%16 = phi i32 [ %32, %30 ], [ 0, %12 ]
%17 = icmp sgt i32 %15, 0
br i1 %17, label %34, label %30
18: ; preds = %30, %12
%19 = phi i32 [ %10, %12 ], [ %31, %30 ]
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%21 = call i32 @imprimeMatriz(i32* %20, i32 %19, i32 %19)
%22 = load i32, i32* %2
%23 = call i32 @produtoEscalar(i32* %20, i32 %22, i32 2)
%24 = load i32, i32* %2
%25 = call i32 @imprimeMatriz(i32* %20, i32 %24, i32 %24)
%26 = bitcast [10 x i32]* %3 to i8*
%27 = bitcast [10 x i32]* %4 to i8*
%28 = load i32, i32* %2
%29 = icmp sgt i32 %28, 0
br i1 %29, label %53, label %44
30: ; preds = %34, %14
%31 = phi i32 [ %15, %14 ], [ %42, %34 ]
%32 = add nuw nsw i32 %16, 1
%33 = icmp slt i32 %32, %31
br i1 %33, label %14, label %18
34: ; preds = %14, %34
%35 = phi i32 [ %41, %34 ], [ 0, %14 ]
%36 = call i32 (...) @rand()
%37 = srem i32 %36, 40
%38 = load i32, i32* %2
%39 = call i64 @pos(i32 %35, i32 %16, i32 %38)
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %39
store i32 %37, i32* %40
%41 = add nuw nsw i32 %35, 1
%42 = load i32, i32* %2
%43 = icmp slt i32 %41, %42
br i1 %43, label %34, label %30
44: ; preds = %53, %18
%45 = phi i32 [ %28, %18 ], [ %59, %53 ]
%46 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%47 = call i32 @imprimeMatriz(i32* %46, i32 %45, i32 1)
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 0
%49 = load i32, i32* %2
%50 = call i32 @multMatrizes(i32* %20, i32* %46, i32* %48, i32 %49)
%51 = load i32, i32* %2
%52 = call i32 @imprimeMatriz(i32* %48, i32 %51, i32 1)
ret i32 0
53: ; preds = %18, %53
%54 = phi i64 [ %58, %53 ], [ 0, %18 ]
%55 = call i32 (...) @rand()
%56 = srem i32 %55, 10
%57 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %54
store i32 %56, i32* %57
%58 = add nuw nsw i64 %54, 1
%59 = load i32, i32* %2
%60 = sext i32 %59 to i64
%61 = icmp slt i64 %58, %60
br i1 %61, label %53, label %44
}