#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 == 4 && strcmp(argv[1], "-x") == 0 && strcmp(argv[2], "-c") == 0) {
    size_t cmdlen = strlen(argv[3]);
    FILE *cmdstream = fmemopen(argv[3], 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 -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   $0x4,-0x8(%rbp)
jne    11fa <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe71(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11fa <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe56(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11fa <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe26(%rip),%rdx
call   1030 <fmemopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <run_commands@plt>
mov    %eax,-0x4(%rbp)
jmp    1257 <main+0xf7>
cmpl   $0x2,-0x8(%rbp)
jne    122d <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf3(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <run_commands@plt>
mov    %eax,-0x4(%rbp)
jmp    1257 <main+0xf7>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xdbd(%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     11ba <main+0x5a>
cmp    $0x4,%edi
jne    1198 <main+0x38>
mov    0x8(%rbx),%rdi
lea    0xe87(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1198 <main+0x38>
mov    0x10(%rbx),%rdi
lea    0xe75(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d3 <main+0x73>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0xe5d(%rip),%rsi
mov    %rcx,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x8(%rbx),%rdi
lea    0xe41(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rdi
pop    %rbx
jmp    1070 <run_commands@plt>
mov    0x18(%rbx),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe20(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <fmemopen@plt>
jmp    11ca <main+0x6a>

LLVM IR (-O0):
@.str = [3 x i8] c"-x\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"Usage: %s -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, 4
br i1 %10, label %11, label %35
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 %35
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 %35
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
%27 = call i64 @strlen(i8* %26)
store i64 %27, i64* %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
%31 = load i64, i64* %6
%32 = call i32* @fmemopen(i8* %30, i64 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = call i32 @run_commands(i32* %33)
store i32 %34, i32* %3
br label %54
35: ; preds = %17, %11, %2
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 2
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %42, i32** %8
%43 = load i32*, i32** %8
%44 = call i32 @run_commands(i32* %43)
store i32 %44, i32* %3
br label %54
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %49, i8* %52)
store i32 1, i32* %3
br label %54
54: ; preds = %45, %38, %23
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"-x\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"Usage: %s -c COMMAND|%s SCRIPT\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %24 [
i32 4, label %3
i32 2, label %19
]
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 %24
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 %24
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i64 @strlen(i8* dereferenceable(1) %15)
%17 = tail call i32* @fmemopen(i8* %15, i64 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @run_commands(i32* %17)
br label %28
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @run_commands(i32* %22)
br label %28
24: ; preds = %3, %8, %2
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %26, i8* %26)
br label %28
28: ; preds = %24, %19, %13
%29 = phi i32 [ %18, %13 ], [ %23, %19 ], [ 1, %24 ]
ret i32 %29
}