#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 /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int lchown(char *, int, int);
int lgetxattr(char *, char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int link(char *, char *);
int llistxattr(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int lremovexattr(char *, char *);
int lsetxattr(char *, char *, char *, int, int /*<<< orphan*/);
int lstat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int symlink(char *, char *);
int unlink(char *);
int link_based_fops(char *filename) {
  int ret = -1;
  int result = 0;
  int fd = 0;
  char newname[255] = {
      0,
  };
  char linkname[255] = {
      0,
  };
  struct stat lstbuf = {
      0,
  };
  fd = creat(filename, 0644);
  if (fd < 0) {
    fd = 0;
    fprintf(stderr, "creat failed: %s\n", strerror(errno));
    return ret;
  }
  strcpy(newname, filename);
  strcat(newname, "_hlink");
  ret = link(filename, newname);
  if (ret < 0) {
    fprintf(stderr, "link failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = unlink(filename);
  if (ret < 0) {
    fprintf(stderr, "unlink failed: %s\n", strerror(errno));
    result |= ret;
  }
  strcpy(linkname, filename);
  strcat(linkname, "_slink");
  ret = symlink(newname, linkname);
  if (ret < 0) {
    fprintf(stderr, "symlink failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = lstat(linkname, &lstbuf);
  if (ret < 0) {
    fprintf(stderr, "lstbuf failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = lchown(linkname, 10001, 10001);
  if (ret < 0) {
    fprintf(stderr, "lchown failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = lsetxattr(linkname, "trusted.lxattr-test", "working", 8, 0);
  if (ret < 0) {
    fprintf(stderr, "lsetxattr failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = llistxattr(linkname, NULL, 0);
  if (ret < 0) {
    ret = -1;
    fprintf(stderr, "llistxattr failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = lgetxattr(linkname, "trusted.lxattr-test", NULL, 0);
  if (ret < 0) {
    ret = -1;
    fprintf(stderr, "lgetxattr failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = lremovexattr(linkname, "trusted.lxattr-test");
  if (ret < 0) {
    fprintf(stderr, "lremovexattr failed: %s\n", strerror(errno));
    result |= ret;
  }
  if (fd)
    close(fd);
  unlink(linkname);
  unlink(newname);
  return result;
}


x86 assembly (clang, -O0):
<link_based_fops>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1080 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1080 <memset@plt>
lea    -0x228(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1a4,%esi
call   10f0 <creat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    12bc <link_based_fops+0xbc>
movl   $0x0,-0x1c(%rbp)
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x22c(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x22c(%rbp),%edi
mov    %rax,%rdx
lea    0xd54(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    167a <link_based_fops+0x47a>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x120(%rbp),%rdi
lea    0xd38(%rip),%rsi
call   10e0 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1100 <link@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1337 <link_based_fops+0x137>
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x230(%rbp)
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x230(%rbp),%edi
mov    %rax,%rdx
lea    0xd0d(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1388 <link_based_fops+0x188>
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x234(%rbp)
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x234(%rbp),%edi
mov    %rax,%rdx
lea    0xc9f(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x220(%rbp),%rdi
lea    0xc86(%rip),%rsi
call   10e0 <strcat@plt>
lea    -0x120(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1070 <symlink@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1406 <link_based_fops+0x206>
mov    0x2c0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x238(%rbp)
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x238(%rbp),%edi
mov    %rax,%rdx
lea    0xc3b(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
lea    -0x228(%rbp),%rsi
call   10a0 <lstat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1461 <link_based_fops+0x261>
mov    0x2bb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x23c(%rbp)
mov    0x2b9c(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x23c(%rbp),%edi
mov    %rax,%rdx
lea    0xbf4(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    $0x2711,%edx
mov    %edx,%esi
call   10d0 <lchown@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    14bc <link_based_fops+0x2bc>
mov    0x2b58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x240(%rbp)
mov    0x2b41(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x240(%rbp),%edi
mov    %rax,%rdx
lea    0xbac(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
lea    0xba3(%rip),%rsi
lea    0xbb0(%rip),%rdx
mov    $0x8,%ecx
xor    %r8d,%r8d
call   10c0 <lsetxattr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1526 <link_based_fops+0x326>
mov    0x2aee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x244(%rbp)
mov    0x2ad7(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x244(%rbp),%edi
mov    %rax,%rdx
lea    0xb71(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <llistxattr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1587 <link_based_fops+0x387>
movl   $0xffffffff,-0x14(%rbp)
mov    0x2a8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x248(%rbp)
mov    0x2a76(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x248(%rbp),%edi
mov    %rax,%rdx
lea    0xb26(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
lea    0xad8(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <lgetxattr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    15ef <link_based_fops+0x3ef>
movl   $0xffffffff,-0x14(%rbp)
mov    0x2a25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24c(%rbp)
mov    0x2a0e(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x24c(%rbp),%edi
mov    %rax,%rdx
lea    0xad5(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
lea    0xa70(%rip),%rsi
call   1120 <lremovexattr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    164a <link_based_fops+0x44a>
mov    0x29ca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x250(%rbp)
mov    0x29b3(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x250(%rbp),%edi
mov    %rax,%rdx
lea    0xa90(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     165c <link_based_fops+0x45c>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
lea    -0x220(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x120(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<link_based_fops>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x210,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0x1ff(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movups %xmm0,0xff(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x8(%rsp)
mov    $0x1a4,%esi
call   10e0 <creat@plt>
test   %eax,%eax
js     15a3 <link_based_fops+0x3b3>
mov    %eax,%r14d
lea    0x110(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xceb(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10f0 <link@plt>
xor    %r15d,%r15d
test   %eax,%eax
jns    1370 <link_based_fops+0x180>
mov    %eax,%ebp
mov    0x2c96(%rip),%rax
mov    (%rax),%r15d
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xcd4(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    %ebp,%r15d
mov    %rbx,%rdi
call   1030 <unlink@plt>
test   %eax,%eax
jns    13ab <link_based_fops+0x1bb>
mov    %eax,%ebp
mov    0x2c5b(%rip),%rax
mov    (%rax),%r12d
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc7c(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
or     %ebp,%r15d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xc6a(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <strcat@plt>
lea    0x110(%rsp),%rdi
mov    %rbp,%rsi
call   1070 <symlink@plt>
test   %eax,%eax
jns    140b <link_based_fops+0x21b>
mov    %eax,%ebx
mov    0x2bf9(%rip),%rax
mov    (%rax),%ebp
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc35(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
or     %ebx,%r15d
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1090 <lstat@plt>
test   %eax,%eax
jns    144b <link_based_fops+0x25b>
mov    %eax,%ebx
mov    0x2bb9(%rip),%rax
mov    (%rax),%ebp
mov    0x2ba8(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc09(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
or     %ebx,%r15d
lea    0x10(%rsp),%rdi
mov    $0x2711,%esi
mov    $0x2711,%edx
call   10c0 <lchown@plt>
test   %eax,%eax
jns    1490 <link_based_fops+0x2a0>
mov    %eax,%ebx
mov    0x2b74(%rip),%rax
mov    (%rax),%ebp
mov    0x2b63(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xbd7(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
or     %ebx,%r15d
lea    0xbd6(%rip),%rsi
lea    0xbe3(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x8,%ecx
xor    %r8d,%r8d
call   10b0 <lsetxattr@plt>
test   %eax,%eax
jns    14e1 <link_based_fops+0x2f1>
mov    %eax,%ebx
mov    0x2b23(%rip),%rax
mov    (%rax),%ebp
mov    0x2b12(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xbb5(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
or     %ebx,%r15d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <llistxattr@plt>
test   %eax,%eax
jns    1521 <link_based_fops+0x331>
mov    0x2ae6(%rip),%rax
mov    (%rax),%ebx
mov    0x2ad5(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xb8e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    $0xffffffff,%r15d
lea    0xb45(%rip),%rsi
lea    0x10(%rsp),%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <lgetxattr@plt>
test   %eax,%eax
jns    1568 <link_based_fops+0x378>
mov    0x2a9f(%rip),%rax
mov    (%rax),%ebx
mov    0x2a8e(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xb5e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    $0xffffffff,%r15d
lea    0xafe(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1110 <lremovexattr@plt>
test   %eax,%eax
js     15e4 <link_based_fops+0x3f4>
test   %r14d,%r14d
je     158a <link_based_fops+0x39a>
mov    %r14d,%edi
call   1080 <close@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
lea    0x110(%rsp),%rdi
call   1030 <unlink@plt>
jmp    15d1 <link_based_fops+0x3e1>
mov    0x2a36(%rip),%rax
mov    (%rax),%ebx
mov    0x2a25(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xa3f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
mov    0x29f3(%rip),%rax
mov    (%rax),%ebp
mov    0x29e2(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xac8(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
or     %ebx,%r15d
test   %r14d,%r14d
jne    1582 <link_based_fops+0x392>
jmp    158a <link_based_fops+0x39a>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"creat failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [7 x i8] c"_hlink\00"
@.str.2 = [17 x i8] c"link failed: %s\0A\00"
@.str.3 = [19 x i8] c"unlink failed: %s\0A\00"
@.str.4 = [7 x i8] c"_slink\00"
@.str.5 = [20 x i8] c"symlink failed: %s\0A\00"
@.str.6 = [19 x i8] c"lstbuf failed: %s\0A\00"
@.str.7 = [19 x i8] c"lchown failed: %s\0A\00"
@.str.8 = [20 x i8] c"trusted.lxattr-test\00"
@.str.9 = [8 x i8] c"working\00"
@.str.10 = [22 x i8] c"lsetxattr failed: %s\0A\00"
@.str.11 = [23 x i8] c"llistxattr failed: %s\0A\00"
@.str.12 = [22 x i8] c"lgetxattr failed: %s\0A\00"
@.str.13 = [25 x i8] c"lremovexattr failed: %s\0A\00"
define i32 @link_based_fops(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [255 x i8]
%8 = alloca [255 x i8]
%9 = alloca %struct.stat
store i8* %0, i8** %3
store i32 -1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%10 = bitcast [255 x i8]* %7 to i8*
%11 = bitcast [255 x i8]* %8 to i8*
%12 = bitcast %struct.stat* %9 to i8*
%13 = load i8*, i8** %3
%14 = call i32 @creat(i8* %13, i32 420)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %1
store i32 0, i32* %6
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %164
23: ; preds = %1
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%29 = load i8*, i8** %3
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%31 = call i32 @link(i8* %29, i8* %30)
store i32 %31, i32* %4
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %23
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = or i32 %40, %39
store i32 %41, i32* %5
br label %42
42: ; preds = %34, %23
%43 = load i8*, i8** %3
%44 = call i32 @unlink(i8* %43)
store i32 %44, i32* %4
%45 = load i32, i32* %4
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = load i32, i32* %4
%53 = load i32, i32* %5
%54 = or i32 %53, %52
store i32 %54, i32* %5
br label %55
55: ; preds = %47, %42
%56 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%57 = load i8*, i8** %3
%58 = call i32 @strcpy(i8* %56, i8* %57)
%59 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%60 = call i32 @strcat(i8* %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%61 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%62 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%63 = call i32 @symlink(i8* %61, i8* %62)
store i32 %63, i32* %4
%64 = load i32, i32* %4
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %55
%67 = load i32, i32* @stderr
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = load i32, i32* %4
%72 = load i32, i32* %5
%73 = or i32 %72, %71
store i32 %73, i32* %5
br label %74
74: ; preds = %66, %55
%75 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%76 = call i32 @lstat(i8* %75, %struct.stat* %9)
store i32 %76, i32* %4
%77 = load i32, i32* %4
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %87
79: ; preds = %74
%80 = load i32, i32* @stderr
%81 = load i32, i32* @errno
%82 = call i8* @strerror(i32 %81)
%83 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %82)
%84 = load i32, i32* %4
%85 = load i32, i32* %5
%86 = or i32 %85, %84
store i32 %86, i32* %5
br label %87
87: ; preds = %79, %74
%88 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%89 = call i32 @lchown(i8* %88, i32 10001, i32 10001)
store i32 %89, i32* %4
%90 = load i32, i32* %4
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %100
92: ; preds = %87
%93 = load i32, i32* @stderr
%94 = load i32, i32* @errno
%95 = call i8* @strerror(i32 %94)
%96 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %95)
%97 = load i32, i32* %4
%98 = load i32, i32* %5
%99 = or i32 %98, %97
store i32 %99, i32* %5
br label %100
100: ; preds = %92, %87
%101 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%102 = call i32 @lsetxattr(i8* %101, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i32 8, i32 0)
store i32 %102, i32* %4
%103 = load i32, i32* %4
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %113
105: ; preds = %100
%106 = load i32, i32* @stderr
%107 = load i32, i32* @errno
%108 = call i8* @strerror(i32 %107)
%109 = call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %108)
%110 = load i32, i32* %4
%111 = load i32, i32* %5
%112 = or i32 %111, %110
store i32 %112, i32* %5
br label %113
113: ; preds = %105, %100
%114 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%115 = call i32 @llistxattr(i8* %114, i32* null, i32 0)
store i32 %115, i32* %4
%116 = load i32, i32* %4
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %126
118: ; preds = %113
store i32 -1, i32* %4
%119 = load i32, i32* @stderr
%120 = load i32, i32* @errno
%121 = call i8* @strerror(i32 %120)
%122 = call i32 @fprintf(i32 %119, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i8* %121)
%123 = load i32, i32* %4
%124 = load i32, i32* %5
%125 = or i32 %124, %123
store i32 %125, i32* %5
br label %126
126: ; preds = %118, %113
%127 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%128 = call i32 @lgetxattr(i8* %127, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32* null, i32 0)
store i32 %128, i32* %4
%129 = load i32, i32* %4
%130 = icmp slt i32 %129, 0
br i1 %130, label %131, label %139
131: ; preds = %126
store i32 -1, i32* %4
%132 = load i32, i32* @stderr
%133 = load i32, i32* @errno
%134 = call i8* @strerror(i32 %133)
%135 = call i32 @fprintf(i32 %132, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %134)
%136 = load i32, i32* %4
%137 = load i32, i32* %5
%138 = or i32 %137, %136
store i32 %138, i32* %5
br label %139
139: ; preds = %131, %126
%140 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%141 = call i32 @lremovexattr(i8* %140, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
store i32 %141, i32* %4
%142 = load i32, i32* %4
%143 = icmp slt i32 %142, 0
br i1 %143, label %144, label %152
144: ; preds = %139
%145 = load i32, i32* @stderr
%146 = load i32, i32* @errno
%147 = call i8* @strerror(i32 %146)
%148 = call i32 @fprintf(i32 %145, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i8* %147)
%149 = load i32, i32* %4
%150 = load i32, i32* %5
%151 = or i32 %150, %149
store i32 %151, i32* %5
br label %152
152: ; preds = %144, %139
%153 = load i32, i32* %6
%154 = icmp ne i32 %153, 0
br i1 %154, label %155, label %158
155: ; preds = %152
%156 = load i32, i32* %6
%157 = call i32 @close(i32 %156)
br label %158
158: ; preds = %155, %152
%159 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%160 = call i32 @unlink(i8* %159)
%161 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%162 = call i32 @unlink(i8* %161)
%163 = load i32, i32* %5
store i32 %163, i32* %2
br label %164
164: ; preds = %158, %17
%165 = load i32, i32* %2
ret i32 %165
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"creat failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [7 x i8] c"_hlink\00"
@.str.2 = [17 x i8] c"link failed: %s\0A\00"
@.str.3 = [19 x i8] c"unlink failed: %s\0A\00"
@.str.4 = [7 x i8] c"_slink\00"
@.str.5 = [20 x i8] c"symlink failed: %s\0A\00"
@.str.6 = [19 x i8] c"lstbuf failed: %s\0A\00"
@.str.7 = [19 x i8] c"lchown failed: %s\0A\00"
@.str.8 = [20 x i8] c"trusted.lxattr-test\00"
@.str.9 = [8 x i8] c"working\00"
@.str.10 = [22 x i8] c"lsetxattr failed: %s\0A\00"
@.str.11 = [23 x i8] c"llistxattr failed: %s\0A\00"
@.str.12 = [22 x i8] c"lgetxattr failed: %s\0A\00"
@.str.13 = [25 x i8] c"lremovexattr failed: %s\0A\00"
define i32 @link_based_fops(i8* %0) {
%2 = alloca [255 x i8]
%3 = alloca [255 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.stat* %4 to i8*
%8 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
store i32 0, i32* %8
%9 = tail call i32 @creat(i8* %0, i32 420)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %114
16: ; preds = %1
%17 = call i32 @strcpy(i8* %5, i8* %0)
%18 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @link(i8* %0, i8* %5)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %21, %16
%27 = phi i32 [ %19, %21 ], [ 0, %16 ]
%28 = call i32 @unlink(i8* %0)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = or i32 %28, %27
br label %36
36: ; preds = %30, %26
%37 = phi i32 [ %35, %30 ], [ %27, %26 ]
%38 = call i32 @strcpy(i8* %6, i8* %0)
%39 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @symlink(i8* %5, i8* %6)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = or i32 %40, %37
br label %48
48: ; preds = %42, %36
%49 = phi i32 [ %47, %42 ], [ %37, %36 ]
%50 = call i32 @lstat(i8* %6, %struct.stat* %4)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %55)
%57 = or i32 %50, %49
br label %58
58: ; preds = %52, %48
%59 = phi i32 [ %57, %52 ], [ %49, %48 ]
%60 = call i32 @lchown(i8* %6, i32 10001, i32 10001)
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %65)
%67 = or i32 %60, %59
br label %68
68: ; preds = %62, %58
%69 = phi i32 [ %67, %62 ], [ %59, %58 ]
%70 = call i32 @lsetxattr(i8* %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i32 8, i32 0)
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %68
%73 = load i32, i32* @stderr
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %75)
%77 = or i32 %70, %69
br label %78
78: ; preds = %72, %68
%79 = phi i32 [ %77, %72 ], [ %69, %68 ]
%80 = call i32 @llistxattr(i8* %6, i32* null, i32 0)
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %87
82: ; preds = %78
%83 = load i32, i32* @stderr
%84 = load i32, i32* @errno
%85 = call i8* @strerror(i32 %84)
%86 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %82, %78
%88 = phi i32 [ -1, %82 ], [ %79, %78 ]
%89 = call i32 @lgetxattr(i8* %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32* null, i32 0)
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %87
%92 = load i32, i32* @stderr
%93 = load i32, i32* @errno
%94 = call i8* @strerror(i32 %93)
%95 = call i32 @fprintf(i32 %92, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %94)
br label %96
96: ; preds = %91, %87
%97 = phi i32 [ -1, %91 ], [ %88, %87 ]
%98 = call i32 @lremovexattr(i8* %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %106
100: ; preds = %96
%101 = load i32, i32* @stderr
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = call i32 @fprintf(i32 %101, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i8* %103)
%105 = or i32 %98, %97
br label %106
106: ; preds = %100, %96
%107 = phi i32 [ %105, %100 ], [ %97, %96 ]
%108 = icmp eq i32 %9, 0
br i1 %108, label %111, label %109
109: ; preds = %106
%110 = call i32 @close(i32 %9)
br label %111
111: ; preds = %109, %106
%112 = call i32 @unlink(i8* %6)
%113 = call i32 @unlink(i8* %5)
br label %114
114: ; preds = %111, %11
%115 = phi i32 [ -1, %11 ], [ %107, %111 ]
ret i32 %115
}