#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 EXIT_SUCCESS;
int count(int **, int, int);
int /*<<< orphan*/ free_2d_array(int **, int);
int **make_2d_array(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int rows, cols;
  scanf("%d %d", &cols, &rows);
  int x, y;
  int **graph = make_2d_array(cols, rows);
  for (y = 0; y < rows; ++y) {
    for (x = 0; x < cols; ++x) {
      scanf("%d", &graph[y][x]);
    }
  }
  printf("Graph:\n");
  for (y = 0; y < rows; ++y) {
    for (x = 0; x < cols; ++x) {
      printf("%d ", graph[y][x]);
    }
    printf("\n");
  }
  printf("Total: %d\n", count((int **)graph, rows, cols));
  free_2d_array(graph, rows);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <make_2d_array@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f0 <main+0xa0>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dd <main+0x8d>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119e <main+0x4e>
jmp    11e2 <main+0x92>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <main+0x3b>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    126f <main+0x11f>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1253 <main+0x103>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1218 <main+0xc8>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1205 <main+0xb5>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <count@plt>
mov    %eax,%esi
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <free_2d_array@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe7c(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1050 <make_2d_array@plt>
mov    %rax,%r15
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jle    1209 <main+0x99>
mov    0x8(%rsp),%eax
lea    0xe4b(%rip),%r14
xor    %r12d,%r12d
jmp    11cc <main+0x5c>
nopl   (%rax)
add    $0x1,%r12
movslq %ecx,%rdx
cmp    %rdx,%r12
jge    1209 <main+0x99>
test   %eax,%eax
jle    11c0 <main+0x50>
xor    %r13d,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%r12,8),%rsi
add    %r13,%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11e0 <main+0x70>
mov    0xc(%rsp),%ecx
jmp    11c0 <main+0x50>
lea    0xe05(%rip),%rdi
call   1060 <puts@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    1281 <main+0x111>
lea    0xde2(%rip),%r14
xor    %r12d,%r12d
jmp    1248 <main+0xd8>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x1,%r12
movslq 0xc(%rsp),%rsi
cmp    %rsi,%r12
jge    1281 <main+0x111>
cmpl   $0x0,0x8(%rsp)
jle    1230 <main+0xc0>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%r12,8),%rax
mov    (%rax,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1260 <main+0xf0>
jmp    1230 <main+0xc0>
mov    0x8(%rsp),%edx
mov    %r15,%rdi
call   1030 <count@plt>
lea    0xd76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%esi
mov    %r15,%rdi
call   1090 <free_2d_array@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"Graph:\0A\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [11 x i8] c"Total: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
store i32 0, i32* %1
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %2)
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = call i32** @make_2d_array(i32 %8, i32 %9)
store i32** %10, i32*** %6
store i32 0, i32* %5
br label %11
11: ; preds = %34, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %37
15: ; preds = %11
store i32 0, i32* %4
br label %16
16: ; preds = %30, %15
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i32**, i32*** %6
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32*, i32** %21, i64 %23
%25 = load i32*, i32** %24
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %28)
br label %30
30: ; preds = %20
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %16
33: ; preds = %16
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %11
37: ; preds = %11
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %39
39: ; preds = %64, %37
%40 = load i32, i32* %5
%41 = load i32, i32* %2
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %67
43: ; preds = %39
store i32 0, i32* %4
br label %44
44: ; preds = %59, %43
%45 = load i32, i32* %4
%46 = load i32, i32* %3
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %62
48: ; preds = %44
%49 = load i32**, i32*** %6
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32*, i32** %49, i64 %51
%53 = load i32*, i32** %52
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %48
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %44
62: ; preds = %44
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %62
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 1
store i32 %66, i32* %5
br label %39
67: ; preds = %39
%68 = load i32**, i32*** %6
%69 = load i32, i32* %2
%70 = load i32, i32* %3
%71 = call i32 @count(i32** %68, i32 %69, i32 %70)
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %71)
%73 = load i32**, i32*** %6
%74 = load i32, i32* %2
%75 = call i32 @free_2d_array(i32** %73, i32 %74)
%76 = load i32, i32* @EXIT_SUCCESS
ret i32 %76
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.5 = [11 x i8] c"Total: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [7 x i8] c"Graph:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %1)
%6 = load i32, i32* %2
%7 = load i32, i32* %1
%8 = call i32** @make_2d_array(i32 %6, i32 %7)
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %37
11: ; preds = %0
%12 = load i32, i32* %2
br label %13
13: ; preds = %11, %31
%14 = phi i32 [ %9, %11 ], [ %32, %31 ]
%15 = phi i32 [ %12, %11 ], [ %33, %31 ]
%16 = phi i64 [ 0, %11 ], [ %34, %31 ]
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %31
18: ; preds = %13
%19 = getelementptr inbounds i32*, i32** %8, i64 %16
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %25, %20 ]
%22 = load i32*, i32** %19
%23 = getelementptr inbounds i32, i32* %22, i64 %21
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
%25 = add nuw nsw i64 %21, 1
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %20, label %29
29: ; preds = %20
%30 = load i32, i32* %1
br label %31
31: ; preds = %29, %13
%32 = phi i32 [ %30, %29 ], [ %14, %13 ]
%33 = phi i32 [ %26, %29 ], [ %15, %13 ]
%34 = add nuw nsw i64 %16, 1
%35 = sext i32 %32 to i64
%36 = icmp slt i64 %34, %35
br i1 %36, label %13, label %37
37: ; preds = %31, %0
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%39 = load i32, i32* %1
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %63
41: ; preds = %37, %57
%42 = phi i64 [ %59, %57 ], [ 0, %37 ]
%43 = load i32, i32* %2
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %57
45: ; preds = %41
%46 = getelementptr inbounds i32*, i32** %8, i64 %42
br label %47
47: ; preds = %45, %47
%48 = phi i64 [ 0, %45 ], [ %53, %47 ]
%49 = load i32*, i32** %46
%50 = getelementptr inbounds i32, i32* %49, i64 %48
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %51)
%53 = add nuw nsw i64 %48, 1
%54 = load i32, i32* %2
%55 = sext i32 %54 to i64
%56 = icmp slt i64 %53, %55
br i1 %56, label %47, label %57
57: ; preds = %47, %41
%58 = call i32 @putchar(i32 10)
%59 = add nuw nsw i64 %42, 1
%60 = load i32, i32* %1
%61 = sext i32 %60 to i64
%62 = icmp slt i64 %59, %61
br i1 %62, label %41, label %63
63: ; preds = %57, %37
%64 = phi i32 [ %39, %37 ], [ %60, %57 ]
%65 = load i32, i32* %2
%66 = call i32 @count(i32** %8, i32 %64, i32 %65)
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %1
%69 = call i32 @free_2d_array(i32** %8, i32 %68)
%70 = load i32, i32* @EXIT_SUCCESS
ret i32 %70
}