#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*/ convert_main(int, char **);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execlp(char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
char *version();
int main(int argc, char **argv) {
  static char help[] =
      "usage: hawk [--version|--help] <command> [<args>]\n\nThe most commonly "
      "used hawk commands are:\n   convert    Convert an image from a format "
      "to another\n   phase      Phase a diffraction pattern\n\nSee 'hawk help "
      "<command>' for more information on a specific command.\n";
  if (argc == 1 || (argc == 2 && (strcmp(argv[1], "--help") == 0 ||
                                  strcmp(argv[1], "help") == 0))) {
    printf("%s\n", help);
    exit(0);
  }
  if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "version") == 0) {
    printf("hawk version %s\n", version());
    exit(0);
  }
  if (strcmp(argv[1], "help") == 0) {
    char buffer[1024];
    snprintf(buffer, 1024, "hawk-%s", argv[2]);
    execlp("man", "man", buffer, (char *)NULL);
    printf("failed to exec man: %s\n", strerror(errno));
    printf("Could not start \"man\"\n");
    exit(-1);
  } else if (strcmp(argv[1], "convert") == 0) {
    convert_main(argc - 1, &argv[1]);
  } else {
    printf("Unknown option: %s\n", argv[1]);
    printf("%s\n", help);
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11e9 <main+0x69>
cmpl   $0x2,-0x8(%rbp)
jne    1205 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe44(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11e9 <main+0x69>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe28(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1205 <main+0x85>
lea    0xe52(%rip),%rdi
lea    0x2e79(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf3(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1241 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd7(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1260 <main+0xe0>
mov    $0x0,%al
call   1070 <version@plt>
mov    %rax,%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd93(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12ef <main+0x16f>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x400,%esi
lea    0xd89(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdx
lea    0xd7e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1090 <execlp@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd5f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1325 <main+0x1a5>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1050 <convert_main@plt>
jmp    1357 <main+0x1d7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd00(%rip),%rdi
lea    0x2d27(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    135c <main+0x1dc>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
cmp    $0x2,%edi
je     11af <main+0x1f>
cmp    $0x1,%ebp
jne    11e1 <main+0x51>
jmp    12e9 <main+0x159>
mov    0x8(%r14),%rdi
lea    0xe46(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12e9 <main+0x159>
mov    0x8(%r14),%rdi
lea    0xe2f(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12e9 <main+0x159>
mov    0x8(%r14),%rdi
lea    0xe1b(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1255 <main+0xc5>
lea    0x8(%r14),%rbx
mov    (%rbx),%rdi
lea    0xe05(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1255 <main+0xc5>
mov    (%rbx),%rdi
lea    0xdea(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1274 <main+0xe4>
mov    (%rbx),%rdi
lea    0xe1a(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12d8 <main+0x148>
add    $0xffffffff,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <convert_main@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1080 <version@plt>
lea    0xdae(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x10(%r14),%rcx
lea    0xda3(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <snprintf@plt>
lea    0xd94(%rip),%rdi
mov    %rdi,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   10a0 <execlp@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd76(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd99(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    (%rbx),%rsi
lea    0xd6c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x2d80(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@main.help = internal global [263 x i8] c"usage: hawk [--version|--help] <command> [<args>]\0A\0AThe most commonly used hawk commands are:\0A convert Convert an image from a format to another\0A phase Phase a diffraction pattern\0A\0ASee 'hawk help <command>' for more information on a specific command.\0A\00"
@.str = [7 x i8] c"--help\00"
@.str.1 = [5 x i8] c"help\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [10 x i8] c"--version\00"
@.str.4 = [8 x i8] c"version\00"
@.str.5 = [17 x i8] c"hawk version %s\0A\00"
@.str.6 = [8 x i8] c"hawk-%s\00"
@.str.7 = [4 x i8] c"man\00"
@.str.8 = [24 x i8] c"failed to exec man: %s\0A\00"
@errno = global i32 0
@.str.9 = [23 x i8] c"Could not start \22man\22\0A\00"
@.str.10 = [8 x i8] c"convert\00"
@.str.11 = [20 x i8] c"Unknown option: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %24, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %12
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18, %12, %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([263 x i8], [263 x i8]* @main.help, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %18, %9
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %27
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %33, %27
%40 = call i8* (...) @version()
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %33
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %62
49: ; preds = %43
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @snprintf(i8* %50, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %53)
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%56 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %55, i8* null)
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %43
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %62
%69 = load i32, i32* %4
%70 = sub nsw i32 %69, 1
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = call i32 @convert_main(i32 %70, i8** %72)
br label %81
74: ; preds = %62
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 1
%77 = load i8*, i8** %76
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i8* %77)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([263 x i8], [263 x i8]* @main.help, i64 0, i64 0))
%80 = call i32 @exit(i32 0)
unreachable
81: ; preds = %68
br label %82
82: ; preds = %81
ret i32 0
}

LLVM IR (-O2):
@main.help = internal global [263 x i8] c"usage: hawk [--version|--help] <command> [<args>]\0A\0AThe most commonly used hawk commands are:\0A convert Convert an image from a format to another\0A phase Phase a diffraction pattern\0A\0ASee 'hawk help <command>' for more information on a specific command.\0A\00"
@.str = [7 x i8] c"--help\00"
@.str.1 = [5 x i8] c"help\00"
@.str.3 = [10 x i8] c"--version\00"
@.str.4 = [8 x i8] c"version\00"
@.str.5 = [17 x i8] c"hawk version %s\0A\00"
@.str.6 = [8 x i8] c"hawk-%s\00"
@.str.7 = [4 x i8] c"man\00"
@.str.8 = [24 x i8] c"failed to exec man: %s\0A\00"
@errno = global i32 0
@.str.10 = [8 x i8] c"convert\00"
@.str.11 = [20 x i8] c"Unknown option: %s\0A\00"
@str = [22 x i8] c"Could not start \22man\22\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
switch i32 %0, label %16 [
i32 1, label %13
i32 2, label %4
]
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2, %9, %4
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([263 x i8], [263 x i8]* @main.help, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %2, %9
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = load i8*, i8** %17
%23 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21, %16
%26 = tail call i8* (...) @version()
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %26)
%28 = tail call i32 @exit(i32 0)
unreachable
29: ; preds = %21
%30 = load i8*, i8** %17
%31 = tail call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @snprintf(i8* %34, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %36)
%38 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %34, i8* null)
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %40)
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %29
%45 = load i8*, i8** %17
%46 = tail call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = add nsw i32 %0, -1
%50 = tail call i32 @convert_main(i32 %49, i8** %17)
ret i32 0
51: ; preds = %44
%52 = load i8*, i8** %17
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i8* %52)
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([263 x i8], [263 x i8]* @main.help, i64 0, i64 0))
%55 = tail call i32 @exit(i32 0)
unreachable
}