#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 uint32_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int get_immutable(char const *);
int open(char const *, int, ...);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int set_immutable(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ unlink(char const *);
int write(int, char *, int);
int main(int argc, char **argv) {
  const char *path;
  char buf[5];
  int fd, rc;
  if (argc < 2) {
    fprintf(stderr, "usage: %s <path>\n", argv[0]);
    return EXIT_FAILURE;
  }
  path = argv[1];
  *(uint32_t *)buf = 0x7;
  buf[4] = 0;
  fd = open(path, O_WRONLY | O_CREAT, 0600);
  if (fd < 0) {
    perror("open(O_WRONLY)");
    return EXIT_FAILURE;
  }
  rc = write(fd, buf, sizeof(buf));
  if (rc != sizeof(buf)) {
    perror("write");
    return EXIT_FAILURE;
  }
  close(fd);
  rc = get_immutable(path);
  if (rc < 0) {
    perror("ioctl(FS_IOC_GETFLAGS)");
    return EXIT_FAILURE;
  } else if (rc) {
    rc = set_immutable(path, 0);
    if (rc < 0) {
      perror("ioctl(FS_IOC_SETFLAGS)");
      return EXIT_FAILURE;
    }
  }
  fd = open(path, O_RDONLY);
  if (fd < 0) {
    perror("open");
    return EXIT_FAILURE;
  }
  if (unlink(path) < 0) {
    perror("unlink");
    return EXIT_FAILURE;
  }
  rc = read(fd, buf, sizeof(buf));
  if (rc > 0) {
    fprintf(stderr, "reading from an unlinked variable "
                    "shouldn't be possible\n");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11df <main+0x4f>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c5 <main+0x235>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x7,-0x1d(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    0x2dee(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1242 <main+0xb2>
lea    0xde6(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c5 <main+0x235>
mov    -0x24(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
mov    %eax,-0x28(%rbp)
movslq -0x28(%rbp),%rax
cmp    $0x5,%rax
je     1281 <main+0xf1>
lea    0xdb6(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c5 <main+0x235>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rdi
call   1080 <get_immutable@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    12bc <main+0x12c>
lea    0xd81(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c5 <main+0x235>
cmpl   $0x0,-0x28(%rbp)
je     1300 <main+0x170>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   10b0 <set_immutable@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    12fb <main+0x16b>
lea    0xd59(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c5 <main+0x235>
jmp    1300 <main+0x170>
jmp    1305 <main+0x175>
mov    -0x18(%rbp),%rdi
mov    0x2cd0(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1343 <main+0x1b3>
lea    0xd28(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c5 <main+0x235>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    1373 <main+0x1e3>
lea    0xcfd(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c5 <main+0x235>
mov    -0x24(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x5,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    13b9 <main+0x229>
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
lea    0xcc0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c5 <main+0x235>
mov    0x2c00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11b7 <main+0x27>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe55(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1285 <main+0xf5>
mov    0x8(%rsi),%rbx
movl   $0x7,(%rsp)
movb   $0x0,0x4(%rsp)
mov    0x2de2(%rip),%rax
mov    0x2e23(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
js     129e <main+0x10e>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x5,%edx
call   1040 <write@plt>
cmp    $0x5,%eax
jne    12ac <main+0x11c>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
call   1080 <get_immutable@plt>
test   %eax,%eax
js     12ba <main+0x12a>
je     1235 <main+0xa5>
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <set_immutable@plt>
test   %eax,%eax
js     12e4 <main+0x154>
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
js     12c8 <main+0x138>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     12d6 <main+0x146>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x5,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1295 <main+0x105>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d24(%rip),%rax
jmp    128c <main+0xfc>
lea    0xd6d(%rip),%rdi
call   10a0 <perror@plt>
jmp    1285 <main+0xf5>
lea    0xd6e(%rip),%rdi
call   10a0 <perror@plt>
jmp    1285 <main+0xf5>
lea    0xd66(%rip),%rdi
call   10a0 <perror@plt>
jmp    1285 <main+0xf5>
lea    0xd86(%rip),%rdi
call   10a0 <perror@plt>
jmp    1285 <main+0xf5>
lea    0xd7d(%rip),%rdi
call   10a0 <perror@plt>
jmp    1285 <main+0xf5>
lea    0xd53(%rip),%rdi
call   10a0 <perror@plt>
jmp    1285 <main+0xf5>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s <path>\0A\00"
@EXIT_FAILURE = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [15 x i8] c"open(O_WRONLY)\00"
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [23 x i8] c"ioctl(FS_IOC_GETFLAGS)\00"
@.str.4 = [23 x i8] c"ioctl(FS_IOC_SETFLAGS)\00"
@O_RDONLY = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [7 x i8] c"unlink\00"
@.str.7 = [57 x i8] c"reading from an unlinked variable shouldn't be possible\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [5 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %97
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %6
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%24 = bitcast i8* %23 to i32*
store i32 7, i32* %24
%25 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 4
store i8 0, i8* %25
%26 = load i8*, i8** %6
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_CREAT
%29 = or i32 %27, %28
%30 = call i32 (i8*, i32, ...) @open(i8* %26, i32 %29, i32 384)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %19
%34 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %97
36: ; preds = %19
%37 = load i32, i32* %8
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%39 = call i32 @write(i32 %37, i8* %38, i32 5)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = icmp ne i64 %41, 5
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
store i32 %45, i32* %3
br label %97
46: ; preds = %36
%47 = load i32, i32* %8
%48 = call i32 @close(i32 %47)
%49 = load i8*, i8** %6
%50 = call i32 @get_immutable(i8* %49)
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %46
%54 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
store i32 %55, i32* %3
br label %97
56: ; preds = %46
%57 = load i32, i32* %9
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %68
59: ; preds = %56
%60 = load i8*, i8** %6
%61 = call i32 @set_immutable(i8* %60, i32 0)
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %59
%65 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
store i32 %66, i32* %3
br label %97
67: ; preds = %59
br label %68
68: ; preds = %67, %56
br label %69
69: ; preds = %68
%70 = load i8*, i8** %6
%71 = load i32, i32* @O_RDONLY
%72 = call i32 (i8*, i32, ...) @open(i8* %70, i32 %71)
store i32 %72, i32* %8
%73 = load i32, i32* %8
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %69
%76 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%77 = load i32, i32* @EXIT_FAILURE
store i32 %77, i32* %3
br label %97
78: ; preds = %69
%79 = load i8*, i8** %6
%80 = call i64 @unlink(i8* %79)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%84 = load i32, i32* @EXIT_FAILURE
store i32 %84, i32* %3
br label %97
85: ; preds = %78
%86 = load i32, i32* %8
%87 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%88 = call i32 @read(i32 %86, i8* %87, i32 5)
store i32 %88, i32* %9
%89 = load i32, i32* %9
%90 = icmp sgt i32 %89, 0
br i1 %90, label %91, label %95
91: ; preds = %85
%92 = load i32, i32* @stderr
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0))
%94 = load i32, i32* @EXIT_FAILURE
store i32 %94, i32* %3
br label %97
95: ; preds = %85
%96 = load i32, i32* @EXIT_SUCCESS
store i32 %96, i32* %3
br label %97
97: ; preds = %95, %91, %82, %75, %64, %53, %43, %33, %12
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s <path>\0A\00"
@EXIT_FAILURE = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [15 x i8] c"open(O_WRONLY)\00"
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [23 x i8] c"ioctl(FS_IOC_GETFLAGS)\00"
@.str.4 = [23 x i8] c"ioctl(FS_IOC_SETFLAGS)\00"
@O_RDONLY = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [7 x i8] c"unlink\00"
@.str.7 = [57 x i8] c"reading from an unlinked variable shouldn't be possible\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %57
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = bitcast [5 x i8]* %3 to i32*
store i32 7, i32* %13
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 4
store i8 0, i8* %14
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %16, %15
%18 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %17, i32 384)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %57
22: ; preds = %10
%23 = call i32 @write(i32 %18, i8* %4, i32 5)
%24 = icmp eq i32 %23, 5
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %57
27: ; preds = %22
%28 = tail call i32 @close(i32 %18)
%29 = tail call i32 @get_immutable(i8* %12)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %57
33: ; preds = %27
%34 = icmp eq i32 %29, 0
br i1 %34, label %40, label %35
35: ; preds = %33
%36 = tail call i32 @set_immutable(i8* %12, i32 0)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %57
40: ; preds = %33, %35
%41 = load i32, i32* @O_RDONLY
%42 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %41)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %57
46: ; preds = %40
%47 = tail call i64 @unlink(i8* %12)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %57
51: ; preds = %46
%52 = call i32 @read(i32 %42, i8* %4, i32 5)
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0))
br label %57
57: ; preds = %51, %54, %49, %44, %38, %31, %25, %20, %6
%58 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %20 ], [ @EXIT_FAILURE, %25 ], [ @EXIT_FAILURE, %31 ], [ @EXIT_FAILURE, %38 ], [ @EXIT_FAILURE, %44 ], [ @EXIT_FAILURE, %49 ], [ @EXIT_FAILURE, %54 ], [ @EXIT_SUCCESS, %51 ]
%59 = load i32, i32* %58
ret i32 %59
}