int test() {
  printf("Testing architecture: %s (TODO)\n", "x86");
  system("/sbin/sysctl kernel.randomize_va_space");
  system("/sbin/sysctl vm.vdso_enabled");
  printf("Executable stack: %s (TODO)\n", "true");
  printf("W^X flag: %s (TODO)\n", "true");
  printf("Red pill: %d\n", swallow_redpill());
  printf("Generate cores: %s (TODO)\n", "true");
  return 0;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
lea    0xec5(%rip),%rdi
lea    0xedf(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1040 <system@plt>
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1040 <system@plt>
lea    0xefd(%rip),%rdi
lea    0xf13(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf0a(%rip),%rdi
lea    0xefe(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <swallow_redpill@plt>
mov    %eax,%esi
lea    0xf01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf01(%rip),%rdi
lea    0xed2(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbx
lea    0xec8(%rip),%rdi
lea    0xee2(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1040 <system@plt>
lea    0xef1(%rip),%rdi
xor    %eax,%eax
call   1040 <system@plt>
lea    0xf00(%rip),%rdi
lea    0xf16(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf0a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <swallow_redpill@plt>
lea    0xf07(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf05(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Testing architecture: %s (TODO)\0A\00"
@.str.1 = [4 x i8] c"x86\00"
@.str.2 = [39 x i8] c"/sbin/sysctl kernel.randomize_va_space\00"
@.str.3 = [29 x i8] c"/sbin/sysctl vm.vdso_enabled\00"
@.str.4 = [29 x i8] c"Executable stack: %s (TODO)\0A\00"
@.str.5 = [5 x i8] c"true\00"
@.str.6 = [21 x i8] c"W^X flag: %s (TODO)\0A\00"
@.str.7 = [14 x i8] c"Red pill: %d\0A\00"
@.str.8 = [27 x i8] c"Generate cores: %s (TODO)\0A\00"
define i32 @test() {
%1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%2 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%3 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%6 = call i32 (...) @swallow_redpill()
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Testing architecture: %s (TODO)\0A\00"
@.str.1 = [4 x i8] c"x86\00"
@.str.2 = [39 x i8] c"/sbin/sysctl kernel.randomize_va_space\00"
@.str.3 = [29 x i8] c"/sbin/sysctl vm.vdso_enabled\00"
@.str.4 = [29 x i8] c"Executable stack: %s (TODO)\0A\00"
@.str.5 = [5 x i8] c"true\00"
@.str.6 = [21 x i8] c"W^X flag: %s (TODO)\0A\00"
@.str.7 = [14 x i8] c"Red pill: %d\0A\00"
@.str.8 = [27 x i8] c"Generate cores: %s (TODO)\0A\00"
define i32 @test() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%6 = tail call i32 (...) @swallow_redpill()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}