#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*/ ConfigureRecordingMenu();
int /*<<< orphan*/ ConnectMenu(int);
int /*<<< orphan*/ LeddarGetKey();
int /*<<< orphan*/ ListSensors(char *, char *, int);
int /*<<< orphan*/ ReplayMenu();
int /*<<< orphan*/ puts(char *);
int toupper(int /*<<< orphan*/);
void MainMenu(void) {
  for (;;) {
    int lChoice;
    puts("\n\nMain Menu");
    puts("  1. Connect");
    puts("  2. Connect to single USB sensor");
    puts("  3. List Sensors");
    puts("  4. Replay Record");
    puts("  5. Configure Recording");
    puts("  6. Quit");
    lChoice = toupper(LeddarGetKey());
    switch (lChoice) {
    case '1':
      ConnectMenu(0);
      break;
    case '2':
      ConnectMenu(1);
      break;
    case '3': {
      char lAddresses[256];
      ListSensors("USB", lAddresses, 255);
      ListSensors("SERIAL", lAddresses, 255);
      break;
    }
    case '4':
      ReplayMenu();
      break;
    case '5':
      ConfigureRecordingMenu();
      break;
    case '6':
    case 'Q':
    case 27:
      puts("\n*** Goodbye! ***");
      return;
    }
  }
}


