#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int run_in_batch_mode(char *);
int run_in_interactive_mode();
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int ret_val = 0;
  if (argc > 2) {
    fprintf(stderr, "shell: Invalid arguments\n");
    fprintf(stderr, "shell: Usage: shell [script_file]\n");
    exit(EXIT_FAILURE);
  }
  if (argc == 1) {
    ret_val = run_in_interactive_mode();
  } else {
    ret_val = run_in_batch_mode(argv[1]);
  }
  return ret_val;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    119f <main+0x5f>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11b8 <main+0x78>
mov    $0x0,%al
call   1050 <run_in_interactive_mode@plt>
mov    %eax,-0x14(%rbp)
jmp    11c8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <run_in_batch_mode@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x3,%edi
jge    115d <main+0x1d>
cmp    $0x1,%edi
jne    1153 <main+0x13>
xor    %eax,%eax
pop    %rbx
jmp    1050 <run_in_interactive_mode@plt>
mov    0x8(%rsi),%rdi
pop    %rbx
jmp    1030 <run_in_batch_mode@plt>
mov    0x2e7c(%rip),%rbx
mov    (%rbx),%edi
lea    0xe93(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe9f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"shell: Invalid arguments\0A\00"
@.str.1 = [35 x i8] c"shell: Usage: shell [script_file]\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 2
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (...) @run_in_interactive_mode()
store i32 %20, i32* %6
br label %26
21: ; preds = %16
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @run_in_batch_mode(i8* %24)
store i32 %25, i32* %6
br label %26
26: ; preds = %21, %19
%27 = load i32, i32* %6
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"shell: Invalid arguments\0A\00"
@.str.1 = [35 x i8] c"shell: Usage: shell [script_file]\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = icmp eq i32 %0, 1
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 (...) @run_in_interactive_mode()
br label %19
15: ; preds = %11
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @run_in_batch_mode(i8* %17)
br label %19
19: ; preds = %15, %13
%20 = phi i32 [ %14, %13 ], [ %18, %15 ]
ret i32 %20
}