#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ handle_command(int, char **);
int /*<<< orphan*/ show_usage();
int /*<<< orphan*/ show_version();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  const char *cmd;
  argc--;
  argv++;
  if (!argc) {
    show_usage();
    exit(1);
  }
  if (!strcmp(argv[0], "--help")) {
    argv[0] = "help";
  } else if (!strcmp(argv[0], "--version")) {
    show_version();
    return 0;
  }
  cmd = argv[0];
  handle_command(argc, argv);
  fprintf(stderr, "Failed to run command %s\n", cmd);
  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
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11a6 <main+0x46>
mov    $0x0,%al
call   1070 <show_usage@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe4c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11d5 <main+0x75>
mov    -0x10(%rbp),%rax
lea    0xe35(%rip),%rcx
mov    %rcx,(%rax)
jmp    1209 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe24(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1204 <main+0xa4>
mov    $0x0,%al
call   1030 <show_version@plt>
movl   $0x0,-0x4(%rbp)
jmp    1240 <main+0xe0>
jmp    1209 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <handle_command@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xddd(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
add    $0xffffffff,%ebp
je     11de <main+0x7e>
mov    %rsi,%rbx
add    $0x8,%rbx
mov    (%rbx),%r14
lea    0xe84(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11a6 <main+0x46>
lea    0xe78(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11b0 <main+0x50>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <show_version@plt>
jmp    11d7 <main+0x77>
lea    0xe55(%rip),%r14
mov    %r14,(%rbx)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <handle_command@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1070 <show_usage@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [5 x i8] c"help\00"
@.str.2 = [10 x i8] c"--version\00"
@stderr = global i32 0
@.str.3 = [26 x i8] c"Failed to run command %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = add nsw i32 %7, -1
store i32 %8, i32* %4
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i32 1
store i8** %10, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = call i32 (...) @show_usage()
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %24
br label %34
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %25
%32 = call i32 (...) @show_version()
store i32 0, i32* %3
br label %44
33: ; preds = %25
br label %34
34: ; preds = %33, %22
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
store i8* %37, i8** %6
%38 = load i32, i32* %4
%39 = load i8**, i8*** %5
%40 = call i32 @handle_command(i32 %38, i8** %39)
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %6
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %42)
store i32 1, i32* %3
br label %44
44: ; preds = %34, %31
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [5 x i8] c"help\00"
@.str.2 = [10 x i8] c"--version\00"
@stderr = global i32 0
@.str.3 = [26 x i8] c"Failed to run command %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = add nsw i32 %0, -1
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = icmp eq i32 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 (...) @show_usage()
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %19
14: ; preds = %9
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 (...) @show_version()
br label %24
19: ; preds = %14, %13
%20 = phi i8* [ %10, %14 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %13 ]
%21 = tail call i32 @handle_command(i32 %3, i8** %4)
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %24
24: ; preds = %19, %17
%25 = phi i32 [ 1, %19 ], [ 0, %17 ]
ret i32 %25
}