#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ system(char *);
int main() {
  int *M;
  int m = 0, n = 0;
  int i, j;
  int total = 0;
  printf("Cuantos renglones tiene su matriz?\n");
  scanf("%d", &m);
  printf("Cuantas columnas tiene su matriz?\n");
  scanf("%d", &n);
  M = (int *)malloc((m * n) * sizeof(int));
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      printf("Ingrese el valor de M[%d][%d]:  ", i + 1, j + 1);
      scanf("%d", M);
      if (*M == 0)
        total++;
    }
  }
  printf("\n\n\tSe ingresaron %d ceros\n\n", total);
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeab(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8d(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1244 <main+0x104>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1231 <main+0xf1>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    121e <main+0xde>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1223 <main+0xe3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d2 <main+0x92>
jmp    1236 <main+0xf6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bf <main+0x7f>
mov    -0x24(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2b(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe83(%rip),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
imul   (%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    1222 <main+0xd2>
mov    %rax,%r13
mov    (%rsp),%eax
lea    0xe3d(%rip),%r14
lea    0xe33(%rip),%r15
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    11e5 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %ecx,%r12d
jge    1224 <main+0xd4>
add    $0x1,%r12d
test   %eax,%eax
jle    11e0 <main+0x90>
xor    %ebx,%ebx
nop
add    $0x1,%ebx
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
cmpl   $0x1,0x0(%r13)
adc    $0x0,%ebp
mov    (%rsp),%eax
cmp    %eax,%ebx
jl     11f0 <main+0xa0>
mov    0x4(%rsp),%ecx
jmp    11e0 <main+0x90>
xor    %ebp,%ebp
lea    0xdf9(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe05(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Cuantos renglones tiene su matriz?\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"Cuantas columnas tiene su matriz?\0A\00"
@.str.3 = [33 x i8] c"Ingrese el valor de M[%d][%d]: \00"
@.str.4 = [28 x i8] c"\0A\0A\09Se ingresaron %d ceros\0A\0A\00"
@.str.5 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = mul nsw i32 %12, %13
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %2
store i32 0, i32* %5
br label %20
20: ; preds = %48, %0
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %51
24: ; preds = %20
store i32 0, i32* %6
br label %25
25: ; preds = %44, %24
%26 = load i32, i32* %6
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %47
29: ; preds = %25
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %33)
%35 = load i32*, i32** %2
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %35)
%37 = load i32*, i32** %2
%38 = load i32, i32* %37
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %43
43: ; preds = %40, %29
br label %44
44: ; preds = %43
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %25
47: ; preds = %25
br label %48
48: ; preds = %47
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %20
51: ; preds = %20
%52 = load i32, i32* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %52)
%54 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [33 x i8] c"Ingrese el valor de M[%d][%d]: \00"
@.str.4 = [28 x i8] c"\0A\0A\09Se ingresaron %d ceros\0A\0A\00"
@.str.5 = [6 x i8] c"pause\00"
@str = [35 x i8] c"Cuantos renglones tiene su matriz?\00"
@str.6 = [34 x i8] c"Cuantas columnas tiene su matriz?\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = shl i32 %9, 2
%12 = mul i32 %11, %10
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
%15 = load i32, i32* %1
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %45
17: ; preds = %0
%18 = load i32, i32* %2
br label %19
19: ; preds = %17, %40
%20 = phi i32 [ %41, %40 ], [ %15, %17 ]
%21 = phi i32 [ %42, %40 ], [ %18, %17 ]
%22 = phi i32 [ %43, %40 ], [ 0, %17 ]
%23 = phi i32 [ %25, %40 ], [ 0, %17 ]
%24 = icmp sgt i32 %21, 0
%25 = add nuw nsw i32 %23, 1
br i1 %24, label %26, label %40
26: ; preds = %19, %26
%27 = phi i32 [ %35, %26 ], [ %22, %19 ]
%28 = phi i32 [ %29, %26 ], [ 0, %19 ]
%29 = add nuw nsw i32 %28, 1
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %29)
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%32 = load i32, i32* %14
%33 = icmp eq i32 %32, 0
%34 = zext i1 %33 to i32
%35 = add nsw i32 %27, %34
%36 = load i32, i32* %2
%37 = icmp slt i32 %29, %36
br i1 %37, label %26, label %38
38: ; preds = %26
%39 = load i32, i32* %1
br label %40
40: ; preds = %19, %38
%41 = phi i32 [ %39, %38 ], [ %20, %19 ]
%42 = phi i32 [ %36, %38 ], [ %21, %19 ]
%43 = phi i32 [ %35, %38 ], [ %22, %19 ]
%44 = icmp slt i32 %25, %41
br i1 %44, label %19, label %45
45: ; preds = %40, %0
%46 = phi i32 [ 0, %0 ], [ %43, %40 ]
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}