#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ execlp(char *, char *, char *, char const *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void disas(const char *path) {
  fprintf(stderr, "[+] Disassembling %s\n", path);
  pid_t pid = fork();
  if (pid) {
    int status = 0;
    waitpid(pid, &status, 0);
    if (status != 0) {
      fprintf(stderr, "failed to disas: %d\n", status);
    }
  } else {
    execlp("otool", "otool", "-tv", path, NULL);
    fprintf(stderr, "failed to exec disassembler\n");
    exit(2);
  }
}


x86 assembly (clang, -O0):
<disas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11cc <disas+0x7c>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmpl   $0x0,-0x14(%rbp)
je     11c7 <disas+0x77>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    120c <disas+0xbc>
mov    -0x8(%rbp),%rcx
lea    0xe54(%rip),%rsi
lea    0xe53(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1060 <execlp@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disas>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e82(%rip),%r14
mov    (%r14),%edi
lea    0xe98(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11b6 <disas+0x66>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0x4(%rsp),%edx
test   %edx,%edx
je     11ae <disas+0x5e>
mov    (%r14),%edi
lea    0xe6f(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6e(%rip),%rdi
lea    0xe6d(%rip),%rdx
mov    %rdi,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1060 <execlp@plt>
mov    (%r14),%edi
lea    0xe59(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x2,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"[+] Disassembling %s\0A\00"
@.str.1 = [21 x i8] c"failed to disas: %d\0A\00"
@.str.2 = [6 x i8] c"otool\00"
@.str.3 = [4 x i8] c"-tv\00"
@.str.4 = [29 x i8] c"failed to exec disassembler\0A\00"
define void @disas(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %2
%7 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i64 (...) @fork()
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %1
store i32 0, i32* %4
%12 = load i64, i64* %3
%13 = call i32 @waitpid(i64 %12, i32* %4, i32 0)
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i32, i32* %4
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %11
br label %27
21: ; preds = %1
%22 = load i8*, i8** %2
%23 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %22, i32* null)
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 2)
unreachable
27: ; preds = %20
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"[+] Disassembling %s\0A\00"
@.str.1 = [21 x i8] c"failed to disas: %d\0A\00"
@.str.2 = [6 x i8] c"otool\00"
@.str.3 = [4 x i8] c"-tv\00"
@.str.4 = [29 x i8] c"failed to exec disassembler\0A\00"
define void @disas(i8* %0) {
%2 = alloca i32
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%9 = call i32 @waitpid(i64 %5, i32* %2, i32 0)
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %15
15: ; preds = %12, %7
ret void
16: ; preds = %1
%17 = tail call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32* null)
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i32 @exit(i32 2)
unreachable
}