#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 EXIT_SUCCESS;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int S_IRGRP;
int S_IROTH;
int S_IRWXU;
int S_IXGRP;
int S_IXOTH;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int input_fd, file_flags;
  mode_t file_perms;
  file_flags = O_RDWR | O_CREAT | O_TRUNC;
  file_perms = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((input_fd = open(argv[1], file_flags, file_perms)) < 0) {
    fprintf(stderr, "Err. opening %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  close(input_fd);
  return (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    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    0x2e92(%rip),%rcx
or     (%rcx),%eax
mov    0x2e81(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    0x2e24(%rip),%rcx
or     (%rcx),%eax
mov    0x2e33(%rip),%rcx
or     (%rcx),%eax
mov    0x2e0a(%rip),%rcx
or     (%rcx),%eax
mov    0x2e29(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d8 <main+0x98>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3b(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1222 <main+0xe2>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe07(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11b0 <main+0x70>
mov    0x2e88(%rip),%rax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e5e(%rip),%rax
or     (%rax),%edx
mov    0x2e35(%rip),%rax
or     (%rax),%edx
mov    0x2e54(%rip),%rax
or     (%rax),%edx
mov    0x2e53(%rip),%rax
mov    0x2e74(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e61(%rip),%rax
or     (%rax),%esi
mov    0x8(%rbx),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11c5 <main+0x85>
mov    %eax,%edi
call   1030 <close@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe3d(%rip),%rsi
jmp    11d9 <main+0x99>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe3d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <pathname>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"Err. opening %s\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
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
store i32 %13, i32* %7
%14 = load i32, i32* @S_IRWXU
%15 = load i32, i32* @S_IRGRP
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IXGRP
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IXOTH
%22 = or i32 %20, %21
store i32 %22, i32* %8
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 2
br i1 %24, label %25, label %33
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = call i32 @open(i8* %36, i32 %37, i32 %38)
store i32 %39, i32* %6
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %33
%42 = load i32, i32* @stderr
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %33
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
%52 = load i32, i32* @EXIT_SUCCESS
ret i32 %52
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <pathname>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"Err. opening %s\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 %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 ([22 x i8], [22 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 = load i32, i32* @S_IRWXU
%12 = load i32, i32* @S_IRGRP
%13 = or i32 %12, %11
%14 = load i32, i32* @S_IXGRP
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IXOTH
%19 = or i32 %17, %18
%20 = load i32, i32* @O_RDWR
%21 = load i32, i32* @O_CREAT
%22 = or i32 %21, %20
%23 = load i32, i32* @O_TRUNC
%24 = or i32 %22, %23
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32 @open(i8* %26, i32 %24, i32 %19)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %10
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %25
%32 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %10
%36 = tail call i32 @close(i32 %27)
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}