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

/* Variables and functions */
int MAP_ANONYMOUS;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ check_cr3s(void *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ check_kaslr(void *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ check_root(void *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ check_sip(void *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ get_system_infos(void *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ get_xnu_core_addresses(void *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ get_xnu_kext_addresses(void *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ kAFL_hypercall(int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(void *, int, int);
void *mmap(void *, int, int, int, int, int /*<<< orphan*/);
int main(int argc, char **argv) {
  uint32_t pos = 0;
  void *info_buffer = mmap((void *)NULL, (128 << 10), PROT_READ | PROT_WRITE,
                           MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  memset(info_buffer, 0xff, (128 << 10));
  get_system_infos(info_buffer, &pos, (128 << 10));
  get_xnu_core_addresses(info_buffer, &pos, (128 << 10));
  get_xnu_kext_addresses(info_buffer, &pos, (128 << 10));
  check_sip(info_buffer, &pos, (128 << 10));
  check_cr3s(info_buffer, &pos, (128 << 10));
  check_kaslr(info_buffer, &pos, (128 << 10));
  check_root(info_buffer, &pos, (128 << 10));
  kAFL_hypercall(11, (uint64_t)info_buffer);
  return 0;
}


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)
movl   $0x0,-0x14(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
mov    0x2e03(%rip),%rax
or     (%rax),%edx
mov    0x2df2(%rip),%rax
mov    (%rax),%ecx
mov    0x2e01(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x20000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xff,%esi
mov    $0x20000,%edx
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x20000,%edx
call   10c0 <get_system_infos@plt>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x20000,%edx
call   1080 <get_xnu_core_addresses@plt>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x20000,%edx
call   1030 <get_xnu_kext_addresses@plt>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x20000,%edx
call   10a0 <check_sip@plt>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x20000,%edx
call   1060 <check_cr3s@plt>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x20000,%edx
call   1090 <check_kaslr@plt>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x20000,%edx
call   1070 <check_root@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
mov    $0xb,%edi
call   10b0 <kAFL_hypercall@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
mov    0x2e45(%rip),%rax
mov    0x2e16(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e03(%rip),%rax
mov    0x2e14(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x20000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xff,%esi
mov    $0x20000,%edx
call   1050 <memset@plt>
lea    0x4(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x20000,%edx
call   10c0 <get_system_infos@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x20000,%edx
call   1080 <get_xnu_core_addresses@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x20000,%edx
call   1030 <get_xnu_kext_addresses@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x20000,%edx
call   10a0 <check_sip@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x20000,%edx
call   1060 <check_cr3s@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x20000,%edx
call   1090 <check_kaslr@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x20000,%edx
call   1070 <check_root@plt>
mov    $0xb,%edi
mov    %ebx,%esi
call   10b0 <kAFL_hypercall@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @PROT_WRITE
%10 = or i32 %8, %9
%11 = load i32, i32* @MAP_PRIVATE
%12 = load i32, i32* @MAP_ANONYMOUS
%13 = or i32 %11, %12
%14 = call i8* @mmap(i8* null, i32 131072, i32 %10, i32 %13, i32 -1, i32 0)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = call i32 @memset(i8* %15, i32 255, i32 131072)
%17 = load i8*, i8** %7
%18 = call i32 @get_system_infos(i8* %17, i32* %6, i32 131072)
%19 = load i8*, i8** %7
%20 = call i32 @get_xnu_core_addresses(i8* %19, i32* %6, i32 131072)
%21 = load i8*, i8** %7
%22 = call i32 @get_xnu_kext_addresses(i8* %21, i32* %6, i32 131072)
%23 = load i8*, i8** %7
%24 = call i32 @check_sip(i8* %23, i32* %6, i32 131072)
%25 = load i8*, i8** %7
%26 = call i32 @check_cr3s(i8* %25, i32* %6, i32 131072)
%27 = load i8*, i8** %7
%28 = call i32 @check_kaslr(i8* %27, i32* %6, i32 131072)
%29 = load i8*, i8** %7
%30 = call i32 @check_root(i8* %29, i32* %6, i32 131072)
%31 = load i8*, i8** %7
%32 = ptrtoint i8* %31 to i32
%33 = call i32 @kAFL_hypercall(i32 11, i32 %32)
ret i32 0
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %6, %5
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = or i32 %9, %8
%11 = tail call i8* @mmap(i8* null, i32 131072, i32 %7, i32 %10, i32 -1, i32 0)
%12 = tail call i32 @memset(i8* %11, i32 255, i32 131072)
%13 = call i32 @get_system_infos(i8* %11, i32* %3, i32 131072)
%14 = call i32 @get_xnu_core_addresses(i8* %11, i32* %3, i32 131072)
%15 = call i32 @get_xnu_kext_addresses(i8* %11, i32* %3, i32 131072)
%16 = call i32 @check_sip(i8* %11, i32* %3, i32 131072)
%17 = call i32 @check_cr3s(i8* %11, i32* %3, i32 131072)
%18 = call i32 @check_kaslr(i8* %11, i32* %3, i32 131072)
%19 = call i32 @check_root(i8* %11, i32* %3, i32 131072)
%20 = ptrtoint i8* %11 to i64
%21 = trunc i64 %20 to i32
%22 = call i32 @kAFL_hypercall(i32 11, i32 %21)
ret i32 0
}