#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*/ mkdir(char *, int);
int open_(char *, int, int);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ symlink(char *, char *);
int /*<<< orphan*/ write(int, char const *, int /*<<< orphan*/);
void prerequisites(void) {
  int fd;
  const char *contents = "0123456789\n";
  mkdir("subdir", 0755);
  fd = open_("topfile", O_RDWR | O_CREAT | O_TRUNC, 0644);
  write(fd, contents, strlen(contents));
  close(fd);
  fd = open_("subdir/bottomfile", O_RDWR | O_CREAT | O_TRUNC, 0644);
  write(fd, contents, strlen(contents));
  close(fd);
  symlink("../topfile", "subdir/symlinkup");
  symlink("/etc/passwd", "subdir/symlinkout");
  symlink("bottomfile", "subdir/symlinkin");
  symlink("subdir/bottomfile", "symlinkdown");
}


x86 assembly (clang, -O0):
<prerequisites>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe92(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    0x2e64(%rip),%rax
or     (%rax),%esi
mov    0x2e53(%rip),%rax
or     (%rax),%esi
lea    0xe82(%rip),%rdi
mov    $0x1a4,%edx
call   1080 <open_@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    0x2e08(%rip),%rax
or     (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
lea    0xe11(%rip),%rdi
mov    $0x1a4,%edx
call   1080 <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   1070 <close@plt>
lea    0xde2(%rip),%rdi
lea    0xde6(%rip),%rsi
call   1060 <symlink@plt>
lea    0xdeb(%rip),%rdi
lea    0xdf0(%rip),%rsi
call   1060 <symlink@plt>
lea    0xdb1(%rip),%rdi
lea    0xdef(%rip),%rsi
call   1060 <symlink@plt>
lea    0xd97(%rip),%rdi
lea    0xded(%rip),%rsi
call   1060 <symlink@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prerequisites>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe9d(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    0x2e58(%rip),%r14
mov    0x2e71(%rip),%r15
mov    (%r15),%esi
or     (%r14),%esi
mov    0x2e5c(%rip),%r12
or     (%r12),%esi
lea    0xe89(%rip),%rdi
mov    $0x1a4,%edx
call   1080 <open_@plt>
mov    %eax,%ebp
lea    0xe4e(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%r12),%esi
lea    0xe35(%rip),%r14
mov    %r14,%rdi
mov    $0x1a4,%edx
call   1080 <open_@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
lea    0xe16(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   1060 <symlink@plt>
lea    0xe1f(%rip),%rdi
lea    0xe24(%rip),%rsi
call   1060 <symlink@plt>
lea    0xde5(%rip),%rdi
lea    0xe23(%rip),%rsi
call   1060 <symlink@plt>
lea    0xe28(%rip),%rsi
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <symlink@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"0123456789\0A\00"
@.str.1 = [7 x i8] c"subdir\00"
@.str.2 = [8 x i8] c"topfile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [18 x i8] c"subdir/bottomfile\00"
@.str.4 = [11 x i8] c"../topfile\00"
@.str.5 = [17 x i8] c"subdir/symlinkup\00"
@.str.6 = [12 x i8] c"/etc/passwd\00"
@.str.7 = [18 x i8] c"subdir/symlinkout\00"
@.str.8 = [11 x i8] c"bottomfile\00"
@.str.9 = [17 x i8] c"subdir/symlinkin\00"
@.str.10 = [12 x i8] c"symlinkdown\00"
define void @prerequisites() {
%1 = alloca i32
%2 = alloca i8*
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 493)
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %4, %5
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %6, %7
%9 = call i32 @open_(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 420)
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = load i8*, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = call i32 @write(i32 %10, i8* %11, i32 %13)
%15 = load i32, i32* %1
%16 = call i32 @close(i32 %15)
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_CREAT
%19 = or i32 %17, %18
%20 = load i32, i32* @O_TRUNC
%21 = or i32 %19, %20
%22 = call i32 @open_(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 420)
store i32 %22, i32* %1
%23 = load i32, i32* %1
%24 = load i8*, i8** %2
%25 = load i8*, i8** %2
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @write(i32 %23, i8* %24, i32 %26)
%28 = load i32, i32* %1
%29 = call i32 @close(i32 %28)
%30 = call i32 @symlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @symlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%32 = call i32 @symlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%33 = call i32 @symlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"0123456789\0A\00"
@.str.1 = [7 x i8] c"subdir\00"
@.str.2 = [8 x i8] c"topfile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [18 x i8] c"subdir/bottomfile\00"
@.str.4 = [11 x i8] c"../topfile\00"
@.str.5 = [17 x i8] c"subdir/symlinkup\00"
@.str.6 = [12 x i8] c"/etc/passwd\00"
@.str.7 = [18 x i8] c"subdir/symlinkout\00"
@.str.8 = [11 x i8] c"bottomfile\00"
@.str.9 = [17 x i8] c"subdir/symlinkin\00"
@.str.10 = [12 x i8] c"symlinkdown\00"
define void @prerequisites() {
%1 = tail call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 493)
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = tail call i32 @open_(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 420)
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @write(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @close(i32 %7)
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_CREAT
%13 = or i32 %12, %11
%14 = load i32, i32* @O_TRUNC
%15 = or i32 %13, %14
%16 = tail call i32 @open_(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 420)
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @write(i32 %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = tail call i32 @close(i32 %16)
%20 = tail call i32 @symlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%21 = tail call i32 @symlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%22 = tail call i32 @symlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%23 = tail call i32 @symlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
ret void
}