#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*/ chdir(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ system(char *);
int main() {
  char cmd[1024];
  puts("欢迎使用MyShell!");
  for (;;) {
    printf("ms>");
    scanf(" %[^\n]", cmd);
    if (!strcmp(cmd, "furong"))
      break;
    if (!strncmp(cmd, "cd ", 3))
      chdir(cmd + 3);
    else
      system(cmd);
  }
  puts("谢谢!");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
call   1040 <puts@plt>
lea    0xe80(%rip),%rdi
call   1070 <printf@plt>
lea    -0x410(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1090 <scanf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    11ce <main+0x5e>
jmp    1215 <main+0xa5>
lea    -0x410(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1204 <main+0x94>
lea    -0x410(%rbp),%rdi
add    $0x3,%rdi
call   1050 <chdir@plt>
jmp    1210 <main+0xa0>
lea    -0x410(%rbp),%rdi
call   1060 <system@plt>
jmp    118e <main+0x1e>
lea    0xe0f(%rip),%rdi
call   1040 <puts@plt>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
lea    0xe91(%rip),%rdi
call   1070 <printf@plt>
lea    0xe89(%rip),%rdi
mov    %rsp,%rsi
call   1080 <scanf@plt>
mov    $0x6f727566,%ebp
mov    (%rsp),%eax
xor    %ebp,%eax
mov    $0x676e6f,%r14d
mov    0x3(%rsp),%ecx
xor    %r14d,%ecx
or     %eax,%ecx
je     121b <main+0xbb>
lea    0xe6d(%rip),%r15
mov    %rsp,%rbx
lea    0xe51(%rip),%r12
lea    0xe4e(%rip),%r13
jmp    11fb <main+0x9b>
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <system@plt>
mov    %r12,%rdi
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    (%rsp),%eax
xor    %ebp,%eax
mov    0x3(%rsp),%ecx
xor    %r14d,%ecx
or     %eax,%ecx
je     121b <main+0xbb>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11d0 <main+0x70>
lea    0x3(%rsp),%rdi
call   1050 <chdir@plt>
jmp    11d8 <main+0x78>
lea    0xe09(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\E6\AC\A2\E8\BF\8E\E4\BD\BF\E7\94\A8MyShell!\00"
@.str.1 = [4 x i8] c"ms>\00"
@.str.2 = [7 x i8] c" %[^\0A]\00"
@.str.3 = [7 x i8] c"furong\00"
@.str.4 = [4 x i8] c"cd \00"
@.str.5 = [8 x i8] c"\E8\B0\A2\E8\B0\A2!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
store i32 0, i32* %1
%3 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %23, %0
%5 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = call i32 @strcmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %4
br label %24
12: ; preds = %4
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%14 = call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%15 = icmp ne i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%18 = getelementptr inbounds i8, i8* %17, i64 3
%19 = call i32 @chdir(i8* %18)
br label %23
20: ; preds = %12
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%22 = call i32 @system(i8* %21)
br label %23
23: ; preds = %20, %16
br label %4
24: ; preds = %11
%25 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [21 x i8] c"\E6\AC\A2\E8\BF\8E\E4\BD\BF\E7\94\A8MyShell!\00"
@.str.1 = [4 x i8] c"ms>\00"
@.str.2 = [7 x i8] c" %[^\0A]\00"
@.str.3 = [7 x i8] c"furong\00"
@.str.4 = [4 x i8] c"cd \00"
@.str.5 = [8 x i8] c"\E8\B0\A2\E8\B0\A2!\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%6 = call i32 @bcmp(i8* dereferenceable(7) %2, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 7)
%7 = icmp eq i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 3
br label %10
10: ; preds = %8, %17
%11 = call i32 @strncmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @chdir(i8* %9)
br label %17
15: ; preds = %10
%16 = call i32 @system(i8* %2)
br label %17
17: ; preds = %15, %13
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%20 = call i32 @bcmp(i8* dereferenceable(7) %2, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 7)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %10
22: ; preds = %17, %0
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}