#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ print_usage(char *);
int pty_exec(int, char *const *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char **argv) {
  int use_shell = 0;
  char *const *cmd;
  if (argc < 2) {
    print_usage(argv[0]);
    return 1;
  }
  if (*(argv[1]) == '-') {
    switch (*(argv[1] + 1)) {
    case 'h':
      print_usage(argv[0]);
      return 0;
    case 'c':
      use_shell = 1;
      if (argc < 3 || strlen(argv[2]) < 1) {
        print_usage(argv[0]);
        return 1;
      }
      break;
    default:
      fprintf(stderr, "ERROR: invalid option '%s'\n", argv[1]);
      print_usage(argv[0]);
      return 1;
    }
  }
  cmd = argv + 1;
  if (use_shell) {
    cmd += 1;
  }
  return pty_exec(use_shell, cmd);
}


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)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1288 <main+0x148>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1257 <main+0x117>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x63,%eax
je     11d9 <main+0x99>
jmp    11b0 <main+0x70>
mov    -0x24(%rbp),%eax
sub    $0x68,%eax
jne    121d <main+0xdd>
jmp    11c1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1288 <main+0x148>
movl   $0x1,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     1200 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jge    1218 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1288 <main+0x148>
jmp    1252 <main+0x112>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdcb(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1288 <main+0x148>
jmp    1257 <main+0x117>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1279 <main+0x139>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <pty_exec@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     115f <main+0x1f>
mov    (%rbx),%rdi
call   1060 <print_usage@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x8(%rbx),%rdx
mov    (%rdx),%bpl
xor    %ecx,%ecx
cmp    $0x2d,%bpl
jne    119f <main+0x5f>
movsbl 0x1(%rdx),%eax
cmp    $0x63,%eax
je     1188 <main+0x48>
cmp    $0x68,%eax
jne    11bf <main+0x7f>
mov    (%rbx),%rdi
call   1060 <print_usage@plt>
xor    %eax,%eax
jmp    1158 <main+0x18>
cmp    $0x3,%edi
jb     114b <main+0xb>
mov    0x10(%rbx),%rdi
call   1040 <strlen@plt>
mov    $0x1,%ecx
test   %eax,%eax
jle    114b <main+0xb>
lea    0x8(%rbx),%rax
add    $0x10,%rbx
cmp    $0x2d,%bpl
cmovne %rax,%rbx
mov    %ecx,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <pty_exec@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
call   1050 <fprintf@plt>
jmp    114b <main+0xb>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"ERROR: invalid option '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @print_usage(i8* %13)
store i32 1, i32* %3
br label %72
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 45
br i1 %21, label %22, label %60
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
switch i32 %28, label %49 [
i32 104, label %29
i32 99, label %34
]
29: ; preds = %22
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @print_usage(i8* %32)
store i32 0, i32* %3
br label %72
34: ; preds = %22
store i32 1, i32* %6
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 3
br i1 %36, label %43, label %37
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @strlen(i8* %40)
%42 = icmp slt i32 %41, 1
br i1 %42, label %43, label %48
43: ; preds = %37, %34
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = call i32 @print_usage(i8* %46)
store i32 1, i32* %3
br label %72
48: ; preds = %37
br label %59
49: ; preds = %22
%50 = load i32, i32* @stderr
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %53)
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 0
%57 = load i8*, i8** %56
%58 = call i32 @print_usage(i8* %57)
store i32 1, i32* %3
br label %72
59: ; preds = %48
br label %60
60: ; preds = %59, %15
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
store i8** %62, i8*** %7
%63 = load i32, i32* %6
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = load i8**, i8*** %7
%67 = getelementptr inbounds i8*, i8** %66, i64 1
store i8** %67, i8*** %7
br label %68
68: ; preds = %65, %60
%69 = load i32, i32* %6
%70 = load i8**, i8*** %7
%71 = call i32 @pty_exec(i32 %69, i8** %70)
store i32 %71, i32* %3
br label %72
72: ; preds = %68, %49, %43, %29, %10
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"ERROR: invalid option '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @print_usage(i8* %5)
br label %39
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 45
br i1 %11, label %12, label %34
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %29 [
i32 104, label %16
i32 99, label %19
]
16: ; preds = %12
%17 = load i8*, i8** %1
%18 = tail call i32 @print_usage(i8* %17)
br label %39
19: ; preds = %12
%20 = icmp ult i32 %0, 3
br i1 %20, label %26, label %21
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @strlen(i8* %23)
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %34
26: ; preds = %21, %19
%27 = load i8*, i8** %1
%28 = tail call i32 @print_usage(i8* %27)
br label %39
29: ; preds = %12
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %9)
%32 = load i8*, i8** %1
%33 = tail call i32 @print_usage(i8* %32)
br label %39
34: ; preds = %21, %7
%35 = phi i32 [ 1, %21 ], [ 0, %7 ]
%36 = getelementptr inbounds i8*, i8** %1, i64 2
%37 = select i1 %11, i8** %36, i8** %8
%38 = tail call i32 @pty_exec(i32 %35, i8** %37)
br label %39
39: ; preds = %34, %29, %26, %16, %4
%40 = phi i32 [ 1, %4 ], [ 1, %29 ], [ 1, %26 ], [ %38, %34 ], [ 0, %16 ]
ret i32 %40
}