#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 deleteq();
int /*<<< orphan*/ insertq(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int A[100][100], B[100], n, i, j, x;
  printf("\nEnter the number of vetices ");
  scanf("%d", &n);
  printf("\nNow enter the adjacency matrix ");
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      scanf("%d", &A[i][j]);
    }
  insertq(0);
  B[0] = 1;
  x = deleteq();
  printf("The BFS travesal order is : %d", x + 1);
  while (x != -1) {
    for (j = 0; j < n; j++) {
      if (A[x][j] == 1 && B[j] != 1) {
        insertq(j);
        B[j] = 1;
      }
    }
    x = deleteq();
    if (x != -1) {
      printf(" %d", x + 1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9df0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef4(%rip),%rdi
lea    -0x9de4(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x9de8(%rbp)
mov    -0x9de8(%rbp),%eax
cmp    -0x9de4(%rbp),%eax
jge    1218 <main+0xd8>
movl   $0x0,-0x9dec(%rbp)
mov    -0x9dec(%rbp),%eax
cmp    -0x9de4(%rbp),%eax
jge    11ff <main+0xbf>
movslq -0x9de8(%rbp),%rax
lea    -0x9c50(%rbp),%rsi
imul   $0x190,%rax,%rax
add    %rax,%rsi
movslq -0x9dec(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe75(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x9dec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9dec(%rbp)
jmp    11a7 <main+0x67>
jmp    1204 <main+0xc4>
mov    -0x9de8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9de8(%rbp)
jmp    118b <main+0x4b>
xor    %edi,%edi
call   1060 <insertq@plt>
movl   $0x1,-0x9de0(%rbp)
mov    $0x0,%al
call   1040 <deleteq@plt>
mov    %eax,-0x9df0(%rbp)
mov    -0x9df0(%rbp),%esi
add    $0x1,%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xffffffff,-0x9df0(%rbp)
je     1320 <main+0x1e0>
movl   $0x0,-0x9dec(%rbp)
mov    -0x9dec(%rbp),%eax
cmp    -0x9de4(%rbp),%eax
jge    12ea <main+0x1aa>
movslq -0x9df0(%rbp),%rcx
lea    -0x9c50(%rbp),%rax
imul   $0x190,%rcx,%rcx
add    %rcx,%rax
movslq -0x9dec(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    12d1 <main+0x191>
movslq -0x9dec(%rbp),%rax
cmpl   $0x1,-0x9de0(%rbp,%rax,4)
01
je     12d1 <main+0x191>
mov    -0x9dec(%rbp),%edi
call   1060 <insertq@plt>
movslq -0x9dec(%rbp),%rax
movl   $0x1,-0x9de0(%rbp,%rax,4)
jmp    12d6 <main+0x196>
mov    -0x9dec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9dec(%rbp)
jmp    1264 <main+0x124>
mov    $0x0,%al
call   1040 <deleteq@plt>
mov    %eax,-0x9df0(%rbp)
cmpl   $0xffffffff,-0x9df0(%rbp)
je     131b <main+0x1db>
mov    -0x9df0(%rbp),%esi
add    $0x1,%esi
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <main+0x10d>
xor    %eax,%eax
add    $0x9df0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9de0,%rsp
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef6(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11df <main+0x9f>
lea    0x1a0(%rsp),%r15
xor    %r12d,%r12d
lea    0xec4(%rip),%r14
jmp    11b3 <main+0x73>
nopl   0x0(%rax)
movslq %eax,%rcx
add    $0x1,%r12
add    $0x190,%r15
cmp    %rcx,%r12
jge    11df <main+0x9f>
test   %eax,%eax
jle    11a0 <main+0x60>
mov    %r15,%r13
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11c0 <main+0x80>
jmp    11a0 <main+0x60>
xor    %edi,%edi
call   1060 <insertq@plt>
movl   $0x1,0x10(%rsp)
xor    %eax,%eax
call   1040 <deleteq@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%esi
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
inc    %eax
jne    1221 <main+0xe1>
xor    %eax,%eax
add    $0x9de0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe32(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1290 <main+0x150>
movslq %ebx,%rcx
imul   $0x190,%rcx,%rcx
lea    (%rsp,%rcx,1),%r15
add    $0x1a0,%r15
xor    %ebx,%ebx
jmp    126c <main+0x12c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
movslq %eax,%rcx
cmp    %rcx,%rbx
jge    1290 <main+0x150>
cmpl   $0x1,(%r15,%rbx,4)
jne    1260 <main+0x120>
cmpl   $0x1,0x10(%rsp,%rbx,4)
je     1260 <main+0x120>
mov    %ebx,%edi
call   1060 <insertq@plt>
movl   $0x1,0x10(%rsp,%rbx,4)
mov    0xc(%rsp),%eax
jmp    1260 <main+0x120>
nop
xor    %eax,%eax
call   1040 <deleteq@plt>
cmp    $0xffffffff,%eax
je     120e <main+0xce>
mov    %eax,%ebx
mov    %eax,%esi
add    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1230 <main+0xf0>

LLVM IR (-O0):
@.str = [30 x i8] c"\0AEnter the number of vetices \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"\0ANow enter the adjacency matrix \00"
@.str.3 = [31 x i8] c"The BFS travesal order is : %d\00"
@.str.4 = [4 x i8] c" %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x [100 x i32]]
%3 = alloca [100 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 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* %4)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %11
11: ; preds = %32, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %11
store i32 0, i32* %6
br label %16
16: ; preds = %28, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %22
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %23, i64 0, i64 %25
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %26)
br label %28
28: ; preds = %20
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %16
31: ; preds = %16
br label %32
32: ; preds = %31
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %11
35: ; preds = %11
%36 = call i32 @insertq(i32 0)
%37 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
store i32 1, i32* %37
%38 = call i32 (...) @deleteq()
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %83, %35
%43 = load i32, i32* %7
%44 = icmp ne i32 %43, -1
br i1 %44, label %45, label %84
45: ; preds = %42
store i32 0, i32* %6
br label %46
46: ; preds = %72, %45
%47 = load i32, i32* %6
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %75
50: ; preds = %46
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %52
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [100 x i32], [100 x i32]* %53, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %71
59: ; preds = %50
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = icmp ne i32 %63, 1
br i1 %64, label %65, label %71
65: ; preds = %59
%66 = load i32, i32* %6
%67 = call i32 @insertq(i32 %66)
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %69
store i32 1, i32* %70
br label %71
71: ; preds = %65, %59, %50
br label %72
72: ; preds = %71
%73 = load i32, i32* %6
%74 = add nsw i32 %73, 1
store i32 %74, i32* %6
br label %46
75: ; preds = %46
%76 = call i32 (...) @deleteq()
store i32 %76, i32* %7
%77 = load i32, i32* %7
%78 = icmp ne i32 %77, -1
br i1 %78, label %79, label %83
79: ; preds = %75
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %81)
br label %83
83: ; preds = %79, %75
br label %42
84: ; preds = %42
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"\0AEnter the number of vetices \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"\0ANow enter the adjacency matrix \00"
@.str.3 = [31 x i8] c"The BFS travesal order is : %d\00"
@.str.4 = [4 x i8] c" %d\00"
define i32 @main() {
%1 = alloca [100 x [100 x i32]]
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = bitcast [100 x [100 x i32]]* %1 to i8*
%5 = bitcast [100 x i32]* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %0, %24
%13 = phi i32 [ %25, %24 ], [ %10, %0 ]
%14 = phi i64 [ %27, %24 ], [ 0, %0 ]
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %24
16: ; preds = %12, %16
%17 = phi i64 [ %20, %16 ], [ 0, %12 ]
%18 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %1, i64 0, i64 %14, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = add nuw nsw i64 %17, 1
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %16, label %24
24: ; preds = %16, %12
%25 = phi i32 [ %13, %12 ], [ %21, %16 ]
%26 = sext i32 %25 to i64
%27 = add nuw nsw i64 %14, 1
%28 = icmp slt i64 %27, %26
br i1 %28, label %12, label %29
29: ; preds = %24, %0
%30 = call i32 @insertq(i32 0)
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
store i32 1, i32* %31
%32 = call i32 (...) @deleteq()
%33 = add nsw i32 %32, 1
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = icmp eq i32 %32, -1
br i1 %35, label %67, label %36
36: ; preds = %29, %64
%37 = phi i32 [ %62, %64 ], [ %32, %29 ]
%38 = load i32, i32* %3
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %61
40: ; preds = %36
%41 = sext i32 %37 to i64
br label %42
42: ; preds = %40, %56
%43 = phi i32 [ %38, %40 ], [ %57, %56 ]
%44 = phi i64 [ 0, %40 ], [ %58, %56 ]
%45 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %1, i64 0, i64 %41, i64 %44
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %56
48: ; preds = %42
%49 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %44
%50 = load i32, i32* %49
%51 = icmp eq i32 %50, 1
br i1 %51, label %56, label %52
52: ; preds = %48
%53 = trunc i64 %44 to i32
%54 = call i32 @insertq(i32 %53)
store i32 1, i32* %49
%55 = load i32, i32* %3
br label %56
56: ; preds = %42, %48, %52
%57 = phi i32 [ %43, %42 ], [ %43, %48 ], [ %55, %52 ]
%58 = add nuw nsw i64 %44, 1
%59 = sext i32 %57 to i64
%60 = icmp slt i64 %58, %59
br i1 %60, label %42, label %61
61: ; preds = %56, %36
%62 = call i32 (...) @deleteq()
%63 = icmp eq i32 %62, -1
br i1 %63, label %67, label %64
64: ; preds = %61
%65 = add nuw nsw i32 %62, 1
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %65)
br label %36
67: ; preds = %61, %29
ret i32 0
}