#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 O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exe_cp(char *, char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int, int);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ write(int, char const *, int /*<<< orphan*/);
void prerequisites(void) {
  int fd;
  const char *script = "#!/bin/sh\nexit $*\n";
  exe_cp("execveat", "execveat.ephemeral");
  exe_cp("execveat", "execveat.path.ephemeral");
  exe_cp("script", "script.ephemeral");
  mkdir("subdir.ephemeral", 0755);
  fd = open("subdir.ephemeral/script", O_RDWR | O_CREAT | O_TRUNC, 0755);
  write(fd, script, strlen(script));
  close(fd);
  mkfifo("pipe", 0755);
}


x86 assembly (clang, -O0):
<prerequisites>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe89(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <exe_cp@plt>
lea    0xe76(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <exe_cp@plt>
lea    0xeca(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <exe_cp@plt>
lea    0xe95(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    0x2e1b(%rip),%rax
or     (%rax),%esi
mov    0x2e0a(%rip),%rax
or     (%rax),%esi
lea    0xe7a(%rip),%rdi
mov    $0x1ed,%edx
call   1090 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
lea    0xe51(%rip),%rdi
mov    $0x1ed,%esi
call   1080 <mkfifo@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prerequisites>:
push   %r14
push   %rbx
push   %rax
lea    0xe98(%rip),%rbx
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <exe_cp@plt>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <exe_cp@plt>
lea    0xeda(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1070 <exe_cp@plt>
lea    0xea5(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    0x2e14(%rip),%rax
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
lea    0xe8a(%rip),%rdi
mov    $0x1ed,%edx
call   1090 <open@plt>
mov    %eax,%ebx
lea    0xe0e(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe6d(%rip),%rdi
mov    $0x1ed,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <mkfifo@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"#!/bin/sh\0Aexit $*\0A\00"
@.str.1 = [9 x i8] c"execveat\00"
@.str.2 = [19 x i8] c"execveat.ephemeral\00"
@.str.3 = [24 x i8] c"execveat.path.ephemeral\00"
@.str.4 = [7 x i8] c"script\00"
@.str.5 = [17 x i8] c"script.ephemeral\00"
@.str.6 = [17 x i8] c"subdir.ephemeral\00"
@.str.7 = [24 x i8] c"subdir.ephemeral/script\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.8 = [5 x i8] c"pipe\00"
define void @prerequisites() {
%1 = alloca i32
%2 = alloca i8*
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = call i32 @exe_cp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%4 = call i32 @exe_cp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%5 = call i32 @exe_cp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%6 = call i32 @mkdir(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 493)
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %11, i32 493)
store i32 %12, i32* %1
%13 = load i32, i32* %1
%14 = load i8*, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @write(i32 %13, i8* %14, i32 %16)
%18 = load i32, i32* %1
%19 = call i32 @close(i32 %18)
%20 = call i32 @mkfifo(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 493)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"#!/bin/sh\0Aexit $*\0A\00"
@.str.1 = [9 x i8] c"execveat\00"
@.str.2 = [19 x i8] c"execveat.ephemeral\00"
@.str.3 = [24 x i8] c"execveat.path.ephemeral\00"
@.str.4 = [7 x i8] c"script\00"
@.str.5 = [17 x i8] c"script.ephemeral\00"
@.str.6 = [17 x i8] c"subdir.ephemeral\00"
@.str.7 = [24 x i8] c"subdir.ephemeral/script\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.8 = [5 x i8] c"pipe\00"
define void @prerequisites() {
%1 = tail call i32 @exe_cp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%2 = tail call i32 @exe_cp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call i32 @exe_cp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%4 = tail call i32 @mkdir(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 493)
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %9, i32 493)
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @write(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @close(i32 %10)
%14 = tail call i32 @mkfifo(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 493)
ret void
}