#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*/ R_OK;
int /*<<< orphan*/ W_OK;
int /*<<< orphan*/ X_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int r;
  int w;
  int x;
  r = access("test.txt", R_OK);
  if (r < 0) {
    printf("Read NG\n");
  } else {
    printf("Read OK\n");
  }
  w = access("test.txt", W_OK);
  if (w < 0) {
    printf("Write NG\n");
  } else {
    printf("Write OK\n");
  }
  x = access("test.txt", X_OK);
  if (x < 0) {
    printf("Exec NG\n");
  } else {
    printf("Exec OK\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
lea    0xec1(%rip),%rdi
call   1040 <access@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1162 <main+0x42>
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
jmp    116e <main+0x4e>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdi
call   1040 <access@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11a1 <main+0x81>
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
jmp    11ad <main+0x8d>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    0xe43(%rip),%rdi
call   1040 <access@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11e0 <main+0xc0>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
jmp    11ec <main+0xcc>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
lea    0xecf(%rip),%rbx
mov    %rbx,%rdi
call   1040 <access@plt>
test   %eax,%eax
lea    0xef1(%rip),%rax
lea    0xec0(%rip),%rdi
cmovs  %rax,%rdi
call   1030 <puts@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %eax,%eax
lea    0xebe(%rip),%rax
lea    0xe9e(%rip),%rdi
cmovs  %rax,%rdi
call   1030 <puts@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %eax,%eax
lea    0xe8c(%rip),%rax
lea    0xe7d(%rip),%rdi
cmovs  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@R_OK = global i32 0
@.str.1 = [9 x i8] c"Read NG\0A\00"
@.str.2 = [9 x i8] c"Read OK\0A\00"
@W_OK = global i32 0
@.str.3 = [10 x i8] c"Write NG\0A\00"
@.str.4 = [10 x i8] c"Write OK\0A\00"
@X_OK = global i32 0
@.str.5 = [9 x i8] c"Exec NG\0A\00"
@.str.6 = [9 x i8] c"Exec OK\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @R_OK
%6 = call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = load i32, i32* @W_OK
%15 = call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %22
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = load i32, i32* @X_OK
%24 = call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %31
29: ; preds = %22
%30 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@str = [8 x i8] c"Read OK\00"
@str.7 = [9 x i8] c"Write OK\00"
@str.8 = [8 x i8] c"Exec OK\00"
@str.9 = [8 x i8] c"Exec NG\00"
@str.10 = [9 x i8] c"Write NG\00"
@str.11 = [8 x i8] c"Read NG\00"
define i32 @main() {
%1 = load i32, i32* @R_OK
%2 = tail call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
%4 = select i1 %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.11, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0)
%5 = tail call i32 @puts(i8* dereferenceable(1) %4)
%6 = load i32, i32* @W_OK
%7 = tail call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
%9 = select i1 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.10, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0)
%10 = tail call i32 @puts(i8* dereferenceable(1) %9)
%11 = load i32, i32* @X_OK
%12 = tail call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.9, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.8, i64 0, i64 0)
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
ret i32 0
}