#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*/ O_RDONLY;
int /*<<< orphan*/ R_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
scalar_t__ open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, const char *argv[]) {
  if (argc != 2) {
    printf("argument too short!\n");
    exit(-1);
  }
  if (access(argv[1], R_OK) < 0) {
    printf("access error for %s\n", argv[1]);
    exit(-1);
  } else
    printf("read access OK\n");
  if (open(argv[1], O_RDONLY) < 0) {
    printf("open error for %s\n", argv[1]);
    exit(-1);
  } else
    printf("open for reading OK\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1178 <main+0x38>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
jge    11b8 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
cmp    $0x0,%rax
jge    1206 <main+0xc6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11a3 <main+0x53>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
js     11b9 <main+0x69>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %rax,%rax
js     11c6 <main+0x76>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    0x8(%rbx),%rsi
lea    0xe3c(%rip),%rdi
jmp    11d1 <main+0x81>
mov    0x8(%rbx),%rsi
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"argument too short!\0A\00"
@R_OK = global i32 0
@.str.1 = [21 x i8] c"access error for %s\0A\00"
@.str.2 = [16 x i8] c"read access OK\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [19 x i8] c"open error for %s\0A\00"
@.str.4 = [21 x i8] c"open for reading OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @R_OK
%16 = call i64 @access(i8* %14, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %11
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %11
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i32, i32* @O_RDONLY
%31 = call i64 @open(i8* %29, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %26
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %26
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39
ret i32 0
}

LLVM IR (-O2):
@R_OK = global i32 0
@.str.1 = [21 x i8] c"access error for %s\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [19 x i8] c"open error for %s\0A\00"
@str = [15 x i8] c"read access OK\00"
@str.5 = [20 x i8] c"open for reading OK\00"
@str.6 = [20 x i8] c"argument too short!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @R_OK
%11 = tail call i64 @access(i8* %9, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = load i8*, i8** %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %7
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%19 = load i8*, i8** %8
%20 = load i32, i32* @O_RDONLY
%21 = tail call i64 @open(i8* %19, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i8*, i8** %8
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = tail call i32 @exit(i32 -1)
unreachable
27: ; preds = %17
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}