#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 RTLD_LOCAL;
int RTLD_NOW;
int /*<<< orphan*/ asprintf(char **, char *, char *);
int /*<<< orphan*/ basename(char *);
char *compile(char *);
int /*<<< orphan*/ disas(char *);
void *dlopen(char *, int);
int /*<<< orphan*/ dump_aot(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ loadlib(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strdup(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  if (argc < 2) {
    usage();
  }
  if (strcmp(argv[1], "-l") == 0) {
    if (argc != 4) {
      usage();
    }
    loadlib(argv[2]);
    dump_aot(strdup(basename(argv[2])), argv[3]);
  } else if (strcmp(argv[1], "-c") == 0) {
    if (argc != 4) {
      usage();
    }
    char *path = compile(argv[2]);
    void *addr = dlopen(path, RTLD_NOW | RTLD_LOCAL);
    unlink(path);
    if (addr == NULL) {
      fprintf(stderr, "failed to load: %s\n", path);
      exit(2);
    }
    dump_aot(strdup(basename(path)), argv[3]);
  } else if (strcmp(argv[1], "-d") == 0) {
    if (argc != 3) {
      usage();
    }
    char *path = compile(argv[2]);
    loadlib(path);
    char *path_aot = NULL;
    asprintf(&path_aot, "%s.aot", path);
    dump_aot(path, path_aot);
    disas(path);
    disas(path_aot);
    unlink(path);
    unlink(path_aot);
  } else {
    usage();
  }
  return 0;
}


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   $0x2,-0x8(%rbp)
jge    11f7 <main+0x27>
mov    $0x0,%al
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdfa(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    125c <main+0x8c>
cmpl   $0x4,-0x8(%rbp)
je     1226 <main+0x56>
mov    $0x0,%al
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <loadlib@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <basename@plt>
mov    %eax,%edi
call   10f0 <strdup@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1070 <dump_aot@plt>
jmp    13c3 <main+0x1f3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd98(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1317 <main+0x147>
cmpl   $0x4,-0x8(%rbp)
je     128b <main+0xbb>
mov    $0x0,%al
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <compile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
mov    0x2d18(%rip),%rax
or     (%rax),%esi
call   1090 <dlopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12f2 <main+0x122>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd23(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <basename@plt>
mov    %eax,%edi
call   10f0 <strdup@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1070 <dump_aot@plt>
jmp    13be <main+0x1ee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcf4(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    13b2 <main+0x1e2>
cmpl   $0x3,-0x8(%rbp)
je     1346 <main+0x176>
mov    $0x0,%al
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <compile@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <loadlib@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    0xca6(%rip),%rsi
call   10c0 <asprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <dump_aot@plt>
mov    -0x28(%rbp),%rdi
call   1050 <disas@plt>
mov    -0x30(%rbp),%rdi
call   1050 <disas@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
jmp    13b9 <main+0x1e9>
mov    $0x0,%al
call   10d0 <usage@plt>
jmp    13be <main+0x1ee>
jmp    13c3 <main+0x1f3>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x1,%edi
jg     11e9 <main+0x19>
xor    %eax,%eax
call   10d0 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0xe0c(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1235 <main+0x65>
mov    0x8(%rbx),%rdi
lea    0xdfa(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1250 <main+0x80>
mov    0x8(%rbx),%rdi
lea    0xdfc(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12bc <main+0xec>
xor    %eax,%eax
call   10d0 <usage@plt>
jmp    12b1 <main+0xe1>
cmp    $0x4,%ebp
je     1241 <main+0x71>
xor    %eax,%eax
call   10d0 <usage@plt>
mov    0x10(%rbx),%rdi
call   1040 <loadlib@plt>
mov    0x10(%rbx),%rdi
jmp    1299 <main+0xc9>
cmp    $0x4,%ebp
je     125c <main+0x8c>
xor    %eax,%eax
call   10d0 <usage@plt>
mov    0x10(%rbx),%rdi
call   1060 <compile@plt>
mov    %rax,%rbp
mov    0x2d79(%rip),%rax
mov    0x2d52(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbp,%rdi
call   1090 <dlopen@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1030 <unlink@plt>
test   %r14,%r14
je     132c <main+0x15c>
mov    %rbp,%rdi
call   10b0 <basename@plt>
mov    %eax,%edi
call   10f0 <strdup@plt>
mov    0x18(%rbx),%rsi
mov    %rax,%rdi
call   1070 <dump_aot@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x3,%ebp
je     12c8 <main+0xf8>
xor    %eax,%eax
call   10d0 <usage@plt>
mov    0x10(%rbx),%rdi
call   1060 <compile@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <loadlib@plt>
movq   $0x0,0x8(%rsp)
lea    0xd31(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
call   10c0 <asprintf@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <dump_aot@plt>
mov    %rbx,%rdi
call   1050 <disas@plt>
mov    0x8(%rsp),%rdi
call   1050 <disas@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x8(%rsp),%rdi
call   1030 <unlink@plt>
jmp    12b1 <main+0xe1>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
mov    %rbp,%rdx
call   10a0 <fprintf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-l\00"
@.str.1 = [3 x i8] c"-c\00"
@RTLD_NOW = global i32 0
@RTLD_LOCAL = global i32 0
@stderr = global i32 0
@.str.2 = [20 x i8] c"failed to load: %s\0A\00"
@.str.3 = [3 x i8] c"-d\00"
@.str.4 = [7 x i8] c"%s.aot\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 i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @usage()
br label %14
14: ; preds = %12, %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %39
20: ; preds = %14
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 4
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (...) @usage()
br label %25
25: ; preds = %23, %20
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @loadlib(i8* %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @basename(i8* %32)
%34 = call i8* @strdup(i32 %33)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = call i32 @dump_aot(i8* %34, i8* %37)
br label %112
39: ; preds = %14
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %77
45: ; preds = %39
%46 = load i32, i32* %4
%47 = icmp ne i32 %46, 4
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 (...) @usage()
br label %50
50: ; preds = %48, %45
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i8* @compile(i8* %53)
store i8* %54, i8** %6
%55 = load i8*, i8** %6
%56 = load i32, i32* @RTLD_NOW
%57 = load i32, i32* @RTLD_LOCAL
%58 = or i32 %56, %57
%59 = call i8* @dlopen(i8* %55, i32 %58)
store i8* %59, i8** %7
%60 = load i8*, i8** %6
%61 = call i32 @unlink(i8* %60)
%62 = load i8*, i8** %7
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %69
64: ; preds = %50
%65 = load i32, i32* @stderr
%66 = load i8*, i8** %6
%67 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %66)
%68 = call i32 @exit(i32 2)
unreachable
69: ; preds = %50
%70 = load i8*, i8** %6
%71 = call i32 @basename(i8* %70)
%72 = call i8* @strdup(i32 %71)
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 3
%75 = load i8*, i8** %74
%76 = call i32 @dump_aot(i8* %72, i8* %75)
br label %111
77: ; preds = %39
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = call i64 @strcmp(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %108
83: ; preds = %77
%84 = load i32, i32* %4
%85 = icmp ne i32 %84, 3
br i1 %85, label %86, label %88
86: ; preds = %83
%87 = call i32 (...) @usage()
br label %88
88: ; preds = %86, %83
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 2
%91 = load i8*, i8** %90
%92 = call i8* @compile(i8* %91)
store i8* %92, i8** %8
%93 = load i8*, i8** %8
%94 = call i32 @loadlib(i8* %93)
store i8* null, i8** %9
%95 = load i8*, i8** %8
%96 = call i32 @asprintf(i8** %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %95)
%97 = load i8*, i8** %8
%98 = load i8*, i8** %9
%99 = call i32 @dump_aot(i8* %97, i8* %98)
%100 = load i8*, i8** %8
%101 = call i32 @disas(i8* %100)
%102 = load i8*, i8** %9
%103 = call i32 @disas(i8* %102)
%104 = load i8*, i8** %8
%105 = call i32 @unlink(i8* %104)
%106 = load i8*, i8** %9
%107 = call i32 @unlink(i8* %106)
br label %110
108: ; preds = %77
%109 = call i32 (...) @usage()
br label %110
110: ; preds = %108, %88
br label %111
111: ; preds = %110, %69
br label %112
112: ; preds = %111, %25
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-l\00"
@.str.1 = [3 x i8] c"-c\00"
@RTLD_NOW = global i32 0
@RTLD_LOCAL = global i32 0
@stderr = global i32 0
@.str.2 = [20 x i8] c"failed to load: %s\0A\00"
@.str.3 = [3 x i8] c"-d\00"
@.str.4 = [7 x i8] c"%s.aot\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (...) @usage()
br label %7
7: ; preds = %5, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %7
%13 = icmp eq i32 %0, 4
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 (...) @usage()
br label %16
16: ; preds = %14, %12
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @loadlib(i8* %18)
%20 = load i8*, i8** %17
%21 = tail call i32 @basename(i8* %20)
%22 = tail call i8* @strdup(i32 %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @dump_aot(i8* %22, i8* %24)
br label %79
26: ; preds = %7
%27 = load i8*, i8** %8
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %54
30: ; preds = %26
%31 = icmp eq i32 %0, 4
br i1 %31, label %34, label %32
32: ; preds = %30
%33 = tail call i32 (...) @usage()
br label %34
34: ; preds = %32, %30
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = tail call i8* @compile(i8* %36)
%38 = load i32, i32* @RTLD_NOW
%39 = load i32, i32* @RTLD_LOCAL
%40 = or i32 %39, %38
%41 = tail call i8* @dlopen(i8* %37, i32 %40)
%42 = tail call i32 @unlink(i8* %37)
%43 = icmp eq i8* %41, null
br i1 %43, label %44, label %48
44: ; preds = %34
%45 = load i32, i32* @stderr
%46 = tail call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%47 = tail call i32 @exit(i32 2)
unreachable
48: ; preds = %34
%49 = tail call i32 @basename(i8* %37)
%50 = tail call i8* @strdup(i32 %49)
%51 = getelementptr inbounds i8*, i8** %1, i64 3
%52 = load i8*, i8** %51
%53 = tail call i32 @dump_aot(i8* %50, i8* %52)
br label %79
54: ; preds = %26
%55 = load i8*, i8** %8
%56 = tail call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %77
58: ; preds = %54
%59 = icmp eq i32 %0, 3
br i1 %59, label %62, label %60
60: ; preds = %58
%61 = tail call i32 (...) @usage()
br label %62
62: ; preds = %60, %58
%63 = getelementptr inbounds i8*, i8** %1, i64 2
%64 = load i8*, i8** %63
%65 = tail call i8* @compile(i8* %64)
%66 = tail call i32 @loadlib(i8* %65)
%67 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%68 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %65)
%69 = load i8*, i8** %3
%70 = call i32 @dump_aot(i8* %65, i8* %69)
%71 = call i32 @disas(i8* %65)
%72 = load i8*, i8** %3
%73 = call i32 @disas(i8* %72)
%74 = call i32 @unlink(i8* %65)
%75 = load i8*, i8** %3
%76 = call i32 @unlink(i8* %75)
br label %79
77: ; preds = %54
%78 = tail call i32 (...) @usage()
br label %79
79: ; preds = %48, %77, %62, %16
ret i32 0
}