#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*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PR_SET_DUMPABLE;
int /*<<< orphan*/ check(int /*<<< orphan*/, char *);
int /*<<< orphan*/ make_cloexec(int);
int /*<<< orphan*/ prctl(int /*<<< orphan*/, int /*<<< orphan*/);
int recv_fd(int);
int /*<<< orphan*/ send_str(int, char *);
int /*<<< orphan*/ spawn_binary(int, int);
int /*<<< orphan*/ waitfor(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int broker_fd = 101;
  int sandbox_fd = 100;
  make_cloexec(broker_fd);
  make_cloexec(sandbox_fd);
  check(prctl(PR_SET_DUMPABLE, 0), "prctl(PR_SET_DUMPABLE, 0)");
  while (1) {
    int exec_fd = recv_fd(sandbox_fd);
    pid_t pid = spawn_binary(broker_fd, exec_fd);
    waitfor(pid);
    send_str(sandbox_fd, "OK");
  }
  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   $0x65,-0x14(%rbp)
movl   $0x64,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <make_cloexec@plt>
mov    -0x18(%rbp),%edi
call   1080 <make_cloexec@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <prctl@plt>
mov    %eax,%edi
lea    0xe43(%rip),%rsi
call   1070 <check@plt>
mov    -0x18(%rbp),%edi
call   1060 <recv_fd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <spawn_binary@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1090 <waitfor@plt>
mov    -0x18(%rbp),%edi
lea    0xe2d(%rip),%rsi
call   1040 <send_str@plt>
jmp    11c2 <main+0x52>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x65,%edi
call   1080 <make_cloexec@plt>
mov    $0x64,%edi
call   1080 <make_cloexec@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <prctl@plt>
lea    0xe64(%rip),%rsi
mov    %eax,%edi
call   1070 <check@plt>
lea    0xe70(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    $0x64,%edi
call   1060 <recv_fd@plt>
mov    $0x65,%edi
mov    %eax,%esi
call   1030 <spawn_binary@plt>
mov    %eax,%edi
call   1090 <waitfor@plt>
mov    $0x64,%edi
mov    %rbx,%rsi
call   1040 <send_str@plt>
jmp    11b0 <main+0x40>

LLVM IR (-O0):
@PR_SET_DUMPABLE = global i32 0
@.str = [26 x i8] c"prctl(PR_SET_DUMPABLE, 0)\00"
@.str.1 = [3 x i8] c"OK\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 101, i32* %6
store i32 100, i32* %7
%10 = load i32, i32* %6
%11 = call i32 @make_cloexec(i32 %10)
%12 = load i32, i32* %7
%13 = call i32 @make_cloexec(i32 %12)
%14 = load i32, i32* @PR_SET_DUMPABLE
%15 = call i32 @prctl(i32 %14, i32 0)
%16 = call i32 @check(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %2, %17
%18 = load i32, i32* %7
%19 = call i32 @recv_fd(i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %6
%21 = load i32, i32* %8
%22 = call i32 @spawn_binary(i32 %20, i32 %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = call i32 @waitfor(i32 %23)
%25 = load i32, i32* %7
%26 = call i32 @send_str(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %17
}

LLVM IR (-O2):
@PR_SET_DUMPABLE = global i32 0
@.str = [26 x i8] c"prctl(PR_SET_DUMPABLE, 0)\00"
@.str.1 = [3 x i8] c"OK\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @make_cloexec(i32 101)
%4 = tail call i32 @make_cloexec(i32 100)
%5 = load i32, i32* @PR_SET_DUMPABLE
%6 = tail call i32 @prctl(i32 %5, i32 0)
%7 = tail call i32 @check(i32 %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %8, %2
%9 = tail call i32 @recv_fd(i32 100)
%10 = tail call i32 @spawn_binary(i32 101, i32 %9)
%11 = tail call i32 @waitfor(i32 %10)
%12 = tail call i32 @send_str(i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %8
}