#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*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int run_batch(char *);
int run_interactive();
int main(int argc, char **argv) {
  switch (argc) {
  case 1:
    return run_interactive();
    break;
  case 2:
    return run_batch(argv[1]);
    break;
  default:
    errno = EINVAL;
    perror("shell: Error");
    printf("Usage:\n");
    printf("\t%s\n", argv[0]);
    printf("\t%s [BATCHFILE]\n", argv[0]);
    return -1;
  }
}


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)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     117b <main+0x3b>
jmp    116a <main+0x2a>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     118a <main+0x4a>
jmp    119f <main+0x5f>
mov    $0x0,%al
call   1040 <run_interactive@plt>
mov    %eax,-0x4(%rbp)
jmp    11fc <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <run_batch@plt>
mov    %eax,-0x4(%rbp)
jmp    11fc <main+0xbc>
mov    0x2e32(%rip),%rax
mov    (%rax),%ecx
mov    0x2e31(%rip),%rax
mov    %ecx,(%rax)
lea    0xe48(%rip),%rdi
call   1060 <perror@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1166 <main+0x16>
cmp    $0x1,%edi
jne    1170 <main+0x20>
xor    %eax,%eax
pop    %rbx
jmp    1050 <run_interactive@plt>
mov    0x8(%rbx),%rdi
pop    %rbx
jmp    1060 <run_batch@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    0x2e60(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe77(%rip),%rdi
call   1070 <perror@plt>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [13 x i8] c"shell: Error\00"
@.str.1 = [8 x i8] c"Usage:\0A\00"
@.str.2 = [5 x i8] c"\09%s\0A\00"
@.str.3 = [17 x i8] c"\09%s [BATCHFILE]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
switch i32 %6, label %14 [
i32 1, label %7
i32 2, label %9
]
7: ; preds = %2
%8 = call i32 (...) @run_interactive()
store i32 %8, i32* %3
br label %26
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @run_batch(i8* %12)
store i32 %13, i32* %3
br label %26
14: ; preds = %2
%15 = load i32, i32* @EINVAL
store i32 %15, i32* @errno
%16 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %24)
store i32 -1, i32* %3
br label %26
26: ; preds = %14, %9, %7
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [13 x i8] c"shell: Error\00"
@.str.2 = [5 x i8] c"\09%s\0A\00"
@.str.3 = [17 x i8] c"\09%s [BATCHFILE]\0A\00"
@str = [7 x i8] c"Usage:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %9 [
i32 1, label %3
i32 2, label %5
]
3: ; preds = %2
%4 = tail call i32 (...) @run_interactive()
br label %17
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @run_batch(i8* %7)
br label %17
9: ; preds = %2
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
%11 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %9, %5, %3
%18 = phi i32 [ -1, %9 ], [ %8, %5 ], [ %4, %3 ]
ret i32 %18
}