#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*/ mostrar_mat(int **);
int /*<<< orphan*/ printf(char *, ...);
void troca_diagonais(int mat[4][4]) {
  int i, j;
  int auxP, auxS;
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      if (i == j) {
        auxP = mat[i][j];
        printf("auxP: %d ", auxP);
      } else if (i + j == (4 - 1)) {
        auxS = mat[i][j];
        printf("auxS: %d ", auxS);
        mat[i][i] = auxS;
        mat[i][j] = auxP;
      }
      printf("\nj: %d", j);
    }
    printf("\n");
  }
  mostrar_mat(mat);
}


x86 assembly (clang, -O0):
<troca_diagonais>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    1234 <troca_diagonais+0x114>
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    1218 <troca_diagonais+0xf8>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1189 <troca_diagonais+0x69>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f9 <troca_diagonais+0xd9>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    $0x3,%eax
jne    11f4 <troca_diagonais+0xd4>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11f9 <troca_diagonais+0xd9>
mov    -0x10(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1144 <troca_diagonais+0x24>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <troca_diagonais+0x13>
mov    -0x8(%rbp),%rdi
call   1040 <mostrar_mat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<troca_diagonais>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xc(%rdi),%r12
mov    %rdi,(%rsp)
xor    %r14d,%r14d
jmp    11df <troca_diagonais+0xaf>
xchg   %ax,%ax
mov    %ebx,%ebp
mov    -0x8(%r12),%ebx
lea    0xeac(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,(%r15)
mov    %ebp,-0x8(%r12)
lea    0xe9e(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rax
mov    0x28(%rax),%ebx
lea    0xe70(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe61(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
add    $0x14,%r15
add    $0x10,%r12
cmp    $0x4,%r14
je     133d <troca_diagonais+0x20d>
cmp    $0x3,%r14
je     1210 <troca_diagonais+0xe0>
test   %r14,%r14
jne    1270 <troca_diagonais+0x140>
mov    (%rsp),%rax
mov    (%rax),%ebx
lea    0xe05(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1233 <troca_diagonais+0x103>
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%r13
mov    %ebx,%ebp
mov    0x30(%r13),%ebx
lea    0xde9(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,(%r15)
mov    %ebp,%ebx
mov    %ebp,0x30(%r13)
lea    0xdda(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%r14
je     1150 <troca_diagonais+0x20>
lea    0xdc0(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r14
jne    12e0 <troca_diagonais+0x1b0>
mov    %ebx,%r13d
jmp    12b2 <troca_diagonais+0x182>
nopl   0x0(%rax,%rax,1)
lea    0xd9d(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r14
jne    1243 <troca_diagonais+0x113>
mov    (%rsp),%rax
mov    0x14(%rax),%r13d
lea    0xd6b(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd6e(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x4(%r12),%ebx
lea    0xd4c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,(%r15)
mov    %r13d,-0x4(%r12)
mov    %r13d,%ebx
jmp    1199 <troca_diagonais+0x69>
nopw   0x0(%rax,%rax,1)
lea    0xd2d(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x3,%r14
je     1328 <troca_diagonais+0x1f8>
test   %r14,%r14
jne    11ac <troca_diagonais+0x7c>
mov    %ebx,%r13d
mov    (%r12),%ebx
lea    0xcfa(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,(%r15)
mov    %r13d,%ebx
mov    %r13d,(%r12)
jmp    11ac <troca_diagonais+0x7c>
mov    (%rsp),%rax
mov    0x3c(%rax),%ebx
lea    0xcca(%rip),%rdi
mov    %ebx,%esi
jmp    11a5 <troca_diagonais+0x75>
mov    (%rsp),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mostrar_mat@plt>

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

LLVM IR (-O2):
@.str = [10 x i8] c"auxP: %d \00"
@.str.1 = [10 x i8] c"auxS: %d \00"
@.str.2 = [7 x i8] c"\0Aj: %d\00"
define void @troca_diagonais([4 x i32]* %0) {
%2 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 1, i64 1
%3 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 3, i64 0
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 0, i64 0
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 3, i64 3
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 2, i64 2
br label %7
7: ; preds = %1, %57
%8 = phi i64 [ 0, %1 ], [ %61, %57 ]
%9 = phi i32 [ undef, %1 ], [ %58, %57 ]
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %8, i64 %8
switch i64 %8, label %20 [
i64 0, label %11
i64 3, label %14
]
11: ; preds = %7
%12 = load i32, i32* %4
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %17
14: ; preds = %7
%15 = load i32, i32* %3
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 %15, i32* %10
store i32 %9, i32* %3
br label %17
17: ; preds = %14, %11
%18 = phi i32 [ %9, %14 ], [ %12, %11 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %23
20: ; preds = %7
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 0)
%22 = icmp eq i64 %8, 1
br i1 %22, label %26, label %23
23: ; preds = %17, %20
%24 = phi i32 [ %18, %17 ], [ %9, %20 ]
%25 = icmp eq i64 %8, 2
br i1 %25, label %38, label %30
26: ; preds = %20
%27 = load i32, i32* %2
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %33
30: ; preds = %23
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 1)
%32 = icmp eq i64 %8, 1
br i1 %32, label %33, label %48
33: ; preds = %26, %30
%34 = phi i32 [ %27, %26 ], [ %24, %30 ]
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %8, i64 2
%36 = load i32, i32* %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %36)
store i32 %36, i32* %10
store i32 %34, i32* %35
br label %45
38: ; preds = %23
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %8, i64 1
%40 = load i32, i32* %39
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %40)
store i32 %40, i32* %10
store i32 %24, i32* %39
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 1)
%43 = load i32, i32* %6
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %33, %38
%46 = phi i32 [ %34, %33 ], [ %43, %38 ]
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %57
48: ; preds = %30
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 2)
switch i64 %8, label %57 [
i64 3, label %54
i64 0, label %50
]
50: ; preds = %48
%51 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %8, i64 3
%52 = load i32, i32* %51
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %52)
store i32 %52, i32* %10
store i32 %24, i32* %51
br label %57
54: ; preds = %48
%55 = load i32, i32* %5
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %48, %45, %54, %50
%58 = phi i32 [ %55, %54 ], [ %24, %50 ], [ %46, %45 ], [ %24, %48 ]
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 3)
%60 = tail call i32 @putchar(i32 10)
%61 = add nuw nsw i64 %8, 1
%62 = icmp eq i64 %61, 4
br i1 %62, label %63, label %7
63: ; preds = %57
%64 = bitcast [4 x i32]* %0 to i32**
%65 = tail call i32 @mostrar_mat(i32** %64)
ret void
}