#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*/ printf(char *, float, ...);
int /*<<< orphan*/ scanf(char *, float *);
int /*<<< orphan*/ system(char *);
int main() {
  int i, j;
  float mat[5][5], soma = 0;
  for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
      printf("Digite o elemento da linha %d e coluna %d: ", (i + 1), (j + 1));
      scanf("%f", &mat[i][j]);
    }
  }
  for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
      if (i == j) {
        soma = (soma + mat[i][j]);
      }
    }
  }
  printf("\nA soma da diagonal principal desta matriz é: %.2f\n\n", soma);
  system("pause");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x74(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11d1 <main+0xa1>
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    11be <main+0x8e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe7d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq -0x8(%rbp),%rax
lea    -0x70(%rbp),%rsi
imul   $0x14,%rax,%rax
add    %rax,%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe81(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1162 <main+0x32>
jmp    11c3 <main+0x93>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1151 <main+0x21>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    1247 <main+0x117>
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    1234 <main+0x104>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1221 <main+0xf1>
movss  -0x74(%rbp),%xmm0
movslq -0x8(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
addss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x74(%rbp)
jmp    1226 <main+0xf6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e9 <main+0xb9>
jmp    1239 <main+0x109>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d8 <main+0xa8>
movss  -0x74(%rbp),%xmm0
lea    0xddc(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe04(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    $0x1,%ebp
xor    %ebx,%ebx
lea    0xeb8(%rip),%r14
lea    0xedd(%rip),%r15
nop
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%al
call   1040 <printf@plt>
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    %r15,%rdi
call   1050 <scanf@plt>
mov    %r14,%rdi
movss  0xc(%rsp),%xmm0
mov    $0x2,%esi
mov    $0x1,%al
call   1040 <printf@plt>
lea    (%rsp,%rbx,1),%rsi
add    $0x14,%rsi
mov    %r15,%rdi
call   1050 <scanf@plt>
mov    %r14,%rdi
movss  0xc(%rsp),%xmm0
mov    $0x3,%esi
mov    $0x1,%al
call   1040 <printf@plt>
lea    (%rsp,%rbx,1),%rsi
add    $0x18,%rsi
mov    %r15,%rdi
call   1050 <scanf@plt>
mov    %r14,%rdi
movss  0xc(%rsp),%xmm0
mov    $0x4,%esi
mov    $0x1,%al
call   1040 <printf@plt>
lea    (%rsp,%rbx,1),%rsi
add    $0x1c,%rsi
mov    %r15,%rdi
call   1050 <scanf@plt>
mov    %r14,%rdi
movss  0xc(%rsp),%xmm0
mov    $0x5,%esi
mov    $0x1,%al
call   1040 <printf@plt>
lea    (%rsp,%rbx,1),%rsi
add    $0x20,%rsi
mov    %r15,%rdi
call   1050 <scanf@plt>
add    $0x14,%rbx
add    $0x1,%ebp
cmp    $0x64,%rbx
jne    1150 <main+0x20>
xorps  %xmm0,%xmm0
addss  0x10(%rsp),%xmm0
addss  0x28(%rsp),%xmm0
addss  0x40(%rsp),%xmm0
addss  0x58(%rsp),%xmm0
addss  0x70(%rsp),%xmm0
lea    0xde6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe0e(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Digite o elemento da linha %d e coluna %d: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [54 x i8] c"\0AA soma da diagonal principal desta matriz \C3\A9: %.2f\0A\0A\00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [5 x [5 x float]]
%5 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %5
store i32 0, i32* %2
br label %6
6: ; preds = %31, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 5
br i1 %8, label %9, label %34
9: ; preds = %6
store i32 0, i32* %3
br label %10
10: ; preds = %27, %9
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 5
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
%16 = sitofp i32 %15 to float
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
%19 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), float %16, i32 %18)
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %4, i64 0, i64 %21
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [5 x float], [5 x float]* %22, i64 0, i64 %24
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %25)
br label %27
27: ; preds = %13
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %10
30: ; preds = %10
br label %31
31: ; preds = %30
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %6
34: ; preds = %6
store i32 0, i32* %2
br label %35
35: ; preds = %61, %34
%36 = load i32, i32* %2
%37 = icmp slt i32 %36, 5
br i1 %37, label %38, label %64
38: ; preds = %35
store i32 0, i32* %3
br label %39
39: ; preds = %57, %38
%40 = load i32, i32* %3
%41 = icmp slt i32 %40, 5
br i1 %41, label %42, label %60
42: ; preds = %39
%43 = load i32, i32* %2
%44 = load i32, i32* %3
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %56
46: ; preds = %42
%47 = load float, float* %5
%48 = load i32, i32* %2
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %4, i64 0, i64 %49
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [5 x float], [5 x float]* %50, i64 0, i64 %52
%54 = load float, float* %53
%55 = fadd float %47, %54
store float %55, float* %5
br label %56
56: ; preds = %46, %42
br label %57
57: ; preds = %56
%58 = load i32, i32* %3
%59 = add nsw i32 %58, 1
store i32 %59, i32* %3
br label %39
60: ; preds = %39
br label %61
61: ; preds = %60
%62 = load i32, i32* %2
%63 = add nsw i32 %62, 1
store i32 %63, i32* %2
br label %35
64: ; preds = %35
%65 = load float, float* %5
%66 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), float %65)
%67 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [44 x i8] c"Digite o elemento da linha %d e coluna %d: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [54 x i8] c"\0AA soma da diagonal principal desta matriz \C3\A9: %.2f\0A\0A\00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca [5 x [5 x float]]
%2 = bitcast [5 x [5 x float]]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %5, %3 ]
%5 = add nuw nsw i64 %4, 1
%6 = trunc i64 %5 to i32
%7 = sitofp i32 %6 to float
%8 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), float %7, i32 1)
%9 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 %4, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %9)
%11 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), float %7, i32 2)
%12 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 %4, i64 1
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %12)
%14 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), float %7, i32 3)
%15 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 %4, i64 2
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %15)
%17 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), float %7, i32 4)
%18 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 %4, i64 3
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %18)
%20 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), float %7, i32 5)
%21 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 %4, i64 4
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %21)
%23 = icmp eq i64 %5, 5
br i1 %23, label %24, label %3
24: ; preds = %3
%25 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 0, i64 0
%26 = load float, float* %25
%27 = fadd float %26, 0.000000e+00
%28 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 1, i64 1
%29 = load float, float* %28
%30 = fadd float %27, %29
%31 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 2, i64 2
%32 = load float, float* %31
%33 = fadd float %30, %32
%34 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 3, i64 3
%35 = load float, float* %34
%36 = fadd float %33, %35
%37 = getelementptr inbounds [5 x [5 x float]], [5 x [5 x float]]* %1, i64 0, i64 4, i64 4
%38 = load float, float* %37
%39 = fadd float %36, %38
%40 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), float %39)
%41 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}