#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 *);
int /*<<< orphan*/ troca_valores(int **);
void test_troca_valores() {
  printf("------------------------------------\n");
  printf("teste Q5: troca_valores.\n");
  int mat[4][4] = {{1, 2, 3, 4}, {1, 1, 1, 1}, {1, 1, 1, 1}, {4, 3, 2, 1}};
  troca_valores(mat);
  if (mat[0][0] == 4 && mat[0][1] == 3 && mat[0][2] == 2 && mat[0][3] == 1 &&
      mat[3][0] == 1 && mat[3][1] == 2 && mat[3][2] == 3 && mat[3][3] == 4) {
    printf("    ok.\n");
  } else {
    printf("    not ok.\n");
  }
}


x86 assembly (clang, -O0):
<test_troca_valores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    0xf05(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
lea    -0x40(%rbp),%rdi
call   1050 <troca_valores@plt>
cmpl   $0x4,-0x40(%rbp)
jne    11cf <test_troca_valores+0x9f>
cmpl   $0x3,-0x3c(%rbp)
jne    11cf <test_troca_valores+0x9f>
cmpl   $0x2,-0x38(%rbp)
jne    11cf <test_troca_valores+0x9f>
cmpl   $0x1,-0x34(%rbp)
jne    11cf <test_troca_valores+0x9f>
cmpl   $0x1,-0x10(%rbp)
jne    11cf <test_troca_valores+0x9f>
cmpl   $0x2,-0xc(%rbp)
jne    11cf <test_troca_valores+0x9f>
cmpl   $0x3,-0x8(%rbp)
jne    11cf <test_troca_valores+0x9f>
cmpl   $0x4,-0x4(%rbp)
jne    11cf <test_troca_valores+0x9f>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
jmp    11db <test_troca_valores+0xab>
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_troca_valores>:
sub    $0x48,%rsp
lea    0xf35(%rip),%rdi
call   1030 <puts@plt>
lea    0xf4e(%rip),%rdi
call   1030 <puts@plt>
movaps 0xf0d(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xef1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb9(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
call   1040 <troca_valores@plt>
movdqa (%rsp),%xmm0
movdqa 0x30(%rsp),%xmm1
pcmpeqd 0xe7a(%rip),%xmm1
pcmpeqd %xmm2,%xmm2
pxor   %xmm2,%xmm1
pcmpeqd 0xe7a(%rip),%xmm0
pxor   %xmm2,%xmm0
packssdw %xmm1,%xmm0
pmovmskb %xmm0,%eax
test   %eax,%eax
lea    0xeff(%rip),%rax
lea    0xeec(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"------------------------------------\0A\00"
@.str.1 = [26 x i8] c"teste Q5: troca_valores.\0A\00"
@__const.test_troca_valores.mat = [4 x [4 x i32]] [[4 x i32] [i32 1, i32 2, i32 3, i32 4], [4 x i32] [i32 1, i32 1, i32 1, i32 1], [4 x i32] [i32 1, i32 1, i32 1, i32 1], [4 x i32] [i32 4, i32 3, i32 2, i32 1]]
@.str.2 = [9 x i8] c" ok.\0A\00"
@.str.3 = [13 x i8] c" not ok.\0A\00"
define void @test_troca_valores() {
%1 = alloca [4 x [4 x i32]]
%2 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast [4 x [4 x i32]]* %1 to i8*
%5 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 0
%6 = bitcast [4 x i32]* %5 to i32**
%7 = call i32 @troca_valores(i32** %6)
%8 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 0
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 4
br i1 %11, label %12, label %49
12: ; preds = %0
%13 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 0
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %13, i64 0, i64 1
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %49
17: ; preds = %12
%18 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 0
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 2
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %49
22: ; preds = %17
%23 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 0
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %23, i64 0, i64 3
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %49
27: ; preds = %22
%28 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 3
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %28, i64 0, i64 0
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %49
32: ; preds = %27
%33 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 3
%34 = getelementptr inbounds [4 x i32], [4 x i32]* %33, i64 0, i64 1
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 2
br i1 %36, label %37, label %49
37: ; preds = %32
%38 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 3
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %38, i64 0, i64 2
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 3
br i1 %41, label %42, label %49
42: ; preds = %37
%43 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 3
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %43, i64 0, i64 3
%45 = load i32, i32* %44
%46 = icmp eq i32 %45, 4
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %51
49: ; preds = %42, %37, %32, %27, %22, %17, %12, %0
%50 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
ret void
}

LLVM IR (-O2):
@__const.test_troca_valores.mat = [4 x [4 x i32]] [[4 x i32] [i32 1, i32 2, i32 3, i32 4], [4 x i32] [i32 1, i32 1, i32 1, i32 1], [4 x i32] [i32 1, i32 1, i32 1, i32 1], [4 x i32] [i32 4, i32 3, i32 2, i32 1]]
@str = [37 x i8] c"------------------------------------\00"
@str.4 = [25 x i8] c"teste Q5: troca_valores.\00"
@str.5 = [12 x i8] c" not ok.\00"
@str.6 = [8 x i8] c" ok.\00"
define void @test_troca_valores() {
%1 = alloca [4 x [4 x i32]]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
%4 = bitcast [4 x [4 x i32]]* %1 to i8*
%5 = bitcast [4 x [4 x i32]]* %1 to i32**
%6 = call i32 @troca_valores(i32** %5)
%7 = bitcast [4 x [4 x i32]]* %1 to <4 x i32>*
%8 = load <4 x i32>, <4 x i32>* %7
%9 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %1, i64 0, i64 3, i64 0
%10 = bitcast i32* %9 to <4 x i32>*
%11 = load <4 x i32>, <4 x i32>* %10
%12 = shufflevector <4 x i32> %8, <4 x i32> %11, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
%13 = freeze <8 x i32> %12
%14 = icmp ne <8 x i32> %13, <i32 4, i32 3, i32 2, i32 1, i32 1, i32 2, i32 3, i32 4>
%15 = bitcast <8 x i1> %14 to i8
%16 = icmp eq i8 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0)
%18 = call i32 @puts(i8* dereferenceable(1) %17)
ret void
}