#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*/ clear_screen();
scalar_t__ compstr(char *, char *);
int /*<<< orphan*/ help_sh();
int /*<<< orphan*/ in_string(char *, int /*<<< orphan*/);
int /*<<< orphan*/ out_char(char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_text_attr(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ version();
void sh() {
  set_text_attr(10);
  printf("Shell 0.1\n");
  printf("Enter help for help\n");
  char com_name[50];
  while ((compstr(com_name, "quit") != 0)) {
    out_char('#');
    out_char(' ');
    in_string(com_name, strlen(com_name));
    if (compstr(com_name, "clear") == 0)
      clear_screen();
    if (compstr(com_name, "version") == 0)
      version();
    if (compstr(com_name, "help") == 0)
      help_sh();
  }
  set_text_attr(15);
  clear_screen();
}


x86 assembly (clang, -O0):
<sh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    $0xa,%edi
call   1070 <set_text_attr@plt>
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <compstr@plt>
cmp    $0x0,%rax
je     126c <sh+0xdc>
mov    $0x23,%edi
call   10b0 <out_char@plt>
mov    $0x20,%edi
call   10b0 <out_char@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1060 <in_string@plt>
lea    -0x40(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1030 <compstr@plt>
cmp    $0x0,%rax
jne    1225 <sh+0x95>
mov    $0x0,%al
call   1090 <clear_screen@plt>
lea    -0x40(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1030 <compstr@plt>
cmp    $0x0,%rax
jne    1246 <sh+0xb6>
mov    $0x0,%al
call   1080 <version@plt>
lea    -0x40(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1030 <compstr@plt>
cmp    $0x0,%rax
jne    1267 <sh+0xd7>
mov    $0x0,%al
call   10a0 <help_sh@plt>
jmp    11ba <sh+0x2a>
mov    $0xf,%edi
call   1070 <set_text_attr@plt>
mov    $0x0,%al
call   1090 <clear_screen@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sh>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    $0xa,%edi
call   1070 <set_text_attr@plt>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3a(%rip),%rsi
mov    %rsp,%rdi
call   1040 <compstr@plt>
test   %rax,%rax
je     127d <sh+0xed>
mov    %rsp,%rbx
lea    0xe24(%rip),%r14
lea    0xe23(%rip),%r15
lea    0xe3d(%rip),%r12
lea    0xe0a(%rip),%r13
jmp    1210 <sh+0x80>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <compstr@plt>
test   %rax,%rax
je     127d <sh+0xed>
mov    $0x23,%edi
call   10b0 <out_char@plt>
mov    $0x20,%edi
call   10b0 <out_char@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <in_string@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <compstr@plt>
test   %rax,%rax
jne    124d <sh+0xbd>
xor    %eax,%eax
call   1090 <clear_screen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <compstr@plt>
test   %rax,%rax
jne    1264 <sh+0xd4>
xor    %eax,%eax
call   1080 <version@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <compstr@plt>
test   %rax,%rax
jne    1200 <sh+0x70>
xor    %eax,%eax
call   10a0 <help_sh@plt>
jmp    1200 <sh+0x70>
mov    $0xf,%edi
call   1070 <set_text_attr@plt>
xor    %eax,%eax
call   1090 <clear_screen@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Shell 0.1\0A\00"
@.str.1 = [21 x i8] c"Enter help for help\0A\00"
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [6 x i8] c"clear\00"
@.str.4 = [8 x i8] c"version\00"
@.str.5 = [5 x i8] c"help\00"
define void @sh() {
%1 = alloca [50 x i8]
%2 = call i32 @set_text_attr(i32 10)
%3 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %33, %0
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%7 = call i64 @compstr(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %34
9: ; preds = %5
%10 = call i32 @out_char(i8 signext 35)
%11 = call i32 @out_char(i8 signext 32)
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @in_string(i8* %12, i32 %14)
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%17 = call i64 @compstr(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %9
%20 = call i32 (...) @clear_screen()
br label %21
21: ; preds = %19, %9
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%23 = call i64 @compstr(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (...) @version()
br label %27
27: ; preds = %25, %21
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%29 = call i64 @compstr(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (...) @help_sh()
br label %33
33: ; preds = %31, %27
br label %5
34: ; preds = %5
%35 = call i32 @set_text_attr(i32 15)
%36 = call i32 (...) @clear_screen()
ret void
}

LLVM IR (-O2):
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [6 x i8] c"clear\00"
@.str.4 = [8 x i8] c"version\00"
@.str.5 = [5 x i8] c"help\00"
@str = [10 x i8] c"Shell 0.1\00"
@str.6 = [20 x i8] c"Enter help for help\00"
define void @sh() {
%1 = alloca [50 x i8]
%2 = tail call i32 @set_text_attr(i32 10)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%6 = call i64 @compstr(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %30, label %8
8: ; preds = %0, %27
%9 = call i32 @out_char(i8 signext 35)
%10 = call i32 @out_char(i8 signext 32)
%11 = call i32 @strlen(i8* %5)
%12 = call i32 @in_string(i8* %5, i32 %11)
%13 = call i64 @compstr(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 (...) @clear_screen()
br label %17
17: ; preds = %15, %8
%18 = call i64 @compstr(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (...) @version()
br label %22
22: ; preds = %20, %17
%23 = call i64 @compstr(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (...) @help_sh()
br label %27
27: ; preds = %25, %22
%28 = call i64 @compstr(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %8
30: ; preds = %27, %0
%31 = call i32 @set_text_attr(i32 15)
%32 = call i32 (...) @clear_screen()
ret void
}