#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*/ bbs_help();
int /*<<< orphan*/ cgc_exit(int /*<<< orphan*/);
int /*<<< orphan*/ do_list(char const *);
int /*<<< orphan*/ do_post(char const *);
int /*<<< orphan*/ do_read(char const *);
int /*<<< orphan*/ send_string(char *);
void handle_menu(const char *str) {
  int cmd = str[0];
  if (str[1] != 0 && str[1] != ' ')
    cmd = 0;
  switch (cmd) {
  case 'H':
  case 'h':
  case '?':
    bbs_help();
    break;
  case 'L':
  case 'l':
    do_list(str);
    break;
  case 'P':
  case 'p':
    do_post(str);
    break;
  case 'R':
  case 'r':
    do_read(str);
    break;
  case 'Q':
  case 'q':
    cgc_exit(0);
    break;
  default:
    send_string("Bad input. Unknown command.\n");
    break;
  }
}


x86 assembly (clang, -O0):
<handle_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     119f <handle_menu+0x3f>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x20,%eax
je     119f <handle_menu+0x3f>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x33,%eax
ja     120a <handle_menu+0xaa>
mov    -0x18(%rbp),%rax
lea    0xe41(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1070 <bbs_help@plt>
jmp    1216 <handle_menu+0xb6>
mov    -0x8(%rbp),%rdi
call   1050 <do_list@plt>
jmp    1216 <handle_menu+0xb6>
mov    -0x8(%rbp),%rdi
call   1080 <do_post@plt>
jmp    1216 <handle_menu+0xb6>
mov    -0x8(%rbp),%rdi
call   1030 <do_read@plt>
jmp    1216 <handle_menu+0xb6>
xor    %edi,%edi
call   1060 <cgc_exit@plt>
jmp    1216 <handle_menu+0xb6>
lea    0xebf(%rip),%rdi
call   1040 <send_string@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_menu>:
testb  $0xdf,0x1(%rdi)
jne    1188 <handle_menu+0x28>
movsbl (%rdi),%eax
add    $0xffffffc1,%eax
cmp    $0x33,%eax
ja     1188 <handle_menu+0x28>
lea    0xe88(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
jmp    1070 <bbs_help@plt>
lea    0xf41(%rip),%rdi
jmp    1040 <send_string@plt>
jmp    1050 <do_list@plt>
xor    %edi,%edi
jmp    1060 <cgc_exit@plt>
jmp    1030 <do_read@plt>
jmp    1080 <do_post@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Bad input. Unknown command.\0A\00"
define void @handle_menu(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
store i32 %7, i32* %3
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 32
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 0, i32* %3
br label %20
20: ; preds = %19, %13, %1
%21 = load i32, i32* %3
switch i32 %21, label %35 [
i32 72, label %22
i32 104, label %22
i32 63, label %22
i32 76, label %24
i32 108, label %24
i32 80, label %27
i32 112, label %27
i32 82, label %30
i32 114, label %30
i32 81, label %33
i32 113, label %33
]
22: ; preds = %20, %20, %20
%23 = call i32 (...) @bbs_help()
br label %37
24: ; preds = %20, %20
%25 = load i8*, i8** %2
%26 = call i32 @do_list(i8* %25)
br label %37
27: ; preds = %20, %20
%28 = load i8*, i8** %2
%29 = call i32 @do_post(i8* %28)
br label %37
30: ; preds = %20, %20
%31 = load i8*, i8** %2
%32 = call i32 @do_read(i8* %31)
br label %37
33: ; preds = %20, %20
%34 = call i32 @cgc_exit(i32 0)
br label %37
35: ; preds = %20
%36 = call i32 @send_string(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %33, %30, %27, %24, %22
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Bad input. Unknown command.\0A\00"
define void @handle_menu(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %2
switch i8 %3, label %17 [
i8 0, label %4
i8 32, label %4
]
4: ; preds = %1, %1
%5 = load i8, i8* %0
%6 = sext i8 %5 to i32
switch i32 %6, label %17 [
i32 72, label %7
i32 104, label %7
i32 63, label %7
i32 76, label %9
i32 108, label %9
i32 80, label %11
i32 112, label %11
i32 82, label %13
i32 114, label %13
i32 81, label %15
i32 113, label %15
]
7: ; preds = %4, %4, %4
%8 = tail call i32 (...) @bbs_help()
br label %19
9: ; preds = %4, %4
%10 = tail call i32 @do_list(i8* %0)
br label %19
11: ; preds = %4, %4
%12 = tail call i32 @do_post(i8* %0)
br label %19
13: ; preds = %4, %4
%14 = tail call i32 @do_read(i8* %0)
br label %19
15: ; preds = %4, %4
%16 = tail call i32 @cgc_exit(i32 0)
br label %19
17: ; preds = %1, %4
%18 = tail call i32 @send_string(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %15, %13, %11, %9, %7
ret void
}