#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*/ EXIT_FAILURE;
int basics();
int bfs();
int dfs();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int menu(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ my_clearscrn();
int /*<<< orphan*/ prompt_and_pause(char *);
int main(void) {
  int menu_choice, retval;
  my_clearscrn();
  prompt_and_pause(
      "--- INITIAL DEMO INFORMATION ---\n\nThis demo contains code from the "
      "book - \"K Loudon: Mastering Algoritms with C\".\n\nFor further details "
      "- check the following:\n\n - \"Chapter 11: Graphs\"\n - The \"graph\" "
      "subfolder - in downloadable example zipfile\n\nTip: Use paper/pencil to "
      "draw initial graphs - and their calculated results.\nCould be useful "
      "here :-)..\n\n");
  do {
    menu_choice = menu("--- GRAPH BASIC USAGE & BFS/DFS DEMO ---\nMENU: 0=Exit "
                       "1=Basic_Graph_Usage 2=BFS/Hop_Count "
                       "3=DFS/Topological_Sort\nSelection ",
                       0, 3);
    switch (menu_choice) {
    case 1:
      if ((retval = basics()) != 0) {
        exit(EXIT_FAILURE);
      }
      break;
    case 2:
      if ((retval = bfs()) != 0) {
        exit(EXIT_FAILURE);
      }
      break;
    case 3:
      if ((retval = dfs()) != 0) {
        exit(EXIT_FAILURE);
      }
      break;
    default:
      prompt_and_pause("\nThat's all folks - Bye..!");
      break;
    }
  } while (menu_choice);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <my_clearscrn@plt>
lea    0xe73(%rip),%rdi
call   1050 <prompt_and_pause@plt>
lea    0xfc4(%rip),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <menu@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1,%eax
je     11de <main+0x6e>
jmp    11bc <main+0x4c>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     1204 <main+0x94>
jmp    11cd <main+0x5d>
mov    -0x10(%rbp),%eax
sub    $0x3,%eax
je     122a <main+0xba>
jmp    1250 <main+0xe0>
mov    $0x0,%al
call   1070 <basics@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     11ff <main+0x8f>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    125c <main+0xec>
mov    $0x0,%al
call   1040 <bfs@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1225 <main+0xb5>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    125c <main+0xec>
mov    $0x0,%al
call   1090 <dfs@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     124b <main+0xdb>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    125c <main+0xec>
lea    0xf82(%rip),%rdi
call   1050 <prompt_and_pause@plt>
jmp    1261 <main+0xf1>
cmpl   $0x0,-0x8(%rbp)
jne    1192 <main+0x22>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1060 <my_clearscrn@plt>
lea    0xe7e(%rip),%rdi
call   1050 <prompt_and_pause@plt>
lea    0xfcf(%rip),%rbx
lea    0x1044(%rip),%r14
jmp    11af <main+0x3f>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <basics@plt>
test   %eax,%eax
jne    1200 <main+0x90>
test   %ebp,%ebp
je     11f9 <main+0x89>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <menu@plt>
mov    %eax,%ebp
cmp    $0x3,%eax
je     11e0 <main+0x70>
cmp    $0x2,%ebp
je     11f0 <main+0x80>
cmp    $0x1,%ebp
je     11a0 <main+0x30>
mov    %r14,%rdi
call   1050 <prompt_and_pause@plt>
test   %ebp,%ebp
jne    11af <main+0x3f>
jmp    11f9 <main+0x89>
nopl   (%rax)
xor    %eax,%eax
call   1090 <dfs@plt>
jmp    11a7 <main+0x37>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <bfs@plt>
jmp    11a7 <main+0x37>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [349 x i8] c"--- INITIAL DEMO INFORMATION ---\0A\0AThis demo contains code from the book - \22K Loudon: Mastering Algoritms with C\22.\0A\0AFor further details - check the following:\0A\0A - \22Chapter 11: Graphs\22\0A - The \22graph\22 subfolder - in downloadable example zipfile\0A\0ATip: Use paper/pencil to draw initial graphs - and their calculated results.\0ACould be useful here :-)..\0A\0A\00"
@.str.1 = [124 x i8] c"--- GRAPH BASIC USAGE & BFS/DFS DEMO ---\0AMENU: 0=Exit 1=Basic_Graph_Usage 2=BFS/Hop_Count 3=DFS/Topological_Sort\0ASelection \00"
@EXIT_FAILURE = global i32 0
@.str.2 = [27 x i8] c"\0AThat's all folks - Bye..!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @my_clearscrn()
%5 = call i32 @prompt_and_pause(i8* getelementptr inbounds ([349 x i8], [349 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %33, %0
%7 = call i32 @menu(i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 3)
store i32 %7, i32* %2
%8 = load i32, i32* %2
switch i32 %8, label %30 [
i32 1, label %9
i32 2, label %16
i32 3, label %23
]
9: ; preds = %6
%10 = call i32 (...) @basics()
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %9
br label %32
16: ; preds = %6
%17 = call i32 (...) @bfs()
store i32 %17, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %16
br label %32
23: ; preds = %6
%24 = call i32 (...) @dfs()
store i32 %24, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %23
br label %32
30: ; preds = %6
%31 = call i32 @prompt_and_pause(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %29, %22, %15
br label %33
33: ; preds = %32
%34 = load i32, i32* %2
%35 = icmp ne i32 %34, 0
br i1 %35, label %6, label %36
36: ; preds = %33
ret i32 0
}

LLVM IR (-O2):
@.str = [349 x i8] c"--- INITIAL DEMO INFORMATION ---\0A\0AThis demo contains code from the book - \22K Loudon: Mastering Algoritms with C\22.\0A\0AFor further details - check the following:\0A\0A - \22Chapter 11: Graphs\22\0A - The \22graph\22 subfolder - in downloadable example zipfile\0A\0ATip: Use paper/pencil to draw initial graphs - and their calculated results.\0ACould be useful here :-)..\0A\0A\00"
@.str.1 = [124 x i8] c"--- GRAPH BASIC USAGE & BFS/DFS DEMO ---\0AMENU: 0=Exit 1=Basic_Graph_Usage 2=BFS/Hop_Count 3=DFS/Topological_Sort\0ASelection \00"
@EXIT_FAILURE = global i32 0
@.str.2 = [27 x i8] c"\0AThat's all folks - Bye..!\00"
define i32 @main() {
%1 = tail call i32 (...) @my_clearscrn()
%2 = tail call i32 @prompt_and_pause(i8* getelementptr inbounds ([349 x i8], [349 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %25, %0
%4 = tail call i32 @menu(i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 3)
switch i32 %4, label %23 [
i32 1, label %5
i32 2, label %11
i32 3, label %17
]
5: ; preds = %3
%6 = tail call i32 (...) @basics()
%7 = icmp eq i32 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %5
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3
%12 = tail call i32 (...) @bfs()
%13 = icmp eq i32 %12, 0
br i1 %13, label %25, label %14
14: ; preds = %11
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %3
%18 = tail call i32 (...) @dfs()
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %17
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %3
%24 = tail call i32 @prompt_and_pause(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %5, %11, %17
%26 = icmp eq i32 %4, 0
br i1 %26, label %27, label %3
27: ; preds = %25
ret i32 0
}