#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*/ bfs(int, int /*<<< orphan*/, int **);
int /*<<< orphan*/ dfs(int, int /*<<< orphan*/, int **);
scalar_t__ malloc(int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, j, i;
  scanf("%d", &n);
  int **a = (int **)malloc(n * sizeof(int));
  for (i = 0; i < n; i++) {
    a[i] = (int *)malloc(n * sizeof(int));
    for (j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  bfs(n, 0, a);
  dfs(n, 0, a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fa <main+0xba>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e7 <main+0xa7>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe2c(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11aa <main+0x6a>
jmp    11ec <main+0xac>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1179 <main+0x39>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1030 <bfs@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1060 <dfs@plt>
xor    %eax,%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    0xeac(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    0xc(%rsp),%edi
test   %edi,%edi
jle    11f3 <main+0xb3>
xor    %r12d,%r12d
lea    0xe81(%rip),%r14
jmp    119c <main+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %edi,%rax
add    $0x1,%r12
cmp    %rax,%r12
jge    11f3 <main+0xb3>
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15,%r12,8)
mov    0xc(%rsp),%edi
test   %edi,%edi
jle    1190 <main+0x50>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edi
cmp    $0x2,%edi
jl     1190 <main+0x50>
mov    $0x1,%r13d
mov    $0x4,%ebx
nop
mov    (%r15,%r12,8),%rsi
add    %rbx,%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
add    $0x1,%r13
movslq 0xc(%rsp),%rdi
add    $0x4,%rbx
cmp    %rdi,%r13
jl     11d0 <main+0x90>
jmp    1190 <main+0x50>
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <bfs@plt>
mov    0xc(%rsp),%edi
xor    %esi,%esi
mov    %r15,%rdx
call   1060 <dfs@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = shl i32 %4, 2
%6 = call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i32**
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %37
10: ; preds = %0, %32
%11 = phi i64 [ %35, %32 ], [ 0, %0 ]
%12 = phi i32 [ %33, %32 ], [ %8, %0 ]
%13 = shl i32 %12, 2
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
%16 = getelementptr inbounds i32*, i32** %7, i64 %11
store i32* %15, i32** %16
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %10
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %15)
%21 = load i32, i32* %1
%22 = icmp sgt i32 %21, 1
br i1 %22, label %23, label %32
23: ; preds = %19, %23
%24 = phi i64 [ %28, %23 ], [ 1, %19 ]
%25 = load i32*, i32** %16
%26 = getelementptr inbounds i32, i32* %25, i64 %24
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %26)
%28 = add nuw nsw i64 %24, 1
%29 = load i32, i32* %1
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %28, %30
br i1 %31, label %23, label %32
32: ; preds = %23, %19, %10
%33 = phi i32 [ %17, %10 ], [ %21, %19 ], [ %29, %23 ]
%34 = sext i32 %33 to i64
%35 = add nuw nsw i64 %11, 1
%36 = icmp slt i64 %35, %34
br i1 %36, label %10, label %37
37: ; preds = %32, %0
%38 = phi i32 [ %8, %0 ], [ %33, %32 ]
%39 = call i32 @bfs(i32 %38, i32 0, i32** %7)
%40 = load i32, i32* %1
%41 = call i32 @dfs(i32 %40, i32 0, i32** %7)
ret i32 0
}