#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 /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ open_rdonly(char *);
int /*<<< orphan*/ symlink(char *, char *);
int execute_symlink() {
  close(open_rdonly("syscalls.txt"));
  symlink("syscalls.txt", "syscalls.symlink");
  symlink("hopefully_no_such_filename_exists.txt", "syscalls2.symlink");
  close(open_rdonly("syscalls2.txt"));
  symlink("syscalls2.txt", "syscalls.symlink");
  return 0;
}


x86 assembly (clang, -O0):
<execute_symlink>:
push   %rbp
mov    %rsp,%rbp
lea    0xec5(%rip),%rdi
call   1030 <open_rdonly@plt>
mov    %eax,%edi
call   1050 <close@plt>
lea    0xeb2(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1040 <symlink@plt>
lea    0xebd(%rip),%rdi
lea    0xedc(%rip),%rsi
call   1040 <symlink@plt>
lea    0xee2(%rip),%rdi
call   1030 <open_rdonly@plt>
mov    %eax,%edi
call   1050 <close@plt>
lea    0xecf(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1040 <symlink@plt>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_symlink>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rbx
mov    %rbx,%rdi
call   1030 <open_rdonly@plt>
mov    %eax,%edi
call   1050 <close@plt>
lea    0xebc(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <symlink@plt>
lea    0xebb(%rip),%rdi
lea    0xeda(%rip),%rsi
call   1040 <symlink@plt>
lea    0xee0(%rip),%rbx
mov    %rbx,%rdi
call   1030 <open_rdonly@plt>
mov    %eax,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <symlink@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"syscalls.txt\00"
@.str.1 = [17 x i8] c"syscalls.symlink\00"
@.str.2 = [38 x i8] c"hopefully_no_such_filename_exists.txt\00"
@.str.3 = [18 x i8] c"syscalls2.symlink\00"
@.str.4 = [14 x i8] c"syscalls2.txt\00"
define i32 @execute_symlink() {
%1 = call i32 @open_rdonly(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = call i32 @close(i32 %1)
%3 = call i32 @symlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @symlink(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%5 = call i32 @open_rdonly(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%6 = call i32 @close(i32 %5)
%7 = call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"syscalls.txt\00"
@.str.1 = [17 x i8] c"syscalls.symlink\00"
@.str.2 = [38 x i8] c"hopefully_no_such_filename_exists.txt\00"
@.str.3 = [18 x i8] c"syscalls2.symlink\00"
@.str.4 = [14 x i8] c"syscalls2.txt\00"
define i32 @execute_symlink() {
%1 = tail call i32 @open_rdonly(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @close(i32 %1)
%3 = tail call i32 @symlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @symlink(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i32 @open_rdonly(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%6 = tail call i32 @close(i32 %5)
%7 = tail call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}