#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 dsp();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int menu(char *, int /*<<< orphan*/, int);
int mst();
int /*<<< orphan*/ my_clearscrn();
int /*<<< orphan*/ prompt_and_pause(char *);
int /*<<< orphan*/ stderr;
int tsp();
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 16: Graph Algorithms\"\n - The "
      "\"graphalg\" 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 ALGORITHMS DEMO ---\nMENU: 0=Exit 1=MST "
                       "2=DSP 3=TSP\nSelection ",
                       0, 3);
    switch (menu_choice) {
    case 1:
      if ((retval = mst()) != 0) {
        if (retval == -2)
          fprintf(stderr,
                  "Error reading vertex data (errcode=%d).. - bailing out!",
                  retval);
        else if (retval == -3)
          fprintf(stderr,
                  "Error reading edge data (errcode=%d).. - bailing out!",
                  retval);
        else
          fprintf(stderr, "Error: Fatal error (errcode=%d).. - bailing out!",
                  retval);
        exit(-1);
      }
      break;
    case 2:
      if ((retval = dsp()) != 0) {
        if (retval == -2)
          fprintf(stderr,
                  "Error reading vertex data (errcode=%d).. - bailing out!",
                  retval);
        else if (retval == -3)
          fprintf(stderr,
                  "Error reading edge data (errcode=%d).. - bailing out!",
                  retval);
        else
          fprintf(stderr, "Error: Fatal error (errcode=%d).. - bailing out!",
                  retval);
        exit(-1);
      }
      break;
    case 3:
      if ((retval = tsp()) != 0) {
        if (retval == -2)
          fprintf(stderr,
                  "Error reading vertex data (errcode=%d).. - bailing out!",
                  retval);
        else if (retval == -3)
          fprintf(stderr,
                  "Error reading edge data (errcode=%d).. - bailing out!",
                  retval);
        else
          fprintf(stderr, "Error: Fatal error (errcode=%d).. - bailing out!",
                  retval);
        exit(-1);
      }
      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   1080 <my_clearscrn@plt>
lea    0xe63(%rip),%rdi
call   1050 <prompt_and_pause@plt>
lea    0xfc1(%rip),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <menu@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1,%eax
je     11ee <main+0x6e>
jmp    11cc <main+0x4c>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     127b <main+0xfb>
jmp    11dd <main+0x5d>
mov    -0x10(%rbp),%eax
sub    $0x3,%eax
je     1308 <main+0x188>
jmp    1395 <main+0x215>
mov    $0x0,%al
call   1090 <mst@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1276 <main+0xf6>
cmpl   $0xfffffffe,-0xc(%rbp)
jne    1228 <main+0xa8>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xf94(%rip),%rsi
call   1070 <fprintf@plt>
jmp    126c <main+0xec>
cmpl   $0xfffffffd,-0xc(%rbp)
jne    124f <main+0xcf>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xfa5(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1267 <main+0xe7>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xfbe(%rip),%rsi
call   1070 <fprintf@plt>
jmp    126c <main+0xec>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    13a1 <main+0x221>
mov    $0x0,%al
call   1060 <dsp@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1303 <main+0x183>
cmpl   $0xfffffffe,-0xc(%rbp)
jne    12b5 <main+0x135>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xf07(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12f9 <main+0x179>
cmpl   $0xfffffffd,-0xc(%rbp)
jne    12dc <main+0x15c>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xf18(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12f4 <main+0x174>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xf31(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12f9 <main+0x179>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    13a1 <main+0x221>
mov    $0x0,%al
call   1030 <tsp@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1390 <main+0x210>
cmpl   $0xfffffffe,-0xc(%rbp)
jne    1342 <main+0x1c2>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe7a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1386 <main+0x206>
cmpl   $0xfffffffd,-0xc(%rbp)
jne    1369 <main+0x1e9>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe8b(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1381 <main+0x201>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xea4(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1386 <main+0x206>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    13a1 <main+0x221>
lea    0xeb5(%rip),%rdi
call   1050 <prompt_and_pause@plt>
jmp    13a6 <main+0x226>
cmpl   $0x0,-0x8(%rbp)
jne    11a2 <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   1080 <my_clearscrn@plt>
lea    0xe6e(%rip),%rdi
call   1050 <prompt_and_pause@plt>
lea    0xfcc(%rip),%rbx
lea    0x10ac(%rip),%r14
jmp    11bc <main+0x3c>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <prompt_and_pause@plt>
test   %ebp,%ebp
je     121e <main+0x9e>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <menu@plt>
mov    %eax,%ebp
cmp    $0x3,%eax
je     11f0 <main+0x70>
cmp    $0x2,%ebp
je     1200 <main+0x80>
cmp    $0x1,%ebp
jne    11b0 <main+0x30>
xor    %eax,%eax
call   1090 <mst@plt>
test   %eax,%eax
je     11b8 <main+0x38>
jmp    120b <main+0x8b>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <tsp@plt>
test   %eax,%eax
je     11b8 <main+0x38>
jmp    120b <main+0x8b>
nopl   (%rax)
xor    %eax,%eax
call   1060 <dsp@plt>
test   %eax,%eax
je     11b8 <main+0x38>
cmp    $0xfffffffd,%eax
je     1225 <main+0xa5>
cmp    $0xfffffffe,%eax
jne    122e <main+0xae>
lea    0xf96(%rip),%rsi
jmp    1235 <main+0xb5>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xfbe(%rip),%rsi
jmp    1235 <main+0xb5>
lea    0xfeb(%rip),%rsi
mov    0x2da4(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,%edx
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [362 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 16: Graph Algorithms\22\0A - The \22graphalg\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 = [72 x i8] c"--- GRAPH ALGORITHMS DEMO ---\0AMENU: 0=Exit 1=MST 2=DSP 3=TSP\0ASelection \00"
@stderr = global i32 0
@.str.2 = [56 x i8] c"Error reading vertex data (errcode=%d).. - bailing out!\00"
@.str.3 = [54 x i8] c"Error reading edge data (errcode=%d).. - bailing out!\00"
@.str.4 = [49 x i8] c"Error: Fatal error (errcode=%d).. - bailing out!\00"
@.str.5 = [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 ([362 x i8], [362 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %87, %0
%7 = call i32 @menu(i8* getelementptr inbounds ([72 x i8], [72 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 %84 [
i32 1, label %9
i32 2, label %34
i32 3, label %59
]
9: ; preds = %6
%10 = call i32 (...) @mst()
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, -2
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i32, i32* %3
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %31
19: ; preds = %12
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, -3
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* %3
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %30
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i32, i32* %3
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26, %22
br label %31
31: ; preds = %30, %15
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %9
br label %86
34: ; preds = %6
%35 = call i32 (...) @dsp()
store i32 %35, i32* %3
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %58
37: ; preds = %34
%38 = load i32, i32* %3
%39 = icmp eq i32 %38, -2
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = load i32, i32* %3
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %56
44: ; preds = %37
%45 = load i32, i32* %3
%46 = icmp eq i32 %45, -3
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = load i32, i32* %3
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %55
51: ; preds = %44
%52 = load i32, i32* @stderr
%53 = load i32, i32* %3
%54 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %51, %47
br label %56
56: ; preds = %55, %40
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %34
br label %86
59: ; preds = %6
%60 = call i32 (...) @tsp()
store i32 %60, i32* %3
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %83
62: ; preds = %59
%63 = load i32, i32* %3
%64 = icmp eq i32 %63, -2
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = load i32, i32* %3
%68 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %67)
br label %81
69: ; preds = %62
%70 = load i32, i32* %3
%71 = icmp eq i32 %70, -3
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = load i32, i32* @stderr
%74 = load i32, i32* %3
%75 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %74)
br label %80
76: ; preds = %69
%77 = load i32, i32* @stderr
%78 = load i32, i32* %3
%79 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %78)
br label %80
80: ; preds = %76, %72
br label %81
81: ; preds = %80, %65
%82 = call i32 @exit(i32 -1)
unreachable
83: ; preds = %59
br label %86
84: ; preds = %6
%85 = call i32 @prompt_and_pause(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %86
86: ; preds = %84, %83, %58, %33
br label %87
87: ; preds = %86
%88 = load i32, i32* %2
%89 = icmp ne i32 %88, 0
br i1 %89, label %6, label %90
90: ; preds = %87
ret i32 0
}

LLVM IR (-O2):
@.str = [362 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 16: Graph Algorithms\22\0A - The \22graphalg\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 = [72 x i8] c"--- GRAPH ALGORITHMS DEMO ---\0AMENU: 0=Exit 1=MST 2=DSP 3=TSP\0ASelection \00"
@stderr = global i32 0
@.str.2 = [56 x i8] c"Error reading vertex data (errcode=%d).. - bailing out!\00"
@.str.3 = [54 x i8] c"Error reading edge data (errcode=%d).. - bailing out!\00"
@.str.4 = [49 x i8] c"Error: Fatal error (errcode=%d).. - bailing out!\00"
@.str.5 = [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 ([362 x i8], [362 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %34, %0
%4 = tail call i32 @menu(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 3)
switch i32 %4, label %32 [
i32 1, label %5
i32 2, label %14
i32 3, label %23
]
5: ; preds = %3
%6 = tail call i32 (...) @mst()
switch i32 %6, label %9 [
i32 0, label %34
i32 -2, label %7
i32 -3, label %8
]
7: ; preds = %5
br label %9
8: ; preds = %5
br label %9
9: ; preds = %5, %8, %7
%10 = phi i8* [ getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), %5 ]
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* %10, i32 %6)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = tail call i32 (...) @dsp()
switch i32 %15, label %18 [
i32 0, label %34
i32 -2, label %16
i32 -3, label %17
]
16: ; preds = %14
br label %18
17: ; preds = %14
br label %18
18: ; preds = %14, %17, %16
%19 = phi i8* [ getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), %16 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), %17 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), %14 ]
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* %19, i32 %15)
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %3
%24 = tail call i32 (...) @tsp()
switch i32 %24, label %27 [
i32 0, label %34
i32 -2, label %25
i32 -3, label %26
]
25: ; preds = %23
br label %27
26: ; preds = %23
br label %27
27: ; preds = %23, %26, %25
%28 = phi i8* [ getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), %25 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), %26 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), %23 ]
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* %28, i32 %24)
%31 = tail call i32 @exit(i32 -1)
unreachable
32: ; preds = %3
%33 = tail call i32 @prompt_and_pause(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %23, %14, %5, %32
%35 = icmp eq i32 %4, 0
br i1 %35, label %36, label %3
36: ; preds = %34
ret i32 0
}