#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 O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
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);
  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);
  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    11bf <main+0x4f>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <main+0x1b0>
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    0x2dcf(%rip),%rax
mov    (%rax),%esi
mov    0x2e0e(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    121b <main+0xab>
lea    0xe0d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <main+0x1b0>
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     125a <main+0xea>
lea    0xddd(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <main+0x1b0>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    129e <main+0x12e>
lea    0xd9f(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <main+0x1b0>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    12ce <main+0x15e>
lea    0xd74(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <main+0x1b0>
mov    -0x24(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x5,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    1314 <main+0x1a4>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1320 <main+0x1b0>
mov    0x2ca5(%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     1197 <main+0x27>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe75(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1234 <main+0xc4>
mov    0x8(%rsi),%rbx
movl   $0x7,(%rsp)
movb   $0x0,0x4(%rsp)
mov    0x2e02(%rip),%rax
mov    0x2e43(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     124d <main+0xdd>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x5,%edx
call   1040 <write@plt>
cmp    $0x5,%eax
jne    125b <main+0xeb>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1269 <main+0xf9>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     1277 <main+0x107>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x5,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1244 <main+0xd4>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d75(%rip),%rax
jmp    123b <main+0xcb>
lea    0xdbe(%rip),%rdi
call   1090 <perror@plt>
jmp    1234 <main+0xc4>
lea    0xdbf(%rip),%rdi
call   1090 <perror@plt>
jmp    1234 <main+0xc4>
lea    0xdb7(%rip),%rdi
call   1090 <perror@plt>
jmp    1234 <main+0xc4>
lea    0xdae(%rip),%rdi
call   1090 <perror@plt>
jmp    1234 <main+0xc4>

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"
@O_RDONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [7 x i8] c"unlink\00"
@.str.5 = [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 %76
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 @open(i8* %26, i32 %29)
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 %76
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 %76
46: ; preds = %36
%47 = load i32, i32* %8
%48 = call i32 @close(i32 %47)
%49 = load i8*, i8** %6
%50 = load i32, i32* @O_RDONLY
%51 = call i32 @open(i8* %49, i32 %50)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %46
%55 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
store i32 %56, i32* %3
br label %76
57: ; preds = %46
%58 = load i8*, i8** %6
%59 = call i64 @unlink(i8* %58)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
store i32 %63, i32* %3
br label %76
64: ; preds = %57
%65 = load i32, i32* %8
%66 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%67 = call i32 @read(i32 %65, i8* %66, i32 5)
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %64
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
store i32 %73, i32* %3
br label %76
74: ; preds = %64
%75 = load i32, i32* @EXIT_SUCCESS
store i32 %75, i32* %3
br label %76
76: ; preds = %74, %70, %61, %54, %43, %33, %12
%77 = load i32, i32* %3
ret i32 %77
}

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"
@O_RDONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [7 x i8] c"unlink\00"
@.str.5 = [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 %45
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 @open(i8* %12, i32 %17)
%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 %45
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 %45
27: ; preds = %22
%28 = tail call i32 @close(i32 %18)
%29 = load i32, i32* @O_RDONLY
%30 = tail call i32 @open(i8* %12, i32 %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %45
34: ; preds = %27
%35 = tail call i64 @unlink(i8* %12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %45
39: ; preds = %34
%40 = call i32 @read(i32 %30, i8* %4, i32 5)
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %39, %42, %37, %32, %25, %20, %6
%46 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %20 ], [ @EXIT_FAILURE, %25 ], [ @EXIT_FAILURE, %32 ], [ @EXIT_FAILURE, %37 ], [ @EXIT_FAILURE, %42 ], [ @EXIT_SUCCESS, %39 ]
%47 = load i32, i32* %46
ret i32 %47
}