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


x86 assembly (clang, -O0):
<test_preenche_matriz_um_e_zero>:
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_um_e_zero@plt>
movl   $0x0,-0x654(%rbp)
movl   $0x0,-0x658(%rbp)
movl   $0x0,-0x654(%rbp)
cmpl   $0x14,-0x654(%rbp)
jge    124b <test_preenche_matriz_um_e_zero+0x12b>
movl   $0x0,-0x658(%rbp)
cmpl   $0x14,-0x658(%rbp)
jge    1232 <test_preenche_matriz_um_e_zero+0x112>
mov    -0x654(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d5 <test_preenche_matriz_um_e_zero+0xb5>
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    1212 <test_preenche_matriz_um_e_zero+0xf2>
mov    -0x654(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1219 <test_preenche_matriz_um_e_zero+0xf9>
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     1219 <test_preenche_matriz_um_e_zero+0xf9>
movl   $0x0,-0x4(%rbp)
jmp    121e <test_preenche_matriz_um_e_zero+0xfe>
mov    -0x658(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x658(%rbp)
jmp    118b <test_preenche_matriz_um_e_zero+0x6b>
jmp    1237 <test_preenche_matriz_um_e_zero+0x117>
mov    -0x654(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x654(%rbp)
jmp    1174 <test_preenche_matriz_um_e_zero+0x54>
cmpl   $0x0,-0x4(%rbp)
je     1266 <test_preenche_matriz_um_e_zero+0x146>
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
jmp    1272 <test_preenche_matriz_um_e_zero+0x152>
lea    0xde8(%rip),%rdi
call   1030 <printf@plt>
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_preenche_matriz_um_e_zero>:
push   %rbx
sub    $0x640,%rsp
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <preenche_matriz_um_e_zero@plt>
mov    $0x1,%ecx
xor    %eax,%eax
jmp    116e <test_preenche_matriz_um_e_zero+0x4e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rax
add    $0x50,%rbx
cmp    $0x14,%rax
je     11b4 <test_preenche_matriz_um_e_zero+0x94>
mov    $0x1,%edx
jmp    1190 <test_preenche_matriz_um_e_zero+0x70>
cs nopw 0x0(%rax,%rax,1)
nop
test   %esi,%esi
je     1186 <test_preenche_matriz_um_e_zero+0x66>
xor    %ecx,%ecx
add    $0x2,%rdx
cmp    $0x15,%rdx
je     1160 <test_preenche_matriz_um_e_zero+0x40>
mov    -0x4(%rbx,%rdx,4),%esi
test   $0x1,%al
jne    11a0 <test_preenche_matriz_um_e_zero+0x80>
cmp    $0x1,%esi
jne    11a4 <test_preenche_matriz_um_e_zero+0x84>
jmp    11a6 <test_preenche_matriz_um_e_zero+0x86>
nop
test   %esi,%esi
je     11a6 <test_preenche_matriz_um_e_zero+0x86>
xor    %ecx,%ecx
mov    (%rbx,%rdx,4),%esi
test   $0x1,%al
jne    1180 <test_preenche_matriz_um_e_zero+0x60>
cmp    $0x1,%esi
jne    1184 <test_preenche_matriz_um_e_zero+0x64>
jmp    1186 <test_preenche_matriz_um_e_zero+0x66>
test   %ecx,%ecx
lea    0xe8d(%rip),%rax
lea    0xe92(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
add    $0x640,%rsp
pop    %rbx
ret

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