#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*/ _IONBF;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ test_anon_wx_mmap();
int /*<<< orphan*/ test_anon_wx_mprotect();
int /*<<< orphan*/ test_mmap_wx_dir(char *);
int main(void) {
  setvbuf(stdout, NULL, _IONBF, 0);
  assert(sizeof(int (*)(void)) == sizeof(void *));
  test_anon_wx_mmap();
  test_anon_wx_mprotect();
  printf("\n");
  printf("[ ] Testing /tmp\n");
  test_mmap_wx_dir("/tmp");
  printf("\n");
  printf("[ ] Testing current directory\n");
  test_mmap_wx_dir(".");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
mov    $0x1,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1080 <test_anon_wx_mmap@plt>
mov    $0x0,%al
call   1070 <test_anon_wx_mprotect@plt>
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
lea    0xe4f(%rip),%rdi
call   1050 <test_mmap_wx_dir@plt>
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
lea    0xe4f(%rip),%rdi
call   1050 <test_mmap_wx_dir@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1070 <setvbuf@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
xor    %eax,%eax
call   1090 <test_anon_wx_mmap@plt>
xor    %eax,%eax
call   1080 <test_anon_wx_mprotect@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe4d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4d(%rip),%rdi
call   1060 <test_mmap_wx_dir@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
lea    0xe1d(%rip),%rdi
call   1060 <test_mmap_wx_dir@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [18 x i8] c"[ ] Testing /tmp\0A\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.3 = [31 x i8] c"[ ] Testing current directory\0A\00"
@.str.4 = [2 x i8] c".\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @stdout
%3 = load i32, i32* @_IONBF
%4 = call i32 @setvbuf(i32 %2, i32* null, i32 %3, i32 0)
%5 = call i32 @assert(i32 1)
%6 = call i32 (...) @test_anon_wx_mmap()
%7 = call i32 (...) @test_anon_wx_mprotect()
%8 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @test_mmap_wx_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @test_mmap_wx_dir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str.2 = [5 x i8] c"/tmp\00"
@.str.4 = [2 x i8] c".\00"
@str = [17 x i8] c"[ ] Testing /tmp\00"
@str.5 = [30 x i8] c"[ ] Testing current directory\00"
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = load i32, i32* @_IONBF
%3 = tail call i32 @setvbuf(i32 %1, i32* null, i32 %2, i32 0)
%4 = tail call i32 @assert(i32 1)
%5 = tail call i32 (...) @test_anon_wx_mmap()
%6 = tail call i32 (...) @test_anon_wx_mprotect()
%7 = tail call i32 @putchar(i32 10)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @test_mmap_wx_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @putchar(i32 10)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
%12 = tail call i32 @test_mmap_wx_dir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}