#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 WCONTINUED;
int WUNTRACED;
int create_user();
int /*<<< orphan*/ delete_user(int);
int execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ setgid(int);
int /*<<< orphan*/ setuid(int);
int /*<<< orphan*/ setup_io();
int /*<<< orphan*/ setup_sandbox(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ waitpid(int, int *, int);
int execute_pyfile() {
  system("rm output.txt input >/dev/null 2>&1");
  int tmp_uid = create_user();
  int cpid = fork();
  if (cpid == -1) {
    fprintf(stderr, "fork failed\n");
  }
  if (cpid > 0) {
    int ret;
    waitpid(cpid, &ret, WUNTRACED | WCONTINUED);
    delete_user(tmp_uid);
  }
  if (cpid == 0) {
    setup_io();
    setup_sandbox(0);
    setgid(tmp_uid);
    setuid(tmp_uid);
    char *exec_argv[2];
    exec_argv[0] = "python2";
    exec_argv[1] = "input.py";
    exec_argv[2] = NULL;
    int ret = execvp("python2", exec_argv);
    exit(ret);
  }
}


x86 assembly (clang, -O0):
<execute_pyfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe31(%rip),%rdi
call   1040 <system@plt>
mov    $0x0,%al
call   1060 <create_user@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1207 <execute_pyfile+0x47>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    1237 <execute_pyfile+0x77>
mov    -0xc(%rbp),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
mov    0x2da4(%rip),%rax
or     (%rax),%edx
lea    -0x10(%rbp),%rsi
call   1080 <waitpid@plt>
mov    -0x8(%rbp),%edi
call   1030 <delete_user@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1298 <execute_pyfile+0xd8>
mov    $0x0,%al
call   10e0 <setup_io@plt>
xor    %edi,%edi
call   10a0 <setup_sandbox@plt>
mov    -0x8(%rbp),%edi
call   1070 <setgid@plt>
mov    -0x8(%rbp),%edi
call   10c0 <setuid@plt>
lea    0xdcb(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xdc8(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xda9(%rip),%rdi
call   1090 <execvp@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_pyfile>:
push   %rbx
sub    $0x10,%rsp
lea    0xe34(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
call   1060 <create_user@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10d0 <fork@plt>
cmp    $0xffffffff,%eax
je     120f <execute_pyfile+0x4f>
test   %eax,%eax
jle    1226 <execute_pyfile+0x66>
mov    0x2def(%rip),%rcx
mov    0x2dd0(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %rsp,%rsi
mov    %eax,%edi
call   1080 <waitpid@plt>
mov    %ebx,%edi
call   1030 <delete_user@plt>
jmp    1228 <execute_pyfile+0x68>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1228 <execute_pyfile+0x68>
je     122e <execute_pyfile+0x6e>
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   10e0 <setup_io@plt>
xor    %edi,%edi
call   10a0 <setup_sandbox@plt>
mov    %ebx,%edi
call   1070 <setgid@plt>
mov    %ebx,%edi
call   10c0 <setuid@plt>
lea    0xde0(%rip),%rdi
mov    %rdi,(%rsp)
lea    0xddd(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rsi
call   1090 <execvp@plt>
mov    %eax,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"rm output.txt input >/dev/null 2>&1\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"fork failed\0A\00"
@WUNTRACED = global i32 0
@WCONTINUED = global i32 0
@.str.2 = [8 x i8] c"python2\00"
@.str.3 = [9 x i8] c"input.py\00"
define i32 @execute_pyfile() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i8*]
%6 = alloca i32
%7 = call i32 @system(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @create_user()
store i32 %8, i32* %2
%9 = call i32 (...) @fork()
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %0
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %3
%20 = load i32, i32* @WUNTRACED
%21 = load i32, i32* @WCONTINUED
%22 = or i32 %20, %21
%23 = call i32 @waitpid(i32 %19, i32* %4, i32 %22)
%24 = load i32, i32* %2
%25 = call i32 @delete_user(i32 %24)
br label %26
26: ; preds = %18, %15
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %43
29: ; preds = %26
%30 = call i32 (...) @setup_io()
%31 = call i32 @setup_sandbox(i32 0)
%32 = load i32, i32* %2
%33 = call i32 @setgid(i32 %32)
%34 = load i32, i32* %2
%35 = call i32 @setuid(i32 %34)
%36 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %36
%37 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %37
%38 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 2
store i8* null, i8** %38
%39 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%40 = call i32 @execvp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %39)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %26
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [36 x i8] c"rm output.txt input >/dev/null 2>&1\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"fork failed\0A\00"
@WUNTRACED = global i32 0
@WCONTINUED = global i32 0
@.str.2 = [8 x i8] c"python2\00"
@.str.3 = [9 x i8] c"input.py\00"
define i32 @execute_pyfile() {
%1 = alloca i32
%2 = alloca [2 x i8*]
%3 = tail call i32 @system(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (...) @create_user()
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %32
10: ; preds = %0
%11 = icmp sgt i32 %5, 0
br i1 %11, label %12, label %19
12: ; preds = %10
%13 = bitcast i32* %1 to i8*
%14 = load i32, i32* @WUNTRACED
%15 = load i32, i32* @WCONTINUED
%16 = or i32 %15, %14
%17 = call i32 @waitpid(i32 %5, i32* %1, i32 %16)
%18 = call i32 @delete_user(i32 %4)
br label %32
19: ; preds = %10
%20 = icmp eq i32 %5, 0
br i1 %20, label %21, label %32
21: ; preds = %19
%22 = tail call i32 (...) @setup_io()
%23 = tail call i32 @setup_sandbox(i32 0)
%24 = tail call i32 @setgid(i32 %4)
%25 = tail call i32 @setuid(i32 %4)
%26 = bitcast [2 x i8*]* %2 to i8*
%27 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %27
%28 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %28
%29 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 2
store i8* null, i8** %29
%30 = call i32 @execvp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %27)
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %12, %7, %19
ret i32 undef
}