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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int O_EXCL;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ handle_fatal_error_and_exit(char *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char *filename;
  mode_t mode;
  if (argc != 2) {
    printf("Usage: %s <filename>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  filename = argv[1];
  mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
  int fd = open(filename, O_WRONLY | O_EXCL | O_CREAT, mode);
  if (fd == -1) {
    handle_fatal_error_and_exit("Error opening a file.\n");
  }
  close(fd);
  exit(EXIT_SUCCESS);
}


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     1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    0x2e2b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e0a(%rip),%rcx
or     (%rcx),%eax
mov    0x2e21(%rip),%rcx
or     (%rcx),%eax
mov    0x2df0(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
mov    0x2de7(%rip),%rax
or     (%rax),%esi
mov    0x2e0e(%rip),%rax
or     (%rax),%esi
mov    -0x1c(%rbp),%edx
call   1060 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    120d <main+0xbd>
lea    0xe0e(%rip),%rdi
call   1050 <handle_fatal_error_and_exit@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11d1 <main+0x81>
mov    0x2e4b(%rip),%rax
mov    0x2e74(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e51(%rip),%rax
or     (%rax),%edx
mov    0x2e68(%rip),%rax
or     (%rax),%edx
mov    0x2e37(%rip),%rax
or     (%rax),%edx
mov    0x2e06(%rip),%rcx
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x8(%rsi),%rdi
mov    0x2e58(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   1060 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11bc <main+0x6c>
lea    0xe5f(%rip),%rdi
call   1050 <handle_fatal_error_and_exit@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    (%rsi),%rsi
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Usage: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@O_WRONLY = global i32 0
@O_EXCL = global i32 0
@O_CREAT = global i32 0
@.str.1 = [23 x i8] c"Error opening a file.\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 i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%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_IWGRP
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IROTH
%30 = or i32 %28, %29
store i32 %30, i32* %7
%31 = load i8*, i8** %6
%32 = load i32, i32* @O_WRONLY
%33 = load i32, i32* @O_EXCL
%34 = or i32 %32, %33
%35 = load i32, i32* @O_CREAT
%36 = or i32 %34, %35
%37 = load i32, i32* %7
%38 = call i32 @open(i8* %31, i32 %36, i32 %37)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %18
%42 = call i32 @handle_fatal_error_and_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %18
%44 = load i32, i32* %8
%45 = call i32 @close(i32 %44)
%46 = load i32, i32* @EXIT_SUCCESS
%47 = call i32 @exit(i32 %46)
unreachable
}

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