#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*/ printDiagonalMatriz(int **);
int /*<<< orphan*/ printMatriz(int **);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int matrixA[3][3];
  int matrixB[3][3];
  int matrizResultado[3][3];
  srand(time(NULL));
  printf("Bienvenido inserta valores a la siguiente matriz de 3x3\n");
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      printf("Posicion [%d][%d]:", i, j);
      scanf("%d", &matrixA[i][j]);
      matrixB[i][j] = rand() % 6 + 2;
      matrizResultado[i][j] = matrixB[i][j] + matrixA[i][j];
    }
  }
  printf("\nMatriz Aleatoria:\n");
  printMatriz(matrixB);
  printf("\nMatriz Resultado:\n");
  printMatriz(matrizResultado);
  printf("\nDiagonal:\n");
  printDiagonalMatriz(matrizResultado);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x3,-0x94(%rbp)
jge    12c6 <main+0x156>
movl   $0x0,-0x98(%rbp)
cmpl   $0x3,-0x98(%rbp)
jge    12ad <main+0x13d>
mov    -0x94(%rbp),%esi
mov    -0x98(%rbp),%edx
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x94(%rbp),%rax
lea    -0x30(%rbp),%rsi
imul   $0xc,%rax,%rax
add    %rax,%rsi
movslq -0x98(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe3d(%rip),%rdi
call   1070 <scanf@plt>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x2,%edx
movslq -0x94(%rbp),%rcx
lea    -0x60(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0x98(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0x94(%rbp),%rcx
lea    -0x60(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0x98(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
movslq -0x94(%rbp),%rcx
lea    -0x30(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0x98(%rbp),%rcx
add    (%rax,%rcx,4),%edx
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0x98(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    11c1 <main+0x51>
jmp    12b2 <main+0x142>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11aa <main+0x3a>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1040 <printMatriz@plt>
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <printMatriz@plt>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1080 <printDiagonalMatriz@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
lea    0xe52(%rip),%r14
lea    0xe5e(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rsp,%rbx,1),%rsi
mov    %r15,%rdi
call   1080 <scanf@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,0x60(%rsp,%rbx,1)
add    (%rsp,%rbx,1),%eax
mov    %eax,0x30(%rsp,%rbx,1)
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rsp,%rbx,1),%rsi
add    $0x4,%rsi
mov    %r15,%rdi
call   1080 <scanf@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,0x64(%rsp,%rbx,1)
add    0x4(%rsp,%rbx,1),%eax
mov    %eax,0x34(%rsp,%rbx,1)
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rsp,%rbx,1),%rsi
add    $0x8,%rsi
mov    %r15,%rdi
call   1080 <scanf@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,0x68(%rsp,%rbx,1)
add    0x8(%rsp,%rbx,1),%eax
mov    %eax,0x38(%rsp,%rbx,1)
add    $0x1,%ebp
add    $0xc,%rbx
cmp    $0x24,%rbx
jne    11c0 <main+0x40>
lea    0xd7c(%rip),%rdi
call   1030 <puts@plt>
lea    0x60(%rsp),%rdi
call   1050 <printMatriz@plt>
lea    0xd79(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <printMatriz@plt>
lea    0xd73(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1090 <printDiagonalMatriz@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [19 x i8] c"Posicion [%d][%d]:\00"
@.str.2 = [3 x i8] c"%d\00"
@str = [56 x i8] c"Bienvenido inserta valores a la siguiente matriz de 3x3\00"
@str.6 = [19 x i8] c"\0AMatriz Aleatoria:\00"
@str.7 = [19 x i8] c"\0AMatriz Resultado:\00"
@str.8 = [11 x i8] c"\0ADiagonal:\00"
define i32 @main() {
%1 = alloca [3 x [3 x i32]]
%2 = alloca [3 x [3 x i32]]
%3 = alloca [3 x [3 x i32]]
%4 = bitcast [3 x [3 x i32]]* %1 to i8*
%5 = bitcast [3 x [3 x i32]]* %2 to i8*
%6 = bitcast [3 x [3 x i32]]* %3 to i8*
%7 = tail call i32 @time(i32* null)
%8 = tail call i32 @srand(i32 %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %0, %10
%11 = phi i64 [ 0, %0 ], [ %43, %10 ]
%12 = trunc i64 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 0)
%14 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i64 0, i64 %11, i64 0
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %14)
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 6
%18 = add nsw i32 %17, 2
%19 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 %11, i64 0
store i32 %18, i32* %19
%20 = load i32, i32* %14
%21 = add nsw i32 %18, %20
%22 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %3, i64 0, i64 %11, i64 0
store i32 %21, i32* %22
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 1)
%24 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i64 0, i64 %11, i64 1
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %24)
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 6
%28 = add nsw i32 %27, 2
%29 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 %11, i64 1
store i32 %28, i32* %29
%30 = load i32, i32* %24
%31 = add nsw i32 %28, %30
%32 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %3, i64 0, i64 %11, i64 1
store i32 %31, i32* %32
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 2)
%34 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i64 0, i64 %11, i64 2
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %34)
%36 = call i32 (...) @rand()
%37 = srem i32 %36, 6
%38 = add nsw i32 %37, 2
%39 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 %11, i64 2
store i32 %38, i32* %39
%40 = load i32, i32* %34
%41 = add nsw i32 %38, %40
%42 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %3, i64 0, i64 %11, i64 2
store i32 %41, i32* %42
%43 = add nuw nsw i64 %11, 1
%44 = icmp eq i64 %43, 3
br i1 %44, label %45, label %10
45: ; preds = %10
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%47 = bitcast [3 x [3 x i32]]* %2 to i32**
%48 = call i32 @printMatriz(i32** %47)
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
%50 = bitcast [3 x [3 x i32]]* %3 to i32**
%51 = call i32 @printMatriz(i32** %50)
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.8, i64 0, i64 0))
%53 = call i32 @printDiagonalMatriz(i32** %50)
ret i32 0
}