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

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ link(char *, char *);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ readlink(char *, char *, int);
int /*<<< orphan*/ symlink(char *, char *);
int main() {
  int fd;
  char buf[128];
  fd = open("foobar", O_WRONLY | O_CREAT, S_IRWXU);
  close(fd);
  link("foobar", "foobar2");
  link("foobar", "foobar");
  link("nonexist", "foo");
  symlink("foobar", "Sfoobar");
  readlink("Sfoobar", buf, sizeof(buf));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    0x2e86(%rip),%rax
or     (%rax),%esi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
lea    0xe92(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
lea    0xe7b(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1070 <link@plt>
lea    0xe68(%rip),%rsi
mov    %rsi,%rdi
call   1070 <link@plt>
lea    0xe4b(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   1070 <link@plt>
lea    0xe46(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   1040 <symlink@plt>
lea    -0x90(%rbp),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x80,%edx
call   1030 <readlink@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    0x2e67(%rip),%rax
mov    0x2e90(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
lea    0xe9a(%rip),%rbx
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,%edi
call   1050 <close@plt>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <link@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1070 <link@plt>
lea    0xe5c(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1070 <link@plt>
lea    0xe56(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <symlink@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x80,%edx
call   1030 <readlink@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"foobar\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [8 x i8] c"foobar2\00"
@.str.2 = [9 x i8] c"nonexist\00"
@.str.3 = [4 x i8] c"foo\00"
@.str.4 = [8 x i8] c"Sfoobar\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
store i32 0, i32* %1
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IRWXU
%8 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = call i32 @close(i32 %9)
%11 = call i32 @link(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @link(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @link(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @symlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%16 = call i32 @readlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %15, i32 128)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"foobar\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [8 x i8] c"foobar2\00"
@.str.2 = [9 x i8] c"nonexist\00"
@.str.3 = [4 x i8] c"foo\00"
@.str.4 = [8 x i8] c"Sfoobar\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IRWXU
%7 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = tail call i32 @close(i32 %7)
%9 = tail call i32 @link(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @link(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @link(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @symlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 @readlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32 128)
ret i32 0
}