#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 ssize_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int close(int);
int flistxattr(int, char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int unlink(char *);
int main(int argc, char *argv[]) {
  char *names;
  char *name;
  ssize_t size;
  int fd;
  int rc;
  fd = open(argv[1], O_RDWR | O_CREAT, 0666);
  if (fd == -1) {
    perror("open");
    return 1;
  }
  rc = unlink(argv[1]);
  if (rc == -1) {
    perror("unlink");
    close(fd);
    return 1;
  }
  size = flistxattr(fd, NULL, 0);
  if (size == -1) {
    perror("flistxattr size");
    close(fd);
    return 1;
  }
  names = malloc(size);
  if (names == NULL) {
    fprintf(stderr, "Cannot allocate names\n");
    close(fd);
    return 1;
  }
  size = flistxattr(fd, names, size);
  if (size == -1) {
    perror("flistxattr");
    free(names);
    close(fd);
    return 1;
  }
  for (name = names; name < names + size; name += strlen(name) + 1)
    if (strcmp(name, "trusted.link") == 0) {
      free(names);
      close(fd);
      return 1;
    }
  free(names);
  rc = close(fd);
  if (rc == -1) {
    perror("close");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    0x2e2a(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10b0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11ff <main+0x5f>
lea    0xe12(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ac <main+0x20c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <unlink@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1239 <main+0x99>
lea    0xde5(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ac <main+0x20c>
mov    -0x28(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <flistxattr@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1274 <main+0xd4>
lea    0xdb1(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ac <main+0x20c>
mov    -0x24(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12b4 <main+0x114>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ac <main+0x20c>
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <flistxattr@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12f9 <main+0x159>
lea    0xd5c(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ac <main+0x20c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x24(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    136f <main+0x1cf>
mov    -0x20(%rbp),%rdi
lea    0xd1a(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1350 <main+0x1b0>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ac <main+0x20c>
jmp    1355 <main+0x1b5>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1301 <main+0x161>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    13a5 <main+0x205>
lea    0xcb7(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ac <main+0x20c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e2a(%rip),%rax
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     129d <main+0xfd>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
call   1040 <unlink@plt>
cmp    $0xffffffff,%eax
je     12ab <main+0x10b>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <flistxattr@plt>
cmp    $0xffffffff,%eax
je     12b4 <main+0x114>
mov    %eax,%ebx
mov    %eax,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1286 <main+0xe6>
mov    %rax,%r15
mov    %r14d,%edi
mov    %rax,%rsi
mov    %ebx,%edx
call   1050 <flistxattr@plt>
cmp    $0xffffffff,%eax
je     12c2 <main+0x122>
test   %eax,%eax
jle    1264 <main+0xc4>
cltq
mov    %r15,%rbp
add    %rax,%rbp
lea    0xe06(%rip),%r12
mov    %r15,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12ce <main+0x12e>
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %rax,%rbx
add    $0x1,%rbx
cmp    %rbp,%rbx
jb     1240 <main+0xa0>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    12e3 <main+0x143>
lea    0xdc7(%rip),%rdi
jmp    12a4 <main+0x104>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
call   1090 <fprintf@plt>
jmp    12d6 <main+0x136>
lea    0xd5c(%rip),%rdi
call   10c0 <perror@plt>
jmp    12de <main+0x13e>
lea    0xd53(%rip),%rdi
jmp    12bb <main+0x11b>
lea    0xd51(%rip),%rdi
call   10c0 <perror@plt>
jmp    12d6 <main+0x136>
lea    0xd6a(%rip),%rdi
call   10c0 <perror@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [7 x i8] c"unlink\00"
@.str.2 = [16 x i8] c"flistxattr size\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"Cannot allocate names\0A\00"
@.str.4 = [11 x i8] c"flistxattr\00"
@.str.5 = [13 x i8] c"trusted.link\00"
@.str.6 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %13, i32 %16, i32 438)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %100
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @unlink(i8* %25)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %22
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* %9
%32 = call i32 @close(i32 %31)
store i32 1, i32* %3
br label %100
33: ; preds = %22
%34 = load i32, i32* %9
%35 = call i32 @flistxattr(i32 %34, i8* null, i32 0)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* %9
%41 = call i32 @close(i32 %40)
store i32 1, i32* %3
br label %100
42: ; preds = %33
%43 = load i32, i32* %8
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %6
%45 = load i8*, i8** %6
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* %9
%51 = call i32 @close(i32 %50)
store i32 1, i32* %3
br label %100
52: ; preds = %42
%53 = load i32, i32* %9
%54 = load i8*, i8** %6
%55 = load i32, i32* %8
%56 = call i32 @flistxattr(i32 %53, i8* %54, i32 %55)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %65
59: ; preds = %52
%60 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%61 = load i8*, i8** %6
%62 = call i32 @free(i8* %61)
%63 = load i32, i32* %9
%64 = call i32 @close(i32 %63)
store i32 1, i32* %3
br label %100
65: ; preds = %52
%66 = load i8*, i8** %6
store i8* %66, i8** %7
br label %67
67: ; preds = %84, %65
%68 = load i8*, i8** %7
%69 = load i8*, i8** %6
%70 = load i32, i32* %8
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = icmp ult i8* %68, %72
br i1 %73, label %74, label %90
74: ; preds = %67
%75 = load i8*, i8** %7
%76 = call i64 @strcmp(i8* %75, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %74
%79 = load i8*, i8** %6
%80 = call i32 @free(i8* %79)
%81 = load i32, i32* %9
%82 = call i32 @close(i32 %81)
store i32 1, i32* %3
br label %100
83: ; preds = %74
br label %84
84: ; preds = %83
%85 = load i8*, i8** %7
%86 = call i64 @strlen(i8* %85)
%87 = add nsw i64 %86, 1
%88 = load i8*, i8** %7
%89 = getelementptr inbounds i8, i8* %88, i64 %87
store i8* %89, i8** %7
br label %67
90: ; preds = %67
%91 = load i8*, i8** %6
%92 = call i32 @free(i8* %91)
%93 = load i32, i32* %9
%94 = call i32 @close(i32 %93)
store i32 %94, i32* %10
%95 = load i32, i32* %10
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %99
97: ; preds = %90
%98 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %100
99: ; preds = %90
store i32 0, i32* %3
br label %100
100: ; preds = %99, %97, %78, %59, %47, %38, %29, %20
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [7 x i8] c"unlink\00"
@.str.2 = [16 x i8] c"flistxattr size\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"Cannot allocate names\0A\00"
@.str.4 = [11 x i8] c"flistxattr\00"
@.str.5 = [13 x i8] c"trusted.link\00"
@.str.6 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %4, i32 %7, i32 438)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %61
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = tail call i32 @unlink(i8* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @close(i32 %8)
br label %61
19: ; preds = %12
%20 = tail call i32 @flistxattr(i32 %8, i8* null, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @close(i32 %8)
br label %61
25: ; preds = %19
%26 = tail call i8* @malloc(i32 %20)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%31 = tail call i32 @close(i32 %8)
br label %61
32: ; preds = %25
%33 = tail call i32 @flistxattr(i32 %8, i8* %26, i32 %20)
%34 = icmp eq i32 %33, -1
br i1 %34, label %39, label %35
35: ; preds = %32
%36 = sext i32 %33 to i64
%37 = getelementptr inbounds i8, i8* %26, i64 %36
%38 = icmp sgt i32 %33, 0
br i1 %38, label %43, label %55
39: ; preds = %32
%40 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%41 = tail call i32 @free(i8* %26)
%42 = tail call i32 @close(i32 %8)
br label %61
43: ; preds = %35, %50
%44 = phi i8* [ %53, %50 ], [ %26, %35 ]
%45 = tail call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = tail call i32 @free(i8* %26)
%49 = tail call i32 @close(i32 %8)
br label %61
50: ; preds = %43
%51 = tail call i64 @strlen(i8* dereferenceable(1) %44)
%52 = add nsw i64 %51, 1
%53 = getelementptr inbounds i8, i8* %44, i64 %52
%54 = icmp ult i8* %53, %37
br i1 %54, label %43, label %55
55: ; preds = %50, %35
%56 = tail call i32 @free(i8* %26)
%57 = tail call i32 @close(i32 %8)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %55, %59, %47, %39, %28, %22, %16, %10
%62 = phi i32 [ 1, %10 ], [ 1, %16 ], [ 1, %22 ], [ 1, %28 ], [ 1, %39 ], [ 1, %47 ], [ 1, %59 ], [ 0, %55 ]
ret i32 %62
}