#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*/ RTLD_NOW;
int dispatch(void *, char *, int, ...);
int /*<<< orphan*/ dlclose(void *);
char *dlerror();
void *dlopen(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
int usage(char *);
int main(int argc, char **argv) {
  char **args;
  if (argc <= 1) {
    return usage("You must pass in a command\n");
  }
  void *handle = dlopen((0), RTLD_NOW);
  if (!handle) {
    fprintf(stderr,
            "Couldn't load handle: %s\nSomething has gone seriously wrong.\n",
            dlerror());
    ;
    return 1;
  }
  argv++;
  argc--;
  int ret = 0;
  if ((strncmp(("help"), (argv[0]), 4) == 0)) {
    if (argc < 2) {
      ret = usage((0));
    } else {
      ret = dispatch(handle, argv[1], 0);
    }
  } else {
    ret = dispatch(handle, argv[0], argc, argv);
  }
  if (handle)
    dlclose(handle);
  return ret;
}


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   $0x1,-0x8(%rbp)
jg     11a4 <main+0x34>
lea    0xe69(%rip),%rdi
call   1080 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12a0 <main+0x130>
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1050 <dlopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f4 <main+0x84>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <main+0x130>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    126a <main+0xfa>
cmpl   $0x2,-0x8(%rbp)
jge    124d <main+0xdd>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <usage@plt>
mov    %eax,-0x24(%rbp)
jmp    1265 <main+0xf5>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1070 <dispatch@plt>
mov    %eax,-0x24(%rbp)
jmp    1286 <main+0x116>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1070 <dispatch@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     129a <main+0x12a>
mov    -0x20(%rbp),%rdi
call   1090 <dlclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x1,%edi
jg     1181 <main+0x11>
lea    0xe84(%rip),%rdi
jmp    1080 <usage@plt>
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1050 <dlopen@plt>
test   %rax,%rax
je     11d7 <main+0x67>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
lea    0xead(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11ff <main+0x8f>
add    $0x8,%rbx
add    $0xffffffff,%ebp
mov    (%rbx),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <dispatch@plt>
jmp    121d <main+0xad>
mov    0x2dfa(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe2e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%ebx
jmp    1227 <main+0xb7>
cmp    $0x2,%ebp
ja     120d <main+0x9d>
xor    %edi,%edi
call   1080 <usage@plt>
jmp    121d <main+0xad>
mov    0x10(%rbx),%rsi
mov    %r14,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <dispatch@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1090 <dlclose@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"You must pass in a command\0A\00"
@RTLD_NOW = global i32 0
@stderr = global i32 0
@.str.1 = [62 x i8] c"Couldn't load handle: %s\0ASomething has gone seriously wrong.\0A\00"
@.str.2 = [5 x i8] c"help\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%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 sle i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @usage(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %3
br label %60
13: ; preds = %2
%14 = load i32, i32* @RTLD_NOW
%15 = call i8* @dlopen(i32 0, i32 %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i8* (...) @dlerror()
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %60
22: ; preds = %13
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i32 1
store i8** %24, i8*** %5
%25 = load i32, i32* %4
%26 = add nsw i32 %25, -1
store i32 %26, i32* %4
store i32 0, i32* %8
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %22
%33 = load i32, i32* %4
%34 = icmp slt i32 %33, 2
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @usage(i8* null)
store i32 %36, i32* %8
br label %43
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 (i8*, i8*, i32, ...) @dispatch(i8* %38, i8* %41, i32 0)
store i32 %42, i32* %8
br label %43
43: ; preds = %37, %35
br label %52
44: ; preds = %22
%45 = load i8*, i8** %7
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = load i32, i32* %4
%50 = load i8**, i8*** %5
%51 = call i32 (i8*, i8*, i32, ...) @dispatch(i8* %45, i8* %48, i32 %49, i8** %50)
store i32 %51, i32* %8
br label %52
52: ; preds = %44, %43
%53 = load i8*, i8** %7
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i8*, i8** %7
%57 = call i32 @dlclose(i8* %56)
br label %58
58: ; preds = %55, %52
%59 = load i32, i32* %8
store i32 %59, i32* %3
br label %60
60: ; preds = %58, %18, %11
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [28 x i8] c"You must pass in a command\0A\00"
@RTLD_NOW = global i32 0
@stderr = global i32 0
@.str.1 = [62 x i8] c"Couldn't load handle: %s\0ASomething has gone seriously wrong.\0A\00"
@.str.2 = [5 x i8] c"help\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @usage(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %34
6: ; preds = %2
%7 = load i32, i32* @RTLD_NOW
%8 = tail call i8* @dlopen(i32 0, i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i8* (...) @dlerror()
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %34
14: ; preds = %6
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %16, i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %14
%20 = icmp ult i32 %0, 3
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = tail call i32 @usage(i8* null)
br label %31
23: ; preds = %19
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32 (i8*, i8*, i32, ...) @dispatch(i8* %8, i8* %25, i32 0)
br label %31
27: ; preds = %14
%28 = add nsw i32 %0, -1
%29 = load i8*, i8** %15
%30 = tail call i32 (i8*, i8*, i32, ...) @dispatch(i8* %8, i8* %29, i32 %28, i8** %15)
br label %31
31: ; preds = %27, %23, %21
%32 = phi i32 [ %22, %21 ], [ %26, %23 ], [ %30, %27 ]
%33 = tail call i32 @dlclose(i8* %8)
br label %34
34: ; preds = %10, %31, %4
%35 = phi i32 [ %5, %4 ], [ %32, %31 ], [ 1, %10 ]
ret i32 %35
}