#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*/ displayMenu();
char getchar();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ readFile(char *);
int /*<<< orphan*/ writeFile(char *);
void commandControl() {
  char *filePath = "/tmp/file_read_write.temp";
  do {
    char c = getchar();
    if ('0' == c) {
      puts("bye bye!");
      break;
    } else if ('1' == c) {
      readFile(filePath);
      displayMenu();
    } else if ('2' == c) {
      writeFile(filePath);
      displayMenu();
    } else if ('\n' == c || '\r' == c) {
      continue;
    } else {
      puts("invalid commander, enter again.");
      displayMenu();
    }
  } while (1);
}


x86 assembly (clang, -O0):
<commandControl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jne    118f <commandControl+0x3f>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
jmp    1238 <commandControl+0xe8>
movsbl -0x9(%rbp),%ecx
mov    $0x31,%eax
cmp    %ecx,%eax
jne    11b5 <commandControl+0x65>
mov    -0x8(%rbp),%rdi
call   1070 <readFile@plt>
mov    $0x0,%al
call   1040 <displayMenu@plt>
jmp    121f <commandControl+0xcf>
movsbl -0x9(%rbp),%ecx
mov    $0x32,%eax
cmp    %ecx,%eax
jne    11db <commandControl+0x8b>
mov    -0x8(%rbp),%rdi
call   1060 <writeFile@plt>
mov    $0x0,%al
call   1040 <displayMenu@plt>
jmp    121a <commandControl+0xca>
movsbl -0x9(%rbp),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
je     11fd <commandControl+0xad>
movsbl -0x9(%rbp),%ecx
mov    $0xd,%eax
cmp    %ecx,%eax
jne    1202 <commandControl+0xb2>
jmp    1229 <commandControl+0xd9>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1040 <displayMenu@plt>
jmp    121a <commandControl+0xca>
jmp    121f <commandControl+0xcf>
jmp    1224 <commandControl+0xd4>
jmp    1229 <commandControl+0xd9>
mov    $0x1,%al
test   $0x1,%al
jne    1163 <commandControl+0x13>
jmp    1238 <commandControl+0xe8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<commandControl>:
push   %r15
push   %r14
push   %rbx
lea    0xf6b(%rip),%r14
lea    0xe9d(%rip),%rbx
lea    0xf3a(%rip),%r15
jmp    117b <commandControl+0x2b>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <displayMenu@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0xf6,%al
cmp    $0x28,%al
ja     116c <commandControl+0x1c>
movzbl %al,%eax
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r15,%rdi
call   1070 <readFile@plt>
jmp    1174 <commandControl+0x24>
mov    %r15,%rdi
call   1060 <writeFile@plt>
jmp    1174 <commandControl+0x24>
lea    0xf0f(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"/tmp/file_read_write.temp\00"
@.str.1 = [9 x i8] c"bye bye!\00"
@.str.2 = [32 x i8] c"invalid commander, enter again.\00"
define void @commandControl() {
%1 = alloca i8*
%2 = alloca i8
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8** %1
br label %3
3: ; preds = %42, %0
%4 = call signext i8 (...) @getchar()
store i8 %4, i8* %2
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp eq i32 48, %6
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %43
10: ; preds = %3
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
%13 = icmp eq i32 49, %12
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i8*, i8** %1
%16 = call i32 @readFile(i8* %15)
%17 = call i32 (...) @displayMenu()
br label %40
18: ; preds = %10
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = icmp eq i32 50, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i8*, i8** %1
%24 = call i32 @writeFile(i8* %23)
%25 = call i32 (...) @displayMenu()
br label %39
26: ; preds = %18
%27 = load i8, i8* %2
%28 = sext i8 %27 to i32
%29 = icmp eq i32 10, %28
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i8, i8* %2
%32 = sext i8 %31 to i32
%33 = icmp eq i32 13, %32
br i1 %33, label %34, label %35
34: ; preds = %30, %26
br label %42
35: ; preds = %30
%36 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 (...) @displayMenu()
br label %38
38: ; preds = %35
br label %39
39: ; preds = %38, %22
br label %40
40: ; preds = %39, %14
br label %41
41: ; preds = %40
br label %42
42: ; preds = %41, %34
br i1 true, label %3, label %43
43: ; preds = %42, %8
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"/tmp/file_read_write.temp\00"
@.str.1 = [9 x i8] c"bye bye!\00"
@.str.2 = [32 x i8] c"invalid commander, enter again.\00"
define void @commandControl() {
br label %1
1: ; preds = %13, %0
%2 = tail call signext i8 (...) @getchar()
switch i8 %2, label %9 [
i8 48, label %3
i8 49, label %5
i8 50, label %7
i8 13, label %13
i8 10, label %13
]
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
ret void
5: ; preds = %1
%6 = tail call i32 @readFile(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %11
7: ; preds = %1
%8 = tail call i32 @writeFile(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %5, %9, %7
%12 = tail call i32 (...) @displayMenu()
br label %13
13: ; preds = %11, %1, %1
br label %1
}