#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*/ free(char *);
int parse_args(char **);
int /*<<< orphan*/ populate_path_from_env();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ process_regular_cmds(char **, int);
int process_special_cmds(char **, int);
int main(int argc, char **argv) {
  if (argc > 1) {
    printf("error: The shell doesn't expect any arguments\n");
    return -1;
  }
  populate_path_from_env();
  while (1) {
    char *args_list[1023 + 1] = {0};
    int arg_num;
    int i = 0;
    printf("dtshell-2.4$");
    arg_num = parse_args(args_list);
    if (arg_num <= 0) {
      continue;
    }
    if (process_special_cmds(args_list, arg_num) == true) {
      goto next;
    }
    process_regular_cmds(args_list, arg_num);
  next:
    for (i = 0; i < arg_num; i++) {
      if (args_list[i] != NULL) {
        free(args_list[i]);
        args_list[i] = NULL;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11ad <main+0x3d>
lea    0xe66(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x2020,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1090 <populate_path_from_env@plt>
lea    -0x2010(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
movl   $0x0,-0x2018(%rbp)
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
lea    -0x2010(%rbp),%rdi
call   1080 <parse_args@plt>
mov    %eax,-0x2014(%rbp)
cmpl   $0x0,-0x2014(%rbp)
jg     1201 <main+0x91>
jmp    11b4 <main+0x44>
lea    -0x2010(%rbp),%rdi
mov    -0x2014(%rbp),%esi
call   1040 <process_special_cmds@plt>
cmp    $0x1,%eax
jne    1221 <main+0xb1>
jmp    1233 <main+0xc3>
lea    -0x2010(%rbp),%rdi
mov    -0x2014(%rbp),%esi
call   1070 <process_regular_cmds@plt>
movl   $0x0,-0x2018(%rbp)
mov    -0x2018(%rbp),%eax
cmp    -0x2014(%rbp),%eax
jge    12a5 <main+0x135>
movslq -0x2018(%rbp),%rax
cmpq   $0x0,-0x2010(%rbp,%rax,8)
je     128c <main+0x11c>
movslq -0x2018(%rbp),%rax
mov    -0x2010(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
movslq -0x2018(%rbp),%rax
movq   $0x0,-0x2010(%rbp,%rax,8)
jmp    1291 <main+0x121>
mov    -0x2018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2018(%rbp)
jmp    123d <main+0xcd>
jmp    11b4 <main+0x44>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2008,%rsp
cmp    $0x2,%edi
jl     11b1 <main+0x31>
lea    0xe74(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   10a0 <populate_path_from_env@plt>
mov    %rsp,%r15
lea    0xe3e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2000,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
call   1090 <parse_args@plt>
test   %eax,%eax
jle    11d0 <main+0x50>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <process_special_cmds@plt>
cmp    $0x1,%eax
je     120e <main+0x8e>
mov    %r15,%rdi
mov    %ebp,%esi
call   1080 <process_regular_cmds@plt>
mov    %ebp,%ebp
xor    %ebx,%ebx
jmp    1229 <main+0xa9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11d0 <main+0x50>
mov    (%rsp,%rbx,8),%rdi
test   %rdi,%rdi
je     1220 <main+0xa0>
call   1030 <free@plt>
movq   $0x0,(%rsp,%rbx,8)
jmp    1220 <main+0xa0>

LLVM IR (-O0):
@.str = [47 x i8] c"error: The shell doesn't expect any arguments\0A\00"
@.str.1 = [13 x i8] c"dtshell-2.4$\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8*]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
ret i32 -1
13: ; preds = %2
%14 = call i32 (...) @populate_path_from_env()
br label %15
15: ; preds = %13, %22, %57
%16 = bitcast [1024 x i8*]* %6 to i8*
store i32 0, i32* %8
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 0
%19 = call i32 @parse_args(i8** %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp sle i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
br label %15
23: ; preds = %15
%24 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 0
%25 = load i32, i32* %7
%26 = call i32 @process_special_cmds(i8** %24, i32 %25)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %23
br label %33
29: ; preds = %23
%30 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 0
%31 = load i32, i32* %7
%32 = call i32 @process_regular_cmds(i8** %30, i32 %31)
br label %33
33: ; preds = %29, %28
store i32 0, i32* %8
br label %34
34: ; preds = %54, %33
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %57
38: ; preds = %34
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %53
44: ; preds = %38
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @free(i8* %48)
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 %51
store i8* null, i8** %52
br label %53
53: ; preds = %44, %38
br label %54
54: ; preds = %53
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %34
57: ; preds = %34
br label %15
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"dtshell-2.4$\00"
@str = [46 x i8] c"error: The shell doesn't expect any arguments\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8*]
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
ret i32 -1
7: ; preds = %2
%8 = tail call i32 (...) @populate_path_from_env()
%9 = bitcast [1024 x i8*]* %3 to i8*
%10 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %3, i64 0, i64 0
br label %11
11: ; preds = %32, %7
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @parse_args(i8** %10)
%14 = icmp slt i32 %13, 1
br i1 %14, label %32, label %15
15: ; preds = %11
%16 = call i32 @process_special_cmds(i8** %10, i32 %13)
%17 = icmp eq i32 %16, 1
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = call i32 @process_regular_cmds(i8** %10, i32 %13)
br label %20
20: ; preds = %18, %15
%21 = zext i32 %13 to i64
br label %22
22: ; preds = %20, %29
%23 = phi i64 [ 0, %20 ], [ %30, %29 ]
%24 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %3, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = call i32 @free(i8* %25)
store i8* null, i8** %24
br label %29
29: ; preds = %22, %27
%30 = add nuw nsw i64 %23, 1
%31 = icmp eq i64 %30, %21
br i1 %31, label %32, label %22
32: ; preds = %29, %11
br label %11
}