#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*/ preenche_matriz_diagonal_principal(int **);
int /*<<< orphan*/ printf(char *);
void test_preenche_matriz_diagonal_principal() {
  printf("------------------------------------\n");
  printf("teste Q2: preenche_matriz_diagonal_p.\n");
  bool certo = true;
  int mat[20][20];
  preenche_matriz_diagonal_principal(mat);
  int i = 0, j = 0;
  for (i = 0; i < 20; i++) {
    for (j = 0; j < 20; j++)
      if ((i == j && mat[i][j] != 1) || (i != j && mat[i][j] != 0))
        certo = false;
  }
  if (certo) {
    printf("    ok.\n");
  } else {
    printf("    not ok.\n");
  }
}


x86 assembly (clang, -O0):
<test_preenche_matriz_diagonal_principal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
lea    -0x650(%rbp),%rdi
call   1040 <preenche_matriz_diagonal_principal@plt>
movl   $0x0,-0x654(%rbp)
movl   $0x0,-0x658(%rbp)
movl   $0x0,-0x654(%rbp)
cmpl   $0x14,-0x654(%rbp)
jge    1241 <test_preenche_matriz_diagonal_principal+0x121>
movl   $0x0,-0x658(%rbp)
cmpl   $0x14,-0x658(%rbp)
jge    1228 <test_preenche_matriz_diagonal_principal+0x108>
mov    -0x654(%rbp),%eax
cmp    -0x658(%rbp),%eax
jne    11d0 <test_preenche_matriz_diagonal_principal+0xb0>
movslq -0x654(%rbp),%rcx
lea    -0x650(%rbp),%rax
imul   $0x50,%rcx,%rcx
add    %rcx,%rax
movslq -0x658(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1208 <test_preenche_matriz_diagonal_principal+0xe8>
mov    -0x654(%rbp),%eax
cmp    -0x658(%rbp),%eax
je     120f <test_preenche_matriz_diagonal_principal+0xef>
movslq -0x654(%rbp),%rcx
lea    -0x650(%rbp),%rax
imul   $0x50,%rcx,%rcx
add    %rcx,%rax
movslq -0x658(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     120f <test_preenche_matriz_diagonal_principal+0xef>
movl   $0x0,-0x4(%rbp)
jmp    1214 <test_preenche_matriz_diagonal_principal+0xf4>
mov    -0x658(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x658(%rbp)
jmp    118b <test_preenche_matriz_diagonal_principal+0x6b>
jmp    122d <test_preenche_matriz_diagonal_principal+0x10d>
mov    -0x654(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x654(%rbp)
jmp    1174 <test_preenche_matriz_diagonal_principal+0x54>
cmpl   $0x0,-0x4(%rbp)
je     125c <test_preenche_matriz_diagonal_principal+0x13c>
lea    0xdfb(%rip),%rdi
call   1030 <printf@plt>
jmp    1268 <test_preenche_matriz_diagonal_principal+0x148>
lea    0xdf3(%rip),%rdi
call   1030 <printf@plt>
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_preenche_matriz_diagonal_principal>:
sub    $0x648,%rsp
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1040 <preenche_matriz_diagonal_principal@plt>
lea    0x4(%rsp),%rax
mov    $0x1,%r8d
xor    %ecx,%ecx
jmp    116e <test_preenche_matriz_diagonal_principal+0x4e>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rcx
add    $0x50,%rax
cmp    $0x14,%rcx
je     11da <test_preenche_matriz_diagonal_principal+0xba>
lea    (%rcx,%rcx,4),%rdx
shl    $0x4,%rdx
add    %rsp,%rdx
lea    (%rdx,%rcx,4),%rsi
xor    %edx,%edx
jmp    11a6 <test_preenche_matriz_diagonal_principal+0x86>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpl   $0x0,(%rax,%rdx,4)
je     1199 <test_preenche_matriz_diagonal_principal+0x79>
xor    %r8d,%r8d
add    $0x1,%rdi
mov    %rdi,%rdx
cmp    $0x14,%rdi
je     1160 <test_preenche_matriz_diagonal_principal+0x40>
cmp    %rdx,%rcx
jne    11c0 <test_preenche_matriz_diagonal_principal+0xa0>
cmpl   $0x1,(%rsi)
jne    11c7 <test_preenche_matriz_diagonal_principal+0xa7>
jmp    11ca <test_preenche_matriz_diagonal_principal+0xaa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpl   $0x0,-0x4(%rax,%rdx,4)
je     11ca <test_preenche_matriz_diagonal_principal+0xaa>
xor    %r8d,%r8d
lea    0x1(%rdx),%rdi
cmp    %rdi,%rcx
jne    1190 <test_preenche_matriz_diagonal_principal+0x70>
cmpl   $0x1,(%rsi)
jne    1196 <test_preenche_matriz_diagonal_principal+0x76>
jmp    1199 <test_preenche_matriz_diagonal_principal+0x79>
test   %r8d,%r8d
lea    0xe67(%rip),%rax
lea    0xe6c(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
add    $0x648,%rsp
ret

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

LLVM IR (-O2):
@str = [37 x i8] c"------------------------------------\00"
@str.4 = [38 x i8] c"teste Q2: preenche_matriz_diagonal_p.\00"
@str.5 = [12 x i8] c" not ok.\00"
@str.6 = [8 x i8] c" ok.\00"
define void @test_preenche_matriz_diagonal_principal() {
%1 = alloca [20 x [20 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 ([38 x i8], [38 x i8]* @str.4, i64 0, i64 0))
%4 = bitcast [20 x [20 x i32]]* %1 to i8*
%5 = bitcast [20 x [20 x i32]]* %1 to i32**
%6 = call i32 @preenche_matriz_diagonal_principal(i32** %5)
br label %7
7: ; preds = %0, %39
%8 = phi i64 [ 0, %0 ], [ %40, %39 ]
%9 = phi i32 [ 1, %0 ], [ %36, %39 ]
%10 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %1, i64 0, i64 %8, i64 %8
br label %11
11: ; preds = %35, %7
%12 = phi i64 [ 0, %7 ], [ %37, %35 ]
%13 = phi i32 [ %9, %7 ], [ %36, %35 ]
%14 = icmp eq i64 %8, %12
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %10
%17 = icmp eq i32 %16, 1
br i1 %17, label %23, label %22
18: ; preds = %11
%19 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %1, i64 0, i64 %8, i64 %12
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18, %15
br label %23
23: ; preds = %15, %18, %22
%24 = phi i32 [ 0, %22 ], [ %13, %18 ], [ %13, %15 ]
%25 = or i64 %12, 1
%26 = icmp eq i64 %8, %25
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %1, i64 0, i64 %8, i64 %25
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %34
31: ; preds = %23
%32 = load i32, i32* %10
%33 = icmp eq i32 %32, 1
br i1 %33, label %35, label %34
34: ; preds = %31, %27
br label %35
35: ; preds = %34, %31, %27
%36 = phi i32 [ 0, %34 ], [ %24, %27 ], [ %24, %31 ]
%37 = add nuw nsw i64 %12, 2
%38 = icmp eq i64 %37, 20
br i1 %38, label %39, label %11
39: ; preds = %35
%40 = add nuw nsw i64 %8, 1
%41 = icmp eq i64 %40, 20
br i1 %41, label %42, label %7
42: ; preds = %39
%43 = icmp eq i32 %36, 0
%44 = select i1 %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0)
%45 = call i32 @puts(i8* dereferenceable(1) %44)
ret void
}