#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*/ SIGINT;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ load_plugins();
int /*<<< orphan*/ perror(char *);
int run_shell(int /*<<< orphan*/ *);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  if (argc != 2) {
    usage();
    return 1;
  }
  FILE *input = stdin;
  if (strcmp(argv[1], "-i") && strcmp(argv[1], "--interactive")) {
    input = fopen(argv[1], "r");
    if (input == NULL) {
      perror("fopen");
      return 2;
    }
    char *line = NULL;
    size_t len = 0;
    if (getline(&line, &len, input) < 0) {
      perror("getline");
      return 127;
    }
    if (strcmp("#! /bin/cash\n", line) != 0) {
      fprintf(stderr,
              "'%s' doesn't look like a script! "
              "(does it have a shebang?)\n",
              argv[1]);
      free(line);
      usage();
      return 3;
    }
    free(line);
  } else {
    signal(SIGINT, SIG_IGN);
  }
  if (load_plugins()) {
    return 127;
  }
  int retval;
  retval = run_shell(input);
  fclose(input);
  return retval;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e3 <main+0x33>
mov    $0x0,%al
call   10a0 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    135b <main+0x1ab>
mov    0x2df6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe00(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     130c <main+0x15c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde5(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     130c <main+0x15c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd5(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1268 <main+0xb8>
lea    0xdbc(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    135b <main+0x1ab>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10d0 <getline@plt>
cmp    $0x0,%rax
jge    12ab <main+0xfb>
lea    0xd7f(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x7f,-0x4(%rbp)
jmp    135b <main+0x1ab>
mov    -0x20(%rbp),%rsi
lea    0xd6b(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     12fe <main+0x14e>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd52(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   10a0 <usage@plt>
movl   $0x3,-0x4(%rbp)
jmp    135b <main+0x1ab>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1323 <main+0x173>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
mov    0x2cbc(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    $0x0,%al
call   1090 <load_plugins@plt>
cmp    $0x0,%rax
je     1340 <main+0x190>
movl   $0x7f,-0x4(%rbp)
jmp    135b <main+0x1ab>
mov    -0x18(%rbp),%rdi
call   1080 <run_shell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1293 <main+0xe3>
mov    %rsi,%rbx
mov    0x2e16(%rip),%rax
mov    (%rax),%r14
mov    0x8(%rsi),%rdi
lea    0xe28(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     12a1 <main+0xf1>
mov    0x8(%rbx),%rdi
lea    0xe12(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     12a1 <main+0xf1>
mov    0x8(%rbx),%rdi
lea    0xe07(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12f1 <main+0x141>
mov    %rax,%r14
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   10d0 <getline@plt>
test   %rax,%rax
js     1304 <main+0x154>
mov    0x8(%rsp),%rsi
lea    0xdcd(%rip),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     12e5 <main+0x135>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdb9(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   10a0 <usage@plt>
mov    $0x3,%ebx
jmp    12db <main+0x12b>
xor    %eax,%eax
call   10a0 <usage@plt>
mov    $0x1,%ebx
jmp    12db <main+0x12b>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
xor    %eax,%eax
call   1090 <load_plugins@plt>
mov    $0x7f,%ebx
test   %rax,%rax
jne    12db <main+0x12b>
mov    %r14,%rdi
call   1080 <run_shell@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    12b8 <main+0x108>
lea    0xd1b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x2,%ebx
jmp    12db <main+0x12b>
lea    0xd0e(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x7f,%ebx
jmp    12db <main+0x12b>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [3 x i8] c"-i\00"
@.str.1 = [14 x i8] c"--interactive\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"fopen\00"
@.str.4 = [8 x i8] c"getline\00"
@.str.5 = [14 x i8] c"#! /bin/cash\0A\00"
@stderr = global i32 0
@.str.6 = [60 x i8] c"'%s' doesn't look like a script! (does it have a shebang?)\0A\00"
@SIGINT = global i32 0
@SIG_IGN = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @usage()
store i32 1, i32* %3
br label %72
14: ; preds = %2
%15 = load i32*, i32** @stdin
store i32* %15, i32** %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %58
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %58
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %6
%32 = load i32*, i32** %6
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %72
36: ; preds = %27
store i8* null, i8** %7
store i64 0, i64* %8
%37 = load i32*, i32** %6
%38 = call i64 @getline(i8** %7, i64* %8, i32* %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i32 127, i32* %3
br label %72
42: ; preds = %36
%43 = load i8*, i8** %7
%44 = call i64 @strcmp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %7
%53 = call i32 @free(i8* %52)
%54 = call i32 (...) @usage()
store i32 3, i32* %3
br label %72
55: ; preds = %42
%56 = load i8*, i8** %7
%57 = call i32 @free(i8* %56)
br label %62
58: ; preds = %21, %14
%59 = load i32, i32* @SIGINT
%60 = load i32, i32* @SIG_IGN
%61 = call i32 @signal(i32 %59, i32 %60)
br label %62
62: ; preds = %58, %55
%63 = call i64 (...) @load_plugins()
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %62
store i32 127, i32* %3
br label %72
66: ; preds = %62
%67 = load i32*, i32** %6
%68 = call i32 @run_shell(i32* %67)
store i32 %68, i32* %9
%69 = load i32*, i32** %6
%70 = call i32 @fclose(i32* %69)
%71 = load i32, i32* %9
store i32 %71, i32* %3
br label %72
72: ; preds = %66, %65, %46, %40, %34, %12
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [3 x i8] c"-i\00"
@.str.1 = [14 x i8] c"--interactive\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"fopen\00"
@.str.4 = [8 x i8] c"getline\00"
@.str.5 = [14 x i8] c"#! /bin/cash\0A\00"
@stderr = global i32 0
@.str.6 = [60 x i8] c"'%s' doesn't look like a script! (does it have a shebang?)\0A\00"
@SIGINT = global i32 0
@SIG_IGN = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %58
8: ; preds = %2
%9 = load i32*, i32** @stdin
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %47, label %14
14: ; preds = %8
%15 = load i8*, i8** %10
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %47, label %18
18: ; preds = %14
%19 = load i8*, i8** %10
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %58
24: ; preds = %18
%25 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%26 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%27 = call i64 @getline(i8** %3, i64* %4, i32* %20)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %42
31: ; preds = %24
%32 = load i8*, i8** %3
%33 = call i64 @strcmp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %44, label %35
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %10
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %3
%40 = call i32 @free(i8* %39)
%41 = call i32 (...) @usage()
br label %42
42: ; preds = %35, %29
%43 = phi i32 [ 127, %29 ], [ 3, %35 ]
br label %58
44: ; preds = %31
%45 = load i8*, i8** %3
%46 = call i32 @free(i8* %45)
br label %51
47: ; preds = %14, %8
%48 = load i32, i32* @SIGINT
%49 = load i32, i32* @SIG_IGN
%50 = tail call i32 @signal(i32 %48, i32 %49)
br label %51
51: ; preds = %44, %47
%52 = phi i32* [ %20, %44 ], [ %9, %47 ]
%53 = call i64 (...) @load_plugins()
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = call i32 @run_shell(i32* %52)
%57 = call i32 @fclose(i32* %52)
br label %58
58: ; preds = %42, %22, %55, %51, %6
%59 = phi i32 [ 1, %6 ], [ 2, %22 ], [ %56, %55 ], [ 127, %51 ], [ %43, %42 ]
ret i32 %59
}