#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*/ *fmemopen(char *, size_t, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int run_commands(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
size_t strlen(char *);
int main(int argc, char *argv[]) {
  if (argc == 5 && strcmp(argv[1], "-x") == 0 && strcmp(argv[2], "-e") == 0 &&
      strcmp(argv[3], "-c") == 0) {
    size_t cmdlen = strlen(argv[4]);
    FILE *cmdstream = fmemopen(argv[4], cmdlen, "r");
    return run_commands(cmdstream);
  } else if (argc == 2) {
    FILE *cmdstream = fopen(argv[1], "r");
    return run_commands(cmdstream);
  } else {
    fprintf(stderr, "Usage: %s -x -e -c COMMAND|%s SCRIPT\n", argv[0], argv[0]);
    return 1;
  }
}


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   $0x5,-0x8(%rbp)
jne    1218 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe71(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1218 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe56(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1218 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe3b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1218 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe0b(%rip),%rdx
call   1030 <fmemopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <run_commands@plt>
mov    %eax,-0x4(%rbp)
jmp    1275 <main+0x115>
cmpl   $0x2,-0x8(%rbp)
jne    124b <main+0xeb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <run_commands@plt>
mov    %eax,-0x4(%rbp)
jmp    1275 <main+0x115>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xda2(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11cf <main+0x6f>
cmp    $0x5,%edi
jne    11ad <main+0x4d>
mov    0x8(%rbx),%rdi
lea    0xe87(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11ad <main+0x4d>
mov    0x10(%rbx),%rdi
lea    0xe75(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11ad <main+0x4d>
mov    0x18(%rbx),%rdi
lea    0xe63(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11e8 <main+0x88>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0xe4b(%rip),%rsi
mov    %rcx,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x8(%rbx),%rdi
lea    0xe2f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rdi
pop    %rbx
jmp    1070 <run_commands@plt>
mov    0x20(%rbx),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe0e(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <fmemopen@plt>
jmp    11df <main+0x7f>

LLVM IR (-O0):
@.str = [3 x i8] c"-x\00"
@.str.1 = [3 x i8] c"-e\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [38 x i8] c"Usage: %s -x -e -c COMMAND|%s SCRIPT\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%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 eq i32 %9, 5
br i1 %10, label %11, label %41
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %41
17: ; preds = %11
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %41
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %41
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 4
%32 = load i8*, i8** %31
%33 = call i64 @strlen(i8* %32)
store i64 %33, i64* %6
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 4
%36 = load i8*, i8** %35
%37 = load i64, i64* %6
%38 = call i32* @fmemopen(i8* %36, i64 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load i32*, i32** %7
%40 = call i32 @run_commands(i32* %39)
store i32 %40, i32* %3
br label %60
41: ; preds = %23, %17, %11, %2
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 2
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %48, i32** %8
%49 = load i32*, i32** %8
%50 = call i32 @run_commands(i32* %49)
store i32 %50, i32* %3
br label %60
51: ; preds = %41
%52 = load i32, i32* @stderr
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %55, i8* %58)
store i32 1, i32* %3
br label %60
60: ; preds = %51, %44, %29
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [3 x i8] c"-x\00"
@.str.1 = [3 x i8] c"-e\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [38 x i8] c"Usage: %s -x -e -c COMMAND|%s SCRIPT\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %29 [
i32 5, label %3
i32 2, label %24
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %3
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 4
%20 = load i8*, i8** %19
%21 = tail call i64 @strlen(i8* dereferenceable(1) %20)
%22 = tail call i32* @fmemopen(i8* %20, i64 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @run_commands(i32* %22)
br label %33
24: ; preds = %2
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = tail call i32 @run_commands(i32* %27)
br label %33
29: ; preds = %3, %8, %13, %2
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %1
%32 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %31, i8* %31)
br label %33
33: ; preds = %29, %24, %18
%34 = phi i32 [ %23, %18 ], [ %28, %24 ], [ 1, %29 ]
ret i32 %34
}