#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, char const *);
int /*<<< orphan*/ basename(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, scalar_t__,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, scalar_t__ *, scalar_t__ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *strstr(char *, char *);
char *strtok_r(char *, char *, char **);
char *vmmap();
void dump_aot(const char *match, const char *out) {
  fprintf(stderr, "[+] Dumping AOT (%s -> %s)\n", match, out);
  char *match_aot = NULL;
  asprintf(&match_aot, "%s.aot", match);
  char *map = vmmap();
  char *lasts = NULL;
  char *line = strtok_r(map, "\n", &map);
  FILE *f = fopen(out, "w");
  while (line) {
    if (strstr(line, ".aot")) {
      uint64_t start, end;
      sscanf(line, "%*s %*s %llx-%llx", &start, &end);
      char *name = strstr(line, ".aot");
      while (*name != ' ' && *name != '/') {
        name--;
      }
      name++;
      if (strcmp(basename(name), match_aot) == 0) {
        printf("%s\n", line);
        fwrite((uint8_t *)start, 1, end - start, f);
      }
    }
    line = strtok_r(map, "\n", &map);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<dump_aot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe18(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   10a0 <asprintf@plt>
mov    $0x0,%al
call   10c0 <vmmap@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdf3(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1355 <dump_aot+0x195>
mov    -0x30(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   10e0 <strstr@plt>
cmp    $0x0,%rax
je     1338 <dump_aot+0x178>
mov    -0x30(%rbp),%rdi
lea    0xdad(%rip),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1090 <sscanf@plt>
mov    -0x30(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   10e0 <strstr@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x51(%rbp)
je     12be <dump_aot+0xfe>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    12ce <dump_aot+0x10e>
jmp    12df <dump_aot+0x11f>
mov    -0x50(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x50(%rbp)
jmp    1299 <dump_aot+0xd9>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   1080 <basename@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1333 <dump_aot+0x173>
mov    -0x30(%rbp),%rsi
lea    0xd23(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
sub    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
jmp    1338 <dump_aot+0x178>
mov    -0x20(%rbp),%rdi
lea    0xcd7(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
jmp    1248 <dump_aot+0x88>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_aot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1070 <fprintf@plt>
movq   $0x0,0x10(%rsp)
lea    0xe1d(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rbp,%rdx
call   10a0 <asprintf@plt>
xor    %eax,%eax
call   10c0 <vmmap@plt>
mov    %rax,(%rsp)
lea    0xdfc(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1050 <strtok_r@plt>
mov    %rax,%r13
lea    0xdf0(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %r13,%r13
je     1330 <dump_aot+0x170>
lea    0xdce(%rip),%rbx
lea    0xdc3(%rip),%r15
mov    %rsp,%r12
lea    0x20(%rsp),%rbp
lea    0x18(%rsp),%r14
jmp    12a4 <dump_aot+0xe4>
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1080 <basename@plt>
mov    0x10(%rsp),%rsi
mov    %eax,%edi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1300 <dump_aot+0x140>
mov    (%rsp),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%r13
test   %rax,%rax
je     1330 <dump_aot+0x170>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10e0 <strstr@plt>
test   %rax,%rax
je     1289 <dump_aot+0xc9>
mov    %r13,%rdi
lea    0xd67(%rip),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1090 <sscanf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10e0 <strstr@plt>
add    $0x1,%rax
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rax),%ecx
cmp    $0x20,%cl
je     1270 <dump_aot+0xb0>
cmp    $0x2f,%cl
je     1270 <dump_aot+0xb0>
add    $0xffffffffffffffff,%rax
jmp    12e0 <dump_aot+0x120>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xd30(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
mov    0x20(%rsp),%rdi
mov    0x18(%rsp),%rdx
sub    %rdi,%rdx
mov    $0x1,%esi
mov    0x8(%rsp),%rcx
call   10d0 <fwrite@plt>
jmp    1289 <dump_aot+0xc9>
mov    0x8(%rsp),%rdi
call   1030 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"[+] Dumping AOT (%s -> %s)\0A\00"
@.str.1 = [7 x i8] c"%s.aot\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [5 x i8] c".aot\00"
@.str.5 = [18 x i8] c"%*s %*s %llx-%llx\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define void @dump_aot(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = load i8*, i8** %4
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
store i8* null, i8** %5
%17 = load i8*, i8** %3
%18 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i8* (...) @vmmap()
store i8* %19, i8** %6
store i8* null, i8** %7
%20 = load i8*, i8** %6
%21 = call i8* @strtok_r(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %6)
store i8* %21, i8** %8
%22 = load i8*, i8** %4
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %23, i32** %9
br label %24
24: ; preds = %70, %2
%25 = load i8*, i8** %8
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %73
27: ; preds = %24
%28 = load i8*, i8** %8
%29 = call i8* @strstr(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %70
31: ; preds = %27
%32 = load i8*, i8** %8
%33 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64* %10, i64* %11)
%34 = load i8*, i8** %8
%35 = call i8* @strstr(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i8* %35, i8** %12
br label %36
36: ; preds = %48, %31
%37 = load i8*, i8** %12
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 32
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i8*, i8** %12
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 47
br label %46
46: ; preds = %41, %36
%47 = phi i1 [ false, %36 ], [ %45, %41 ]
br i1 %47, label %48, label %51
48: ; preds = %46
%49 = load i8*, i8** %12
%50 = getelementptr inbounds i8, i8* %49, i32 -1
store i8* %50, i8** %12
br label %36
51: ; preds = %46
%52 = load i8*, i8** %12
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %12
%54 = load i8*, i8** %12
%55 = call i32 @basename(i8* %54)
%56 = load i8*, i8** %5
%57 = call i64 @strcmp(i32 %55, i8* %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %69
59: ; preds = %51
%60 = load i8*, i8** %8
%61 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %60)
%62 = load i64, i64* %10
%63 = inttoptr i64 %62 to i32*
%64 = load i64, i64* %11
%65 = load i64, i64* %10
%66 = sub nsw i64 %64, %65
%67 = load i32*, i32** %9
%68 = call i32 @fwrite(i32* %63, i32 1, i64 %66, i32* %67)
br label %69
69: ; preds = %59, %51
br label %70
70: ; preds = %69, %27
%71 = load i8*, i8** %6
%72 = call i8* @strtok_r(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %6)
store i8* %72, i8** %8
br label %24
73: ; preds = %24
%74 = load i32*, i32** %9
%75 = call i32 @fclose(i32* %74)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"[+] Dumping AOT (%s -> %s)\0A\00"
@.str.1 = [7 x i8] c"%s.aot\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [5 x i8] c".aot\00"
@.str.5 = [18 x i8] c"%*s %*s %llx-%llx\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define void @dump_aot(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%10 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = bitcast i8** %4 to i8*
%12 = call i8* (...) @vmmap()
store i8* %12, i8** %4
%13 = call i8* @strtok_r(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %4)
%14 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i8* %13, null
br i1 %15, label %49, label %16
16: ; preds = %2
%17 = bitcast i64* %5 to i8*
%18 = bitcast i64* %6 to i8*
br label %19
19: ; preds = %16, %45
%20 = phi i8* [ %13, %16 ], [ %47, %45 ]
%21 = call i8* @strstr(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %45, label %23
23: ; preds = %19
%24 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64* %5, i64* %6)
%25 = call i8* @strstr(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %29, %23
%27 = phi i8* [ %25, %23 ], [ %30, %29 ]
%28 = load i8, i8* %27
switch i8 %28, label %29 [
i8 32, label %31
i8 47, label %31
]
29: ; preds = %26
%30 = getelementptr inbounds i8, i8* %27, i64 -1
br label %26
31: ; preds = %26, %26
%32 = getelementptr inbounds i8, i8* %27, i64 1
%33 = call i32 @basename(i8* %32)
%34 = load i8*, i8** %3
%35 = call i64 @strcmp(i32 %33, i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %31
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %20)
%39 = load i64, i64* %5
%40 = inttoptr i64 %39 to i32*
%41 = load i64, i64* %6
%42 = sub nsw i64 %41, %39
%43 = call i32 @fwrite(i32* %40, i32 1, i64 %42, i32* %14)
br label %44
44: ; preds = %37, %31
br label %45
45: ; preds = %44, %19
%46 = load i8*, i8** %4
%47 = call i8* @strtok_r(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %4)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %19
49: ; preds = %45, %2
%50 = call i32 @fclose(i32* %14)
ret void
}