x86 assembly (clang, -O0):
<MainMenu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xf5a(%rip),%rdi
call   1040 <puts@plt>
lea    0xf5a(%rip),%rdi
call   1040 <puts@plt>
lea    0xf5b(%rip),%rdi
call   1040 <puts@plt>
lea    0xf71(%rip),%rdi
call   1040 <puts@plt>
lea    0xf77(%rip),%rdi
call   1040 <puts@plt>
lea    0xf7e(%rip),%rdi
call   1040 <puts@plt>
lea    0xf8b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <LeddarGetKey@plt>
mov    %eax,%edi
call   1030 <toupper@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffe5,%eax
mov    %eax,%ecx
mov    %rcx,-0x118(%rbp)
sub    $0x36,%eax
ja     128c <MainMenu+0x11c>
mov    -0x118(%rbp),%rax
lea    0xdfa(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %edi,%edi
call   1080 <ConnectMenu@plt>
jmp    128c <MainMenu+0x11c>
mov    $0x1,%edi
call   1080 <ConnectMenu@plt>
jmp    128c <MainMenu+0x11c>
lea    -0x110(%rbp),%rsi
lea    0xf27(%rip),%rdi
mov    $0xff,%edx
call   1090 <ListSensors@plt>
lea    -0x110(%rbp),%rsi
lea    0xf13(%rip),%rdi
mov    $0xff,%edx
call   1090 <ListSensors@plt>
jmp    128c <MainMenu+0x11c>
mov    $0x0,%al
call   1050 <ReplayMenu@plt>
jmp    128c <MainMenu+0x11c>
mov    $0x0,%al
call   1070 <ConfigureRecordingMenu@plt>
jmp    128c <MainMenu+0x11c>
lea    0xeec(%rip),%rdi
call   1040 <puts@plt>
add    $0x120,%rsp
pop    %rbp
ret
jmp    117b <MainMenu+0xb>

x86 assembly (clang, -O2):
<MainMenu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xf6d(%rip),%rbx
lea    0xf88(%rip),%rbp
lea    0xf93(%rip),%r12
lea    0xf9f(%rip),%r13
lea    0xfb1(%rip),%r14
lea    0xe55(%rip),%r15
jmp    11c0 <MainMenu+0x50>
xor    %eax,%eax
call   1070 <ConfigureRecordingMenu@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xf15(%rip),%rdi
call   1040 <puts@plt>
lea    0xf15(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <LeddarGetKey@plt>
mov    %eax,%edi
call   1030 <toupper@plt>
add    $0xffffffe5,%eax
cmp    $0x36,%eax
ja     11c0 <MainMenu+0x50>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
xor    %edi,%edi
call   1080 <ConnectMenu@plt>
jmp    11c0 <MainMenu+0x50>
mov    $0x1,%edi
call   1080 <ConnectMenu@plt>
jmp    11c0 <MainMenu+0x50>
lea    0xf24(%rip),%rdi
mov    %r14,%r15
mov    %r13,%r14
mov    %r12,%r13
mov    %rsp,%r12
mov    %r12,%rsi
mov    $0xff,%edx
call   1090 <ListSensors@plt>
lea    0xf08(%rip),%rdi
mov    %r12,%rsi
mov    %r13,%r12
mov    %r14,%r13
mov    %r15,%r14
lea    0xd92(%rip),%r15
mov    $0xff,%edx
call   1090 <ListSensors@plt>
jmp    11c0 <MainMenu+0x50>
xor    %eax,%eax
call   1050 <ReplayMenu@plt>
jmp    11c0 <MainMenu+0x50>
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"\0A\0AMain Menu\00"
@.str.1 = [13 x i8] c" 1. Connect\00"
@.str.2 = [34 x i8] c" 2. Connect to single USB sensor\00"
@.str.3 = [18 x i8] c" 3. List Sensors\00"
@.str.4 = [19 x i8] c" 4. Replay Record\00"
@.str.5 = [25 x i8] c" 5. Configure Recording\00"
@.str.6 = [10 x i8] c" 6. Quit\00"
@.str.7 = [4 x i8] c"USB\00"
@.str.8 = [7 x i8] c"SERIAL\00"
@.str.9 = [18 x i8] c"\0A*** Goodbye! ***\00"
define void @MainMenu() {
%1 = alloca i32
%2 = alloca [256 x i8]
br label %3
3: ; preds = %29, %0
%4 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @puts(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%10 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 (...) @LeddarGetKey()
%12 = call i32 @toupper(i32 %11)
store i32 %12, i32* %1
%13 = load i32, i32* %1
switch i32 %13, label %29 [
i32 49, label %14
i32 50, label %16
i32 51, label %18
i32 52, label %23
i32 53, label %25
i32 54, label %27
i32 81, label %27
i32 27, label %27
]
14: ; preds = %3
%15 = call i32 @ConnectMenu(i32 0)
br label %29
16: ; preds = %3
%17 = call i32 @ConnectMenu(i32 1)
br label %29
18: ; preds = %3
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%20 = call i32 @ListSensors(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %19, i32 255)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%22 = call i32 @ListSensors(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %21, i32 255)
br label %29
23: ; preds = %3
%24 = call i32 (...) @ReplayMenu()
br label %29
25: ; preds = %3
%26 = call i32 (...) @ConfigureRecordingMenu()
br label %29
27: ; preds = %3, %3, %3
%28 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
ret void
29: ; preds = %3, %25, %23, %18, %16, %14
br label %3
}

LLVM IR (-O2):
@.str = [12 x i8] c"\0A\0AMain Menu\00"
@.str.1 = [13 x i8] c" 1. Connect\00"
@.str.2 = [34 x i8] c" 2. Connect to single USB sensor\00"
@.str.3 = [18 x i8] c" 3. List Sensors\00"
@.str.4 = [19 x i8] c" 4. Replay Record\00"
@.str.5 = [25 x i8] c" 5. Configure Recording\00"
@.str.6 = [10 x i8] c" 6. Quit\00"
@.str.7 = [4 x i8] c"USB\00"
@.str.8 = [7 x i8] c"SERIAL\00"
@.str.9 = [18 x i8] c"\0A*** Goodbye! ***\00"
define void @MainMenu() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %15, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 (...) @LeddarGetKey()
%12 = call i32 @toupper(i32 %11)
switch i32 %12, label %15 [
i32 49, label %13
i32 50, label %16
i32 51, label %18
i32 52, label %21
i32 53, label %23
i32 54, label %25
i32 81, label %25
i32 27, label %25
]
13: ; preds = %3
%14 = call i32 @ConnectMenu(i32 0)
br label %15
15: ; preds = %13, %16, %18, %21, %23, %3
br label %3
16: ; preds = %3
%17 = call i32 @ConnectMenu(i32 1)
br label %15
18: ; preds = %3
%19 = call i32 @ListSensors(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %2, i32 255)
%20 = call i32 @ListSensors(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %2, i32 255)
br label %15
21: ; preds = %3
%22 = call i32 (...) @ReplayMenu()
br label %15
23: ; preds = %3
%24 = call i32 (...) @ConfigureRecordingMenu()
br label %15
25: ; preds = %3, %3, %3
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
ret void
}