#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_CREAT;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <path_to_test>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  fd = open(argv[1], O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if (fd >= 0) {
    close(fd);
    exit(EXIT_SUCCESS);
  }
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118a <main+0x4a>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
mov    0x2e35(%rip),%rax
or     (%rax),%edx
mov    0x2e14(%rip),%rax
or     (%rax),%edx
mov    0x2e03(%rip),%rax
or     (%rax),%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11e7 <main+0xa7>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jne    1195 <main+0x55>
mov    0x8(%rsi),%rdi
mov    0x2e5f(%rip),%rax
mov    0x2e88(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e95(%rip),%rax
mov    0x2e5e(%rip),%rcx
or     (%rcx),%edx
mov    (%rax),%esi
mov    0x2e4b(%rip),%rax
or     (%rax),%edx
call   1050 <open@plt>
test   %eax,%eax
js     11ad <main+0x6d>
mov    %eax,%edi
call   1030 <close@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe58(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s <path_to_test>\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_CREAT
%22 = load i32, i32* @S_IRUSR
%23 = load i32, i32* @S_IWUSR
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IRGRP
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IROTH
%28 = or i32 %26, %27
%29 = call i32 @open(i8* %20, i32 %21, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %17
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* @EXIT_SUCCESS
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %17
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s <path_to_test>\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @S_IRUSR
%15 = load i32, i32* @S_IWUSR
%16 = or i32 %15, %14
%17 = load i32, i32* @S_IRGRP
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = tail call i32 @open(i8* %12, i32 %13, i32 %20)
%22 = icmp sgt i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %10
%24 = tail call i32 @close(i32 %21)
%25 = load i32, i32* @EXIT_SUCCESS
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %10
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
}