int main() {
  int sz, **m, i, j, sumMain, sumMinor;
  printf("Type in the size of the matrix to calculate: ");
  scanf("%d", &sz);
  m = (int *)calloc(sz, sizeof(int));
  for (i = 0; i < sz; i++)
    m[i] = (int *)calloc(sz, sizeof(int));
  printf("Type in the elements of the matrix, separate by spaces or change of "
         "line:\n");
  for (i = 0; i < sz; i++)
    for (j = 0; j < sz; j++)
      scanf("%d", &m[i][j]);
  sumMain = trace(m, sz);
  sumMinor = sumMinorDiagonal(m, sz);
  printf("The sum of the elements of the main and minor diagonals are ");
  if (sumMain == sumMinor)
    printf("equal to %d.\n", sumMain);
  else
    printf("different.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11cf <main+0x7f>
movslq -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1198 <main+0x48>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1249 <main+0xf9>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1236 <main+0xe6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f7 <main+0xa7>
jmp    123b <main+0xeb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e4 <main+0x94>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x0,%al
call   1070 <trace@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x0,%al
call   1030 <sumMinorDiagonal@plt>
mov    %eax,-0x20(%rbp)
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    129b <main+0x14b>
mov    -0x1c(%rbp),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a9 <main+0x159>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xead(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movslq 0xc(%rsp),%r15
mov    $0x4,%esi
mov    %r15,%rdi
call   1060 <calloc@plt>
mov    %rax,%r14
test   %r15,%r15
jle    11ca <main+0x6a>
mov    %r15d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    $0x4,%esi
mov    %r15,%rdi
call   1060 <calloc@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <main+0x50>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    1231 <main+0xd1>
lea    0xe49(%rip),%r15
xor    %r12d,%r12d
jmp    11fc <main+0x9c>
nopw   0x0(%rax,%rax,1)
movslq %esi,%rax
add    $0x1,%r12
cmp    %rax,%r12
jge    1231 <main+0xd1>
test   %esi,%esi
jle    11f0 <main+0x90>
mov    (%r14,%r12,8),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rsi
add    $0x4,%rbx
cmp    %rsi,%rbp
jl     1210 <main+0xb0>
jmp    11f0 <main+0x90>
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <trace@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <sumMinorDiagonal@plt>
mov    %eax,%ebp
lea    0xddd(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebp,%ebx
jne    1271 <main+0x111>
lea    0xe08(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    127d <main+0x11d>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Type in the size of the matrix to calculate: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [75 x i8] c"Type in the elements of the matrix, separate by spaces or change of line:\0A\00"
@.str.3 = [61 x i8] c"The sum of the elements of the main and minor diagonals are \00"
@.str.4 = [14 x i8] c"equal to %d.\0A\00"
@.str.5 = [12 x i8] c"different.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = call i8* @calloc(i64 %11, i64 4)
%13 = bitcast i8* %12 to i32*
%14 = bitcast i32* %13 to i32**
store i32** %14, i32*** %3
store i32 0, i32* %4
br label %15
15: ; preds = %28, %0
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = call i8* @calloc(i64 %21, i64 4)
%23 = bitcast i8* %22 to i32*
%24 = load i32**, i32*** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32*, i32** %24, i64 %26
store i32* %23, i32** %27
br label %28
28: ; preds = %19
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %15
31: ; preds = %15
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %33
33: ; preds = %56, %31
%34 = load i32, i32* %4
%35 = load i32, i32* %2
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %59
37: ; preds = %33
store i32 0, i32* %5
br label %38
38: ; preds = %52, %37
%39 = load i32, i32* %5
%40 = load i32, i32* %2
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %55
42: ; preds = %38
%43 = load i32**, i32*** %3
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32*, i32** %43, i64 %45
%47 = load i32*, i32** %46
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %50)
br label %52
52: ; preds = %42
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %38
55: ; preds = %38
br label %56
56: ; preds = %55
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %33
59: ; preds = %33
%60 = load i32**, i32*** %3
%61 = load i32, i32* %2
%62 = call i32 (i32**, i32, ...) bitcast (i32 (...)* @trace to i32 (i32**, i32, ...)*)(i32** %60, i32 %61)
store i32 %62, i32* %6
%63 = load i32**, i32*** %3
%64 = load i32, i32* %2
%65 = call i32 (i32**, i32, ...) bitcast (i32 (...)* @sumMinorDiagonal to i32 (i32**, i32, ...)*)(i32** %63, i32 %64)
store i32 %65, i32* %7
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%67 = load i32, i32* %6
%68 = load i32, i32* %7
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %73
70: ; preds = %59
%71 = load i32, i32* %6
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %71)
br label %75
73: ; preds = %59
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %75
75: ; preds = %73, %70
ret i32 0
}

LLVM IR (-O2):
@.str = [46 x i8] c"Type in the size of the matrix to calculate: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [61 x i8] c"The sum of the elements of the main and minor diagonals are \00"
@.str.4 = [14 x i8] c"equal to %d.\0A\00"
@str = [74 x i8] c"Type in the elements of the matrix, separate by spaces or change of line:\00"
@str.6 = [11 x i8] c"different.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = call i8* @calloc(i64 %6, i64 4)
%8 = bitcast i8* %7 to i32**
%9 = icmp sgt i32 %5, 0
br i1 %9, label %10, label %19
10: ; preds = %0
%11 = zext i32 %5 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %17, %12 ]
%14 = call i8* @calloc(i64 %6, i64 4)
%15 = getelementptr inbounds i32*, i32** %8, i64 %13
%16 = bitcast i32** %15 to i8**
store i8* %14, i8** %16
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %11
br i1 %18, label %19, label %12
19: ; preds = %12, %0
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
%21 = load i32, i32* %1
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %43
23: ; preds = %19, %38
%24 = phi i32 [ %39, %38 ], [ %21, %19 ]
%25 = phi i64 [ %41, %38 ], [ 0, %19 ]
%26 = icmp sgt i32 %24, 0
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = getelementptr inbounds i32*, i32** %8, i64 %25
%29 = load i32*, i32** %28
br label %30
30: ; preds = %27, %30
%31 = phi i64 [ 0, %27 ], [ %34, %30 ]
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %32)
%34 = add nuw nsw i64 %31, 1
%35 = load i32, i32* %1
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %34, %36
br i1 %37, label %30, label %38
38: ; preds = %30, %23
%39 = phi i32 [ %24, %23 ], [ %35, %30 ]
%40 = sext i32 %39 to i64
%41 = add nuw nsw i64 %25, 1
%42 = icmp slt i64 %41, %40
br i1 %42, label %23, label %43
43: ; preds = %38, %19
%44 = phi i32 [ %21, %19 ], [ %39, %38 ]
%45 = call i32 (i32**, i32, ...) bitcast (i32 (...)* @trace to i32 (i32**, i32, ...)*)(i32** %8, i32 %44)
%46 = load i32, i32* %1
%47 = call i32 (i32**, i32, ...) bitcast (i32 (...)* @sumMinorDiagonal to i32 (i32**, i32, ...)*)(i32** %8, i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%49 = icmp eq i32 %45, %47
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %54
52: ; preds = %43
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
br label %54
54: ; preds = %52, %50
ret i32 0
}