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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  const char *path;
  char buf[4];
  int fd, rc;
  if (argc < 2) {
    fprintf(stderr, "usage: %s <path>\n", argv[0]);
    return EXIT_FAILURE;
  }
  path = argv[1];
  fd = open(path, O_RDWR | O_CREAT, 0600);
  if (fd < 0) {
    perror("open(O_WRONLY)");
    return EXIT_FAILURE;
  }
  rc = read(fd, buf, sizeof(buf));
  if (rc != 0) {
    fprintf(stderr, "Reading a new var should return EOF\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    118f <main+0x4f>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1237 <main+0xf7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11e5 <main+0xa5>
lea    0xe43(%rip),%rdi
call   1060 <perror@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1237 <main+0xf7>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     122b <main+0xeb>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1237 <main+0xf7>
mov    0x2d8e(%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   %rax
cmp    $0x1,%edi
jg     1162 <main+0x22>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xea7(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11b2 <main+0x72>
mov    0x8(%rsi),%rdi
mov    0x2e73(%rip),%rax
mov    0x2e84(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11c6 <main+0x86>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <read@plt>
test   %eax,%eax
je     11bd <main+0x7d>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
mov    0x2dfc(%rip),%rax
jmp    11b9 <main+0x79>
lea    0xe45(%rip),%rdi
call   1060 <perror@plt>
jmp    11b2 <main+0x72>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s <path>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [15 x i8] c"open(O_WRONLY)\00"
@.str.2 = [37 x i8] c"Reading a new var should return EOF\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 [4 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 %45
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 = load i8*, i8** %6
%24 = load i32, i32* @O_RDWR
%25 = load i32, i32* @O_CREAT
%26 = or i32 %24, %25
%27 = call i32 @open(i8* %23, i32 %26, i32 384)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %19
%31 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
store i32 %32, i32* %3
br label %45
33: ; preds = %19
%34 = load i32, i32* %8
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 4)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
store i32 %42, i32* %3
br label %45
43: ; preds = %33
%44 = load i32, i32* @EXIT_SUCCESS
store i32 %44, i32* %3
br label %45
45: ; preds = %43, %39, %30, %12
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s <path>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [15 x i8] c"open(O_WRONLY)\00"
@.str.2 = [37 x i8] c"Reading a new var should return EOF\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 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 %26
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_CREAT
%15 = or i32 %14, %13
%16 = tail call i32 @open(i8* %12, i32 %15, i32 384)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %26
20: ; preds = %10
%21 = call i32 @read(i32 %16, i8* %4, i32 4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %20, %23, %18, %6
%27 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %18 ], [ @EXIT_FAILURE, %23 ], [ @EXIT_SUCCESS, %20 ]
%28 = load i32, i32* %27
ret i32 %28
}