#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 */
struct stat {
  int st_nlink;
  scalar_t__ st_ino;
};
typedef scalar_t__ ino_t;

/* Variables and functions */
scalar_t__ EPERM;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ assert(int);
int close(int);
scalar_t__ errno;
int /*<<< orphan*/ fill_random(void *, int);
int link(char *, char *);
int lseek(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
void *malloc(int);
int /*<<< orphan*/ memcmp(void *, void *, int);
int open(char *, int, int);
int read(int, void *, int);
scalar_t__ stat(char *, struct stat *);
scalar_t__ unlink(char *);
int write(scalar_t__, void *, int);
int test_vfs_link(void) {
  int n;
  struct stat sb;
  ino_t fileino;
  void *wrbuf = malloc(64);
  void *rdbuf = malloc(32);
  fill_random(wrbuf, 64);
  n = open("/tmp"
           "/file",
           O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
  assert(n == 0 + 3);
  ;
  assert(stat("/tmp"
              "/file",
              &sb) == 0);
  assert(sb.st_nlink == 1);
  fileino = sb.st_ino;
  n = write(0 + 3, wrbuf, 32);
  assert(n >= 0);
  ;
  assert(link("/tmp"
              "/file",
              "/tmp"
              "/file2") == 0);
  assert(stat("/tmp"
              "/file2",
              &sb) == 0);
  assert(sb.st_ino == fileino);
  assert(sb.st_nlink == 2);
  n = open("/tmp"
           "/file2",
           O_RDWR, 0);
  assert(n == 1 + 3);
  ;
  assert(read(4, rdbuf, 32) == 32);
  assert(!memcmp(wrbuf, rdbuf, 32));
  assert(link("/tmp"
              "/file2",
              "/tmp"
              "/file3") == 0);
  assert(stat("/tmp"
              "/file3",
              &sb) == 0);
  assert(sb.st_ino == fileino);
  assert(sb.st_nlink == 3);
  n = open("/tmp"
           "/file3",
           O_RDWR, 0);
  assert(n == 2 + 3);
  ;
  n = lseek(0 + 3, 0, SEEK_SET);
  assert(n >= 0);
  ;
  n = write(0 + 3, wrbuf + 32, 32);
  assert(n >= 0);
  ;
  assert(read(5, rdbuf, 32) == 32);
  assert(!memcmp(wrbuf + 32, rdbuf, 32));
  n = close(1 + 3);
  assert(n == 0);
  ;
  assert(unlink("/tmp"
                "/file2") == 0);
  assert(stat("/tmp"
              "/file",
              &sb) == 0);
  assert(sb.st_nlink == 2);
  assert(unlink("/tmp"
                "/file") == 0);
  assert(stat("/tmp"
              "/file3",
              &sb) == 0);
  assert(sb.st_nlink == 1);
  assert(unlink("/tmp"
                "/file3") == 0);
  assert(link("/tmp", "/tmp/foo") == -1 && errno == EPERM);
  return 0;
}


x86 assembly (clang, -O0):
<test_vfs_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x40,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x20,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x40,%esi
call   1040 <fill_random@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    0x2df6(%rip),%rax
or     (%rax),%esi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
mov    0x2da4(%rip),%rax
or     (%rax),%edx
lea    0xde3(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xdc3(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
cmpl   $0x1,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rsi
mov    $0x3,%edi
mov    $0x20,%edx
call   1050 <write@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xd62(%rip),%rdi
lea    0xd65(%rip),%rsi
call   10e0 <link@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xd49(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
cmpl   $0x2,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    0x2cd8(%rip),%rax
mov    (%rax),%esi
lea    0xcf9(%rip),%rdi
xor    %edx,%edx
call   10d0 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x30(%rbp),%rsi
mov    $0x4,%edi
mov    $0x20,%edx
call   1080 <read@plt>
cmp    $0x20,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xc90(%rip),%rdi
lea    0xc94(%rip),%rsi
call   10e0 <link@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xc78(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
cmpl   $0x3,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    0x2bfc(%rip),%rax
mov    (%rax),%esi
lea    0xc28(%rip),%rdi
xor    %edx,%edx
call   10d0 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    0x2bb1(%rip),%rax
mov    (%rax),%edx
mov    $0x3,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x28(%rbp),%rsi
add    $0x20,%rsi
mov    $0x3,%edi
mov    $0x20,%edx
call   1050 <write@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x30(%rbp),%rsi
mov    $0x5,%edi
mov    $0x20,%edx
call   1080 <read@plt>
cmp    $0x20,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x28(%rbp),%rdi
add    $0x20,%rdi
mov    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    $0x4,%edi
call   1070 <close@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xb3e(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xb17(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
cmpl   $0x2,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xae5(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xadd(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
cmpl   $0x1,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xaab(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xa99(%rip),%rdi
lea    0xa97(%rip),%rsi
call   10e0 <link@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x31(%rbp)
jne    15bd <test_vfs_link+0x3fd>
mov    0x2a1e(%rip),%rax
mov    (%rax),%rax
mov    0x29f4(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_vfs_link>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x40,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
mov    $0x20,%edi
call   10c0 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x40,%esi
call   1040 <fill_random@plt>
mov    0x2de4(%rip),%rcx
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
or     (%rcx),%esi
mov    0x2dca(%rip),%rax
mov    0x2da3(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xde0(%rip),%rbp
mov    %rbp,%rdi
call   10d0 <open@plt>
xor    %edi,%edi
cmp    $0x3,%eax
sete   %dil
call   10a0 <assert@plt>
lea    0x8(%rsp),%r15
mov    %rbp,%rdi
mov    %r15,%rsi
call   10b0 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10a0 <assert@plt>
xor    %edi,%edi
cmpl   $0x1,0x8(%rsp)
sete   %dil
call   10a0 <assert@plt>
mov    0x10(%rsp),%r14
mov    $0x3,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1050 <write@plt>
not    %eax
shr    $0x1f,%eax
mov    %eax,%edi
call   10a0 <assert@plt>
lea    0xd7c(%rip),%r13
mov    %rbp,%rdi
mov    %r13,%rsi
call   10e0 <link@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   10b0 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10a0 <assert@plt>
xor    %edi,%edi
cmp    %r14,0x10(%rsp)
sete   %dil
call   10a0 <assert@plt>
xor    %edi,%edi
cmpl   $0x2,0x8(%rsp)
sete   %dil
call   10a0 <assert@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
xor    %edx,%edx
call   10d0 <open@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   10a0 <assert@plt>
mov    $0x4,%edi
mov    %r12,%rsi
mov    $0x20,%edx
call   1080 <read@plt>
xor    %edi,%edi
cmp    $0x20,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x20,%edx
call   1090 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
lea    0xcd1(%rip),%rbp
mov    %r13,%rdi
mov    %rbp,%rsi
call   10e0 <link@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10b0 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10a0 <assert@plt>
xor    %edi,%edi
cmp    %r14,0x10(%rsp)
sete   %dil
call   10a0 <assert@plt>
xor    %edi,%edi
cmpl   $0x3,0x8(%rsp)
sete   %dil
call   10a0 <assert@plt>
mov    0x2c44(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %edx,%edx
call   10d0 <open@plt>
xor    %edi,%edi
cmp    $0x5,%eax
sete   %dil
call   10a0 <assert@plt>
mov    0x2c03(%rip),%rax
mov    (%rax),%edx
mov    $0x3,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
not    %eax
shr    $0x1f,%eax
mov    %eax,%edi
call   10a0 <assert@plt>
add    $0x20,%rbx
mov    $0x3,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1050 <write@plt>
not    %eax
shr    $0x1f,%eax
mov    %eax,%edi
call   10a0 <assert@plt>
mov    $0x5,%edi
mov    %r12,%rsi
mov    $0x20,%edx
call   1080 <read@plt>
xor    %edi,%edi
cmp    $0x20,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x20,%edx
call   1090 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    $0x4,%edi
call   1070 <close@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %r13,%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10a0 <assert@plt>
lea    0xb96(%rip),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10a0 <assert@plt>
xor    %edi,%edi
cmpl   $0x2,0x8(%rsp)
sete   %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10a0 <assert@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10b0 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10a0 <assert@plt>
xor    %edi,%edi
cmpl   $0x1,0x8(%rsp)
sete   %dil
call   10a0 <assert@plt>
mov    %rbp,%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10a0 <assert@plt>
lea    0xb31(%rip),%rdi
lea    0xb2f(%rip),%rsi
call   10e0 <link@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x2ac0(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2a96(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   10a0 <assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
@.str = [10 x i8] c"/tmp/file\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@.str.1 = [11 x i8] c"/tmp/file2\00"
@.str.2 = [11 x i8] c"/tmp/file3\00"
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c"/tmp\00"
@.str.4 = [9 x i8] c"/tmp/foo\00"
@errno = global i64 0
@EPERM = global i64 0
define i32 @test_vfs_link() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = call i8* @malloc(i32 64)
store i8* %6, i8** %4
%7 = call i8* @malloc(i32 32)
store i8* %7, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @fill_random(i8* %8, i32 64)
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IWUSR
%14 = load i32, i32* @S_IRUSR
%15 = or i32 %13, %14
%16 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15)
store i32 %16, i32* %1
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 3
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i64 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 1
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%31 = load i64, i64* %30
store i64 %31, i64* %3
%32 = load i8*, i8** %4
%33 = call i32 @write(i64 3, i8* %32, i32 32)
store i32 %33, i32* %1
%34 = load i32, i32* %1
%35 = icmp sge i32 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = call i32 @link(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp eq i32 %38, 0
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = call i64 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %2)
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%47 = load i64, i64* %46
%48 = load i64, i64* %3
%49 = icmp eq i64 %47, %48
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%53 = load i32, i32* %52
%54 = icmp eq i32 %53, 2
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = load i32, i32* @O_RDWR
%58 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %57, i32 0)
store i32 %58, i32* %1
%59 = load i32, i32* %1
%60 = icmp eq i32 %59, 4
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = load i8*, i8** %5
%64 = call i32 @read(i32 4, i8* %63, i32 32)
%65 = icmp eq i32 %64, 32
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = load i8*, i8** %4
%69 = load i8*, i8** %5
%70 = call i32 @memcmp(i8* %68, i8* %69, i32 32)
%71 = icmp ne i32 %70, 0
%72 = xor i1 %71, true
%73 = zext i1 %72 to i32
%74 = call i32 @assert(i32 %73)
%75 = call i32 @link(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%76 = icmp eq i32 %75, 0
%77 = zext i1 %76 to i32
%78 = call i32 @assert(i32 %77)
%79 = call i64 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %2)
%80 = icmp eq i64 %79, 0
%81 = zext i1 %80 to i32
%82 = call i32 @assert(i32 %81)
%83 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%84 = load i64, i64* %83
%85 = load i64, i64* %3
%86 = icmp eq i64 %84, %85
%87 = zext i1 %86 to i32
%88 = call i32 @assert(i32 %87)
%89 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%90 = load i32, i32* %89
%91 = icmp eq i32 %90, 3
%92 = zext i1 %91 to i32
%93 = call i32 @assert(i32 %92)
%94 = load i32, i32* @O_RDWR
%95 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %94, i32 0)
store i32 %95, i32* %1
%96 = load i32, i32* %1
%97 = icmp eq i32 %96, 5
%98 = zext i1 %97 to i32
%99 = call i32 @assert(i32 %98)
%100 = load i32, i32* @SEEK_SET
%101 = call i32 @lseek(i64 3, i32 0, i32 %100)
store i32 %101, i32* %1
%102 = load i32, i32* %1
%103 = icmp sge i32 %102, 0
%104 = zext i1 %103 to i32
%105 = call i32 @assert(i32 %104)
%106 = load i8*, i8** %4
%107 = getelementptr i8, i8* %106, i64 32
%108 = call i32 @write(i64 3, i8* %107, i32 32)
store i32 %108, i32* %1
%109 = load i32, i32* %1
%110 = icmp sge i32 %109, 0
%111 = zext i1 %110 to i32
%112 = call i32 @assert(i32 %111)
%113 = load i8*, i8** %5
%114 = call i32 @read(i32 5, i8* %113, i32 32)
%115 = icmp eq i32 %114, 32
%116 = zext i1 %115 to i32
%117 = call i32 @assert(i32 %116)
%118 = load i8*, i8** %4
%119 = getelementptr i8, i8* %118, i64 32
%120 = load i8*, i8** %5
%121 = call i32 @memcmp(i8* %119, i8* %120, i32 32)
%122 = icmp ne i32 %121, 0
%123 = xor i1 %122, true
%124 = zext i1 %123 to i32
%125 = call i32 @assert(i32 %124)
%126 = call i32 @close(i32 4)
store i32 %126, i32* %1
%127 = load i32, i32* %1
%128 = icmp eq i32 %127, 0
%129 = zext i1 %128 to i32
%130 = call i32 @assert(i32 %129)
%131 = call i64 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%132 = icmp eq i64 %131, 0
%133 = zext i1 %132 to i32
%134 = call i32 @assert(i32 %133)
%135 = call i64 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%136 = icmp eq i64 %135, 0
%137 = zext i1 %136 to i32
%138 = call i32 @assert(i32 %137)
%139 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%140 = load i32, i32* %139
%141 = icmp eq i32 %140, 2
%142 = zext i1 %141 to i32
%143 = call i32 @assert(i32 %142)
%144 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%145 = icmp eq i64 %144, 0
%146 = zext i1 %145 to i32
%147 = call i32 @assert(i32 %146)
%148 = call i64 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %2)
%149 = icmp eq i64 %148, 0
%150 = zext i1 %149 to i32
%151 = call i32 @assert(i32 %150)
%152 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%153 = load i32, i32* %152
%154 = icmp eq i32 %153, 1
%155 = zext i1 %154 to i32
%156 = call i32 @assert(i32 %155)
%157 = call i64 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%158 = icmp eq i64 %157, 0
%159 = zext i1 %158 to i32
%160 = call i32 @assert(i32 %159)
%161 = call i32 @link(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%162 = icmp eq i32 %161, -1
br i1 %162, label %163, label %167
163: ; preds = %0
%164 = load i64, i64* @errno
%165 = load i64, i64* @EPERM
%166 = icmp eq i64 %164, %165
br label %167
167: ; preds = %163, %0
%168 = phi i1 [ false, %0 ], [ %166, %163 ]
%169 = zext i1 %168 to i32
%170 = call i32 @assert(i32 %169)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
@.str = [10 x i8] c"/tmp/file\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@.str.1 = [11 x i8] c"/tmp/file2\00"
@.str.2 = [11 x i8] c"/tmp/file3\00"
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c"/tmp\00"
@.str.4 = [9 x i8] c"/tmp/foo\00"
@errno = global i64 0
@EPERM = global i64 0
define i32 @test_vfs_link() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
%4 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%5 = tail call i32 @fill_random(i8* %3, i32 64)
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = load i32, i32* @S_IWUSR
%10 = load i32, i32* @S_IRUSR
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11)
%13 = icmp eq i32 %12, 3
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = call i64 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%26 = load i64, i64* %25
%27 = call i32 @write(i64 3, i8* %3, i32 32)
%28 = xor i32 %27, -1
%29 = lshr i32 %28, 31
%30 = call i32 @assert(i32 %29)
%31 = call i32 @link(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call i64 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%36 = icmp eq i64 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i64, i64* %25
%40 = icmp eq i64 %39, %26
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load i32, i32* %20
%44 = icmp eq i32 %43, 2
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i32, i32* @O_RDWR
%48 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %47, i32 0)
%49 = icmp eq i32 %48, 4
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = call i32 @read(i32 4, i8* %4, i32 32)
%53 = icmp eq i32 %52, 32
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = call i32 @memcmp(i8* %3, i8* %4, i32 32)
%57 = icmp eq i32 %56, 0
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = call i32 @link(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%61 = icmp eq i32 %60, 0
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = call i64 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %1)
%65 = icmp eq i64 %64, 0
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = load i64, i64* %25
%69 = icmp eq i64 %68, %26
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = load i32, i32* %20
%73 = icmp eq i32 %72, 3
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = load i32, i32* @O_RDWR
%77 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %76, i32 0)
%78 = icmp eq i32 %77, 5
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
%81 = load i32, i32* @SEEK_SET
%82 = call i32 @lseek(i64 3, i32 0, i32 %81)
%83 = xor i32 %82, -1
%84 = lshr i32 %83, 31
%85 = call i32 @assert(i32 %84)
%86 = getelementptr i8, i8* %3, i64 32
%87 = call i32 @write(i64 3, i8* %86, i32 32)
%88 = xor i32 %87, -1
%89 = lshr i32 %88, 31
%90 = call i32 @assert(i32 %89)
%91 = call i32 @read(i32 5, i8* %4, i32 32)
%92 = icmp eq i32 %91, 32
%93 = zext i1 %92 to i32
%94 = call i32 @assert(i32 %93)
%95 = call i32 @memcmp(i8* %86, i8* %4, i32 32)
%96 = icmp eq i32 %95, 0
%97 = zext i1 %96 to i32
%98 = call i32 @assert(i32 %97)
%99 = call i32 @close(i32 4)
%100 = icmp eq i32 %99, 0
%101 = zext i1 %100 to i32
%102 = call i32 @assert(i32 %101)
%103 = call i64 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%104 = icmp eq i64 %103, 0
%105 = zext i1 %104 to i32
%106 = call i32 @assert(i32 %105)
%107 = call i64 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%108 = icmp eq i64 %107, 0
%109 = zext i1 %108 to i32
%110 = call i32 @assert(i32 %109)
%111 = load i32, i32* %20
%112 = icmp eq i32 %111, 2
%113 = zext i1 %112 to i32
%114 = call i32 @assert(i32 %113)
%115 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%116 = icmp eq i64 %115, 0
%117 = zext i1 %116 to i32
%118 = call i32 @assert(i32 %117)
%119 = call i64 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %1)
%120 = icmp eq i64 %119, 0
%121 = zext i1 %120 to i32
%122 = call i32 @assert(i32 %121)
%123 = load i32, i32* %20
%124 = icmp eq i32 %123, 1
%125 = zext i1 %124 to i32
%126 = call i32 @assert(i32 %125)
%127 = call i64 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%128 = icmp eq i64 %127, 0
%129 = zext i1 %128 to i32
%130 = call i32 @assert(i32 %129)
%131 = call i32 @link(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%132 = icmp eq i32 %131, -1
%133 = load i64, i64* @errno
%134 = load i64, i64* @EPERM
%135 = icmp eq i64 %133, %134
%136 = select i1 %132, i1 %135, i1 false
%137 = zext i1 %136 to i32
%138 = call i32 @assert(i32 %137)
ret i32 0
}