#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int /*<<< orphan*/ printf(char *);
int main(void) {
  char *nomeDoArquivoDeEntrada = "entrada.txt";
  FILE *arquivoEntrada = fopen(nomeDoArquivoDeEntrada, "r");
  if (!arquivoEntrada) {
    printf("Não consegui ler o arquivo de entrada\n");
    exit(EXIT_FAILURE);
  }
  char *nomeDoArquivoDeSaida = "saida.txt";
  FILE *arquivoSaida = fopen(nomeDoArquivoDeSaida, "w");
  if (!arquivoSaida) {
    printf("Não consegui abrir o arquivo de saída\n");
    exit(EXIT_FAILURE);
  }
  int numeroDeCasosDeTeste = 0;
  fscanf(arquivoEntrada, "%d", &numeroDeCasosDeTeste);
  int numeroLinhas;
  int numeroColunas;
  for (int casoTeste = 0; casoTeste < numeroDeCasosDeTeste; casoTeste++) {
    fscanf(arquivoEntrada, "%d %d", &numeroLinhas, &numeroColunas);
    int matriz[numeroLinhas][numeroColunas];
    for (int linhaAtual = 0; linhaAtual < numeroLinhas; linhaAtual++) {
      for (int colunaAtual = 0; colunaAtual < numeroColunas; colunaAtual++) {
        fscanf(arquivoEntrada, "%d", &matriz[linhaAtual][colunaAtual]);
      }
    }
    int normaUm = 0;
    int normaInf = 0;
    int normaFro = 0;
    fprintf(arquivoSaida, "%d %d %d\n", normaUm, normaInf, normaFro);
  }
  fclose(arquivoEntrada);
  fclose(arquivoSaida);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b6 <main+0x56>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe79(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11fa <main+0x9a>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe62(%rip),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    133e <main+0x1de>
mov    -0x18(%rbp),%rdi
lea    0xe36(%rip),%rsi
xor    %eax,%eax
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1050 <fscanf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
mov    %rax,-0x78(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x40(%rbp)
mov    %rcx,%rdx
imul   %rax,%rdx
lea    0xf(,%rdx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x70(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x48(%rbp)
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    12fa <main+0x19a>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    12e7 <main+0x187>
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0x18(%rbp),%rdi
movslq -0x54(%rbp),%rax
imul   %rcx,%rax
shl    $0x2,%rax
add    %rax,%rdx
movslq -0x58(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1299 <main+0x139>
jmp    12ec <main+0x18c>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1286 <main+0x126>
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x5c(%rbp),%edx
mov    -0x60(%rbp),%ecx
mov    -0x64(%rbp),%r8d
lea    0xd4d(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    121e <main+0xbe>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe88(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12ec <main+0x18c>
mov    %rax,%rbx
lea    0xe77(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
test   %rax,%rax
je     12f5 <main+0x195>
movl   $0x0,-0x34(%rbp)
lea    0xe5f(%rip),%rsi
lea    -0x34(%rbp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmpl   $0x0,-0x34(%rbp)
jle    12ca <main+0x16a>
lea    0xe40(%rip),%r15
xor    %eax,%eax
jmp    121a <main+0xba>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    -0x40(%rbp),%rdi
lea    0xe25(%rip),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <fprintf@plt>
mov    -0x50(%rbp),%rsp
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cmp    -0x34(%rbp),%eax
jge    12ca <main+0x16a>
mov    %eax,-0x38(%rbp)
mov    %rbx,%rdi
lea    0xdf3(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %rsp,-0x50(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x2c(%rbp),%ecx
mov    %rcx,-0x48(%rbp)
imul   %rcx,%rax
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    -0x30(%rbp),%ecx
test   %ecx,%ecx
jle    11f0 <main+0x90>
mov    -0x2c(%rbp),%eax
shlq   $0x2,-0x48(%rbp)
xor    %r14d,%r14d
jmp    1294 <main+0x134>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
movslq %ecx,%rdx
add    -0x48(%rbp),%r13
cmp    %rdx,%r14
jge    11f0 <main+0x90>
test   %eax,%eax
jle    1280 <main+0x120>
mov    %r13,-0x58(%rbp)
xor    %r12d,%r12d
nop
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
add    $0x1,%r12
movslq -0x2c(%rbp),%rax
add    $0x4,%r13
cmp    %rax,%r12
jl     12a0 <main+0x140>
mov    -0x30(%rbp),%ecx
mov    -0x58(%rbp),%r13
jmp    1280 <main+0x120>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd37(%rip),%rdi
jmp    12fc <main+0x19c>
lea    0xd55(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"entrada.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"N\C3\A3o consegui ler o arquivo de entrada\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [10 x i8] c"saida.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [41 x i8] c"N\C3\A3o consegui abrir o arquivo de sa\C3\ADda\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [6 x i8] c"%d %d\00"
@.str.8 = [10 x i8] c"%d %d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%18 = load i8*, i8** %2
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %3
%20 = load i32*, i32** %3
%21 = icmp ne i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %0
%23 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %4
%27 = load i8*, i8** %4
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %28, i32** %5
%29 = load i32*, i32** %5
%30 = icmp ne i32* %29, null
br i1 %30, label %35, label %31
31: ; preds = %26
%32 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %26
store i32 0, i32* %6
%36 = load i32*, i32** %3
%37 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %6)
store i32 0, i32* %9
br label %38
38: ; preds = %85, %35
%39 = load i32, i32* %9
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %88
42: ; preds = %38
%43 = load i32*, i32** %3
%44 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32* %7, i32* %8)
%45 = load i32, i32* %7
%46 = zext i32 %45 to i64
%47 = load i32, i32* %8
%48 = zext i32 %47 to i64
%49 = call i8* @llvm.stacksave()
store i8* %49, i8** %10
%50 = mul nuw i64 %46, %48
%51 = alloca i32, i64 %50
store i64 %46, i64* %11
store i64 %48, i64* %12
store i32 0, i32* %13
br label %52
52: ; preds = %75, %42
%53 = load i32, i32* %13
%54 = load i32, i32* %7
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %78
56: ; preds = %52
store i32 0, i32* %14
br label %57
57: ; preds = %71, %56
%58 = load i32, i32* %14
%59 = load i32, i32* %8
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %74
61: ; preds = %57
%62 = load i32*, i32** %3
%63 = load i32, i32* %13
%64 = sext i32 %63 to i64
%65 = mul nsw i64 %64, %48
%66 = getelementptr inbounds i32, i32* %51, i64 %65
%67 = load i32, i32* %14
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %66, i64 %68
%70 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %69)
br label %71
71: ; preds = %61
%72 = load i32, i32* %14
%73 = add nsw i32 %72, 1
store i32 %73, i32* %14
br label %57
74: ; preds = %57
br label %75
75: ; preds = %74
%76 = load i32, i32* %13
%77 = add nsw i32 %76, 1
store i32 %77, i32* %13
br label %52
78: ; preds = %52
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
%79 = load i32*, i32** %5
%80 = load i32, i32* %15
%81 = load i32, i32* %16
%82 = load i32, i32* %17
%83 = call i32 @fprintf(i32* %79, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %80, i32 %81, i32 %82)
%84 = load i8*, i8** %10
br label %85
85: ; preds = %78
%86 = load i32, i32* %9
%87 = add nsw i32 %86, 1
store i32 %87, i32* %9
br label %38
88: ; preds = %38
%89 = load i32*, i32** %3
%90 = call i32 @fclose(i32* %89)
%91 = load i32*, i32** %5
%92 = call i32 @fclose(i32* %91)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"entrada.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [10 x i8] c"saida.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [6 x i8] c"%d %d\00"
@.str.8 = [10 x i8] c"%d %d %d\0A\00"
@str = [39 x i8] c"N\C3\A3o consegui ler o arquivo de entrada\00"
@str.9 = [40 x i8] c"N\C3\A3o consegui abrir o arquivo de sa\C3\ADda\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.9, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %10
%18 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%19 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%20 = bitcast i32* %2 to i8*
%21 = bitcast i32* %3 to i8*
%22 = load i32, i32* %1
%23 = icmp sgt i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %49, %17
%25 = call i32 @fclose(i32* %4)
%26 = call i32 @fclose(i32* %11)
ret i32 0
27: ; preds = %17, %49
%28 = phi i32 [ %51, %49 ], [ 0, %17 ]
%29 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32* %2, i32* %3)
%30 = load i32, i32* %2
%31 = zext i32 %30 to i64
%32 = load i32, i32* %3
%33 = zext i32 %32 to i64
%34 = call i8* @llvm.stacksave()
%35 = mul nuw i64 %33, %31
%36 = alloca i32, i64 %35
%37 = load i32, i32* %2
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %27
%40 = load i32, i32* %3
br label %41
41: ; preds = %39, %56
%42 = phi i32 [ %37, %39 ], [ %57, %56 ]
%43 = phi i32 [ %40, %39 ], [ %58, %56 ]
%44 = phi i64 [ 0, %39 ], [ %59, %56 ]
%45 = icmp sgt i32 %43, 0
br i1 %45, label %46, label %56
46: ; preds = %41
%47 = mul nuw nsw i64 %44, %33
%48 = getelementptr inbounds i32, i32* %36, i64 %47
br label %62
49: ; preds = %56, %27
%50 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 0, i32 0, i32 0)
%51 = add nuw nsw i32 %28, 1
%52 = load i32, i32* %1
%53 = icmp slt i32 %51, %52
br i1 %53, label %27, label %24
54: ; preds = %62
%55 = load i32, i32* %2
br label %56
56: ; preds = %54, %41
%57 = phi i32 [ %55, %54 ], [ %42, %41 ]
%58 = phi i32 [ %67, %54 ], [ %43, %41 ]
%59 = add nuw nsw i64 %44, 1
%60 = sext i32 %57 to i64
%61 = icmp slt i64 %59, %60
br i1 %61, label %41, label %49
62: ; preds = %46, %62
%63 = phi i64 [ 0, %46 ], [ %66, %62 ]
%64 = getelementptr inbounds i32, i32* %48, i64 %63
%65 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %64)
%66 = add nuw nsw i64 %63, 1
%67 = load i32, i32* %3
%68 = sext i32 %67 to i64
%69 = icmp slt i64 %66, %68
br i1 %69, label %62, label %54
}