#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_IRUSR;
int S_IXUSR;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int);
int main(int args, char *argv[]) {
  int errn;
  int status = open(argv[1], O_CREAT, S_IRUSR | S_IXUSR | S_IRGRP);
  if (status == -1) {
    errn = errno;
    printf("open: %s\n", strerror(errn));
    exit(EXIT_FAILURE);
  }
  printf("File %s created with 540 permisions\n", argv[1]);
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    0x2e69(%rip),%rax
or     (%rax),%edx
mov    0x2e48(%rip),%rax
or     (%rax),%edx
call   1040 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c5 <main+0x85>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2ea9(%rip),%rax
mov    0x2e62(%rip),%rcx
mov    0x2e83(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    (%rax),%esi
mov    0x2e5e(%rip),%rax
or     (%rax),%edx
call   1040 <open@plt>
cmp    $0xffffffff,%eax
jne    11a1 <main+0x61>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe75(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x8(%rbx),%rsi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@errno = global i32 0
@.str = [10 x i8] c"open: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [37 x i8] c"File %s created with 540 permisions\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 i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IXUSR
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRGRP
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %10, i32 %11, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %27
20: ; preds = %2
%21 = load i32, i32* @errno
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_SUCCESS
%33 = call i32 @exit(i32 %32)
unreachable
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@errno = global i32 0
@.str = [10 x i8] c"open: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [37 x i8] c"File %s created with 540 permisions\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IXUSR
%8 = or i32 %7, %6
%9 = load i32, i32* @S_IRGRP
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* %4, i32 %5, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8*, i8** %3
%21 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_SUCCESS
%23 = tail call i32 @exit(i32 %22)
unreachable
}