#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 */
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
int print(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strchr(char const *, char);
int /*<<< orphan*/ strcmp(char const *, char *);
char *strstr(char const *, char *);
int lss(const char *p) {
  char *start;
  char *end;
  int res;
  int i = 0;
  char *cmd[] = {
      "ls",
      "ls -a",
      "ls -l",
  };
  start = strstr(p, "ls");
  if (!start) {
    printf("can't support this format \n");
    return 1;
  }
  end = strchr(p, '\n');
  *end = '\0';
  for (i = 0; i < sizeof(cmd) / sizeof(char *); ++i) {
    if (!strcmp(p, cmd[i])) {
      switch (i) {
      case 0:
        res = print(".");
        break;
      case 1:
        res = print("a");
        break;
      case 2:
        res = print("l");
        break;
      case 3:
        break;
      default:
        break;
      }
    }
  }
  if (res != 0)
    printf("can't support %s command ,please check again \n", p);
  return res;
}


x86 assembly (clang, -O0):
<lss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x2c96(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c93(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c90(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bd <lss+0x6d>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ab <lss+0x15b>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rax
cmp    $0x3,%rax
jae    1289 <lss+0x139>
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1276 <lss+0x126>
mov    -0x28(%rbp),%eax
mov    %rax,-0x48(%rbp)
sub    $0x3,%rax
ja     126c <lss+0x11c>
mov    -0x48(%rbp),%rax
lea    0xdde(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe09(%rip),%rdi
call   1050 <print@plt>
mov    %eax,-0x24(%rbp)
jmp    1271 <lss+0x121>
lea    0xdd1(%rip),%rdi
call   1050 <print@plt>
mov    %eax,-0x24(%rbp)
jmp    1271 <lss+0x121>
lea    0xdc3(%rip),%rdi
call   1050 <print@plt>
mov    %eax,-0x24(%rbp)
jmp    1271 <lss+0x121>
jmp    1271 <lss+0x121>
jmp    1271 <lss+0x121>
jmp    1276 <lss+0x126>
jmp    127b <lss+0x12b>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11dd <lss+0x8d>
cmpl   $0x0,-0x24(%rbp)
je     12a5 <lss+0x155>
mov    -0x10(%rbp),%rsi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lss>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe93(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11f3 <lss+0x93>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    11a8 <lss+0x48>
lea    0xe6e(%rip),%rdi
call   1060 <print@plt>
mov    %eax,%ebp
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    11c9 <lss+0x69>
lea    0xe45(%rip),%rdi
call   1060 <print@plt>
mov    %eax,%ebp
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1206 <lss+0xa6>
test   %ebp,%ebp
je     1218 <lss+0xb8>
lea    0xe2a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    121a <lss+0xba>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
jmp    121a <lss+0xba>
lea    0xe00(%rip),%rdi
call   1060 <print@plt>
mov    %eax,%ebp
test   %ebp,%ebp
jne    11e0 <lss+0x80>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@.str.1 = [6 x i8] c"ls -a\00"
@.str.2 = [6 x i8] c"ls -l\00"
@__const.lss.cmd = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [28 x i8] c"can't support this format \0A\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [2 x i8] c"l\00"
@.str.7 = [47 x i8] c"can't support %s command ,please check again \0A\00"
define i32 @lss(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x i8*]
store i8* %0, i8** %3
store i32 0, i32* %7
%9 = bitcast [3 x i8*]* %8 to i8*
%10 = load i8*, i8** %3
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
br label %55
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i8* @strchr(i8* %17, i8 signext 10)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
store i8 0, i8* %19
store i32 0, i32* %7
br label %20
20: ; preds = %44, %16
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = icmp ult i64 %22, 3
br i1 %23, label %24, label %47
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %25, i8* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %43, label %32
32: ; preds = %24
%33 = load i32, i32* %7
switch i32 %33, label %41 [
i32 0, label %34
i32 1, label %36
i32 2, label %38
i32 3, label %40
]
34: ; preds = %32
%35 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 %35, i32* %6
br label %42
36: ; preds = %32
%37 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 %37, i32* %6
br label %42
38: ; preds = %32
%39 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 %39, i32* %6
br label %42
40: ; preds = %32
br label %42
41: ; preds = %32
br label %42
42: ; preds = %41, %40, %38, %36, %34
br label %43
43: ; preds = %42, %24
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %20
47: ; preds = %20
%48 = load i32, i32* %6
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i8*, i8** %3
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %47
%54 = load i32, i32* %6
store i32 %54, i32* %2
br label %55
55: ; preds = %53, %14
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@.str.1 = [6 x i8] c"ls -a\00"
@.str.2 = [6 x i8] c"ls -l\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [2 x i8] c"l\00"
@.str.7 = [47 x i8] c"can't support %s command ,please check again \0A\00"
@str = [27 x i8] c"can't support this format \00"
define i32 @lss(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %29
6: ; preds = %1
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
store i8 0, i8* %7
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %6, %10
%13 = phi i32 [ undef, %6 ], [ %11, %10 ]
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = phi i32 [ %13, %12 ], [ %17, %16 ]
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = phi i32 [ %19, %18 ], [ %23, %22 ]
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i8* %0)
br label %29
29: ; preds = %24, %27, %4
%30 = phi i32 [ 1, %4 ], [ %25, %27 ], [ 0, %24 ]
ret i32 %30
}