#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*/ func1(int);
int /*<<< orphan*/ func2(int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void menu(int fd) {
  while (1) {
    char option[2];
    write(fd, "-Tutorial-\n", 11);
    write(fd, "1.Manual\n", 9);
    write(fd, "2.Practice\n", 11);
    write(fd, "3.Quit\n", 7);
    write(fd, ">", 1);
    read(fd, option, 2);
    switch (option[0]) {
    case '1':
      func1(fd);
      break;
    case '2':
      func2(fd);
      break;
    case '3':
      write(fd, "You still did not solve my challenge.\n", 38);
      return;
    default:
      write(fd, "unknown option.\n", 16);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0xeab(%rip),%rsi
mov    $0xb,%edx
mov    %edx,-0x10(%rbp)
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
lea    0xea0(%rip),%rsi
mov    $0x9,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%edx
mov    -0x4(%rbp),%edi
lea    0xe93(%rip),%rsi
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
lea    0xe90(%rip),%rsi
mov    $0x7,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
lea    0xe84(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x6(%rbp),%rsi
mov    $0x2,%edx
call   1050 <read@plt>
movsbl -0x6(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x31,%eax
je     11f8 <menu+0xb8>
jmp    11d6 <menu+0x96>
mov    -0xc(%rbp),%eax
sub    $0x32,%eax
je     1205 <menu+0xc5>
jmp    11e7 <menu+0xa7>
mov    -0xc(%rbp),%eax
sub    $0x33,%eax
je     1212 <menu+0xd2>
jmp    122c <menu+0xec>
mov    -0x4(%rbp),%edi
call   1030 <func1@plt>
jmp    1240 <menu+0x100>
mov    -0x4(%rbp),%edi
call   1060 <func2@plt>
jmp    1240 <menu+0x100>
mov    -0x4(%rbp),%edi
lea    0xe10(%rip),%rsi
mov    $0x26,%edx
call   1040 <write@plt>
add    $0x10,%rsp
pop    %rbp
ret
mov    -0x4(%rbp),%edi
lea    0xe1d(%rip),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
jmp    114b <menu+0xb>

x86 assembly (clang, -O2):
<menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xeb8(%rip),%r15
lea    0xebb(%rip),%r12
lea    0xec0(%rip),%r13
lea    0xec1(%rip),%rbp
lea    0x6(%rsp),%r14
jmp    1177 <menu+0x37>
mov    %ebx,%edi
call   1060 <func2@plt>
mov    %ebx,%edi
lea    0xe80(%rip),%rsi
mov    $0xb,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x9,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0xb,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x7,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <read@plt>
movsbl 0x6(%rsp),%eax
cmp    $0x31,%eax
je     1210 <menu+0xd0>
cmp    $0x32,%eax
je     1170 <menu+0x30>
cmp    $0x33,%eax
je     121c <menu+0xdc>
mov    %ebx,%edi
lea    0xe61(%rip),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
jmp    1177 <menu+0x37>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <func1@plt>
jmp    1177 <menu+0x37>
lea    0xe09(%rip),%rsi
mov    %ebx,%edi
mov    $0x26,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <write@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"-Tutorial-\0A\00"
@.str.1 = [10 x i8] c"1.Manual\0A\00"
@.str.2 = [12 x i8] c"2.Practice\0A\00"
@.str.3 = [8 x i8] c"3.Quit\0A\00"
@.str.4 = [2 x i8] c">\00"
@.str.5 = [39 x i8] c"You still did not solve my challenge.\0A\00"
@.str.6 = [17 x i8] c"unknown option.\0A\00"
define void @menu(i32 %0) {
%2 = alloca i32
%3 = alloca [2 x i8]
store i32 %0, i32* %2
br label %4
4: ; preds = %1, %33
%5 = load i32, i32* %2
%6 = call i32 @write(i32 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%7 = load i32, i32* %2
%8 = call i32 @write(i32 %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%9 = load i32, i32* %2
%10 = call i32 @write(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%11 = load i32, i32* %2
%12 = call i32 @write(i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%13 = load i32, i32* %2
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%15 = load i32, i32* %2
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 2)
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
switch i32 %20, label %30 [
i32 49, label %21
i32 50, label %24
i32 51, label %27
]
21: ; preds = %4
%22 = load i32, i32* %2
%23 = call i32 @func1(i32 %22)
br label %33
24: ; preds = %4
%25 = load i32, i32* %2
%26 = call i32 @func2(i32 %25)
br label %33
27: ; preds = %4
%28 = load i32, i32* %2
%29 = call i32 @write(i32 %28, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 38)
ret void
30: ; preds = %4
%31 = load i32, i32* %2
%32 = call i32 @write(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 16)
br label %33
33: ; preds = %30, %24, %21
br label %4
}

LLVM IR (-O2):
@.str = [12 x i8] c"-Tutorial-\0A\00"
@.str.1 = [10 x i8] c"1.Manual\0A\00"
@.str.2 = [12 x i8] c"2.Practice\0A\00"
@.str.3 = [8 x i8] c"3.Quit\0A\00"
@.str.4 = [2 x i8] c">\00"
@.str.5 = [39 x i8] c"You still did not solve my challenge.\0A\00"
@.str.6 = [17 x i8] c"unknown option.\0A\00"
define void @menu(i32 %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %19, %1
%5 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%6 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%7 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%8 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%9 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%10 = call i32 @read(i32 %0, i8* %3, i32 2)
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
switch i32 %12, label %17 [
i32 49, label %13
i32 50, label %15
i32 51, label %20
]
13: ; preds = %4
%14 = tail call i32 @func1(i32 %0)
br label %19
15: ; preds = %4
%16 = tail call i32 @func2(i32 %0)
br label %19
17: ; preds = %4
%18 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 16)
br label %19
19: ; preds = %13, %15, %17
br label %4
20: ; preds = %4
%21 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 38)
ret void
}