#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 */
struct rlimit {
  int rlim_cur;
  int rlim_max;
};

/* Variables and functions */
int /*<<< orphan*/ CLONE_IO;
int /*<<< orphan*/ CLONE_NEWIPC;
int /*<<< orphan*/ CLONE_NEWNS;
int /*<<< orphan*/ PR_SET_PDEATHSIG;
int /*<<< orphan*/ RLIMIT_AS;
int /*<<< orphan*/ RLIMIT_CORE;
int /*<<< orphan*/ RLIMIT_FSIZE;
int /*<<< orphan*/ RLIMIT_STACK;
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ prctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ setpgrp();
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ unshare(int /*<<< orphan*/);
void sandbox_common() {
  prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  setpgrp();
  setsid();
  struct rlimit rlim;
  rlim.rlim_cur = rlim.rlim_max = 128 << 20;
  setrlimit(RLIMIT_AS, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 1 << 20;
  setrlimit(RLIMIT_FSIZE, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 1 << 20;
  setrlimit(RLIMIT_STACK, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 0;
  setrlimit(RLIMIT_CORE, &rlim);
  unshare(CLONE_NEWNS);
  unshare(CLONE_NEWIPC);
  unshare(CLONE_IO);
}


x86 assembly (clang, -O0):
<sandbox_common>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1050 <prctl@plt>
mov    $0x0,%al
call   1070 <setpgrp@plt>
mov    $0x0,%al
call   1040 <setsid@plt>
movl   $0x8000000,-0x4(%rbp)
movl   $0x8000000,-0x8(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <setrlimit@plt>
movl   $0x100000,-0x4(%rbp)
movl   $0x100000,-0x8(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <setrlimit@plt>
movl   $0x100000,-0x4(%rbp)
movl   $0x100000,-0x8(%rbp)
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <setrlimit@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <setrlimit@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1030 <unshare@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1030 <unshare@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   1030 <unshare@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sandbox_common>:
push   %r14
push   %rbx
push   %rax
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <prctl@plt>
xor    %eax,%eax
call   1070 <setpgrp@plt>
xor    %eax,%eax
call   1040 <setsid@plt>
movabs $0x800000008000000,%rax
mov    %rax,(%rsp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <setrlimit@plt>
movabs $0x10000000100000,%r14
mov    %r14,(%rsp)
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1060 <setrlimit@plt>
mov    %r14,(%rsp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1060 <setrlimit@plt>
movq   $0x0,(%rsp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1060 <setrlimit@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1030 <unshare@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1030 <unshare@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1030 <unshare@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@PR_SET_PDEATHSIG = global i32 0
@SIGKILL = global i32 0
@RLIMIT_AS = global i32 0
@RLIMIT_FSIZE = global i32 0
@RLIMIT_STACK = global i32 0
@RLIMIT_CORE = global i32 0
@CLONE_NEWNS = global i32 0
@CLONE_NEWIPC = global i32 0
@CLONE_IO = global i32 0
define void @sandbox_common() {
%1 = alloca %struct.rlimit
%2 = load i32, i32* @PR_SET_PDEATHSIG
%3 = load i32, i32* @SIGKILL
%4 = call i32 @prctl(i32 %2, i32 %3, i32 0, i32 0, i32 0)
%5 = call i32 (...) @setpgrp()
%6 = call i32 (...) @setsid()
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 134217728, i32* %7
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 134217728, i32* %8
%9 = load i32, i32* @RLIMIT_AS
%10 = call i32 @setrlimit(i32 %9, %struct.rlimit* %1)
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 1048576, i32* %11
%12 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 1048576, i32* %12
%13 = load i32, i32* @RLIMIT_FSIZE
%14 = call i32 @setrlimit(i32 %13, %struct.rlimit* %1)
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 1048576, i32* %15
%16 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 1048576, i32* %16
%17 = load i32, i32* @RLIMIT_STACK
%18 = call i32 @setrlimit(i32 %17, %struct.rlimit* %1)
%19 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 0, i32* %19
%20 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 0, i32* %20
%21 = load i32, i32* @RLIMIT_CORE
%22 = call i32 @setrlimit(i32 %21, %struct.rlimit* %1)
%23 = load i32, i32* @CLONE_NEWNS
%24 = call i32 @unshare(i32 %23)
%25 = load i32, i32* @CLONE_NEWIPC
%26 = call i32 @unshare(i32 %25)
%27 = load i32, i32* @CLONE_IO
%28 = call i32 @unshare(i32 %27)
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@PR_SET_PDEATHSIG = global i32 0
@SIGKILL = global i32 0
@RLIMIT_AS = global i32 0
@RLIMIT_FSIZE = global i32 0
@RLIMIT_STACK = global i32 0
@RLIMIT_CORE = global i32 0
@CLONE_NEWNS = global i32 0
@CLONE_NEWIPC = global i32 0
@CLONE_IO = global i32 0
define void @sandbox_common() {
%1 = alloca %struct.rlimit
%2 = load i32, i32* @PR_SET_PDEATHSIG
%3 = load i32, i32* @SIGKILL
%4 = tail call i32 @prctl(i32 %2, i32 %3, i32 0, i32 0, i32 0)
%5 = tail call i32 (...) @setpgrp()
%6 = tail call i32 (...) @setsid()
%7 = bitcast %struct.rlimit* %1 to i8*
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
store i32 134217728, i32* %8
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
store i32 134217728, i32* %9
%10 = load i32, i32* @RLIMIT_AS
%11 = call i32 @setrlimit(i32 %10, %struct.rlimit* %1)
store i32 1048576, i32* %8
store i32 1048576, i32* %9
%12 = load i32, i32* @RLIMIT_FSIZE
%13 = call i32 @setrlimit(i32 %12, %struct.rlimit* %1)
store i32 1048576, i32* %8
store i32 1048576, i32* %9
%14 = load i32, i32* @RLIMIT_STACK
%15 = call i32 @setrlimit(i32 %14, %struct.rlimit* %1)
store i32 0, i32* %8
store i32 0, i32* %9
%16 = load i32, i32* @RLIMIT_CORE
%17 = call i32 @setrlimit(i32 %16, %struct.rlimit* %1)
%18 = load i32, i32* @CLONE_NEWNS
%19 = call i32 @unshare(i32 %18)
%20 = load i32, i32* @CLONE_NEWIPC
%21 = call i32 @unshare(i32 %20)
%22 = load i32, i32* @CLONE_IO
%23 = call i32 @unshare(i32 %22)
ret void
}