#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ backstage(char *, char **, int);
int /*<<< orphan*/ clear_command(char **, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int read_command(char *, char **, int /*<<< orphan*/ *);
int myshell(char *args[], int size) {
  FILE *fp;
  char command[100];
  char *argv[1000];
  char s[1000];
  if (size == 0) {
    printf("myshell：没有参数\n");
    return 0;
  }
  fp = fopen(args[0], "r");
  if (fp == NULL) {
    printf("打开文件失败\n");
    return 0;
  }
  while (!feof(fp)) {
    size = read_command(command, argv, fp);
    if (size == -1)
      break;
    backstage(command, argv, size);
    clear_command(argv, size);
  }
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<myshell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x23c0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11a4 <myshell+0x34>
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1264 <myshell+0xf4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe66(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11de <myshell+0x6e>
lea    0xe4d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1264 <myshell+0xf4>
jmp    11e3 <myshell+0x73>
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1201 <myshell+0x91>
jmp    1254 <myshell+0xe4>
lea    -0x90(%rbp),%rdi
lea    -0x1fd0(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <read_command@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    122a <myshell+0xba>
jmp    1254 <myshell+0xe4>
lea    -0x90(%rbp),%rdi
lea    -0x1fd0(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <backstage@plt>
lea    -0x1fd0(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <clear_command@plt>
jmp    11e3 <myshell+0x73>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x23c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myshell>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1fb8,%rsp
test   %esi,%esi
je     11f7 <myshell+0x87>
mov    (%rdi),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1200 <myshell+0x90>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11e8 <myshell+0x78>
mov    %rsp,%r14
lea    0x70(%rsp),%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <read_command@plt>
cmp    $0xffffffff,%eax
je     11e8 <myshell+0x78>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <backstage@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1090 <clear_command@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11b0 <myshell+0x40>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
jmp    120e <myshell+0x9e>
lea    0xe17(%rip),%rdi
jmp    1207 <myshell+0x97>
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1fb8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"myshell\EF\BC\9A\E6\B2\A1\E6\9C\89\E5\8F\82\E6\95\B0\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"\E6\89\93\E5\BC\80\E6\96\87\E4\BB\B6\E5\A4\B1\E8\B4\A5\0A\00"
define i32 @myshell(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [100 x i8]
%8 = alloca [1000 x i8*]
%9 = alloca [1000 x i8]
store i8** %0, i8*** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %48
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %48
23: ; preds = %14
br label %24
24: ; preds = %37, %23
%25 = load i32*, i32** %6
%26 = call i32 @feof(i32* %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br i1 %28, label %29, label %45
29: ; preds = %24
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%31 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %8, i64 0, i64 0
%32 = load i32*, i32** %6
%33 = call i32 @read_command(i8* %30, i8** %31, i32* %32)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %37
36: ; preds = %29
br label %45
37: ; preds = %29
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%39 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %8, i64 0, i64 0
%40 = load i32, i32* %5
%41 = call i32 @backstage(i8* %38, i8** %39, i32 %40)
%42 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %8, i64 0, i64 0
%43 = load i32, i32* %5
%44 = call i32 @clear_command(i8** %42, i32 %43)
br label %24
45: ; preds = %36, %24
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
store i32 1, i32* %3
br label %48
48: ; preds = %45, %21, %12
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@str = [19 x i8] c"\E6\89\93\E5\BC\80\E6\96\87\E4\BB\B6\E5\A4\B1\E8\B4\A5\00"
@str.3 = [23 x i8] c"myshell\EF\BC\9A\E6\B2\A1\E6\9C\89\E5\8F\82\E6\95\B0\00"
define i32 @myshell(i8** nocapture %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = alloca [1000 x i8*]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast [1000 x i8*]* %4 to i8*
%7 = icmp eq i32 %1, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.3, i64 0, i64 0))
br label %30
10: ; preds = %2
%11 = load i8*, i8** %0
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %4, i64 0, i64 0
%16 = call i32 @feof(i32* %12)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %28
18: ; preds = %10
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %30
20: ; preds = %14, %23
%21 = call i32 @read_command(i8* %5, i8** %15, i32* %12)
%22 = icmp eq i32 %21, -1
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = call i32 @backstage(i8* %5, i8** %15, i32 %21)
%25 = call i32 @clear_command(i8** %15, i32 %21)
%26 = call i32 @feof(i32* %12)
%27 = icmp eq i32 %26, 0
br i1 %27, label %20, label %28
28: ; preds = %23, %20, %14
%29 = call i32 @fclose(i32* %12)
br label %30
30: ; preds = %28, %18, %8
%31 = phi i32 [ 0, %8 ], [ 0, %18 ], [ 1, %28 ]
ret i32 %31
}