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


x86 assembly (clang, -O0):
<execute_link>:
push   %rbp
mov    %rsp,%rbp
lea    0xec5(%rip),%rdi
call   1030 <open_rdonly@plt>
mov    %eax,%edi
call   1040 <close@plt>
lea    0xeb2(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <link@plt>
lea    0xeba(%rip),%rdi
lea    0xed9(%rip),%rsi
call   1050 <link@plt>
lea    0xedc(%rip),%rdi
call   1030 <open_rdonly@plt>
mov    %eax,%edi
call   1040 <close@plt>
lea    0xec9(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1050 <link@plt>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_link>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rbx
mov    %rbx,%rdi
call   1030 <open_rdonly@plt>
mov    %eax,%edi
call   1040 <close@plt>
lea    0xebc(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <link@plt>
lea    0xeb8(%rip),%rdi
lea    0xed7(%rip),%rsi
call   1050 <link@plt>
lea    0xeda(%rip),%rbx
mov    %rbx,%rdi
call   1030 <open_rdonly@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <link@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 = [14 x i8] c"syscalls.link\00"
@.str.2 = [38 x i8] c"hopefully_no_such_filename_exists.txt\00"
@.str.3 = [15 x i8] c"syscalls2.link\00"
@.str.4 = [14 x i8] c"syscalls2.txt\00"
define i32 @execute_link() {
%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 @link(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @link(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 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 @link(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"syscalls.txt\00"
@.str.1 = [14 x i8] c"syscalls.link\00"
@.str.2 = [38 x i8] c"hopefully_no_such_filename_exists.txt\00"
@.str.3 = [15 x i8] c"syscalls2.link\00"
@.str.4 = [14 x i8] c"syscalls2.txt\00"
define i32 @execute_link() {
%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 @link(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @link(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 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 @link(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}