#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*/ print_data();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_data();
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ write_data(int);
int main(int argc, char **argv) {
  int data;
  char cmd;
  do {
    printf("select:\nw\t--write\nr\t--read\np\t--print\nq\t--quit\n");
    scanf("%s", &cmd);
    switch (cmd) {
    case 'w':
      printf("please input data:");
      scanf("%d", &data);
      write_data(data);
      break;
    case 'r':
      read_data();
      break;
    case 'p':
      print_data();
      break;
    case 'q':
      printf("quit\n");
      break;
    default:
      printf("Command error.\n");
    }
  } while (cmd != 'q');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
lea    0xed6(%rip),%rdi
xor    %eax,%eax
lea    -0x15(%rbp),%rsi
call   1070 <scanf@plt>
movsbl -0x15(%rbp),%eax
add    $0xffffff90,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x7,%eax
ja     1202 <main+0xb2>
mov    -0x20(%rbp),%rax
lea    0xe5b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x14(%rbp),%edi
call   1060 <write_data@plt>
jmp    120e <main+0xbe>
mov    $0x0,%al
call   1030 <read_data@plt>
jmp    120e <main+0xbe>
mov    $0x0,%al
call   1050 <print_data@plt>
jmp    120e <main+0xbe>
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
jmp    120e <main+0xbe>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
jmp    1213 <main+0xc3>
movsbl -0x15(%rbp),%eax
cmp    $0x71,%eax
jne    1166 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xec7(%rip),%r14
lea    0xea7(%rip),%r15
lea    0x3(%rsp),%rbx
lea    0xe7b(%rip),%rbp
lea    0xeaa(%rip),%r12
lea    0x4(%rsp),%r13
jmp    11b7 <main+0x57>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xec0(%rip),%rdi
call   1040 <puts@plt>
cmpb   $0x71,0x3(%rsp)
je     1237 <main+0xd7>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movsbl 0x3(%rsp),%eax
add    $0xffffff90,%eax
cmp    $0x7,%eax
ja     11a0 <main+0x40>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
xor    %eax,%eax
call   1060 <print_data@plt>
jmp    11ac <main+0x4c>
nopl   0x0(%rax)
lea    0xe6b(%rip),%rdi
jmp    11a7 <main+0x47>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <read_data@plt>
jmp    11ac <main+0x4c>
nopl   0x0(%rax)
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
call   1070 <write_data@plt>
jmp    11ac <main+0x4c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"select:\0Aw\09--write\0Ar\09--read\0Ap\09--print\0Aq\09--quit\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [19 x i8] c"please input data:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [6 x i8] c"quit\0A\00"
@.str.5 = [16 x i8] c"Command error.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %27, %2
%9 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%11 = load i8, i8* %7
%12 = sext i8 %11 to i32
switch i32 %12, label %24 [
i32 119, label %13
i32 114, label %18
i32 112, label %20
i32 113, label %22
]
13: ; preds = %8
%14 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%16 = load i32, i32* %6
%17 = call i32 @write_data(i32 %16)
br label %26
18: ; preds = %8
%19 = call i32 (...) @read_data()
br label %26
20: ; preds = %8
%21 = call i32 (...) @print_data()
br label %26
22: ; preds = %8
%23 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %26
24: ; preds = %8
%25 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %22, %20, %18, %13
br label %27
27: ; preds = %26
%28 = load i8, i8* %7
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 113
br i1 %30, label %8, label %31
31: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [19 x i8] c"please input data:\00"
@.str.3 = [3 x i8] c"%d\00"
@str = [46 x i8] c"select:\0Aw\09--write\0Ar\09--read\0Ap\09--print\0Aq\09--quit\00"
@str.6 = [5 x i8] c"quit\00"
@str.7 = [15 x i8] c"Command error.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
br label %6
6: ; preds = %24, %2
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
switch i32 %10, label %22 [
i32 119, label %11
i32 114, label %16
i32 112, label %18
i32 113, label %20
]
11: ; preds = %6
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %3
%15 = call i32 @write_data(i32 %14)
br label %24
16: ; preds = %6
%17 = call i32 (...) @read_data()
br label %24
18: ; preds = %6
%19 = call i32 (...) @print_data()
br label %24
20: ; preds = %6
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.6, i64 0, i64 0))
br label %24
22: ; preds = %6
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
br label %24
24: ; preds = %11, %16, %18, %20, %22
%25 = load i8, i8* %4
%26 = icmp eq i8 %25, 113
br i1 %26, label %27, label %6
27: ; preds = %24
ret i32 0
}